]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Add a 'set program-interpreter' command.
authorJohn Baldwin <jhb@FreeBSD.org>
Thu, 28 May 2020 17:58:54 +0000 (10:58 -0700)
committerJohn Baldwin <jhb@FreeBSD.org>
Thu, 1 Sep 2022 23:47:42 +0000 (16:47 -0700)
This is a bit of a hack, but it allows you to override the initial
path to the runtime linker instead of having GDB always trust the
contents of .interp.  This is useful for running purecap binaries
under a hybrid world or vice versa via 'run'.

gdb/solib-svr4.c

index 98c8522ffd5bacc5ec6d450687b490150f4260cd..cca55b87c6cd26433784448779efbd8bf67cbec1 100644 (file)
@@ -28,6 +28,7 @@
 #include "symfile.h"
 #include "objfiles.h"
 #include "gdbcore.h"
+#include "gdbcmd.h"
 #include "target.h"
 #include "inferior.h"
 #include "infrun.h"
@@ -552,11 +553,32 @@ read_program_header (int type, int *p_arch_size, CORE_ADDR *base_addr)
   return buf;
 }
 
+/* If non-empty, overrides the value of .interp in binaries.  */
+static std::string program_interpreter;
+
+static void
+show_program_interpreter (struct ui_file *file, int from_tty,
+                         struct cmd_list_element *c, const char *value)
+{
+  if (value == NULL || value[0] == '\0')
+    fprintf_filtered (file,
+                     _("The program interpreter override is not set.\n"));
+  else
+    fprintf_filtered (file, _("The program interpreter is %s.\n"), value);
+}
 
 /* Return program interpreter string.  */
 static gdb::optional<gdb::byte_vector>
 find_program_interpreter (void)
 {
+  if (!program_interpreter.empty ())
+    {
+      size_t len = program_interpreter.length () + 1;
+      gdb::byte_vector buf (len);
+      memcpy(buf.data (), program_interpreter.c_str (), len);
+      return buf;
+    }
+
   /* If we have a current exec_bfd, use its section table.  */
   if (current_program_space->exec_bfd ()
       && (bfd_get_flavour (current_program_space->exec_bfd ())
@@ -3244,4 +3266,14 @@ _initialize_svr4_solib ()
 
   gdb::observers::free_objfile.attach (svr4_free_objfile_observer,
                                       "solib-svr4");
+
+  add_setshow_optional_filename_cmd ("program-interpreter", class_support,
+                                    &program_interpreter, _("\
+Set a program interpreter override."), _("\
+Show the current program interpreter override."), _("\
+The program interpreter override is used to locate a program interpreter\n\
+instead of the .interp section."),
+                                    NULL,
+                                    show_program_interpreter,
+                                    &setlist, &showlist);
 }