Background
I am modifying the source code of vim and I need to use a debugger.
Problem
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.
What I Tried
- Make sure vim is built with debug symbols (
make CMAKE_BUILD_TYPE=Debug) - Try with normal cgdb (
VIMRUNTIME=runtime cgdb --args ./build/bin/nvim my-file) - Try attaching to the process separately (
sudo cgdb -p 62556) - Try with some flags (
VIMRUNTIME=runtime gdb ./build/bin/nvim -q --tui)
Question
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?
sudo?sudo, it says "Could not attach process. If your uid matches the uid of the target process, check the setting of /proc/sys/kernel/yama/ptrace_scope, or try again as the root user." When I attach withsudo, it just doesn't do the breakpoints. For instance, I usedbreak do_searchand thencin gdb, then went to the vim process and did a search. gdb did not break at all, even though I can confirm that thedo_searchfunction is running based on some other behavior that executed properly in vim.i bshows it with an address and shows anEnbvalue ofy, which I assume means that it's enabled.attachis that you are attaching to the wrong process. If you usepsor some such you should be able to identify the two vim processes, then you can attach to the correct one. You could even useadd-inferiorwithin GDB to create two inferiors, and attach to both vim processes -- breakpoints apply to all inferiors, so whichever process hits a function the breakpoint will trigger.