Search code examples
linuxdebuggingmemorygdbvimspector

vimspector, read memory at address


I trying to debug (for study purposes) simple program written with c language. I use vimspector(gdb) as debugger.
How can I read memory at certain address with vimspector?
I found vimspector can do this (someone's screenshot as a proof): https://camo.githubusercontent.com/da69c1bda28db4e3f22f35ac9d52b22b1eab80afcfabd2003b98aefeb7e54929/68747470733a2f2f61736369696e656d612e6f72672f612f6573456e634178503435434a6d6f38456d31735174785259652e737667

Section "dump memory" of vimspector's readme says:

Some debug adapters provide a way to dump process memory associated with variables. This can be done from the Variables and Watches windows with:

  • The WinBar option "Dump"
  • <leader>m mapping (by default, can be customised)
  • vimspector#ReadMemory() function

I tried to call function vimspector#ReadMemory and got errors everytime

:call vimspector#ReadMemory()
Cannot find memory reference for that

:call vimspector#ReadMemory(myvar)
E116: Invalid arguments for function vimspector#ReadMemory

:call vimspector#ReadMemory(0x7ffff7e959d7)
TypeError: vimspector.debug_session.DebugSession.ReadMemory() argument after ** must be a mapping, not str

When I trying <leader>m nothing happened.


Solution

  • I also find this issue and search by google, found your question, but seems no one answers it, by serval minutes of trying, I found the root cause, you need to trigger this function inside variable or watch windows, by default, they were layout at left side. then you can press <leader>m on a variable or address, magic will happen.

    please mentions that, after trigger <leader>m, you need to wait about 2 seconds, then vimspector will ask you to input some parameters to dump the memory.

    hopes this will help you