opcodes/
[binutils-gdb.git] / gdb / target.c
index 18e10cbdceddaced27e8a7422acece332b0b98a6..377724df5ed89dfa578f89d0681e9c575a38b955 100644 (file)
@@ -381,16 +381,12 @@ target_has_execution_current (void)
   return target_has_execution_1 (inferior_ptid);
 }
 
-/* Add possible target architecture T to the list and add a new
-   command 'target T->to_shortname'.  Set COMPLETER as the command's
-   completer if not NULL.  */
+/* Complete initialization of T.  This ensures that various fields in
+   T are set, if needed by the target implementation.  */
 
 void
-add_target_with_completer (struct target_ops *t,
-                          completer_ftype *completer)
+complete_target_initialization (struct target_ops *t)
 {
-  struct cmd_list_element *c;
-
   /* Provide default values for all "must have" methods.  */
   if (t->to_xfer_partial == NULL)
     t->to_xfer_partial = default_xfer_partial;
@@ -409,6 +405,19 @@ add_target_with_completer (struct target_ops *t,
 
   if (t->to_has_execution == NULL)
     t->to_has_execution = (int (*) (struct target_ops *, ptid_t)) return_zero;
+}
+
+/* Add possible target architecture T to the list and add a new
+   command 'target T->to_shortname'.  Set COMPLETER as the command's
+   completer if not NULL.  */
+
+void
+add_target_with_completer (struct target_ops *t,
+                          completer_ftype *completer)
+{
+  struct cmd_list_element *c;
+
+  complete_target_initialization (t);
 
   if (!target_structs)
     {
@@ -1084,26 +1093,11 @@ unpush_target (struct target_ops *t)
   return 1;
 }
 
-void
-pop_target (void)
-{
-  target_close (target_stack);         /* Let it clean up.  */
-  if (unpush_target (target_stack) == 1)
-    return;
-
-  fprintf_unfiltered (gdb_stderr,
-                     "pop_target couldn't find target %s\n",
-                     current_target.to_shortname);
-  internal_error (__FILE__, __LINE__,
-                 _("failed internal consistency check"));
-}
-
 void
 pop_all_targets_above (enum strata above_stratum)
 {
   while ((int) (current_target.to_stratum) > (int) above_stratum)
     {
-      target_close (target_stack);
       if (!unpush_target (target_stack))
        {
          fprintf_unfiltered (gdb_stderr,
@@ -3772,6 +3766,8 @@ debug_to_open (char *args, int from_tty)
 void
 target_close (struct target_ops *targ)
 {
+  gdb_assert (!target_is_pushed (targ));
+
   if (targ->to_xclose != NULL)
     targ->to_xclose (targ);
   else if (targ->to_close != NULL)
@@ -4979,7 +4975,7 @@ maintenance_print_target_stack (char *cmd, int from_tty)
 int target_async_permitted = 0;
 
 /* The set command writes to this variable.  If the inferior is
-   executing, linux_nat_async_permitted is *not* updated.  */
+   executing, target_async_permitted is *not* updated.  */
 static int target_async_permitted_1 = 0;
 
 static void