1

I'm writing a bare metal application in ARMv7 using the AAPCS ABI with GCC 6.2 and I having some issue debugging processor faults in leaf functions.

The debugger (gdb) cannot display a proper stack trace because LR is not saved to the stack when the function is a leaf function.

Is it possible to force GCC to add LR to the stack for all functions, and not optimize this away in leaf functions?

Knut T.
  • 21
  • 2
  • 2
    Are you sure that solves the problem? – fuz Sep 09 '16 at 08:57
  • Does `-fno-omit-frame-pointer` do anything for ARM? For x86, it asks the compiler to always emit the classic prologue / epilogue (`push ebp`, etc.), but it's more about non-leaf functions. Some compilers don't respect it for leaf functions, IIRC. (I think maybe clang). – Peter Cordes Sep 09 '16 at 15:27
  • GDB shouldn't need LR saved on the stack, it can just use the value saved in the register itself. – Ross Ridge Sep 09 '16 at 15:59
  • 1
    See: [Recover FP for broken back trace](http://stackoverflow.com/questions/38798592/recover-frame-pointer-for-broken-back-trace). The newer AAPCS does not require storing an LR. You need GDB to match the compiler and the binary needs to have the unwind info. You can [detach the debug info, it is found by directory or a build id](https://sourceware.org/gdb/onlinedocs/gdb/Separate-Debug-Files.html). The debugger can retrieve PC/LR and use unwind tables to reconstruct the 'stack trace'. Impossible without unwind info though. – artless noise Sep 09 '16 at 16:46

0 Answers0