Hi Brian,

On Tue, 2020-10-20 at 20:41 -0400, Brian Dodge via Elfutils-devel
wrote:
> I am attempting to use elfutils / libdw to create a library for
> tagging 
> function's local/automatic variable storage. I hope to use dwarf info to 
> get the stack frame offsets, etc. for function's local vars.
> 
> I started with readelf.c as an example for iterating through CU/DIE.  
> Since my code isn't "part of" elfutils I am not including private 
> headers such as libdwP.h.  Because of that some of the code derived from 
> readelf won't compile of course.

In general readelf is not a great example since it is mainly used to
dump data from ELF sections and it does DWARF data decoding as part of
these ELF sections, which doesn't always makes sense in other contexts.
For example eu-readelf --debug-dump=abbrev decodes the DWARF
abbreviations table, but this isn't really something one would normally
do. The abbrevs aren't really that useful on their own. When working
with libdw you would simply use functions that deal with Dwarf_Dies and
Dwarf_Attributes. How the attribute values are encoded exactly is not
something you need to care about in almost all cases. readelf reuses
some of the code in libdw, but as you noticed it also cheats a little
and relies on some internals which it gets at with libdwP.h. Something
no other tool really should do. If there is specific information you
really need and cannot get unless using libdwP.h please report it as a
bug and we can see if we can produce a real (stable) interface. Please
don't use libdwP.h, it is not a guaranteed public API and things might
break between (minor) releases.

> Are these structure accesses simply short-cuts and it is possible to get 
> the info needed via API functions?  For things like "cu->version" it 
> seems I can get that via the API dwarf_cu_info, but for some things I 
> don't quite see what I'd need in the public headers. For example, in the 
> (readelf.c) function get_indexed_addr, the line:
> 
> Elf_Data *debug_addr = cu->dbg->sectiondata[IDX_debug_addr];
> 
> uses the (private) structure Dwarf_CU to get at the (private) structure 
> Dwarf, to get at the sectiondata.  I can get the Dwarf via 
> dwarf_cu_getdwarf, but Is there another way to get at the section data 
> (and IDX_debug_addr) ?

There currently isn't. In general if you need an address from an DIE
Attribute you should simply use dwarf_formaddr (attr, &addr). Which
gives you the address however/where it is stored.

Do you really need to access the .debug_addr section data directly? If
so, what kind of information do you need from it? The
header(s)/values(s), the indexes, the actual address tables? I rather
not expose the precise data encoding because it might change between
DWARF versions.

Cheers,

Mark

Reply via email to