diff options
author | Simon Marchi <simon.marchi@efficios.com> | 2024-05-30 14:53:54 -0400 |
---|---|---|
committer | Simon Marchi <simon.marchi@polymtl.ca> | 2024-06-07 23:09:03 -0400 |
commit | 0a70e1a8a94b29d9fe461d0a401f7c2d02f8c441 (patch) | |
tree | 5ae3a4d8a02f58e11b6fc168e2451a12ee7f65af /gdb | |
parent | 9ad8c5832d0092e1c02069b1189ec0ff59089957 (diff) | |
download | gdb-0a70e1a8a94b29d9fe461d0a401f7c2d02f8c441.zip gdb-0a70e1a8a94b29d9fe461d0a401f7c2d02f8c441.tar.gz gdb-0a70e1a8a94b29d9fe461d0a401f7c2d02f8c441.tar.bz2 |
gdb: replace `get_exec_file (0)` calls with `current_program_space->exec_filename ()`
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>
Diffstat (limited to 'gdb')
-rw-r--r-- | gdb/bsd-kvm.c | 3 | ||||
-rw-r--r-- | gdb/corefile.c | 5 | ||||
-rw-r--r-- | gdb/elf-none-tdep.c | 4 | ||||
-rw-r--r-- | gdb/exec.c | 6 | ||||
-rw-r--r-- | gdb/fbsd-tdep.c | 4 | ||||
-rw-r--r-- | gdb/go32-nat.c | 2 | ||||
-rw-r--r-- | gdb/infcmd.c | 5 | ||||
-rw-r--r-- | gdb/nat/fork-inferior.c | 2 | ||||
-rw-r--r-- | gdb/nto-procfs.c | 2 | ||||
-rw-r--r-- | gdb/procfs.c | 7 | ||||
-rw-r--r-- | gdb/remote.c | 2 | ||||
-rw-r--r-- | gdb/symfile.c | 2 | ||||
-rw-r--r-- | gdb/target.c | 4 |
13 files changed, 22 insertions, 26 deletions
diff --git a/gdb/bsd-kvm.c b/gdb/bsd-kvm.c index a1020b0..7ef8c34 100644 --- a/gdb/bsd-kvm.c +++ b/gdb/bsd-kvm.c @@ -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) diff --git a/gdb/corefile.c b/gdb/corefile.c index 3ae3fc7..aa35e3a 100644 --- a/gdb/corefile.c +++ b/gdb/corefile.c @@ -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.")); } diff --git a/gdb/elf-none-tdep.c b/gdb/elf-none-tdep.c index 1e43dc2..d46c41c 100644 --- a/gdb/elf-none-tdep.c +++ b/gdb/elf-none-tdep.c @@ -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); @@ -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. */ diff --git a/gdb/fbsd-tdep.c b/gdb/fbsd-tdep.c index 77f46ce..367f641 100644 --- a/gdb/fbsd-tdep.c +++ b/gdb/fbsd-tdep.c @@ -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 (); diff --git a/gdb/go32-nat.c b/gdb/go32-nat.c index 386c73c..f59a7ed 100644 --- a/gdb/go32-nat.c +++ b/gdb/go32-nat.c @@ -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; diff --git a/gdb/infcmd.c b/gdb/infcmd.c index 69db665..71514d5 100644 --- a/gdb/infcmd.c +++ b/gdb/infcmd.c @@ -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 { diff --git a/gdb/nat/fork-inferior.c b/gdb/nat/fork-inferior.c index c1082eb..172eef0 100644 --- a/gdb/nat/fork-inferior.c +++ b/gdb/nat/fork-inferior.c @@ -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; diff --git a/gdb/nto-procfs.c b/gdb/nto-procfs.c index 95a75b4..c3a4579 100644 --- a/gdb/nto-procfs.c +++ b/gdb/nto-procfs.c @@ -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) diff --git a/gdb/procfs.c b/gdb/procfs.c index b5bda4d..93d1113 100644 --- a/gdb/procfs.c +++ b/gdb/procfs.c @@ -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 (); diff --git a/gdb/remote.c b/gdb/remote.c index 349bc8c..311430b 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -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. */ diff --git a/gdb/symfile.c b/gdb/symfile.c index f7f5be5..0445e5a 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -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. */ diff --git a/gdb/target.c b/gdb/target.c index 276e215..1b5aa11 100644 --- a/gdb/target.c +++ b/gdb/target.c @@ -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", |