简体   繁体   中英

Print minimal stack in gdb

I want to attach a command to a breakpoint that writes a full callstack to a file every time the breakpoint is hit. Since I know that this may hit performance hard, I want to print out the information as condensed as possible. However, the bt command always prints a lot of info, like symbols, line in a file etc.

Is there an alternative to bt that prints out as little as possible while still allowing to reconstruct the call hierarchy after debugging has finished? Like, only printing out the instruction pointers of the functions in the stack?

Regards

Since I know that this may hit performance hard, I want to print out the information as condensed as possible.

It's not printing the information that is slow. The mere fact that you hit a breakpoint will already slow down your program immensely (if the breakpoint is hit often).

Like, only printing out the instruction pointers of the functions in the stack?

You don't need GDB for that. On many platforms the program can obtain this info directly (eg from backtrace function) and log it to disk. That is usually at least a 100 times faster than doing it in GDB.

the bt command always prints a lot of info, like symbols, line in a file etc.

You can control exactly what is printed with a Python unwinder or frame decorator .

You can remove all debug info from the binary you are debugging using strip tool.

bt should work fast on binary without symbols, you will not get any line numbers or function names, only raw memory addresses in bt output. If you are going to set breakpoint you will have to set it on memory address as there is no debug info anymore in binary.

To reconstruct the call hierarchy after debugging has finished you can use addr2line , see this question: How to use addr2line command in linux . I don't know automated way of resolving all addresses in bt output. Probably you will have to resolve them one by one or write a script to do it automatically. Note that now the binary should be unstripped (with debug symbols).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM