2

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?

1 Answer 1

6

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.