public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] libdwfl: add dwfl_local_find_debuginfo callback
@ 2021-06-13  3:27 Nick Gasson
  2021-07-02 21:59 ` Mark Wielaard
  0 siblings, 1 reply; 3+ messages in thread
From: Nick Gasson @ 2021-06-13  3:27 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Nick Gasson

This patch adds a variant of dwfl_standard_find_debuginfo that only
searches the local filesystem and does not fall back to debuginfod.

In my application I am using libdw to decode stack traces where some of
the loaded DSOs are generated on-the-fly by LLVM.  If these don't have
debug information I want the find_debuginfo callback to fail immediately
and not fall back to debuginfod which will never succeed.  Similarly if
the main executable is stripped.  I supposed I could unset the
DEBUGINFOD_URLS environment variable before calling into libdw, but that
seems a bit hacky and liable to break in the future if the debuginfod
client loads the URLs from a different place.

Signed-off-by: Nick Gasson <nick@nickg.me.uk>
---
 libdw/libdw.map          |  1 +
 libdwfl/find-debuginfo.c | 40 ++++++++++++++++++++++++++++++++--------
 libdwfl/libdwfl.h        |  9 ++++++++-
 libdwfl/libdwflP.h       |  1 +
 4 files changed, 42 insertions(+), 9 deletions(-)

diff --git a/libdw/libdw.map b/libdw/libdw.map
index 8ab0a2a062da..b8593f8ebf56 100644
--- a/libdw/libdw.map
+++ b/libdw/libdw.map
@@ -114,6 +114,7 @@ ELFUTILS_0.122 {
     dwfl_linux_proc_find_elf;
     dwfl_linux_proc_maps_report;
     dwfl_linux_proc_report;
+    dwfl_local_find_debuginfo;
     dwfl_module_addrdie;
     dwfl_module_addrname;
     dwfl_module_getdwarf;
diff --git a/libdwfl/find-debuginfo.c b/libdwfl/find-debuginfo.c
index 449df5a14b19..51f3fe622b07 100644
--- a/libdwfl/find-debuginfo.c
+++ b/libdwfl/find-debuginfo.c
@@ -346,14 +346,14 @@ fail_free:
 }
 
 int
-dwfl_standard_find_debuginfo (Dwfl_Module *mod,
-			      void **userdata __attribute__ ((unused)),
-			      const char *modname __attribute__ ((unused)),
-			      GElf_Addr base __attribute__ ((unused)),
-			      const char *file_name,
-			      const char *debuglink_file,
-			      GElf_Word debuglink_crc,
-			      char **debuginfo_file_name)
+dwfl_local_find_debuginfo (Dwfl_Module *mod,
+			   void **userdata __attribute__ ((unused)),
+			   const char *modname __attribute__ ((unused)),
+			   GElf_Addr base __attribute__ ((unused)),
+			   const char *file_name,
+			   const char *debuglink_file,
+			   GElf_Word debuglink_crc,
+			   char **debuginfo_file_name)
 {
   if (mod == NULL)
     return -1;
@@ -401,6 +401,28 @@ dwfl_standard_find_debuginfo (Dwfl_Module *mod,
       free (canon);
     }
 
+  return fd;
+}
+INTDEF (dwfl_local_find_debuginfo)
+
+int
+dwfl_standard_find_debuginfo (Dwfl_Module *mod,
+			      void **userdata,
+			      const char *modname,
+			      GElf_Addr base,
+			      const char *file_name,
+			      const char *debuglink_file,
+			      GElf_Word debuglink_crc,
+			      char **debuginfo_file_name)
+{
+  /* First try to find debug information in the local filesystem. */
+  int fd = INTUSE(dwfl_local_find_debuginfo) (mod, userdata,
+					      modname, base,
+					      file_name,
+					      debuglink_file,
+					      debuglink_crc,
+					      debuginfo_file_name);
+
 #ifdef ENABLE_LIBDEBUGINFOD
   /* Still nothing? Try if we can use the debuginfod client.
      But note that we might be looking for the alt file.
@@ -412,6 +434,8 @@ dwfl_standard_find_debuginfo (Dwfl_Module *mod,
      handles build-ids.  */
   if (fd < 0)
     {
+      const unsigned char *bits = NULL;
+      int bits_len = 0;
       if (mod->dw != NULL)
 	{
 	  const char *altname;
diff --git a/libdwfl/libdwfl.h b/libdwfl/libdwfl.h
index f98f1d525d94..9d3eb43729c7 100644
--- a/libdwfl/libdwfl.h
+++ b/libdwfl/libdwfl.h
@@ -292,12 +292,19 @@ extern int dwfl_build_id_find_debuginfo (Dwfl_Module *, void **,
    If there is no build ID or no valid debuginfo found by ID,
    it searches the debuginfo path by name, as described above.
    Any file found in the path is validated by build ID if possible,
-   or else by CRC32 checksum if enabled, and skipped if it does not match.  */
+   or else by CRC32 checksum if enabled, and skipped if it does not match.
+   The debuginfod client is consulted if no debug information is found
+   in the local filesystem. */
 extern int dwfl_standard_find_debuginfo (Dwfl_Module *, void **,
 					 const char *, Dwarf_Addr,
 					 const char *, const char *,
 					 GElf_Word, char **);
 
+/* As dwfl_standard_find_debuginfo, but does not fall back to debuginfod. */
+extern int dwfl_local_find_debuginfo (Dwfl_Module *, void **,
+				      const char *, Dwarf_Addr,
+				      const char *, const char *,
+				      GElf_Word, char **);
 
 /* This callback must be used when using dwfl_offline_* to report modules,
    if ET_REL is to be supported.  */
diff --git a/libdwfl/libdwflP.h b/libdwfl/libdwflP.h
index 4344e356b452..8be4f341bbab 100644
--- a/libdwfl/libdwflP.h
+++ b/libdwfl/libdwflP.h
@@ -760,6 +760,7 @@ INTDECL (dwfl_report_end)
 INTDECL (dwfl_build_id_find_elf)
 INTDECL (dwfl_build_id_find_debuginfo)
 INTDECL (dwfl_standard_find_debuginfo)
+INTDECL (dwfl_local_find_debuginfo)
 INTDECL (dwfl_link_map_report)
 INTDECL (dwfl_linux_kernel_find_elf)
 INTDECL (dwfl_linux_kernel_module_section_address)
-- 
2.30.2


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-07-04 14:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-13  3:27 [PATCH] libdwfl: add dwfl_local_find_debuginfo callback Nick Gasson
2021-07-02 21:59 ` Mark Wielaard
2021-07-04 14:12   ` Nick Gasson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).