[Dwarf-discuss] Question on loclist

Daniel Berlin dberlin
Thu Oct 5 13:51:57 GMT 2006


> I compiled kernel with debug info option, and use dwarfdump to extract
> information out. Then I got something corresponding to the above code:
>
> ...
>                 DW_AT_name                  do_rmdir
>                 DW_AT_decl_file             1 fs/namei.c
>                 DW_AT_decl_line             1988
>                 DW_AT_prototyped            yes(1)
>                 DW_AT_type                  <193>
>                 DW_AT_low_pc                0xc01617a0
>                 DW_AT_high_pc               0xc0161873
>                 DW_AT_frame_base            DW_OP_reg5
> <2><41023>      DW_TAG_formal_parameter
>                 DW_AT_name                  dfd
>                 DW_AT_decl_file             1 fs/namei.c
>                 DW_AT_decl_line             1987
>                 DW_AT_type                  <49>
>                 DW_AT_location              <loclist with 3 entries follows>
>                         [ 0]<lowpc=0x2e00><highpc=0x2e19>DW_OP_reg0
>                         [ 1]<lowpc=0x2e19><highpc=0x2e3f>DW_OP_reg3
>                         [ 2]<lowpc=0x2ec4><highpc=0x2ec7>DW_OP_reg3
> <2><41039>      DW_TAG_formal_parameter
>                 DW_AT_name                  pathname
>                 DW_AT_decl_file             1 fs/namei.c
>                 DW_AT_decl_line             1987
>                 DW_AT_type                  <64>
>                 DW_AT_location              <loclist with 1 entries follows>
>                         [ 0]<lowpc=0x2e00><highpc=0x2e19>DW_OP_reg2
> <2><41055>      DW_TAG_variable
>                 DW_AT_name                  error
>                 DW_AT_decl_file             1 fs/namei.c
>                 DW_AT_decl_line             1989
>                 DW_AT_type                  <49>
>                 DW_AT_location              <loclist with 3 entries follows>
>                         [ 0]<lowpc=0x2e3b><highpc=0x2e3d>DW_OP_reg0
>                         [ 1]<lowpc=0x2e3f><highpc=0x2e53>DW_OP_reg3
>                         [ 2]<lowpc=0x2e7a><highpc=0x2ec7>DW_OP_reg3
> <2><41071>      DW_TAG_variable
>                 DW_AT_name                  name
>                 DW_AT_decl_file             1 fs/namei.c
>                 DW_AT_decl_line             1990
>                 DW_AT_type                  <82>
>                 DW_AT_location              <loclist with 2 entries follows>
>                         [ 0]<lowpc=0x2e1b><highpc=0x2eca>DW_OP_reg6
>                         [ 1]<lowpc=0x2ecf><highpc=0x2ed3>DW_OP_reg6
> .....
>
>
> I have few questions:
>
> 1) Why the location of variable "name" is not made with plain location
> expression (like DW_OP_breg5...), but loclist?

Because GCC decided to use a location list, and it turned out later it
only had one entry.  For various internal reasons, we don't convert it
back to a location expression.
>
> 2) Why location of "name" consists of 2 entries?
Because the ranges appear disjoint, it could not merge them, since
there appears to be a point during the routine where there is no way
to validly get the value of name.


> "[1]<lowpc=0x2ecf><highpc=0x2ed3>DW_OP_reg6" makes more sense to me,
> as the range is exactly 4bytes, and name is in fact a pointer of 4
> bytes.

The lowpc and highpc are the range of program counters over which the
expression is valid, *not* the place in memory where the variable
lives.


> But how about the 1st entry? What is its meaning?

It means that during program execution, when the program counter is
between 0x2e1b and 0x2eca, that the variable is in register 6.

>
> 3) Most important question to my project: in the case like above, how
> to determine the run-time address of "name"? (Suppose that I can have
> value of all the registers - I am on x86)

It depends.
The absolute simplest way is to store all the location ranges and
expression, for the variable in an array:

When you want to know the value of the variable
1. get the value of the current PC.
2. Look through the array to see if the PC falls within any of the
location ranges.
    a. If it does, evaluate the location expression to get the
location of the variable
    b. If it does not, the value is optimized out
3. Use the location of the variable to read it's value





More information about the Dwarf-discuss mailing list