]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
eu-stack: add support for sysroot option
authorLuke Diamand <ldiamand@roku.com>
Tue, 2 Jul 2024 17:30:59 +0000 (19:30 +0200)
committerAaron Merey <amerey@redhat.com>
Thu, 4 Jul 2024 22:41:23 +0000 (18:41 -0400)
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

index f4c5ba8c4df9042c3ca747e86914c02c43d8d9bf..eb87f5f137b268892cf5c94e63e68b736165dbcd 100644 (file)
@@ -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 }
     };