[Dwarf-Discuss] dwarf and local variables's offset
Jan Kratochvil
jan.kratochvil@redhat.com
Mon May 4 19:22:23 GMT 2009
Hi,
DW_AT_frame_base specifies some virtual "frame base" address. Technically it
can be arbitrary address, it is used just by the DWARF expressions as
a reference point.
DWARF would work the same if you had:
> Offset Begin End Expression
> 00000000 080483c4 080483ec (DW_OP_breg5: 108)
> 00000000 <End of list>
+
> >> ?<2><8d>: Abbrev Number: 6 (DW_TAG_variable)
> > [...]
> >> ? ? <98> ? DW_AT_location ? ?: 2 byte block: 91 ?? ? ? ?(DW_OP_fbreg: -116)
As some constant can be added to the frame base and later subtracted for the
value locations addresses.
DWARF3 says:
# The frame base for a procedure is typically an address fixed relative to the
# first unit of storage allocated for the procedure?s stack frame.
So the address is right above the frame pointer and return address on the
stack. For i386 -fno-omit-frame-pointer code that corresponds to +8 = +4 +4
as there is both the return address and the stored caller's %ebp value.
This is a typical i386 -fno-omit-frame-pointer function prologue:
--- Here frame base is %esp + 4 as the return address is already stored there
by the caller's `call' instruction.
XXXXXXX: 55 push %ebp
--- Here frame base is %esp + 8 as also the %ebp reg. got stored to the stack.
XXXXXXX: 89 e5 mov %esp,%ebp
--- Here frame base is %ebp + 8 as since this point compiler may temporarily
push something on the stack (%esp) while %ebp should remain constant
through the function.
(.debug_loc you provided in your mail looks as imperfect, it could better
describe the first 3 bytes of the function containing the prologue.)
> 2) Why DW_OP_breg5 and (%ebp ) are not same????
Frame base is therefore unrelated to the register %ebp. Also for
-fomit-frame-pointer - which is even default on x86_64 - there is nothing like
%ebp to choose. Only %esp (%rsp) has a valid value and the location list
(.debug_loc) has to track the actual value as %esp/%rsp is being changed
through the function.
> ie) Why it is 8 only???
> If I compile my program again, it can be some other value???
GCC follows what the DWARF spec. says so it should behave deterministically.
Regards,
Jan
On Mon, 04 May 2009 11:04:52 +0200, ranjith kumar wrote:
> Hi,
> In the contes of the .debug_loc section:
> _____________________________________________
> Offset Begin End Expression
> 00000000 080483c4 080483ec (DW_OP_breg5: 8)
> 00000000 <End of list>
> ___________________________________________
>
> 1) What does "DW_OP_breg5: 8" mean???
> ie) Why it is 8 only???
> If I compile my program again, it can be some other value???
> Or that value is constant for the given machine? If so it represents
> what information about the machine?
>
> 2) Why DW_OP_breg5 and (%ebp ) are not same????
>
> I could not figure it out it in dwarf3.pdf.
> Thanks in advace.
More information about the Dwarf-discuss
mailing list