summaryrefslogtreecommitdiff
path: root/gdb/target.c
diff options
context:
space:
mode:
authorAndrew Burgess <aburgess@redhat.com>2022-09-22 12:22:22 +0100
committerAndrew Burgess <aburgess@redhat.com>2022-12-14 13:57:22 +0000
commitc8181f706f5a481e9667195d1f5d1623db6cc7f2 (patch)
tree6f4bf3f6732629ce964a48226c97e32c3125989a /gdb/target.c
parent9678f8fe975c213c94735221dcb438395e4de9e1 (diff)
downloadbinutils-gdb-c8181f706f5a481e9667195d1f5d1623db6cc7f2.tar.gz
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.
Diffstat (limited to 'gdb/target.c')
-rw-r--r--gdb/target.c40
1 files changed, 1 insertions, 39 deletions
diff --git a/gdb/target.c b/gdb/target.c
index 417d384a67e..b7cd3b9b454 100644
--- a/gdb/target.c
+++ b/gdb/target.c
@@ -1245,44 +1245,6 @@ target_stack::unpush (target_ops *t)
return true;
}
-/* Unpush TARGET and assert that it worked. */
-
-static void
-unpush_target_and_assert (struct target_ops *target)
-{
- if (!current_inferior ()->unpush_target (target))
- {
- gdb_printf (gdb_stderr,
- "pop_all_targets couldn't find target %s\n",
- target->shortname ());
- internal_error (_("failed internal consistency check"));
- }
-}
-
-void
-pop_all_targets_above (enum strata above_stratum)
-{
- while ((int) (current_inferior ()->top_target ()->stratum ())
- > (int) above_stratum)
- unpush_target_and_assert (current_inferior ()->top_target ());
-}
-
-/* See target.h. */
-
-void
-pop_all_targets_at_and_above (enum strata stratum)
-{
- while ((int) (current_inferior ()->top_target ()->stratum ())
- >= (int) stratum)
- unpush_target_and_assert (current_inferior ()->top_target ());
-}
-
-void
-pop_all_targets (void)
-{
- pop_all_targets_above (dummy_stratum);
-}
-
void
target_unpusher::operator() (struct target_ops *ops) const
{
@@ -2539,7 +2501,7 @@ target_preopen (int from_tty)
it doesn't (which seems like a win for UDI), remove it now. */
/* Leave the exec target, though. The user may be switching from a
live process to a core of the same program. */
- pop_all_targets_above (file_stratum);
+ current_inferior ()->pop_all_targets_above (file_stratum);
target_pre_inferior (from_tty);
}