[Dwarf-discuss] Question about variable location in Dwarf

Nettleton, Brian brian.nettleton
Wed Oct 4 20:29:27 GMT 2006


Yes, I believe that DW_OP_breg5 is ebp for x86.  

Not sure what exactly you're trying to do, but one (obvious??)
recommendation would be to use a debugger to get the address of the
variable, they are already built to read the DWARF data and figure out
all the details.  Of course if you're trying to write your own debugger
(or similar?) then this doesn't really help you.

-Brian Nettleton



> -----Original Message-----
> From: dwarf-discuss-bounces at lists.freestandards.org 
> [mailto:dwarf-discuss-bounces at lists.freestandards.org] On 
> Behalf Of Jun Koi
> Sent: Wednesday, October 04, 2006 11:28 AM
> To: dwarf-discuss at lists.freestandards.org
> Subject: [Dwarf-discuss] Question about variable location in Dwarf
> 
> Hello,
> 
> I am having some problem interpreting Dwarf format. I am trying to get
> the address of a local variable in my C program by analyzing the Dwarf
> format. Here is my simple code:
> 
> ....
> int main()
> {
>         static char buffer[512];
>         struct old_utsname old;
> ...
> }
> 
> I use dwarfdump on the debugged binary of my code, and get 
> the below data:
> 
> ...
> <1><  578>      DW_TAG_subprogram
>                 DW_AT_sibling               <655>
>                 DW_AT_external              yes(1)
>                 DW_AT_name                  main
>                 DW_AT_decl_file             1 
> /home/jun/projects/olduname.c
>                 DW_AT_decl_line             24
>                 DW_AT_type                  <208>
>                 DW_AT_low_pc                0x8048433
>                 DW_AT_high_pc               0x804854e
>                 DW_AT_frame_base            DW_OP_reg5
> <2><  605>      DW_TAG_variable
>                 DW_AT_name                  buffer
>                 DW_AT_decl_file             1 
> /home/bun/projects/olduname.c
>                 DW_AT_decl_line             25
>                 DW_AT_type                  <655>
>                 DW_AT_location              DW_OP_addr 0x80497c0
> <2><  625>      DW_TAG_variable
>                 DW_AT_name                  old
>                 DW_AT_decl_file             1 
> /home/bun/projects/olduname.c
>                 DW_AT_decl_line             26
>                 DW_AT_type                  <291>
>                 DW_AT_location              DW_OP_breg5-329
> 
> .....
> 
> So I understand that the (run-time) virtual address of the variable
> "buffer" is at 0x80497c0. But how can I get the virtual address of the
> variable "old"? It seems that I must get it by computing "DW_OP_breg5
> - 329"? But how can I get the value of DW_OP_breg5 in this case?
> 
> I understand that DW_OP_breg5 is the value of a register, right? But
> what is that register? (ebp? I am on Intel x86)
> 
> Thank you a lot,
> Jun
> 
> _______________________________________________
> Dwarf-discuss mailing list
> Dwarf-discuss at lists.freestandards.org
> http://lists.freestandards.org/mailman/listinfo/dwarf-discuss
> 





More information about the Dwarf-discuss mailing list