location list

Mark Wielaard mark@klomp.org
Tue Jun 2 17:19:47 GMT 2020


Hi,

On Tue, 2020-06-02 at 14:18 +0000, Sasha Da Rocha Pinheiro wrote:
> I am trying to parse a location list given as an sec_offset. 
> How do I get this offset value that points to .debug_loc so I can
> call dwarf_getlocations()?
> Should I pass this offset as the second parameter of this call? 

Normally an offset isn't enough information to resolve an DIE attribute
reference. So if at all possible you should try to use an
Dwarf_Attribute you got from some DIE.

It isn't really supported, but you could try creating a "fake"
attribute that carries all information. e.g.

Dwarf_Attribute loc_attr;
loc_attr.code = DW_AT_location;
loc_attr.form = DW_FORM_data4; /* Assuming 32bit DWARF.  */
loc_attr.valp = &offset; /* Your offset should be a 32bit type.  */
loc_attr.cu = cu;

dwarf_getlocations (&loc_attr, offset, ...);

Note that the CU needs to be version 3 or lower for the above to work.
If the CU is > 3 then the only correct form to use is
DW_FORM_sec_offset, and your valp should point to a uleb128 encoded
offset value.

But in general I would not recommend this approach. It isn't really
supported. And some code might do sanity checks on the valp pointer and
decide it looks bogus and just error out. Also you have to have a valid
Dwarf_CU pointer around because you cannot create a valid fake CU
easily.

So try to keep a reference (or copy) around of the Dwarf_Attribute from
which you got this offset and use that for your dwarf_getlocations
call.

Cheers,

Mark


More information about the Elfutils-devel mailing list