How can I jump to a frame in a stack trace according to the function name in gdb?

23,284

Solution 1

Two options:

  • up 200 will bring you up 200 frames
  • If you know the initial caller of the recursive routine, you can do f[rame] <caller-func> - this will jump to the frame of address caller-func.

See Frame Selection in the manual.

Solution 2

You have to use bt with minus. It is similar to bt, but print first the outermost n frames.
For example:
bt -100

And it is likely you will see the frame that you need to inspect on the first or second screen.
Once insecting the stack trace using bt -100 helped me to fix a pboblem with a lot of recursive calls easily.

And then issue command
f <here the number of your frame you need to inspect>

Share:
23,284

Related videos on Youtube

Nathan Fellman
Author by

Nathan Fellman

SOreadytohelp

Updated on July 09, 2022

Comments

  • Nathan Fellman
    Nathan Fellman almost 2 years

    I'm debugging a stack overflow due to infinite recursion. The program fails when the stack is 700 calls deep.

    I want to jump to the frame in which the function was initially called. However, gdb shows me the stack trace from the top of the stack about 20 entries at a time, and I wonder if I can somehow skip straight to the calling function without looking through the stack trace to find its number.

    To that end, I want to be able to jump to a stack frame based on its name instead of its number.

    Can this be done in gdb?

  • Marenz
    Marenz about 10 years
    Awesome. Been looking for a way to do this. The confusing thing was always that "frame" doesn't support this notation but "bt" does.
  • Jake Levi
    Jake Levi over 2 years
    NB, as mentioned in the link, you can also use frame function <caller-function-name>, referring to the name of the function, instead of its frame level in the current stack-trace