From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id A9120385840F for ; Thu, 30 May 2024 18:55:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A9120385840F Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=efficios.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=efficios.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A9120385840F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=158.69.221.121 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1717095309; cv=none; b=OqjVXLROAmemRlRHLEBnfjXhGYNbmKTy+OCdktP3nBv6elIZvxPrcy+EJSFgRwvjGxcRdk8+GHUIF/XUnLqIgdek473cgS1ijVkO6j9Zx2chSh4GwxfMP0tRLnxk2eze357G7/0puSCqC8m3M9pn8ftUJYHVtPN21fr8X9EGm+0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1717095309; c=relaxed/simple; bh=mtClCD1CeIcFL+8vffn7duZiVsnhqhvE5yD1tPbqT3s=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=jPfxEfgHHEbdrpBWZYsv1aUG1jr0F6EOc55VTc4HSITl7RS4Zd6vvuvO1iF2IZKLw7AZ8lhwCFNJHuQB5+/WFakoQLr9Mwpnv+MPV6tJT4fiw+WHt5oHT4hSUPfLVGTrcyiUOTIKQMuH41vLXlS7fztLThyk99k8cCE45Vd6rj0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from localhost.localdomain (unknown [142.169.16.229]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 00FC11E0C1; Thu, 30 May 2024 14:55:05 -0400 (EDT) From: Simon Marchi To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH 2/4] gdb: replace `get_exec_file (0)` calls with `current_program_space->exec_filename ()` Date: Thu, 30 May 2024 14:53:54 -0400 Message-ID: <20240530185509.265901-3-simon.marchi@efficios.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240530185509.265901-1-simon.marchi@efficios.com> References: <20240530185509.265901-1-simon.marchi@efficios.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1171.3 required=5.0 tests=BAYES_00,GIT_PATCH_0,KAM_DMARC_NONE,KAM_DMARC_STATUS,RCVD_IN_BARRACUDACENTRAL,SPF_HELO_PASS,SPF_SOFTFAIL,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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 --- gdb/bsd-kvm.c | 3 +-- gdb/corefile.c | 5 +---- gdb/elf-none-tdep.c | 4 ++-- gdb/exec.c | 6 +++--- gdb/fbsd-tdep.c | 4 ++-- gdb/go32-nat.c | 2 +- gdb/infcmd.c | 5 ++--- gdb/nat/fork-inferior.c | 2 +- gdb/nto-procfs.c | 2 +- gdb/procfs.c | 7 ++++--- gdb/remote.c | 2 +- gdb/symfile.c | 2 +- gdb/target.c | 4 ++-- gdbserver/server.cc | 4 ++-- gdbsupport/common-inferior.h | 6 +++--- 15 files changed, 27 insertions(+), 31 deletions(-) diff --git a/gdb/bsd-kvm.c b/gdb/bsd-kvm.c index a1020b05b193..7ef8c349a6e7 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 3ae3fc7b6337..aa35e3aa4e1f 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 00d46992b248..8763aa85406f 100644 --- a/gdb/elf-none-tdep.c +++ b/gdb/elf-none-tdep.c @@ -42,9 +42,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); diff --git a/gdb/exec.c b/gdb/exec.c index 4fe4d3bb50ad..496f3b130708 100644 --- a/gdb/exec.c +++ b/gdb/exec.c @@ -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 a80f604fa780..000635748de5 100644 --- a/gdb/fbsd-tdep.c +++ b/gdb/fbsd-tdep.c @@ -684,9 +684,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 386c73ce26b1..f59a7ed5a2bc 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 02f6f0b3683f..c40500b62d9f 100644 --- a/gdb/infcmd.c +++ b/gdb/infcmd.c @@ -367,7 +367,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; @@ -421,7 +420,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 @@ -2497,7 +2496,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 c1082eb04411..172eef0f93b0 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 95a75b46d4fc..c3a45796dcc7 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 (get_exec_file (1)); + argv[0] = const_cast (get_exec_file ()); if (!argv[0]) { if (exec_file) diff --git a/gdb/procfs.c b/gdb/procfs.c index b5bda4dfb858..93d1113893d2 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 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 965427c96a0d..38e406078982 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -2870,7 +2870,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 7ebb07d5394b..78e68139c6f7 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -1843,7 +1843,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 ddf10c28e1c7..de360f044562 100644 --- a/gdb/target.c +++ b/gdb/target.c @@ -3572,7 +3572,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 ()); @@ -3589,7 +3589,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: %s, %s\n", exec_file, diff --git a/gdbserver/server.cc b/gdbserver/server.cc index 789af36d9a42..82f4318457cb 100644 --- a/gdbserver/server.cc +++ b/gdbserver/server.cc @@ -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 (); diff --git a/gdbsupport/common-inferior.h b/gdbsupport/common-inferior.h index bc6afd65f2b5..9c19e9d9fdd9 100644 --- a/gdbsupport/common-inferior.h +++ b/gdbsupport/common-inferior.h @@ -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. -- 2.45.1