]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
dwarflint: Remember the referring CU when read src lines
authorDjordje Todorovic <djordje.todorovic@rt-rk.com>
Tue, 26 Sep 2017 13:45:10 +0000 (15:45 +0200)
committerMark Wielaard <mark@klomp.org>
Fri, 6 Oct 2017 19:38:48 +0000 (21:38 +0200)
Signed-off-by: Djordje Todorovic <djordje.todorovic@rt-rk.com>
libdw/dwarf_getsrclines.c
libdw/dwarf_macro_getsrcfiles.c
libdw/libdw.h
libdw/libdwP.h
tests/dwarf-getmacros.c

index d02c38db40eb8f01b19acb662f214fa62b057d89..51ffea730b8c4bfcbb83fe20488a6d57c9fcf9f4 100644 (file)
@@ -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;
index 3b1794b112f3061ee9271a5cefb7dfbb2afaadf7..2b0b8122cce38a42de43a655fa5fb822f2e47188 100644 (file)
@@ -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;
index e42c087397bb2e0ec6fe2aff0ac9b4c5948af0a2..26f6a56701afbdf272898d9c9f0fa34b412a2948 100644 (file)
@@ -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
index 673263cfe7461bc33b47a2c0cf1ca55b5c34f0db..3962197c0628bd38076c9fbce58cb6356a6c97ff 100644 (file)
@@ -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
index ac70248ddabb934c1331bcfe0e9303280fa094b4..644f50b4ef13318a2df3197f1053dd1ec970d114 100644 (file)
@@ -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 ()));