]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
eu-stacktrace WIP: optional debuginfo callbacks as in stack.c
authorSerhei Makarov <serhei@serhei.io>
Fri, 26 Jan 2024 17:56:00 +0000 (12:56 -0500)
committerSerhei Makarov <serhei@serhei.io>
Fri, 26 Jan 2024 17:57:08 +0000 (12:57 -0500)
This is an #ifdef option since it's really of dubious utility.

src/stacktrace.c

index 6519915bf6a5ce973b6eb631a016ed70783cf486..77b208322d4dbbbacf37e324e255d5de532d696e 100644 (file)
@@ -151,9 +151,14 @@ static bool show_samples = false;
 static bool show_failures = true; /* TODO: disable by default in release version */
 static bool show_summary = true; /* TODO: disable by default in release version */
 
-/* Enable to show even more diagnostics on modules: */
+/* Enables even more diagnostics on modules: */
 /* #define DEBUG_MODULES */
 
+/* Enables standard access to DWARF debuginfo, matching stack.c.
+   This is of dubious benefit -- for profiling, we really should
+   aim to resolve everything with minimal overhead using eh CFI. */
+/* #define FIND_DEBUGINFO */
+
 /* Program exit codes.  All samples processed without any errors is
    GOOD.  Some non-fatal errors during processing is an ERROR.  A
    fatal error or no samples processed at all is BAD.  A command line
@@ -639,6 +644,19 @@ static const Dwfl_Thread_Callbacks sample_thread_callbacks =
   NULL, /* sample_thread_detach */
 };
 
+#ifdef FIND_DEBUGINFO
+
+static char *debuginfo_path = NULL;
+
+static const Dwfl_Callbacks sample_callbacks =
+  {
+    .find_elf = dwfl_linux_proc_find_elf,
+    .find_debuginfo = dwfl_standard_find_debuginfo,
+    .debuginfo_path = &debuginfo_path,
+  };
+
+#else
+
 int
 nop_find_debuginfo (Dwfl_Module *mod __attribute__((unused)),
                    void **userdata __attribute__((unused)),
@@ -650,7 +668,7 @@ nop_find_debuginfo (Dwfl_Module *mod __attribute__((unused)),
                    char **debuginfo_file_name __attribute__((unused)))
 {
 #ifdef DEBUG_MODULES
-  fprintf(stderr, "DEBUG nop_find_debuginfo modname=%s file_name=%s debuglink_file=%s\n",
+  fprintf(stderr, "nop_find_debuginfo: modname=%s file_name=%s debuglink_file=%s\n",
          modname, file_name, debuglink_file);
 #endif
   return -1;
@@ -662,6 +680,8 @@ static const Dwfl_Callbacks sample_callbacks =
   .find_debuginfo = nop_find_debuginfo, /* work with CFI only */
 };
 
+#endif /* FIND_DEBUGINFO */
+
 /* TODO: Code mirrors dwfl_linux_proc_attach();
    should probably move this function to libdwfl/linux-pid-attach.c
    and switch to including the public dwfl interface? */