gdb: fix shellcheck warnings SC2154 (referenced but not assigned) in gdbarch.sh
[deliverable/binutils-gdb.git] / gdb / target.c
index 33c41cc4b69ad5cc3e5d75e4da5bd6768342e8ee..2dc356d935f90bc56cb0c4af8415fbf7fb8b977a 100644 (file)
@@ -49,6 +49,7 @@
 #include "gdbsupport/byte-vector.h"
 #include "terminal.h"
 #include <unordered_map>
+#include "target-connection.h"
 
 static void generic_tls_error (void) ATTRIBUTE_NORETURN;
 
@@ -65,9 +66,6 @@ static void default_rcmd (struct target_ops *, const char *, struct ui_file *);
 static ptid_t default_get_ada_task_ptid (struct target_ops *self,
                                         long lwp, long tid);
 
-static int default_follow_fork (struct target_ops *self, int follow_child,
-                               int detach_fork);
-
 static void default_mourn_inferior (struct target_ops *self);
 
 static int default_search_memory (struct target_ops *ops,
@@ -561,7 +559,11 @@ decref_target (target_ops *t)
 {
   t->decref ();
   if (t->refcount () == 0)
-    target_close (t);
+    {
+      if (t->stratum () == process_stratum)
+       connection_list_remove (as_process_stratum_target (t));
+      target_close (t);
+    }
 }
 
 /* See target.h.  */
@@ -573,6 +575,9 @@ target_stack::push (target_ops *t)
 
   strata stratum = t->stratum ();
 
+  if (stratum == process_stratum)
+    connection_list_add (as_process_stratum_target (t));
+
   /* If there's already a target at this stratum, remove it.  */
 
   if (m_stack[stratum] != NULL)
@@ -2119,7 +2124,7 @@ target_resume (ptid_t ptid, int step, enum gdb_signal signal)
   /* We only set the internal executing state here.  The user/frontend
      running state is set at a higher level.  This also clears the
      thread's stop_pc as side effect.  */
-  set_executing (curr_target, ptid, 1);
+  set_executing (curr_target, ptid, true);
   clear_inline_frame_state (curr_target, ptid);
 }
 
@@ -2157,9 +2162,9 @@ target_program_signals (gdb::array_view<const unsigned char> program_signals)
   current_top_target ()->program_signals (program_signals);
 }
 
-static int
-default_follow_fork (struct target_ops *self, int follow_child,
-                    int detach_fork)
+static bool
+default_follow_fork (struct target_ops *self, bool follow_child,
+                    bool detach_fork)
 {
   /* Some target returned a fork event, but did not know how to follow it.  */
   internal_error (__FILE__, __LINE__,
@@ -2169,8 +2174,8 @@ default_follow_fork (struct target_ops *self, int follow_child,
 /* Look through the list of possible targets for a target that can
    follow forks.  */
 
-int
-target_follow_fork (int follow_child, int detach_fork)
+bool
+target_follow_fork (bool follow_child, bool detach_fork)
 {
   return current_top_target ()->follow_fork (follow_child, detach_fork);
 }
@@ -3926,6 +3931,26 @@ target_is_non_stop_p (void)
              && target_always_non_stop_p ()));
 }
 
+/* See target.h.  */
+
+bool
+exists_non_stop_target ()
+{
+  if (target_is_non_stop_p ())
+    return true;
+
+  scoped_restore_current_thread restore_thread;
+
+  for (inferior *inf : all_inferiors ())
+    {
+      switch_to_inferior_no_thread (inf);
+      if (target_is_non_stop_p ())
+       return true;
+    }
+
+  return false;
+}
+
 /* Controls if targets can report that they always run in non-stop
    mode.  This is just for maintainers to use when debugging gdb.  */
 enum auto_boolean target_non_stop_enabled = AUTO_BOOLEAN_AUTO;
@@ -4022,6 +4047,8 @@ set_write_memory_permission (const char *args, int from_tty,
   update_observer_mode ();
 }
 
+void _initialize_target ();
+
 void
 _initialize_target ()
 {
This page took 0.025549 seconds and 4 git commands to generate.