[v8,4/6] gdb: introduce 'all_non_exited_process_targets' and 'switch_to_target_no_thread'

Message ID 20200513205338.14233-5-palves@redhat.com
State New
Headers show
Series
  • Handle already-exited threads in 'stop_all_threads'
Related show

Commit Message

Lancelot SIX via Gdb-patches May 13, 2020, 8:53 p.m.
From: Tankut Baris Aktemur <tankut.baris.aktemur@intel.com>


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-04-30  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/process-stratum-target.c | 24 ++++++++++++++++++++++++
 gdb/process-stratum-target.h | 10 ++++++++++
 2 files changed, 34 insertions(+)

-- 
2.14.5

Comments

Lancelot SIX via Gdb-patches May 14, 2020, 8:44 a.m. | #1
On Wednesday, May 13, 2020 10:54 PM, Pedro Alves wrote:
> 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-04-30  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/process-stratum-target.c | 24 ++++++++++++++++++++++++

>  gdb/process-stratum-target.h | 10 ++++++++++

>  2 files changed, 34 insertions(+)

> 

> diff --git a/gdb/process-stratum-target.c b/gdb/process-stratum-target.c

> index f3fd9ee905d..9fb358a6a9f 100644

> --- a/gdb/process-stratum-target.c

> +++ b/gdb/process-stratum-target.c

> @@ -83,3 +83,27 @@ 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 ()

> +{


Christian suggested adding a comment here to state why a set was needed.
I thought about this:

/* 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;

> +}


Thanks.
-Baris


Intel Deutschland GmbH
Registered Address: Am Campeon 10-12, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de
Managing Directors: Christin Eisenschmid, Gary Kershaw
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928
Lancelot SIX via Gdb-patches May 14, 2020, 11:12 a.m. | #2
On 5/14/20 9:44 AM, Aktemur, Tankut Baris wrote:

> Christian suggested adding a comment here to state why a set was needed.

> I thought about this:

> 

> /* Inferiors may share targets.  To eliminate duplicates, use a set.  */


Sure, sounds good.

(Note I had done one change compared to your previous version I forgot
to mention -- the "#include <set>" should be in the .h file, rather
than in the .c file, because std::set is used in the .h file already.)

Thanks,
Pedro Alves
Lancelot SIX via Gdb-patches May 14, 2020, 11:23 a.m. | #3
On Thursday, May 14, 2020 1:13 PM, Pedro Alves wrote:
> (Note I had done one change compared to your previous version I forgot

> to mention -- the "#include <set>" should be in the .h file, rather

> than in the .c file, because std::set is used in the .h file already.)


Yes, I diff'ed the patches pairwise and noticed that.  Thanks!

-Baris


Intel Deutschland GmbH
Registered Address: Am Campeon 10-12, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de
Managing Directors: Christin Eisenschmid, Gary Kershaw
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928

Patch

diff --git a/gdb/process-stratum-target.c b/gdb/process-stratum-target.c
index f3fd9ee905d..9fb358a6a9f 100644
--- a/gdb/process-stratum-target.c
+++ b/gdb/process-stratum-target.c
@@ -83,3 +83,27 @@  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 ()
+{
+  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;
+    }
+}
diff --git a/gdb/process-stratum-target.h b/gdb/process-stratum-target.h
index 1be02100dcf..7e7905bf750 100644
--- a/gdb/process-stratum-target.h
+++ b/gdb/process-stratum-target.h
@@ -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) */