]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb: remove some dead code from core_target_open
authorAndrew Burgess <aburgess@redhat.com>
Wed, 27 Aug 2025 18:51:56 +0000 (19:51 +0100)
committerAndrew Burgess <aburgess@redhat.com>
Thu, 4 Sep 2025 15:07:10 +0000 (16:07 +0100)
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>
gdb/corelow.c

index af534bfb26f5be612922717b8a083b0f5546b29c..02d13a81793861cc9b9662f95c9cd340eccab793 100644 (file)
@@ -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);