gdb: introduce 'all_non_exited_process_targets' and 'switch_to_target_no_thread'
authorTankut Baris Aktemur <tankut.baris.aktemur@intel.com>
Thu, 14 May 2020 11:59:54 +0000 (13:59 +0200)
committerTankut Baris Aktemur <tankut.baris.aktemur@intel.com>
Thu, 14 May 2020 11:59:54 +0000 (13:59 +0200)
Introduce two new convenience functions:

1. all_non_exited_process_targets: returns a collection of all process
stratum targets that have non-exited inferiors on them.  Useful for
iterating targets.

2. switch_to_target_no_thread: switch the context to the first
inferior of the given target, and to no selected thread.

gdb/ChangeLog:
2020-05-14  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

* process-stratum-target.h: Include <set>.
(all_non_exited_process_targets, switch_to_target_no_thread): New
function declarations.
* process-stratum-target.c (all_non_exited_process_targets)
(switch_to_target_no_thread): New function implementations.

gdb/ChangeLog
gdb/process-stratum-target.c
gdb/process-stratum-target.h

index c27876b5c81044b0c47ac68c202af19f884f5797..9f93948d803127ca4f88d9f8903f60559b159566 100644 (file)
@@ -1,3 +1,11 @@
+2020-05-14  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>
+
+       * process-stratum-target.h: Include <set>.
+       (all_non_exited_process_targets, switch_to_target_no_thread): New
+       function declarations.
+       * process-stratum-target.c (all_non_exited_process_targets)
+       (switch_to_target_no_thread): New function implementations.
+
 2020-05-14  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>
 
        * infrun.c (handle_inferior_event): Extract out a piece of code
index f3fd9ee905db65e5bd52efa77c82608f3d3ad3e9..9eff5ab56eaafe8c3963c914c83f67939e997421 100644 (file)
@@ -83,3 +83,28 @@ process_stratum_target::has_execution (inferior *inf)
      through hoops.  */
   return inf->pid != 0;
 }
+
+/* See process-stratum-target.h.  */
+
+std::set<process_stratum_target *>
+all_non_exited_process_targets ()
+{
+  /* Inferiors may share targets.  To eliminate duplicates, use a set.  */
+  std::set<process_stratum_target *> targets;
+  for (inferior *inf : all_non_exited_inferiors ())
+    targets.insert (inf->process_target ());
+
+  return targets;
+}
+
+/* See process-stratum-target.h.  */
+
+void
+switch_to_target_no_thread (process_stratum_target *target)
+{
+  for (inferior *inf : all_inferiors (target))
+    {
+      switch_to_inferior_no_thread (inf);
+      break;
+    }
+}
index 1be02100dcff31cd227053651e59cdde9a8f138f..7e7905bf75028c4c392262366415983a89cf9427 100644 (file)
@@ -21,6 +21,7 @@
 #define PROCESS_STRATUM_TARGET_H
 
 #include "target.h"
+#include <set>
 
 /* Abstract base class inherited by all process_stratum targets.  */
 
@@ -82,4 +83,13 @@ as_process_stratum_target (target_ops *target)
   return static_cast<process_stratum_target *> (target);
 }
 
+/* Return a collection of targets that have non-exited inferiors.  */
+
+extern std::set<process_stratum_target *> all_non_exited_process_targets ();
+
+/* Switch to the first inferior (and program space) of TARGET, and
+   switch to no thread selected.  */
+
+extern void switch_to_target_no_thread (process_stratum_target *target);
+
 #endif /* !defined (PROCESS_STRATUM_TARGET_H) */