Under -mergefunc-preserve-debug-info MergeFunctions::writeThunk():
- Does not create a new function for the thunk.
- Retains the debug info (and associated instructions) in the entry block for the thunk's parameters. PS: -debug will display the algorithm at work.
- Creates debug-info for the call (to the "master-copy") made by the thunk and its return value.
- Does not mark the call made by the thunk as a tail-call, so that the backtrace indicates the execution flow at -O0.
- Erases the rest of the function, retaining the (minimally sized) entry block.
GDB (7.11.1) features verified to work at [-O0, -O2]:
(gdb) info functions # Thunked function will now be listed.
(gdb) step <thunked function> # Reaches the "master-copy" function that the thunk calls.
(gdb) backtrace # When inside the thunk, will show call chain leading up to the thunk
- When we step into the master-copy function called by the thunk, will
- show call chain leading upto the master-copy (including thunk, one-above, at -O0)
- but PS: at -O<non-zero> the call does get tail-call'optimized, so will not show, as generally. (gdb) finish # When inside the thunk and when inside the master-copy when called from the thunk (gdb) break # On thunked function
- On master-copy function, breaks on newly inserted call made from within thunk
- On call-site of thunked function in another translation unit (not the TU of its definition)