diff options
author | Simon Marchi <simon.marchi@efficios.com> | 2024-05-30 14:53:56 -0400 |
---|---|---|
committer | Simon Marchi <simon.marchi@polymtl.ca> | 2024-06-07 23:09:03 -0400 |
commit | 7831bc9185340d294e02eb9e1312ec9dc865e2ff (patch) | |
tree | a9e62fd2dd355cefaa62b691ab147425504c9907 /gdb/nat | |
parent | 449637674f3146537e8f58520ce1058b9dd58c0a (diff) | |
download | gdb-7831bc9185340d294e02eb9e1312ec9dc865e2ff.zip gdb-7831bc9185340d294e02eb9e1312ec9dc865e2ff.tar.gz gdb-7831bc9185340d294e02eb9e1312ec9dc865e2ff.tar.bz2 |
gdb: remove get_exec_file
I believe that the get_exec_file function is unnecessary, and the code
can be simplified if we remove it.
Consider for instance when you "run" a program on Linux with native
debugging.
1. run_command_1 obtains the executable file from
`current_program_space->exec_filename ()`
2. it passes it to `run_target->create_inferior()`, which is
`inf_ptrace_target::create_inferior()` in this case, which then
passes it to `fork_inferior()`
3. `fork_inferior()` then has a fallback, where if the passed exec file
is nullptr, it gets its from `get_exec_file()`.
4. `get_exec_file()` returns `current_program_space->exec_filename ()`
- just like the things we started with - or errors out if the
current program space doesn't have a specified executable.
If there's no exec filename passed in step 1, there's not going to be
any in step 4, so it seems pointless to call `get_exec_file()`, we could
just error out when `exec_file` is nullptr. But we can't error out
directly in `fork_inferior()`, since the error is GDB-specific, and that
function is shared with GDBserver.
Speaking of GDBserver, all code paths that lead to `fork_inferior()`
provide a non-nullptr exec file.
Therefore, to simplify things:
- Make `fork_inferior()` assume that the passed exec file is not
nullptr, don't call `get_exec_file()`
- Change some targets (darwin-nat, go32-nat, gnu-nat, inf-ptrace,
nto-procfs, procfs) to error out when the exec file passed to their
create_inferior method is nullptr. Some targets are fine with a
nullptr exec file, so we can't check that in `run_command_1()`.
- Add the `no_executable_specified_error()` function, which re-uses the
error message that `get_exec_file()` had.
- Change some targets (go32-nat, nto-procfs) to not call
`get_exec_file()`, since it's pointless for the same reason as in the
example above, if it returns, it's going the be the same value as the
`exec_file` parameter. Just rely on `exec_file`.
- Remove the final use of `get_exec_file()`, in `load_command()`.
- Remove the `get_exec_file()` implementations in GDB and GDBserver and
remove the shared declaration.
Change-Id: I601c16498e455f7baa1f111a179da2f6c913baa3
Approved-By: Tom Tromey <tom@tromey.com>
Diffstat (limited to 'gdb/nat')
-rw-r--r-- | gdb/nat/fork-inferior.c | 16 |
1 files changed, 5 insertions, 11 deletions
diff --git a/gdb/nat/fork-inferior.c b/gdb/nat/fork-inferior.c index 172eef0..2fd9cba 100644 --- a/gdb/nat/fork-inferior.c +++ b/gdb/nat/fork-inferior.c @@ -265,26 +265,20 @@ execv_argv::init_for_shell (const char *exec_file, /* See nat/fork-inferior.h. */ pid_t -fork_inferior (const char *exec_file_arg, const std::string &allargs, - char **env, traceme_ftype traceme_fun, - init_trace_ftype init_trace_fun, pre_trace_ftype pre_trace_fun, - const char *shell_file_arg, exec_ftype exec_fun) +fork_inferior (const char *exec_file, const std::string &allargs, char **env, + traceme_ftype traceme_fun, init_trace_ftype init_trace_fun, + pre_trace_ftype pre_trace_fun, const char *shell_file_arg, + exec_ftype exec_fun) { pid_t pid; /* Set debug_fork then attach to the child while it sleeps, to debug. */ int debug_fork = 0; const char *shell_file; - const char *exec_file; char **save_our_env; int i; int save_errno; - /* 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 (); - else - exec_file = exec_file_arg; + gdb_assert (exec_file != nullptr); /* 'startup_with_shell' is declared in inferior.h and bound to the "set startup-with-shell" option. If 0, we'll just do a |