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

Michael Eager eager@eagercon.com
Mon Feb 4 23:17:34 GMT 2008

Neeraj kushwaha wrote:
> Hi All,
> I am trying to find the value of local variable which are stored in 
> register.
> for ex:
> int a;
> void foo()
> {
> register int b;
> int c;
> }
> dwarf info:
> DW_TAG_subprogram
> DW_AT_name = foo
> DW_TAG_variable
> DW_AT_name = b
> DW_AT_type = <4>
> DW_AT_location = DW_OP_reg0
>  From this dwarf debug information I get that local variable b is stored 
> at DW_OP_reg0. But how to find this register value. Suppose this foo() 
> funciton call another function, then this register value will get stored 
> in stack before invoking the function call.

The DWARF says that when the PC is within the range of the function foo(),
b is stored in R0.

When foo() calls another function, the processor ABI describes which
registers are saved and where they are saved.  The ABI also describes how
to find the previous function's registers and data.  If the current
PC is within a function called from foo(), the ABI describes (more or
less as part of the description of the calling sequence) how to unwind
the stack and find the values in the registers belonging to foo().

Michael Eager	 eager at eagercon.com
1960 Park Blvd., Palo Alto, CA 94306  650-325-8077

More information about the Dwarf-discuss mailing list