diff options
author | Mark Wielaard <mark@klomp.org> | 2020-05-08 12:33:11 +0200 |
---|---|---|
committer | Mark Wielaard <mark@klomp.org> | 2020-05-08 17:47:12 +0200 |
commit | e1db5cdc9f230f8de4df1a0f38dca69b283ee57a (patch) | |
tree | 87eed4be05a4c19baa323e9dec6d714d58402f4a /libdw | |
parent | b1d2404cc6ca0d9ce786e229a87c24db49163cfe (diff) | |
download | elfutils-e1db5cdc9f230f8de4df1a0f38dca69b283ee57a.tar.gz |
libdw: Use correct CU to resolve file names in dwarf_decl_file.
dwarf_decl_file uses dwarf_attr_integrate to get the DW_AT_decl_file
attribute. This means the attribute might come from a different DIE
in a different CU. If so, we need to use the CU associated with the
attribute, not the original DIE, to resolve the file name.
Also add a bit more documentation to dwarf_attr_integrate explaining
that the attribute returned might come from a different CU (and even
different Dwarf).
Signed-off-by: Mark Wielaard <mark@klomp.org>
Diffstat (limited to 'libdw')
-rw-r--r-- | libdw/ChangeLog | 7 | ||||
-rw-r--r-- | libdw/dwarf_decl_file.c | 2 | ||||
-rw-r--r-- | libdw/dwarf_ranges.c | 5 | ||||
-rw-r--r-- | libdw/libdw.h | 9 |
4 files changed, 21 insertions, 2 deletions
diff --git a/libdw/ChangeLog b/libdw/ChangeLog index 75fc8f06..34def10d 100644 --- a/libdw/ChangeLog +++ b/libdw/ChangeLog @@ -1,3 +1,10 @@ +2020-05-08 Mark Wielaard <mark@klomp.org> + + * dwarf_decl_file.c (dwarf_decl_file): Use attr CU instead of DIE + CU to resolve file name. + * dwarf_ranges.c(dwarf_ranges): Document which CU we use when. + * libdw.h (dwarf_attr_integrate): Extend documentation. + 2020-04-25 Mark Wielaard <mark@klomp.org> * libdw_alloc.c (__libdw_alloc_tail): Call Dwarf oom_handler() diff --git a/libdw/dwarf_decl_file.c b/libdw/dwarf_decl_file.c index 5657132f..d4aa0a18 100644 --- a/libdw/dwarf_decl_file.c +++ b/libdw/dwarf_decl_file.c @@ -55,7 +55,7 @@ dwarf_decl_file (Dwarf_Die *die) } /* Get the array of source files for the CU. */ - struct Dwarf_CU *cu = die->cu; + struct Dwarf_CU *cu = attr_mem.cu; if (cu->lines == NULL) { Dwarf_Lines *lines; diff --git a/libdw/dwarf_ranges.c b/libdw/dwarf_ranges.c index f67d8a5a..520f9ffe 100644 --- a/libdw/dwarf_ranges.c +++ b/libdw/dwarf_ranges.c @@ -506,6 +506,11 @@ dwarf_ranges (Dwarf_Die *die, ptrdiff_t offset, Dwarf_Addr *basep, Dwarf_Attribute attr_mem; Dwarf_Attribute *attr = INTUSE(dwarf_attr) (die, DW_AT_ranges, &attr_mem); + /* Note that above we use dwarf_attr, not dwarf_attr_integrate. + The only case where the ranges can come from another DIE + attribute are the split CU case. In that case we also have a + different CU to check against. But that is already set up + above using __libdw_find_split_unit. */ if (attr == NULL && is_cudie (die) && die->cu->unit_type == DW_UT_split_compile) diff --git a/libdw/libdw.h b/libdw/libdw.h index e20961be..1a4e15a1 100644 --- a/libdw/libdw.h +++ b/libdw/libdw.h @@ -474,7 +474,14 @@ extern Dwarf_Attribute *dwarf_attr (Dwarf_Die *die, unsigned int search_name, extern int dwarf_hasattr (Dwarf_Die *die, unsigned int search_name); /* These are the same as dwarf_attr and dwarf_hasattr, respectively, - but they resolve an indirect attribute through DW_AT_abstract_origin. */ + but they resolve an indirect attribute through + DW_AT_abstract_origin, DW_AT_specification or, if the DIE is a + top-level split CU, the skeleton DIE. Note that the attribute + might come from a DIE in a different CU (possibly from a different + Dwarf file). In that case all attribute information needs to be + resolved through the CU associated with the returned + Dwarf_Attribute. The dwarf_form functions already do this + automatically. */ extern Dwarf_Attribute *dwarf_attr_integrate (Dwarf_Die *die, unsigned int search_name, Dwarf_Attribute *result) |