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>
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);