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>
This commit is contained in:
Simon Marchi 2024-05-30 14:53:54 -04:00 committed by Simon Marchi
parent 9ad8c5832d
commit 0a70e1a8a9
15 changed files with 27 additions and 31 deletions

View 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)

View 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."));
}

View 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);

View 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. */

View 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 ();

View 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;

View 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
{

View 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;

View 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)

View 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 ();

View 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. */

View 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. */

View 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",

View 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 ();

View 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.