c++debugginggdbbacktrace

Why GDB backtrace show to me only parent's call instead of nested functions?


I'm trying backtrace on gdb, basically with this on setupCommands (in VSCode):

{
    "description": "Backtrace",
    "text": "set backtrace past-main",
    "ignoreFailures": true
}

When I do bt -10, it show to me only the parent's call, not the nested one.

For example, if I have: functA call funcB (and inside funcB i call funcC and funcD), if I stop at the end of funcB, I can just see funcA and funcB (without C and D).

How can I enable whole tracing in the backtrace? To see EVERY instructions calls at any level, on every thread? (I just need last 1000, for example).


Solution

  • You appear to have misunderstood what the backtrace is. It is the call-stack backtrace, not a trace of the execution path of the code.

    If you stop in B, then C and D are not in the call stack. If you were to stop in C you would see A->B->C and if you stop in D then A->B->D.

    From the documentation (my emphasis):

    A backtrace is a summary of how your program got where it is. It shows one line per frame, for many frames, starting with the currently executing frame (frame zero), followed by its caller (frame one), and on up the stack.

    here "frame" refers to a stack-frame.