Get GDB to print stack trace on returning to its prompt
How can I get GDB to print a stacktrace (e.g. to run the bt command automatically) each time it returns control to 开发者_运维技巧me at its prompt?
You may use the "define" command to define new commands that do the normal action and run backtrace afterwards, or you can use the "define hookpost-command"-form to extend an existing command with additional actions.
(gdb) define hookpost-next
Type commands for definition of "hookpost-next".
End with a line saying just "end".
>backtrace
>end
(gdb) next
19 for (int k = 0; k<loops; ++k){
#0 main () at optimize.cpp:19
You can put this into a .gdbinit file to be automatically loaded by gdb when it starts:
define hookpost-next
backtrace
end
You can do that for each of the commands you want to extend with backtrace.
精彩评论