Sometimes I have to spend a lot of function calls, even for external libraries I donβt have any control, or I donβt want to change.
Once I realized that you can combine breakpoints of the gdb regular expression (the usual ones are also approved), and then just execute a set of commands that will be run every time these breakpoints are triggered. See: http://www.ofb.net/gnu/gdb/gdb_35.html
For example, if you want to track all the functions starting with the prefix "MPI_", you can do:
(gdb) rbreak MPI_ [...] (gdb) command 1-XX (gdb) silent (gdb) bt 1 (gdb) echo \n\n (gdb) continue (gdb) end
The Silent command is used to hide gdb messages when a breakpoint is detected. I usually print a couple of blank lines to make them easier to read.
Then you run the program: (gdb)
Once your program starts, gdb will display the N top levels of the backtrace.
If you need more detailed information, you can also print the local variables of a given breakpoint, just insert more commands between command and end .
Bonus tip: add all this to your .gdbinit file and complete the execution in the file.
Jorge BellΓ³n Aug 24 '16 at 13:11 2016-08-24 13:11
source share