From patchwork Fri Sep 6 23:28:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 34439 Received: (qmail 40156 invoked by alias); 6 Sep 2019 23:37:39 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 40147 invoked by uid 89); 6 Sep 2019 23:37:38 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy= X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 06 Sep 2019 23:37:37 +0000 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 555D589AC7 for ; Fri, 6 Sep 2019 23:28:28 +0000 (UTC) Received: from localhost.localdomain (ovpn04.gateway.prod.ext.ams2.redhat.com [10.39.146.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id E62ED5D9D3 for ; Fri, 6 Sep 2019 23:28:27 +0000 (UTC) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 22/23] Require always-non-stop for multi-target resumptions Date: Sat, 7 Sep 2019 00:28:06 +0100 Message-Id: <20190906232807.6191-23-palves@redhat.com> In-Reply-To: <20190906232807.6191-1-palves@redhat.com> References: <20190906232807.6191-1-palves@redhat.com> Currently, we can only support resuming multiple targets at the same time if all targets are in non-stop mode (or user-visible all-stop mode with target backend in non-stop mode). This patch makes GDB error out if the user tries to resume more than one target at the same time and one of the resumed targets isn't in non-stop mode: (gdb) info inferiors Num Description Connection Executable 1 process 15303 1 (native) a.out * 2 process 15286 2 (extended-remote :9999) a.out (gdb) set schedule-multiple on (gdb) c Continuing. Connection 2 (extended-remote :9999) does not support multi-target resumption. This is here later in the series instead of in the main multi-target patch because it depends the previous patch, which added process_stratum_target::connection_string(). gdb/ChangeLog: yyyy-mm-dd Pedro Alves * infrun.c: Include "target-connection.h". (check_multi_target_resumption): New. (proceed): Call it. * target-connection.c (make_target_connection_string): Make static. * target-connection.h (make_target_connection_string): Declare. --- gdb/infrun.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++ gdb/target-connection.c | 7 ++----- gdb/target-connection.h | 8 ++++++++ 3 files changed, 63 insertions(+), 5 deletions(-) diff --git a/gdb/infrun.c b/gdb/infrun.c index 33088a11e7..dc84e002f6 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -30,6 +30,7 @@ #include "gdbcmd.h" #include "cli/cli-script.h" #include "target.h" +#include "target-connection.h" #include "gdbthread.h" #include "annotate.h" #include "symfile.h" @@ -2876,6 +2877,56 @@ commit_resume_all_targets () } } +/* Check that all the targets we're about to resume are in non-stop + mode, since that's the only way we support handling events from + multiple targets simultaneously. */ + +static void +check_multi_target_resumption (process_stratum_target *resume_target) +{ + if (!non_stop && resume_target == nullptr) + { + scoped_restore_current_thread restore_thread; + + /* This is used to track whether we're resuming more than one + target. */ + process_stratum_target *first_connection = nullptr; + + /* The first inferior we see with a target that does not work in + always-non-stop mode. */ + inferior *first_not_non_stop = nullptr; + + for (inferior *inf : all_non_exited_inferiors (resume_target)) + { + switch_to_inferior_no_thread (inf); + + if (!target_has_execution) + continue; + + process_stratum_target *proc_target + = current_inferior ()->process_target(); + + if (!target_is_non_stop_p ()) + first_not_non_stop = inf; + + if (first_connection == nullptr) + first_connection = proc_target; + else if (first_connection != proc_target + && first_not_non_stop != nullptr) + { + switch_to_inferior_no_thread (first_not_non_stop); + + proc_target = current_inferior ()->process_target(); + + error (_("Connection %d (%s) does not support " + "multi-target resumption."), + proc_target->connection_number, + make_target_connection_string (proc_target).c_str ()); + } + } + } +} + /* Basic routine for continuing the program in various fashions. ADDR is the address to resume at, or -1 for resume where stopped. @@ -2926,6 +2977,8 @@ proceed (CORE_ADDR addr, enum gdb_signal siggnal) process_stratum_target *resume_target = user_visible_resume_target (resume_ptid); + check_multi_target_resumption (resume_target); + if (addr == (CORE_ADDR) -1) { if (pc == cur_thr->suspend.stop_pc diff --git a/gdb/target-connection.c b/gdb/target-connection.c index f13e649977..c6e1e3f600 100644 --- a/gdb/target-connection.c +++ b/gdb/target-connection.c @@ -53,12 +53,9 @@ connection_list_remove (process_stratum_target *t) t->connection_number = 0; } -/* Make a target connection string for T. This is usually T's - shortname, but it includes the result of - process_stratum_target::connection_string() too if T supports - it. */ +/* See target-connection.h. */ -static std::string +std::string make_target_connection_string (process_stratum_target *t) { if (t->connection_string () != NULL) diff --git a/gdb/target-connection.h b/gdb/target-connection.h index 0e2dc128d8..0b31924b99 100644 --- a/gdb/target-connection.h +++ b/gdb/target-connection.h @@ -20,6 +20,8 @@ #ifndef TARGET_CONNECTION_H #define TARGET_CONNECTION_H +#include + struct process_stratum_target; /* Add a process target to the connection list, if not already @@ -29,4 +31,10 @@ void connection_list_add (process_stratum_target *t); /* Remove a process target from the connection list. */ void connection_list_remove (process_stratum_target *t); +/* Make a target connection string for T. This is usually T's + shortname, but it includes the result of + process_stratum_target::connection_string() too if T supports + it. */ +std::string make_target_connection_string (process_stratum_target *t); + #endif /* TARGET_CONNECTION_H */