From: Djordje Todorovic Date: Tue, 26 Sep 2017 13:45:10 +0000 (+0200) Subject: dwarflint: Remember the referring CU when read src lines X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=bd121d61b6772149d1a5c8bfdaa5605199a55fec;p=thirdparty%2Felfutils.git dwarflint: Remember the referring CU when read src lines Signed-off-by: Djordje Todorovic --- diff --git a/libdw/dwarf_getsrclines.c b/libdw/dwarf_getsrclines.c index d02c38db4..51ffea730 100644 --- a/libdw/dwarf_getsrclines.c +++ b/libdw/dwarf_getsrclines.c @@ -147,13 +147,16 @@ add_new_line (struct line_state *state, struct linelist *new_line) } static int -read_srclines (Dwarf *dbg, +read_srclines (Dwarf_Die *cudie, Dwarf *dbg, const unsigned char *linep, const unsigned char *lineendp, const char *comp_dir, unsigned address_size, Dwarf_Lines **linesp, Dwarf_Files **filesp) { int res = -1; + /* Get the information if it is not already known. */ + struct Dwarf_CU *const cu = cudie->cu; + size_t nfilelist = 0; unsigned int ndirlist = 0; @@ -763,6 +766,12 @@ read_srclines (Dwarf *dbg, if (filesp != NULL) *filesp = files; + /* Remember the referring CU. */ + files->cu = cu; + + /* Make the file data structure available through the CU. */ + cu->files = files; + size_t buf_size = (sizeof (Dwarf_Lines) + (sizeof (Dwarf_Line) * state.nlinelist)); void *buf = libdw_alloc (dbg, Dwarf_Lines, buf_size, 1); @@ -848,7 +857,7 @@ files_lines_compare (const void *p1, const void *p2) int internal_function -__libdw_getsrclines (Dwarf *dbg, Dwarf_Off debug_line_offset, +__libdw_getsrclines (Dwarf_Die *cudie, Dwarf *dbg, Dwarf_Off debug_line_offset, const char *comp_dir, unsigned address_size, Dwarf_Lines **linesp, Dwarf_Files **filesp) { @@ -869,7 +878,7 @@ __libdw_getsrclines (Dwarf *dbg, Dwarf_Off debug_line_offset, struct files_lines_s *node = libdw_alloc (dbg, struct files_lines_s, sizeof *node, 1); - if (read_srclines (dbg, linep, lineendp, comp_dir, address_size, + if (read_srclines (cudie, dbg, linep, lineendp, comp_dir, address_size, &node->lines, &node->files) != 0) return -1; @@ -934,7 +943,7 @@ dwarf_getsrclines (Dwarf_Die *cudie, Dwarf_Lines **lines, size_t *nlines) NULL, &debug_line_offset) == NULL) return -1; - if (__libdw_getsrclines (cu->dbg, debug_line_offset, + if (__libdw_getsrclines (cudie, cu->dbg, debug_line_offset, __libdw_getcompdir (cudie), cu->address_size, &cu->lines, &cu->files) < 0) return -1; diff --git a/libdw/dwarf_macro_getsrcfiles.c b/libdw/dwarf_macro_getsrcfiles.c index 3b1794b11..2b0b8122c 100644 --- a/libdw/dwarf_macro_getsrcfiles.c +++ b/libdw/dwarf_macro_getsrcfiles.c @@ -33,7 +33,7 @@ #include "libdwP.h" int -dwarf_macro_getsrcfiles (Dwarf *dbg, Dwarf_Macro *macro, +dwarf_macro_getsrcfiles (Dwarf_Die *cudie, Dwarf *dbg, Dwarf_Macro *macro, Dwarf_Files **files, size_t *nfiles) { /* macro is declared NN */ @@ -71,7 +71,7 @@ dwarf_macro_getsrcfiles (Dwarf *dbg, Dwarf_Macro *macro, the same unit through dwarf_getsrcfiles, and the file names will be broken. */ - if (__libdw_getsrclines (dbg, line_offset, table->comp_dir, + if (__libdw_getsrclines (cudie, dbg, line_offset, table->comp_dir, table->is_64bit ? 8 : 4, NULL, &table->files) < 0) table->files = (void *) -1; diff --git a/libdw/libdw.h b/libdw/libdw.h index e42c08739..26f6a5670 100644 --- a/libdw/libdw.h +++ b/libdw/libdw.h @@ -895,8 +895,8 @@ extern ptrdiff_t dwarf_getmacros_off (Dwarf *dbg, Dwarf_Off macoff, invalid. (Which is to say it's only valid within the dwarf_getmacros* callback.) Returns 0 for success or a negative value in case of an error. */ -extern int dwarf_macro_getsrcfiles (Dwarf *dbg, Dwarf_Macro *macro, - Dwarf_Files **files, size_t *nfiles) +extern int dwarf_macro_getsrcfiles (Dwarf_Die *cudie, Dwarf *dbg, + Dwarf_Macro *macro, Dwarf_Files **files, size_t *nfiles) __nonnull_attribute__ (2, 3, 4); /* Return macro opcode. That's a constant that can be either from diff --git a/libdw/libdwP.h b/libdw/libdwP.h index 673263cfe..3962197c0 100644 --- a/libdw/libdwP.h +++ b/libdw/libdwP.h @@ -771,7 +771,7 @@ void __libdw_empty_loc_attr (Dwarf_Attribute *attr) the loaded unit and optionally set *LINESP and/or *FILESP (if not NULL) with loaded information. Returns 0 for success or a negative value for failure. */ -int __libdw_getsrclines (Dwarf *dbg, Dwarf_Off debug_line_offset, +int __libdw_getsrclines (Dwarf_Die *cudie, Dwarf *dbg, Dwarf_Off debug_line_offset, const char *comp_dir, unsigned address_size, Dwarf_Lines **linesp, Dwarf_Files **filesp) internal_function diff --git a/tests/dwarf-getmacros.c b/tests/dwarf-getmacros.c index ac70248dd..644f50b4e 100644 --- a/tests/dwarf-getmacros.c +++ b/tests/dwarf-getmacros.c @@ -60,7 +60,9 @@ mac (Dwarf_Macro *macro, void *dbg) { Dwarf_Files *files; size_t nfiles; - if (dwarf_macro_getsrcfiles (dbg, macro, &files, &nfiles) < 0) + Dwarf_Die cudie_mem, *cudie = dwarf_offdie (dbg, 0, &cudie_mem); + + if (dwarf_macro_getsrcfiles (cudie, dbg, macro, &files, &nfiles) < 0) printf ("dwarf_macro_getsrcfiles: %s\n", dwarf_errmsg (dwarf_errno ()));