From: John Baldwin Date: Thu, 28 May 2020 17:58:54 +0000 (-0700) Subject: Add a 'set program-interpreter' command. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5523045f81c619c1e586377f84498f3c97aa94e5;p=thirdparty%2Fbinutils-gdb.git Add a 'set program-interpreter' command. 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'. --- diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c index 98c8522ffd5..cca55b87c6c 100644 --- a/gdb/solib-svr4.c +++ b/gdb/solib-svr4.c @@ -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 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); }