0

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

user5024425
  • 397
  • 3
  • 14
  • "*may* hit"? have you tried it? have you tried to filter it before the actual IO? – Karoly Horvath May 11 '17 at 12:07
  • My hope was that there is a stripped down version of bt that only generates the function addresses. Other than that, I don't know how to filter bt output for function addresses. – user5024425 May 11 '17 at 12:12
  • There's a reason I asked those questions, people have this tendency to generate artificial problems... – Karoly Horvath May 11 '17 at 12:14
  • I still only need that info for further processing. If I can reduce the output to this info, processing it afterwards is easier for me. – user5024425 May 11 '17 at 12:18

2 Answers2

2

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 (e.g. 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.

Employed Russian
  • 199,314
  • 34
  • 295
  • 362
0

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).

Community
  • 1
  • 1
ks1322
  • 33,961
  • 14
  • 109
  • 164