[Dwarf-Discuss] find local variable information from the dwarf

David Anderson davea42@earthlink.net
Tue Jan 22 02:56:39 GMT 2008


Neeraj kushwaha wrote:
> Thanks for the reply.
>
> But how to interpret these lines
>
>   
>> *         DW_AT_frame_base            [
>>     
> *>* 0]<lowpc=0x24><highpc=0x28>DW_OP_breg4+4
> *>*                     [ 1]<lowpc=0x28><highpc=0x2e>DW_OP_reg1
> *>*                     [ 2]<lowpc=0x2e><highpc=0x2f>DW_OP_breg4+4
> *>*                     [ 3]<lowpc=0x2f><highpc=0x31>DW_OP_breg4+8
> *>*                     [ 4]<lowpc=0x31><highpc=0x56>DW_OP_breg5+8
> *
>
> Please explain briefly.
>
>
>
> Regards
>
> Neeraj
>
> On Jan 22, 2008 12:50 AM, David Anderson <davea42 at earthlink.net> wrote:
>
>   
>> Neeraj kushwaha wrote:
>>     
>>> Hi All,
>>>
>>> I am trying to find the location and value of local variable in a stack
>>> frame from the core dump.
>>> As GDB can fetch the value and location of local variable using the
>>> information from the dwarf debugging format.
>>>
>>> I am trying to manually find the location and value of the local
>>>       
>> variable
>>     
>>> from the core.
>>>
>>> This is what i did; from the a.out, I extracted the dwarf information
>>>       
>> using
>>     
>>> "dwarfdump -a a.out"
>>>
>>> and using the GDB i am trying to print the dump from the core "x/88b
>>>       
>> main1"
>>     
>>> But I am not able to find the location information of the local variable
>>>
>>> for example:
>>>
>>>         DW_AT_name                  c
>>>         DW_AT_decl_file             1 /home/neeraj/4.c
>>>         DW_AT_decl_line             15
>>>         DW_AT_type                  <177>
>>>         DW_AT_location              DW_OP_fbreg -20
>>>
>>>
>>> local variable is at location DW_OP_fbreg - 20. But how to find the
>>> DW_OP_fbreg?
>>>
>>>
>>>       
>> Look back a few lines.  The fbreg is defined in the subprogram
>> DIE (DW_AT_frame_base):
>>
>>     
>>> <1><  315>    DW_TAG_subprogram
>>>         DW_AT_external              yes(1)
>>>         DW_AT_name                  main
>>>         DW_AT_decl_file             1 /home/neeraj/4.c
>>>         DW_AT_decl_line             14
>>>         DW_AT_type                  <177>
>>>         DW_AT_low_pc                0x8048398
>>>         DW_AT_high_pc               0x80483ca
>>>         DW_AT_frame_base            [
>>> 0]<lowpc=0x24><highpc=0x28>DW_OP_breg4+4
>>>                     [ 1]<lowpc=0x28><highpc=0x2e>DW_OP_reg1
>>>                     [ 2]<lowpc=0x2e><highpc=0x2f>DW_OP_breg4+4
>>>                     [ 3]<lowpc=0x2f><highpc=0x31>DW_OP_breg4+8
>>>                     [ 4]<lowpc=0x31><highpc=0x56>DW_OP_breg5+8
>>>
>>>       
Two quotations from the dwarf specification should help:

1. DW_OP_fbreg
The DW_OP_fbreg operation provides a signed LEB128 offset from
the address specified by
the location description in the DW_AT_frame_base attribute of the
current function. (This is
typically a ?stack pointer? register plus or minus some offset.
On more sophisticated systems
it might be a location list that adjusts the offset according to
changes in the stack pointer as
the PC changes.)

And from an example in the spec:

DW_OP_fbreg -50
Given an DW_AT_frame_base value of ?DW_OP_breg31 64,? this example
computes the address of a local variable that is -50 bytes from a
logical frame pointer that is computed by adding 64 to the current
stack pointer (register 31).

So depending on where you are in the function one of the frame base rules
applies. Apply that rule, then the value involved is the fbreg.

Your variable had:

DW_AT_location              DW_OP_fbreg -20  

so the actual location is that frame base -20.


Hope this helps.
DavidAnderson





More information about the Dwarf-discuss mailing list