[Dwarf-discuss] Question about variable location in Dwarf

Jun Koi junkoi2004
Wed Oct 4 18:28:20 GMT 2006


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





More information about the Dwarf-discuss mailing list