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

Neeraj kushwaha kushneeraj@gmail.com
Mon Jan 21 05:23:03 GMT 2008


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?

Secondly I don't see the local variable are word aligned.

Please anyone guide me how to find the location and value of local variable
from the dwarf format and looking at the dump.

I am putting all the information here. (source code, gdb dump, dwarf
information)

/* 4.c */
#include<stdio.h>

int main1()
{
int b=0xabccddef;
int *p=0;
*p=10;
return 0;
}

int main()
{
int c=0xeeffeeff;
int ab=0xaabbccdd;
main1();
return 0;
}

-----------------------------------------------------------------------

(gdb) x/88b main1
0x8048374 <main1>:      0x55    0x89    0xe5    0x83    0xec    0x10
0xc7    0x45
0x804837c <main1+8>:    0xf8    0xef    0xdd    0xcc    0xab    0xc7
0x45    0xfc
0x8048384 <main1+16>:   0x00    0x00    0x00    0x00    0x8b    0x45
0xfc    0xc7
0x804838c <main1+24>:   0x00    0x0a    0x00    0x00    0x00    0xb8
0x00    0x00
0x8048394 <main1+32>:   0x00    0x00    0xc9    0xc3    0x8d    0x4c
0x24    0x04
0x804839c <main+4>:     0x83    0xe4    0xf0    0xff    0x71    0xfc
0x55    0x89
0x80483a4 <main+12>:    0xe5    0x51    0x83    0xec    0x10    0xc7
0x45    0xf4
0x80483ac <main+20>:    0xff    0xee    0xff    0xee    0xc7    0x45
0xf8    0xdd
0x80483b4 <main+28>:    0xcc    0xbb    0xaa    0xe8    0xb8    0xff
0xff    0xff
0x80483bc <main+36>:    0xb8    0x00    0x00    0x00    0x00    0x83
0xc4    0x10
0x80483c4 <main+44>:    0x59    0x5d    0x8d    0x61    0xfc    0xc3
0x90    0x90

-------------------------------------------------------------------------------------------


.debug_info

COMPILE_UNIT<header overall offset = 0>:
<0><   11>    DW_TAG_compile_unit
        DW_AT_stmt_list             0
        DW_AT_high_pc               0x80483ca
        DW_AT_low_pc                0x8048374
        DW_AT_producer              GNU C 4.1.2 20070925 (Red Hat 4.1.2-27)
        DW_AT_language              DW_LANG_C89
        DW_AT_name                  4.c
        DW_AT_comp_dir              /home/neeraj

LOCAL_SYMBOLS:
<1><   82>    DW_TAG_base_type
        DW_AT_name                  unsigned int
        DW_AT_byte_size             4
        DW_AT_encoding              DW_ATE_unsigned
<1><   89>    DW_TAG_base_type
        DW_AT_name                  unsigned char
        DW_AT_byte_size             1
        DW_AT_encoding              DW_ATE_unsigned_char
<1><  106>    DW_TAG_base_type
        DW_AT_name                  short unsigned int
        DW_AT_byte_size             2
        DW_AT_encoding              DW_ATE_unsigned
<1><  128>    DW_TAG_base_type
        DW_AT_name                  long unsigned int
        DW_AT_byte_size             4
        DW_AT_encoding              DW_ATE_unsigned
<1><  149>    DW_TAG_base_type
        DW_AT_name                  signed char
        DW_AT_byte_size             1
        DW_AT_encoding              DW_ATE_signed_char
<1><  164>    DW_TAG_base_type
        DW_AT_name                  short int
        DW_AT_byte_size             2
        DW_AT_encoding              DW_ATE_signed
<1><  177>    DW_TAG_base_type
        DW_AT_name                  int
        DW_AT_byte_size             4
        DW_AT_encoding              DW_ATE_signed
<1><  184>    DW_TAG_base_type
        DW_AT_name                  long long int
        DW_AT_byte_size             8
        DW_AT_encoding              DW_ATE_signed
<1><  201>    DW_TAG_base_type
        DW_AT_name                  long long unsigned int
        DW_AT_byte_size             8
        DW_AT_encoding              DW_ATE_unsigned
<1><  227>    DW_TAG_base_type
        DW_AT_name                  long int
        DW_AT_byte_size             4
        DW_AT_encoding              DW_ATE_signed
<1><  239>    DW_TAG_base_type
        DW_AT_name                  unsigned int
        DW_AT_byte_size             4
        DW_AT_encoding              DW_ATE_unsigned
<1><  246>    DW_TAG_base_type
        DW_AT_name                  char
        DW_AT_byte_size             1
        DW_AT_encoding              DW_ATE_signed_char
<1><  254>    DW_TAG_subprogram
        DW_AT_sibling               <309>
        DW_AT_external              yes(1)
        DW_AT_name                  main1
        DW_AT_decl_file             1 /home/neeraj/4.c
        DW_AT_decl_line             6
        DW_AT_type                  <177>
        DW_AT_low_pc                0x8048374
        DW_AT_high_pc               0x8048398
        DW_AT_frame_base            [ 0]<lowpc=0x0><highpc=0x1>DW_OP_breg4+4
                    [ 1]<lowpc=0x1><highpc=0x3>DW_OP_breg4+8
                    [ 2]<lowpc=0x3><highpc=0x24>DW_OP_breg5+8
<2><  284>    DW_TAG_variable
        DW_AT_name                  b
        DW_AT_decl_file             1 /home/neeraj/4.c
        DW_AT_decl_line             7
        DW_AT_type                  <177>
        DW_AT_location              DW_OP_fbreg -16
<2><  296>    DW_TAG_variable
        DW_AT_name                  p
        DW_AT_decl_file             1 /home/neeraj/4.c
        DW_AT_decl_line             8
        DW_AT_type                  <309>
        DW_AT_location              DW_OP_fbreg -12
<1><  309>    DW_TAG_pointer_type
        DW_AT_byte_size             4
        DW_AT_type                  <177>
<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
<2><  340>    DW_TAG_variable
        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
<2><  352>    DW_TAG_variable
        DW_AT_name                  ab
        DW_AT_decl_file             1 /home/neeraj/4.c
        DW_AT_decl_line             16
        DW_AT_type                  <177>
        DW_AT_location              DW_OP_fbreg -16

line number info
<source>    [row,column]    <pc>    //<new statement or basic block
/home/neeraj/4.c:    [  6,-1]    0x8048374    // new statement
/home/neeraj/4.c:    [  7,-1]    0x804837a    // new statement
/home/neeraj/4.c:    [  8,-1]    0x8048381    // new statement
/home/neeraj/4.c:    [  9,-1]    0x8048388    // new statement
/home/neeraj/4.c:    [ 10,-1]    0x8048391    // new statement
/home/neeraj/4.c:    [ 11,-1]    0x8048396    // new statement
/home/neeraj/4.c:    [ 14,-1]    0x8048398    // new statement
/home/neeraj/4.c:    [ 15,-1]    0x8048398    // new statement
/home/neeraj/4.c:    [ 16,-1]    0x804839f    // new statement
/home/neeraj/4.c:    [ 17,-1]    0x80483a6    // new statement
/home/neeraj/4.c:    [ 18,-1]    0x80483ab    // new statement
/home/neeraj/4.c:    [ 19,-1]    0x80483b0    // new statement
/home/neeraj/4.c:    [ 19,-1]    0x80483b0    // new statement    // end of
text sequence

.debug_pubnames
global main1           die 254, cu-die 11, off-in-cu 254, cu 0
global main            die 315, cu-die 11, off-in-cu 315, cu 0

.debug_macinfo

.debug_loc format <o b e l> means section-offset begin-addr end-addr
length-of-block-entry
     <obel> 0x00000000 0x000000000 0x00000001        2
     <obel> 0x0000000c 0x000000001 0x00000003        2
     <obel> 0x00000018 0x000000003 0x00000024        2
     <obel> 0x00000024 0x000000000 0x00000000        0
     <obel> 0x0000002c 0x000000024 0x00000028        2
     <obel> 0x00000038 0x000000028 0x0000002e        1
     <obel> 0x00000043 0x00000002e 0x0000002f        2
     <obel> 0x0000004f 0x00000002f 0x00000031        2
     <obel> 0x0000005b 0x000000031 0x00000056        2
     <obel> 0x00000067 0x000000000 0x00000000        0

.debug_abbrev
<   1><    0><code:  1> DW_TAG_compile_unit DW_children_yes
      <    3>    DW_AT_stmt_list             DW_FORM_data4
      <    5>    DW_AT_high_pc               DW_FORM_addr
      <    7>    DW_AT_low_pc                DW_FORM_addr
      <    9>    DW_AT_producer              DW_FORM_string
      <   11>    DW_AT_language              DW_FORM_data1
      <   13>    DW_AT_name                  DW_FORM_string
      <   15>    DW_AT_comp_dir              DW_FORM_string
<   2><   19><code:  2> DW_TAG_base_type    DW_children_no
      <   22>    DW_AT_name                  DW_FORM_strp
      <   24>    DW_AT_byte_size             DW_FORM_data1
      <   26>    DW_AT_encoding              DW_FORM_data1
<   3><   30><code:  3> DW_TAG_base_type    DW_children_no
      <   33>    DW_AT_name                  DW_FORM_string
      <   35>    DW_AT_byte_size             DW_FORM_data1
      <   37>    DW_AT_encoding              DW_FORM_data1
<   4><   41><code:  4> DW_TAG_subprogram   DW_children_yes
      <   44>    DW_AT_sibling               DW_FORM_ref4
      <   46>    DW_AT_external              DW_FORM_flag
      <   48>    DW_AT_name                  DW_FORM_string
      <   50>    DW_AT_decl_file             DW_FORM_data1
      <   52>    DW_AT_decl_line             DW_FORM_data1
      <   54>    DW_AT_type                  DW_FORM_ref4
      <   56>    DW_AT_low_pc                DW_FORM_addr
      <   58>    DW_AT_high_pc               DW_FORM_addr
      <   60>    DW_AT_frame_base            DW_FORM_data4
<   5><   64><code:  5> DW_TAG_variable     DW_children_no
      <   67>    DW_AT_name                  DW_FORM_string
      <   69>    DW_AT_decl_file             DW_FORM_data1
      <   71>    DW_AT_decl_line             DW_FORM_data1
      <   73>    DW_AT_type                  DW_FORM_ref4
      <   75>    DW_AT_location              DW_FORM_block1
<   6><   79><code:  6> DW_TAG_pointer_type DW_children_no
      <   82>    DW_AT_byte_size             DW_FORM_data1
      <   84>    DW_AT_type                  DW_FORM_ref4
<   7><   88><code:  7> DW_TAG_subprogram   DW_children_yes
      <   91>    DW_AT_external              DW_FORM_flag
      <   93>    DW_AT_name                  DW_FORM_string
      <   95>    DW_AT_decl_file             DW_FORM_data1
      <   97>    DW_AT_decl_line             DW_FORM_data1
      <   99>    DW_AT_type                  DW_FORM_ref4
      <  101>    DW_AT_low_pc                DW_FORM_addr
      <  103>    DW_AT_high_pc               DW_FORM_addr
      <  105>    DW_AT_frame_base            DW_FORM_data4
<   8><  109><code:  0> null .debug_abbrev entry

.debug_string
name at offset 0, length 12 is unsigned int

.debug_aranges

arange starts at 8048374, length of 86, cu_die_offset = 11

COMPILE_UNIT<header overall offset = 0>:
<0><   11>    DW_TAG_compile_unit
        DW_AT_stmt_list             0
        DW_AT_high_pc               0x80483ca
        DW_AT_low_pc                0x8048374
        DW_AT_producer              GNU C 4.1.2 20070925 (Red Hat 4.1.2-27)
        DW_AT_language              DW_LANG_C89
        DW_AT_name                  4.c
        DW_AT_comp_dir              /home/neeraj

.debug_frame

fde:
<  0><0x8048374:0x8048398><main1><fde offset 0x14 length: 0x14><eh offset
none>
    08048374:    cfa=04(r4/a0) r8/t0=-4(cfa)
    08048375:    cfa=08(r4/a0) r5/a1=-8(cfa) r8/t0=-4(cfa)
    08048377:    cfa=08(r5/a1) r5/a1=-8(cfa) r8/t0=-4(cfa)
<  0><0x8048398:0x80483ca><main><fde offset 0x2c length: 0x24><eh offset
none>
    08048398:    cfa=04(r4/a0) r8/t0=-4(cfa)
    0804839c:    cfa=00(r1/at) r4/a0=r1/at r8/t0=-4(cfa)
    080483a2:    cfa=04(r4/a0) r4/a0=r1/at r8/t0=-4(cfa)
    080483a3:    cfa=08(r4/a0) r4/a0=r1/at r5/a1=-8(cfa) r8/t0=-4(cfa)
    080483a5:    cfa=08(r5/a1) r4/a0=r1/at r5/a1=-8(cfa) r8/t0=-4(cfa)
    080483a6:    cfa=08(r5/a1) r4/a0=-12(cfa) r5/a1=-8(cfa) r8/t0=-4(cfa)

.eh_frame

fde:
<  0><0xfffffee8:0xffffff51><><fde offset 0x8c length: 0x1c><eh offset none>
    fffffee8:    cfa=04(r4/a0) r8/t0=-4(cfa)
    fffffee9:    cfa=08(r4/a0) r5/a1=-8(cfa) r8/t0=-4(cfa)
    fffffeeb:    cfa=08(r5/a1) r5/a1=-8(cfa) r8/t0=-4(cfa)
    fffffeee:    cfa=08(r5/a1) r3/v1=-20(cfa) r5/a1=-8(cfa) r6/a2=-16(cfa)
r7/a3=-12(cfa) r8/t0=-4(cfa)
<  0><0xfffffef4:0xfffffef9><><fde offset 0x70 length: 0x18><eh offset none>
    fffffef4:    cfa=04(r4/a0) r8/t0=-4(cfa)
    fffffef5:    cfa=08(r4/a0) r5/a1=-8(cfa) r8/t0=-4(cfa)
    fffffef7:    cfa=08(r5/a1) r5/a1=-8(cfa) r8/t0=-4(cfa)

.debug_static_func

.debug_static_vars

.debug_types

.debug_weaknames


--------------------------------------------------------------------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.dwarfstd.org/private.cgi/dwarf-discuss-dwarfstd.org/attachments/20080121/a9995fc1/attachment.htm>



More information about the Dwarf-discuss mailing list