[Dwarf-Discuss] how to find local variable stored in register

Jim Blandy jimb@red-bean.com
Tue Feb 5 21:36:39 GMT 2008


On Feb 5, 2008 11:13 AM, Robinson, Paul T (NonStop)
<paul.t.robinson at hp.com> wrote:
> How do you unwind, if you don't know where the registers are saved?
> Seems like this would have to be part of the ABI.

Well, it's a lot of work.

DWARF CFI describes where to find the caller's registers at every
instruction in the callee.  When that's present, it's the ideal way to
do unwinding.  When CFI (or something like it) isn't available, well,
it's hard.  GDB actually inspects the function's machine code,
starting at the entry point and following along up to the current PC
(although often it needs to give up before that point), trying to
glean the frame size, saved register locations, and so on.

Some ABIs, but not all, specify enough information to find callers' PC
values, so you can at least get backtraces that list the functions by
name, without arguments or local variable values.  However, these ABIs
usually have a run-time cost associated with that feature; for
example, they might require functions to save a frame pointer, even if
they have a constant frame size.  So, in practice, compilers often
provide options to bend the ABI and neglect these responsibilities.
When people want to debug such code, even a plain function-only
backtrace requires help.




More information about the Dwarf-discuss mailing list