[libbacktrace] Return struct dwarf_data pointer from elf_add
authorTom de Vries <tdevries@suse.de>
Thu, 17 Jan 2019 00:07:32 +0000 (00:07 +0000)
committerTom de Vries <vries@gcc.gnu.org>
Thu, 17 Jan 2019 00:07:32 +0000 (00:07 +0000)
Allow the caller of elf_add access to the struct dwarf_data pointer
corresponding to the added elf.

2019-01-17  Tom de Vries  <tdevries@suse.de>

* internal.h (backtrace_dwarf_add): Add fileline_entry parameter.
* dwarf.c (backtrace_dwarf_add): Add and handle fileline_entry parameter.
* elf.c (elf_add): Add and handle fileline_entry parameter.  Add
argument to backtrace_dwarf_add call.
(phdr_callback, backtrace_initialize): Add argument to elf_add calls.
* pecoff.c (coff_add): Add argument to backtrace_dwarf_add call.
* xcoff.c (xcoff_add): Same.

From-SVN: r267993

libbacktrace/ChangeLog
libbacktrace/dwarf.c
libbacktrace/elf.c
libbacktrace/internal.h
libbacktrace/pecoff.c
libbacktrace/xcoff.c

index d76341ac70e2dbe9040a7567d8b21b9719cd9234..f2d2954b1c6adbb42975a2da5ef2aada0a89b80c 100644 (file)
@@ -1,3 +1,13 @@
+2019-01-17  Tom de Vries  <tdevries@suse.de>
+
+       * internal.h (backtrace_dwarf_add): Add fileline_entry parameter.
+       * dwarf.c (backtrace_dwarf_add): Add and handle fileline_entry parameter.
+       * elf.c (elf_add): Add and handle fileline_entry parameter.  Add
+       argument to backtrace_dwarf_add call.
+       (phdr_callback, backtrace_initialize): Add argument to elf_add calls.
+       * pecoff.c (coff_add): Add argument to backtrace_dwarf_add call.
+       * xcoff.c (xcoff_add): Same.
+
 2019-01-17  Tom de Vries  <tdevries@suse.de>
 
        * elf.c (elf_add): Add and handle with_buildid_data and
index dca5d909d9f6473ef460d3d9ce86c9fef38a8583..190c6fc131f9f28bece08b6d2438f7484d8a0e04 100644 (file)
@@ -3064,7 +3064,8 @@ backtrace_dwarf_add (struct backtrace_state *state,
                     size_t dwarf_str_size,
                     int is_bigendian,
                     backtrace_error_callback error_callback,
-                    void *data, fileline *fileline_fn)
+                    void *data, fileline *fileline_fn,
+                    struct dwarf_data **fileline_entry)
 {
   struct dwarf_data *fdata;
 
@@ -3076,6 +3077,9 @@ backtrace_dwarf_add (struct backtrace_state *state,
   if (fdata == NULL)
     return 0;
 
+  if (fileline_entry != NULL)
+    *fileline_entry = fdata;
+
   if (!state->threaded)
     {
       struct dwarf_data **pp;
index abe4cded5e9c021188268b8f4f24311c427df682..a863327df10824f153e8e4148713e16158b8d817 100644 (file)
@@ -2638,8 +2638,8 @@ static int
 elf_add (struct backtrace_state *state, const char *filename, int descriptor,
         uintptr_t base_address, backtrace_error_callback error_callback,
         void *data, fileline *fileline_fn, int *found_sym, int *found_dwarf,
-        int exe, int debuginfo, const char *with_buildid_data,
-        uint32_t with_buildid_size)
+        struct dwarf_data **fileline_entry, int exe, int debuginfo,
+        const char *with_buildid_data, uint32_t with_buildid_size)
 {
   struct backtrace_view ehdr_view;
   b_elf_ehdr ehdr;
@@ -3042,7 +3042,8 @@ elf_add (struct backtrace_state *state, const char *filename, int descriptor,
            backtrace_release_view (state, &debugaltlink_view, error_callback,
                                    data);
          ret = elf_add (state, NULL, d, base_address, error_callback, data,
-                        fileline_fn, found_sym, found_dwarf, 0, 1, NULL, 0);
+                        fileline_fn, found_sym, found_dwarf, NULL, 0, 1, NULL,
+                        0);
          if (ret < 0)
            backtrace_close (d, error_callback, data);
          else
@@ -3080,7 +3081,8 @@ elf_add (struct backtrace_state *state, const char *filename, int descriptor,
            backtrace_release_view (state, &debugaltlink_view, error_callback,
                                    data);
          ret = elf_add (state, NULL, d, base_address, error_callback, data,
-                        fileline_fn, found_sym, found_dwarf, 0, 1, NULL, 0);
+                        fileline_fn, found_sym, found_dwarf, NULL, 0, 1, NULL,
+                        0);
          if (ret < 0)
            backtrace_close (d, error_callback, data);
          else
@@ -3106,8 +3108,9 @@ elf_add (struct backtrace_state *state, const char *filename, int descriptor,
          int ret;
 
          ret = elf_add (state, filename, d, base_address, error_callback, data,
-                        fileline_fn, found_sym, found_dwarf, 0, 1,
-                        debugaltlink_buildid_data, debugaltlink_buildid_size);
+                        fileline_fn, found_sym, found_dwarf, NULL,
+                        0, 1, debugaltlink_buildid_data,
+                        debugaltlink_buildid_size);
          backtrace_release_view (state, &debugaltlink_view, error_callback,
                                  data);
          debugaltlink_view_valid = 0;
@@ -3262,7 +3265,8 @@ elf_add (struct backtrace_state *state, const char *filename, int descriptor,
                            sections[DEBUG_STR].data,
                            sections[DEBUG_STR].size,
                            ehdr.e_ident[EI_DATA] == ELFDATA2MSB,
-                           error_callback, data, fileline_fn))
+                           error_callback, data, fileline_fn,
+                           fileline_entry))
     goto fail;
 
   *found_dwarf = 1;
@@ -3352,7 +3356,7 @@ phdr_callback (struct dl_phdr_info *info, size_t size ATTRIBUTE_UNUSED,
 
   if (elf_add (pd->state, filename, descriptor, info->dlpi_addr,
               pd->error_callback, pd->data, &elf_fileline_fn, pd->found_sym,
-              &found_dwarf, 0, 0, NULL, 0))
+              &found_dwarf, NULL, 0, 0, NULL, 0))
     {
       if (found_dwarf)
        {
@@ -3380,7 +3384,8 @@ backtrace_initialize (struct backtrace_state *state, const char *filename,
   struct phdr_data pd;
 
   ret = elf_add (state, filename, descriptor, 0, error_callback, data,
-                &elf_fileline_fn, &found_sym, &found_dwarf, 1, 0, NULL, 0);
+                &elf_fileline_fn, &found_sym, &found_dwarf, NULL, 1, 0, NULL,
+                0);
   if (!ret)
     return 0;
 
index bf3e7d1989f57bb5918a00354b4ccbd34fed5a5a..d9ab401ce416b9f42b29a1045edac6dff644f786 100644 (file)
@@ -286,6 +286,8 @@ extern int backtrace_initialize (struct backtrace_state *state,
                                 void *data,
                                 fileline *fileline_fn);
 
+struct dwarf_data;
+
 /* Add file/line information for a DWARF module.  */
 
 extern int backtrace_dwarf_add (struct backtrace_state *state,
@@ -302,7 +304,8 @@ extern int backtrace_dwarf_add (struct backtrace_state *state,
                                size_t dwarf_str_size,
                                int is_bigendian,
                                backtrace_error_callback error_callback,
-                               void *data, fileline *fileline_fn);
+                               void *data, fileline *fileline_fn,
+                               struct dwarf_data **fileline_entry);
 
 /* A test-only hook for elf_uncompress_zdebug.  */
 
index f51fc0f13c5b81a84387e61497b91ef1120d5ef1..cd20cbe17a740182902cce2e67f637cdfc2b100a 100644 (file)
@@ -867,7 +867,8 @@ coff_add (struct backtrace_state *state, int descriptor,
                            sections[DEBUG_STR].data,
                            sections[DEBUG_STR].size,
                            0, /* FIXME */
-                           error_callback, data, fileline_fn))
+                           error_callback, data, fileline_fn,
+                           NULL))
     goto fail;
 
   *found_dwarf = 1;
index 111134d4d216468e84d7bca8cf4148f7f89e36af..095800b4f717d9e7602727c0691a3cfd3b889ebe 100644 (file)
@@ -1315,7 +1315,8 @@ xcoff_add (struct backtrace_state *state, int descriptor, off_t offset,
                                dwsect[DWSECT_STR].data,
                                dwsect[DWSECT_STR].size,
                                1, /* big endian */
-                               error_callback, data, fileline_fn))
+                               error_callback, data, fileline_fn,
+                               NULL))
        goto fail;
     }