forked from Imagelibrary/binutils-gdb
gdb: remove the pop_all_targets (and friends) global functions
This commit removes the global functions pop_all_targets, pop_all_targets_above, and pop_all_targets_at_and_above, and makes them methods on the inferior class. As the pop_all_targets functions will unpush each target, which decrements the targets reference count, it is possible that the target might be closed. Right now, closing a target, in some cases, depends on the current inferior being set correctly, that is, to the inferior from which the target was popped. To facilitate this I have used switch_to_inferior_no_thread within the new methods. Previously it was the responsibility of the caller to ensure that the correct inferior was selected. In a couple of places (event-top.c and top.c) I have been able to remove a previous switch_to_inferior_no_thread call. In remote_unpush_target (remote.c) I have left the switch_to_inferior_no_thread call as it is required for the generic_mourn_inferior call.
This commit is contained in:
@@ -103,6 +103,48 @@ inferior::unpush_target (struct target_ops *t)
|
||||
return m_target_stack.unpush (t);
|
||||
}
|
||||
|
||||
/* See inferior.h. */
|
||||
|
||||
void
|
||||
inferior::unpush_target_and_assert (struct target_ops *target)
|
||||
{
|
||||
gdb_assert (current_inferior () == this);
|
||||
|
||||
if (!unpush_target (target))
|
||||
internal_error ("pop_all_targets couldn't find target %s\n",
|
||||
target->shortname ());
|
||||
}
|
||||
|
||||
/* See inferior.h. */
|
||||
|
||||
void
|
||||
inferior::pop_all_targets_above (enum strata stratum)
|
||||
{
|
||||
/* Unpushing a target might cause it to close. Some targets currently
|
||||
rely on the current_inferior being set for their ::close method, so we
|
||||
temporarily switch inferior now. */
|
||||
scoped_restore_current_pspace_and_thread restore_pspace_and_thread;
|
||||
switch_to_inferior_no_thread (this);
|
||||
|
||||
while (top_target ()->stratum () > stratum)
|
||||
unpush_target_and_assert (top_target ());
|
||||
}
|
||||
|
||||
/* See inferior.h. */
|
||||
|
||||
void
|
||||
inferior::pop_all_targets_at_and_above (enum strata stratum)
|
||||
{
|
||||
/* Unpushing a target might cause it to close. Some targets currently
|
||||
rely on the current_inferior being set for their ::close method, so we
|
||||
temporarily switch inferior now. */
|
||||
scoped_restore_current_pspace_and_thread restore_pspace_and_thread;
|
||||
switch_to_inferior_no_thread (this);
|
||||
|
||||
while (top_target ()->stratum () >= stratum)
|
||||
unpush_target_and_assert (top_target ());
|
||||
}
|
||||
|
||||
void
|
||||
inferior::set_tty (std::string terminal_name)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user