From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2104) id 2DB0938708A8; Thu, 14 May 2020 12:16:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2DB0938708A8 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Tankut Baris Aktemur To: gdb-cvs@sourceware.org Subject: [binutils-gdb] gdb: introduce 'all_non_exited_process_targets' and 'switch_to_target_no_thread' X-Act-Checkin: binutils-gdb X-Git-Author: Tankut Baris Aktemur X-Git-Refname: refs/heads/master X-Git-Oldrev: 293b3ebcba93960b4e39b27eeddaa4a01f024d0c X-Git-Newrev: d890404b63b8a0b6c28212388f21421d029f6ad2 Message-Id: <20200514121634.2DB0938708A8@sourceware.org> Date: Thu, 14 May 2020 12:16:34 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 14 May 2020 12:16:34 -0000 https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=d890404b63b8a0b6c28212388f21421d029f6ad2 commit d890404b63b8a0b6c28212388f21421d029f6ad2 Author: Tankut Baris Aktemur Date: Thu May 14 13:59:54 2020 +0200 gdb: introduce 'all_non_exited_process_targets' and 'switch_to_target_no_thread' 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 * process-stratum-target.h: Include . (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. Diff: --- gdb/ChangeLog | 8 ++++++++ gdb/process-stratum-target.c | 25 +++++++++++++++++++++++++ gdb/process-stratum-target.h | 10 ++++++++++ 3 files changed, 43 insertions(+) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index c27876b5c81..9f93948d803 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,11 @@ +2020-05-14 Tankut Baris Aktemur + + * process-stratum-target.h: Include . + (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 * infrun.c (handle_inferior_event): Extract out a piece of code diff --git a/gdb/process-stratum-target.c b/gdb/process-stratum-target.c index f3fd9ee905d..9eff5ab56ea 100644 --- a/gdb/process-stratum-target.c +++ b/gdb/process-stratum-target.c @@ -83,3 +83,28 @@ process_stratum_target::has_execution (inferior *inf) through hoops. */ return inf->pid != 0; } + +/* See process-stratum-target.h. */ + +std::set +all_non_exited_process_targets () +{ + /* Inferiors may share targets. To eliminate duplicates, use a set. */ + std::set 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 /* Abstract base class inherited by all process_stratum targets. */ @@ -82,4 +83,13 @@ as_process_stratum_target (target_ops *target) return static_cast (target); } +/* Return a collection of targets that have non-exited inferiors. */ + +extern std::set 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) */