From: Andrew Burgess Date: Wed, 27 Aug 2025 18:51:56 +0000 (+0100) Subject: gdb: remove some dead code from core_target_open X-Git-Tag: gdb-17-branchpoint~35 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9cede382cb96b08bff9dcdb18aa959ec6f18f04f;p=thirdparty%2Fbinutils-gdb.git 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 --- diff --git a/gdb/corelow.c b/gdb/corelow.c index af534bfb26f..02d13a81793 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);