[PATCH v2 2/3] eu-stack: add support for sysroot option

Michal Sekletar msekleta@redhat.com
Tue Jul 2 17:30:59 GMT 2024


From: Luke Diamand <ldiamand@roku.com>

Use the dwfl_set_sysroot() function to set the sysroot to be
used when analysing a core:

e.g.
   $ eu-stack --core core --sysroot /path/to/sysroot -e crashing_prog

Signed-off-by: Luke Diamand <ldiamand@roku.com>
Signed-off-by: Michal Sekletar <msekleta@redhat.com>
---
 src/stack.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/src/stack.c b/src/stack.c
index f4c5ba8c..79c9af9c 100644
--- a/src/stack.c
+++ b/src/stack.c
@@ -73,6 +73,7 @@ static int core_fd = -1;
 static Elf *core = NULL;
 static const char *exec = NULL;
 static char *debuginfo_path = NULL;
+static const char *sysroot = NULL;
 
 static const Dwfl_Callbacks proc_callbacks =
   {
@@ -559,6 +560,10 @@ parse_opt (int key, char *arg __attribute__ ((unused)),
       show_modules = true;
       break;
 
+    case 'S':
+      sysroot = arg;
+      break;
+
     case ARGP_KEY_END:
       if (core == NULL && exec != NULL)
 	argp_error (state,
@@ -592,6 +597,8 @@ parse_opt (int key, char *arg __attribute__ ((unused)),
 	  dwfl = dwfl_begin (&core_callbacks);
 	  if (dwfl == NULL)
 	    error (EXIT_BAD, 0, "dwfl_begin: %s", dwfl_errmsg (-1));
+	  if (sysroot && dwfl_set_sysroot (dwfl, sysroot) < 0)
+	    error (EXIT_BAD, 0, "dwfl_set_sysroot: %m");
 	  if (dwfl_core_file_report (dwfl, core, exec) < 0)
 	    error (EXIT_BAD, 0, "dwfl_core_file_report: %s", dwfl_errmsg (-1));
 	}
@@ -675,6 +682,8 @@ main (int argc, char **argv)
 	N_("Show at most MAXFRAMES per thread (default 256, use 0 for unlimited)"), 0 },
       { "list-modules", 'l', NULL, 0,
 	N_("Show module memory map with build-id, elf and debug files detected"), 0 },
+      { "sysroot", 'S', "sysroot", 0,
+  N_("Set the sysroot to search for libraries referenced from the core file"), 0 },
       { NULL, 0, NULL, 0, NULL, 0 }
     };
 
-- 
2.39.3 (Apple Git-146)



More information about the Elfutils-devel mailing list