I am modifying the source code of vim and I need to use a debugger.
Since vim is a terminal program, it takes over the terminal when it starts. So as soon as I start
inside gdb, I'm just inside vim and I can't use gdb commands. When I quit vim, then I can get back to gdb but, well... then the target program ends so I can't debug it.
If I enter gdb, set breakpoints, then run vim and interact with it, my breakpoints don't actually break.
make CMAKE_BUILD_TYPE=Debug
)VIMRUNTIME=runtime cgdb --args ./build/bin/nvim my-file
)sudo cgdb -p 62556
)VIMRUNTIME=runtime gdb ./build/bin/nvim -q --tui
)How can I run gdb (or cgdb) in such a way where I can interact with gdb and also interact with the terminal program that I am debugging?
The approach with cgdb -p <pid>
was close, and the right idea. However, some programs (and Neovim in particular) will spawn an additional process. Sometimes that is the process to which you have to connect in order for breakpoints to work.
To properly view the list of processes, use ps aux
. In this case, it shows one process for nvim
and a separate process for nvim --embed
. In order to debug the process, I had to connect to the --embed
one.
Neovim provides some details about how to debug the program. This is also a viable method in this case, though not generically applicable.