]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb: replace `get_exec_file (0)` calls with `current_program_space->exec_filename ()`
authorSimon Marchi <simon.marchi@efficios.com>
Thu, 30 May 2024 18:53:54 +0000 (14:53 -0400)
committerSimon Marchi <simon.marchi@polymtl.ca>
Sat, 8 Jun 2024 03:09:03 +0000 (23:09 -0400)
Calls of `get_exec_file (0)` are equivalent to just getting the exec
filename from the current program space.  I'm looking to remove
`get_exec_file`, so replace these uses with
`current_program_space->exec_filename ()`.

Remove the `err` parameter of `get_exec_wrapper` since all the calls
that remain pass 1, meaning to error out if no executable is specified.

Change-Id: I7729ea4c7f03dbb046211cc5aa3858ab3a551965
Approved-By: Tom Tromey <tom@tromey.com>
15 files changed:
gdb/bsd-kvm.c
gdb/corefile.c
gdb/elf-none-tdep.c
gdb/exec.c
gdb/fbsd-tdep.c
gdb/go32-nat.c
gdb/infcmd.c
gdb/nat/fork-inferior.c
gdb/nto-procfs.c
gdb/procfs.c
gdb/remote.c
gdb/symfile.c
gdb/target.c
gdbserver/server.cc
gdbsupport/common-inferior.h

index a1020b05b1939ba5d1c3a80326f11027821b5008..7ef8c349a6e7e1ea6055a0fb91490529fa6b950f 100644 (file)
@@ -108,7 +108,6 @@ static void
 bsd_kvm_target_open (const char *arg, int from_tty)
 {
   char errbuf[_POSIX2_LINE_MAX];
-  const char *execfile = NULL;
   kvm_t *temp_kd;
   std::string filename;
 
@@ -121,7 +120,7 @@ bsd_kvm_target_open (const char *arg, int from_tty)
        filename = gdb_abspath (filename.c_str ());
     }
 
-  execfile = get_exec_file (0);
+  const char *execfile = current_program_space->exec_filename ();
   temp_kd = kvm_openfiles (execfile, filename.c_str (), NULL,
                           write_files ? O_RDWR : O_RDONLY, errbuf);
   if (temp_kd == NULL)
index 3ae3fc7b633720f4a8e6b1ba7a642e88951dd1c0..aa35e3aa4e1f57d5f139b2dea03d0400485b908f 100644 (file)
@@ -79,14 +79,11 @@ validate_files (void)
 /* See gdbsupport/common-inferior.h.  */
 
 const char *
-get_exec_file (int err)
+get_exec_file ()
 {
   if (current_program_space->exec_filename () != nullptr)
     return current_program_space->exec_filename ();
 
-  if (!err)
-    return NULL;
-
   error (_("No executable file specified.\n\
 Use the \"file\" or \"exec-file\" command."));
 }
index 1e43dc2410369fbb426b6c93ac6a24670add29db..d46c41cb11d025478571c886c3e8ac2cc3dabbb3 100644 (file)
@@ -43,9 +43,9 @@ elf_none_make_corefile_notes (struct gdbarch *gdbarch, bfd *obfd,
   std::string psargs;
   static const size_t fname_len = 16;
   static const size_t psargs_len = 80;
-  if (get_exec_file (0))
+  if (current_program_space->exec_filename () != nullptr)
     {
-      const char *exe = get_exec_file (0);
+      const char *exe = current_program_space->exec_filename ();
       fname = lbasename (exe);
       psargs = std::string (exe);
 
index 4fe4d3bb50adbb0a42943055df1d8c2c16942a88..496f3b130708e81e3bd6163608c5fe42dd3ac54a 100644 (file)
@@ -215,7 +215,7 @@ validate_exec_file (int from_tty)
   if (exec_file_mismatch_mode == exec_file_mismatch_off)
     return;
 
-  const char *current_exec_file = get_exec_file (0);
+  const char *current_exec_file = current_program_space->exec_filename ();
   struct inferior *inf = current_inferior ();
   /* Try to determine a filename from the process itself.  */
   const char *pid_exec_file = target_pid_to_exec_file (inf->pid);
@@ -233,7 +233,7 @@ validate_exec_file (int from_tty)
      did not change).  If exec file changed, reopen_exec_file has
      allocated another file name, so get_exec_file again.  */
   reopen_exec_file ();
-  current_exec_file = get_exec_file (0);
+  current_exec_file = current_program_space->exec_filename ();
 
   const bfd_build_id *exec_file_build_id
     = build_id_bfd_get (current_program_space->exec_bfd ());
@@ -314,7 +314,7 @@ exec_file_locate_attach (int pid, int defer_bp_reset, int from_tty)
   symfile_add_flags add_flags = 0;
 
   /* Do nothing if we already have an executable filename.  */
-  if (get_exec_file (0) != NULL)
+  if (current_program_space->exec_filename () != nullptr)
     return;
 
   /* Try to determine a filename from the process itself.  */
index 77f46ced5917d47a2dcb04e8cf1471feb2a0af4d..367f6410cdd960f013db32cb9ae02446ef613cb6 100644 (file)
@@ -685,9 +685,9 @@ fbsd_make_corefile_notes (struct gdbarch *gdbarch, bfd *obfd, int *note_size)
 
   gdb_assert (gdbarch_iterate_over_regset_sections_p (gdbarch));
 
-  if (get_exec_file (0))
+  if (current_program_space->exec_filename () != nullptr)
     {
-      const char *fname = lbasename (get_exec_file (0));
+      const char *fname = lbasename (current_program_space->exec_filename ());
       std::string psargs = fname;
 
       const std::string &infargs = current_inferior ()->args ();
index 386c73ce26b1981c94fdd1c37d69ec2c4fd8ee2e..f59a7ed5a2bc9439fee6d0a62c044064921e96f9 100644 (file)
@@ -684,7 +684,7 @@ go32_nat_target::create_inferior (const char *exec_file,
   /* If no exec file handed to us, get it from the exec-file command -- with
      a good, common error message if none is specified.  */
   if (exec_file == 0)
-    exec_file = get_exec_file (1);
+    exec_file = get_exec_file ();
 
   resume_signal = -1;
   resume_is_step = 0;
index 69db665da75f26e76b878929d0faa818e8966425..71514d5ba66ea16d1694326428aecb76e5fea4a3 100644 (file)
@@ -368,7 +368,6 @@ enum run_how
 static void
 run_command_1 (const char *args, int from_tty, enum run_how run_how)
 {
-  const char *exec_file;
   struct ui_out *uiout = current_uiout;
   struct target_ops *run_target;
   int async_exec;
@@ -422,7 +421,7 @@ run_command_1 (const char *args, int from_tty, enum run_how run_how)
       tbreak_command (arg.c_str (), 0);
     }
 
-  exec_file = get_exec_file (0);
+  const char *exec_file = current_program_space->exec_filename ();
 
   /* We keep symbols from add-symbol-file, on the grounds that the
      user might want to add some symbols before running the program
@@ -2498,7 +2497,7 @@ setup_inferior (int from_tty)
 
   /* If no exec file is yet known, try to determine it from the
      process itself.  */
-  if (get_exec_file (0) == nullptr)
+  if (current_program_space->exec_filename () == nullptr)
     exec_file_locate_attach (inferior_ptid.pid (), 1, from_tty);
   else
     {
index c1082eb0441126edd5bf8c0196afc6104c5f633c..172eef0f93b021f76d0621e4f8e77a210cd07bfc 100644 (file)
@@ -282,7 +282,7 @@ fork_inferior (const char *exec_file_arg, const std::string &allargs,
   /* If no exec file handed to us, get it from the exec-file command
      -- with a good, common error message if none is specified.  */
   if (exec_file_arg == NULL)
-    exec_file = get_exec_file (1);
+    exec_file = get_exec_file ();
   else
     exec_file = exec_file_arg;
 
index 95a75b46d4fcd471493a7bc4296f3ba25d8f74a5..c3a45796dcc7810ad4aed4704c1819775770af8a 100644 (file)
@@ -1190,7 +1190,7 @@ nto_procfs_target::create_inferior (const char *exec_file,
 
   argv = xmalloc ((allargs.size () / (unsigned) 2 + 2) *
                  sizeof (*argv));
-  argv[0] = const_cast<char *> (get_exec_file (1));
+  argv[0] = const_cast<char *> (get_exec_file ());
   if (!argv[0])
     {
       if (exec_file)
index b5bda4dfb858f7e07e9c91d117872cf4999d2755..93d1113893d271b1c047a2decdfc2a8e999d6964 100644 (file)
@@ -3577,11 +3577,12 @@ procfs_target::make_corefile_notes (bfd *obfd, int *note_size)
   gdb::unique_xmalloc_ptr<char> note_data;
   enum gdb_signal stop_signal;
 
-  if (get_exec_file (0))
+  if (const auto exec_filename = current_program_space->exec_filename ();
+      exec_filename != nullptr)
     {
-      strncpy (fname, lbasename (get_exec_file (0)), sizeof (fname));
+      strncpy (fname, lbasename (exec_filename), sizeof (fname));
       fname[sizeof (fname) - 1] = 0;
-      strncpy (psargs, get_exec_file (0), sizeof (psargs));
+      strncpy (psargs, exec_filename, sizeof (psargs));
       psargs[sizeof (psargs) - 1] = 0;
 
       const std::string &inf_args = current_inferior ()->args ();
index 349bc8cf005e48acd50e6c29bc85fd9ef2f8f115..311430b12a1018eaa14d6afb0142b892f5580196 100644 (file)
@@ -2872,7 +2872,7 @@ remote_target::remote_add_inferior (bool fake_pid_p, int pid, int attached,
 
   /* If no main executable is currently open then attempt to
      open the file that was executed to create this inferior.  */
-  if (try_open_exec && get_exec_file (0) == NULL)
+  if (try_open_exec && current_program_space->exec_filename () == nullptr)
     exec_file_locate_attach (pid, 0, 1);
 
   /* Check for exec file mismatch, and let the user solve it.  */
index f7f5be5a39a580a402dca675a8df06fbbc80997b..0445e5a816511d761d6d277597ed51369551e96d 100644 (file)
@@ -1835,7 +1835,7 @@ load_command (const char *arg, int from_tty)
     {
       const char *parg, *prev;
 
-      arg = get_exec_file (1);
+      arg = get_exec_file ();
 
       /* We may need to quote this string so buildargv can pull it
         apart.  */
index 276e215945ef48d9d06e1eed11fdaf347f71d0b4..1b5aa11ed6f5d94f2f2983972e63cb666e08d389 100644 (file)
@@ -3574,7 +3574,7 @@ target_announce_detach (int from_tty)
     return;
 
   pid = inferior_ptid.pid ();
-  exec_file = get_exec_file (0);
+  exec_file = current_program_space->exec_filename ();
   if (exec_file == nullptr)
     gdb_printf ("Detaching from pid %s\n",
                target_pid_to_str (ptid_t (pid)).c_str ());
@@ -3592,7 +3592,7 @@ target_announce_attach (int from_tty, int pid)
   if (!from_tty)
     return;
 
-  const char *exec_file = get_exec_file (0);
+  const char *exec_file = current_program_space->exec_filename ();
 
   if (exec_file != nullptr)
     gdb_printf ("Attaching to program: %ps, %s\n",
index 789af36d9a42cbd496abba574cdaced7338da159..82f4318457cb2915d22a0643e124e42131be2894 100644 (file)
@@ -285,9 +285,9 @@ get_exec_wrapper ()
 /* See gdbsupport/common-inferior.h.  */
 
 const char *
-get_exec_file (int err)
+get_exec_file ()
 {
-  if (err && program_path.get () == NULL)
+  if (program_path.get () == NULL)
     error (_("No executable file specified."));
 
   return program_path.get ();
index bc6afd65f2b5f01914a916eea4d556cec7d198d1..9c19e9d9fdd93c6b94995d155dec62633c0e40e9 100644 (file)
@@ -28,9 +28,9 @@
 extern const char *get_exec_wrapper ();
 
 /* Return the name of the executable file as a string.
-   ERR nonzero means get error if there is none specified;
-   otherwise return 0 in that case.  */
-extern const char *get_exec_file (int err);
+
+   Error out if no executable is specified.  */
+extern const char *get_exec_file ();
 
 /* Return the inferior's current working directory.