Unwind the stack even if GDB can’t? (ARM)

Reason

Since GCC 5.0 for ARM the default used ABI is AAPCS1. With AAPCS the stack unwinding works based on unwind tables. The GDB won’t provide a backtrace if these tables are missing in the binaries.2

Alternative: The stack is really corrupted. Then the following solution may not help.


Solution

The following user-defined command tries to unwind the stack based on the hope that GCC created the stack frames in the common structure even if not forced by AAPCS itself.3

(gdb) define stackwalker
  set $a = $arg0
  while $a < *(long*) $a
    x/2a $a
    set $a = *(long*) $a
  end
end
(gdb) stackwalker $fp

Drawback

This simple solution doesn’t provide the possibility to switch between frames (‘(gdb) frame <idx>’).


1 Procedure Call Standard for the Arm 64-bit Architecture
2 GCC build flag: ‘-fno-asynchronous-unwind-tables’
3 “It may elect not to maintain a frame chain and to use the frame pointer register as a general-purpose callee-saved register.” (Link, Spec on GitHub, Tag: 2022Q3)