aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Burgess <aburgess@redhat.com>2025-08-27 19:51:56 +0100
committerAndrew Burgess <aburgess@redhat.com>2025-09-04 16:07:10 +0100
commit9cede382cb96b08bff9dcdb18aa959ec6f18f04f (patch)
tree75e48f8e6b02c99bbb51d1516fe7ad4403902ddb
parent9463d3e7563186ea9800ff2ba8ae909c31e5e854 (diff)
downloadbinutils-9cede382cb96b08bff9dcdb18aa959ec6f18f04f.zip
binutils-9cede382cb96b08bff9dcdb18aa959ec6f18f04f.tar.gz
binutils-9cede382cb96b08bff9dcdb18aa959ec6f18f04f.tar.bz2
gdb: remove some dead code from core_target_open
In core_target_open we call target_preopen which pops all targets above the file_stratum, this will include the core_target, if the core target is currently loaded. Currently, the core file BFD is stored in the program_space of an inferior. The only way to set the core file BFD is by creating a core_target (in core_target_open). And when a core_target is closed the core file BFD within the program_space is reset to nullptr (see core_target::close and core_target::clear_core, both in corelow.c). What this means is that, if there is no core_target loaded then there will be no core file BFD in the program_space. And in core_target_open, after the call to target_preopen, there will be no core_target loaded, and thus, no core file BFD in the program_space. There is currently code in core_target_open which checks to see if there is a core file BFD set in the current program space. For the reasons given above, I believe this is dead code and can be removed. I've added some asserts to validate my assumptions. There should be no user visible changes after this commit. Approved-By: Simon Marchi <simon.marchi@efficios.com>
-rw-r--r--gdb/corelow.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/gdb/corelow.c b/gdb/corelow.c
index af534bf..02d13a8 100644
--- a/gdb/corelow.c
+++ b/gdb/corelow.c
@@ -1052,16 +1052,17 @@ core_target_open (const char *arg, int from_tty)
target_preopen (from_tty);
+ /* The target_preopen call will remove any existing process stratum
+ target, which includes any existing core_target. */
+ gdb_assert (current_inferior ()->process_target () == nullptr);
+
+ /* Which will clear up any existing core file BFD. */
+ gdb_assert (current_program_space->core_bfd () == nullptr);
+
std::string filename = extract_single_filename_arg (arg);
if (filename.empty ())
- {
- if (current_program_space->core_bfd ())
- error (_("No core file specified. (Use `detach' "
- "to stop debugging a core file.)"));
- else
- error (_("No core file specified."));
- }
+ error (_("No core file specified."));
if (!IS_ABSOLUTE_PATH (filename.c_str ()))
filename = gdb_abspath (filename);