alexgolec
alexgolec

Reputation: 28252

How do I get an entire stack trace in gdb in one shot?

I'm debugging a kernel, and apparently the way fault handlers operate on ARM is they go through hundreds of layers of __pabt_usr's before they reach any actual code. Anyway, I'm doing this debugging remotely through an emulator, and fetching the trace bit by bit is slow. Is there any way to fetch the whole thing at once?

EDIT: Printing the stack trace in reverse would also be helpful.

Upvotes: 26

Views: 50437

Answers (2)

Melroy van den Berg
Melroy van den Berg

Reputation: 3166

Just either type: backtrace, bt or where.

For a full backtrace type: backtrace full or type: bt full

See also: https://visualgdb.com/gdbreference/commands/backtrace

Upvotes: 1

terminus
terminus

Reputation: 14462

I don't know if the full backtrace can be given but you can give a numeric argument to 'bt' to get more frames:

(gdb) bt 10
#0  x () at test.c:4
#1  0x080483bf in x () at test.c:4
#2  0x080483bf in x () at test.c:4
#3  0x080483bf in x () at test.c:4
#4  0x080483bf in x () at test.c:4
#5  0x080483bf in x () at test.c:4
#6  0x080483bf in x () at test.c:4
#7  0x080483bf in x () at test.c:4
#8  0x080483bf in x () at test.c:4
#9  0x080483bf in x () at test.c:4
(More stack frames follow...)

This also works with negative numbers, which give the outermost frames:

(gdb) bt -2
#122467 0x080483bf in x () at test.c:4
#122468 0x080483bf in x () at test.c:4

So if you need the last couple of frames, you could use a negative number.

Upvotes: 34

Related Questions