Debugging Optimized Code

Posted by Beetle B. on Tue 21 January 2020

gdb has stuff for handling macros, but you likely need to compile your program in a way to add these to the debug symbols. See this section if you want to expand a macro, or show the definition of one, or see all macros defined in the current scope, etc.

Inline Functions

GDB displays inlined functions just like non-inlined functions. They appear in backtraces. You can view their arguments and local variables, step into them with ‘step’, skip them with ‘next’, and escape from them with ‘finish’.

You can check whether a function was inlined by using the ‘info frame’ command.

Single instruction steps always show the inlined body (i.e. using stepi and nexti).

Setting breakpoints at the call site of an inlined function may not work, because the call site does not contain any code. GDB may incorrectly move the breakpoint to the next line of the enclosing function, after the call.

Tail Call Frames

Function ‘B’ can call function ‘C’ in its very last statement. In unoptimized compilation the call of ‘C’ is immediately followed by return instruction at the end of ‘B’ code. Optimizing compiler may replace the call and return in function ‘B’ into one jump to function ‘C’ instead. Such use of a jump instruction is called tail call.

There are some commands related to this. Read later if needed.

tags : gdb