mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2024-11-27 03:51:15 +08:00
7831bc9185
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>
61 lines
2.0 KiB
C++
61 lines
2.0 KiB
C++
/* Functions to deal with the inferior being executed on GDB or
|
|
GDBserver.
|
|
|
|
Copyright (C) 1986-2024 Free Software Foundation, Inc.
|
|
|
|
This file is part of GDB.
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
|
|
|
#ifndef COMMON_COMMON_INFERIOR_H
|
|
#define COMMON_COMMON_INFERIOR_H
|
|
|
|
#include "gdbsupport/array-view.h"
|
|
|
|
/* Return the exec wrapper to be used when starting the inferior, or NULL
|
|
otherwise. */
|
|
extern const char *get_exec_wrapper ();
|
|
|
|
/* Return the inferior's current working directory.
|
|
|
|
If it is not set, the string is empty. */
|
|
extern const std::string &get_inferior_cwd ();
|
|
|
|
/* Whether to start up the debuggee under a shell.
|
|
|
|
If startup-with-shell is set, GDB's "run" will attempt to start up
|
|
the debuggee under a shell. This also happens when using GDBserver
|
|
under extended remote mode.
|
|
|
|
This is in order for argument-expansion to occur. E.g.,
|
|
|
|
(gdb) run *
|
|
|
|
The "*" gets expanded by the shell into a list of files.
|
|
|
|
While this is a nice feature, it may be handy to bypass the shell
|
|
in some cases. To disable this feature, do "set startup-with-shell
|
|
false".
|
|
|
|
The catch-exec traps expected during start-up will be one more if
|
|
the target is started up with a shell. */
|
|
extern bool startup_with_shell;
|
|
|
|
/* Compute command-line string given argument vector. This does the
|
|
same shell processing as fork_inferior. */
|
|
extern std::string
|
|
construct_inferior_arguments (gdb::array_view<char * const>);
|
|
|
|
#endif /* COMMON_COMMON_INFERIOR_H */
|