Is it possible to control gdb from the debugged program? I’m hoping for a library that can help with this, ideally with an API such as gdb_sendcmd("bt"), but I can live with something like connecting to local gdb via a socket.
Primary use case is programmatically adding a data breakpoint to monitor when a certain memory address next gets modified. Target language is, naturally, C; anything applicable to it can be reused with C++ and Objective-C.
Answer from Employed Russian has solved my direct problem, but I’d still love to know how I can run GDB commands programmatically from the debugged program. It may speed up some debugging if I could simply add code to the project instead of writing extra startup commands for GDB that would create breakpoints with attached commands.
So if there is a way to run commands programmatically, I’d still love to hear it 😉
The Python interface exported by GDB allows you to do many things. Maybe something like this would fit your requirements:
(just write than in a file, and source it from your
.gdbinitfile)and on the application side:
I think the code is straight forward, but as I mentioned in https://stackoverflow.com/a/8884512/341106, not everything is allowed in the
stopcallback, GDB is in an intermediate state, but many things will work as expected.EDIT: needless to say, this won’t work if you app is not compiled with debug symbols!