Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

kernel

gdb

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.

like image 504
alexgolec Avatar asked Nov 27 '10 16:11

alexgolec


People also ask

How do you do a full backtrace?

To print a backtrace of the entire stack, use the backtrace command, or its alias bt . This command will print one line per frame for frames in the stack. By default, all stack frames are printed. You can stop the backtrace at any time by typing the system interrupt character, normally Ctrl-c .

What is full stack trace?

A full stack trace allows you to see the chain of files from when your custom tag reached your set breakpoint. If you click on any of the pages in the caller chain then FusionDebug will show you that page and will highlight the line at which the next page in the chain was called.

How do I see all threads in GDB?

Use the "info threads" command to see the IDs of currently known threads. The GDB thread debugging facility allows you to observe all threads while your program runs--but whenever GDB takes control, one thread in particular is always the focus of debugging. This thread is called the current thread.


1 Answers

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.

like image 121
terminus Avatar answered Oct 02 '22 06:10

terminus