From patchwork Fri Sep 6 23:27:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 34434 Received: (qmail 36017 invoked by alias); 6 Sep 2019 23:35:43 -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 36008 invoked by uid 89); 6 Sep 2019 23:35:43 -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:35:41 +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 D334A8EA5B for ; Fri, 6 Sep 2019 23:28:14 +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 6426E5D9D3 for ; Fri, 6 Sep 2019 23:28:14 +0000 (UTC) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 05/23] Make target_ops::has_execution take an 'inferior *' instead of a ptid_t Date: Sat, 7 Sep 2019 00:27:49 +0100 Message-Id: <20190906232807.6191-6-palves@redhat.com> In-Reply-To: <20190906232807.6191-1-palves@redhat.com> References: <20190906232807.6191-1-palves@redhat.com> With the multi-target work, each inferior will have its own target stack, so to call a target method, we'll need to make sure that the inferior in question is the current one, otherwise target->beneath() calls will find the target beneath in the wrong inferior. In some places, it's much more convenient to be able to check whether an inferior has execution without having to switch to it in order to call target_has_execution on the right inferior/target stack, to avoid side effects with switching inferior/thread/program space. The current target_ops::has_execution method takes a ptid_t as parameter, which, in a multi-target world, isn't sufficient to identify the target. This patch prepares to address that, by changing the parameter to an inferior pointer instead. From the inferior, we'll be able to query its target stack to tell which target is beneath. Also adds a new inferior::has_execution() method to make callers a bit more natural to read. gdb/ChangeLog: yyyy-mm-dd Pedro Alves * corelow.c (core_target::has_execution): Change parameter type to inferior pointer. * inferior.c (number_of_live_inferiors): Use inferior::has_execution instead of target_has_execution_1. * inferior.h (inferior::has_execution): New. * linux-thread-db.c (thread_db_target::update_thread_list): Use inferior::has_execution instead of target_has_execution_1. * process-stratum-target.c (process_stratum_target::has_execution): Change parameter type to inferior pointer. Check the inferior's PID instead of inferior_ptid. * process-stratum-target.h (process_stratum_target::has_execution): Change parameter type to inferior pointer. * record-full.c (record_full_core_target::has_execution): Change parameter type to inferior pointer. * target.c (target_has_execution_1): Change parameter type to inferior pointer. (target_has_execution_current): Adjust. * target.h (target_ops::has_execution): Change parameter type to inferior pointer. (target_has_execution_1): Change parameter type to inferior pointer. Change return type to bool. * tracefile.h (tracefile_target::has_execution): Change parameter type to inferior pointer. --- gdb/corelow.c | 2 +- gdb/inferior.c | 2 +- gdb/inferior.h | 3 +++ gdb/linux-thread-db.c | 2 +- gdb/process-stratum-target.c | 8 ++++---- gdb/process-stratum-target.h | 2 +- gdb/record-full.c | 4 ++-- gdb/target.c | 12 ++++++------ gdb/target.h | 7 ++++--- gdb/tracefile.h | 2 +- 10 files changed, 24 insertions(+), 20 deletions(-) diff --git a/gdb/corelow.c b/gdb/corelow.c index 5e9634e9d7..0fba93f802 100644 --- a/gdb/corelow.c +++ b/gdb/corelow.c @@ -92,7 +92,7 @@ public: bool has_memory () override; bool has_stack () override; bool has_registers () override; - bool has_execution (ptid_t) override { return false; } + bool has_execution (inferior *inf) override { return false; } bool info_proc (const char *, enum info_proc_what) override; diff --git a/gdb/inferior.c b/gdb/inferior.c index 2d58a11ba8..994938d564 100644 --- a/gdb/inferior.c +++ b/gdb/inferior.c @@ -352,7 +352,7 @@ number_of_live_inferiors (void) int num_inf = 0; for (inferior *inf : all_non_exited_inferiors ()) - if (target_has_execution_1 (ptid_t (inf->pid))) + if (inf->has_execution ()) for (thread_info *tp ATTRIBUTE_UNUSED : inf->non_exited_threads ()) { /* Found a live thread in this inferior, go to the next diff --git a/gdb/inferior.h b/gdb/inferior.h index 9cfb03cdbb..ce9bcbf122 100644 --- a/gdb/inferior.h +++ b/gdb/inferior.h @@ -360,6 +360,9 @@ public: /* Returns true if we can delete this inferior. */ bool deletable () const { return refcount () == 0; } + bool has_execution () + { return target_has_execution_1 (this); } + /* Pointer to next inferior in singly-linked list of inferiors. */ struct inferior *next = NULL; diff --git a/gdb/linux-thread-db.c b/gdb/linux-thread-db.c index 1d32e9195c..b2c9d6d77c 100644 --- a/gdb/linux-thread-db.c +++ b/gdb/linux-thread-db.c @@ -1619,7 +1619,7 @@ thread_db_target::update_thread_list () stop. That uses thread_db entry points that do not walk libpthread's thread list, so should be safe, as well as more efficient. */ - if (target_has_execution_1 (thread->ptid)) + if (thread->inf->has_execution ()) continue; thread_db_find_new_threads_1 (thread); diff --git a/gdb/process-stratum-target.c b/gdb/process-stratum-target.c index 2c4b812f86..1517088f0f 100644 --- a/gdb/process-stratum-target.c +++ b/gdb/process-stratum-target.c @@ -77,9 +77,9 @@ process_stratum_target::has_registers () } bool -process_stratum_target::has_execution (ptid_t the_ptid) +process_stratum_target::has_execution (inferior *inf) { - /* If there's no thread selected, then we can't make it run through - hoops. */ - return the_ptid != null_ptid; + /* If there's a process running already, we can't make it run + through hoops. */ + return inf->pid != 0; } diff --git a/gdb/process-stratum-target.h b/gdb/process-stratum-target.h index 2e620f82e8..a14e4f3a72 100644 --- a/gdb/process-stratum-target.h +++ b/gdb/process-stratum-target.h @@ -50,7 +50,7 @@ public: bool has_memory () override; bool has_stack () override; bool has_registers () override; - bool has_execution (ptid_t the_ptid) override; + bool has_execution (inferior *inf) override; }; #endif /* !defined (PROCESS_STRATUM_TARGET_H) */ diff --git a/gdb/record-full.c b/gdb/record-full.c index 8ed973ad12..1b03301da4 100644 --- a/gdb/record-full.c +++ b/gdb/record-full.c @@ -319,7 +319,7 @@ public: struct bp_target_info *, enum remove_bp_reason) override; - bool has_execution (ptid_t) override; + bool has_execution (inferior *inf) override; }; static record_full_target record_full_ops; @@ -2244,7 +2244,7 @@ record_full_core_target::remove_breakpoint (struct gdbarch *gdbarch, /* "has_execution" method for prec over corefile. */ bool -record_full_core_target::has_execution (ptid_t the_ptid) +record_full_core_target::has_execution (inferior *inf) { return true; } diff --git a/gdb/target.c b/gdb/target.c index a19a9bce13..68f874bf4b 100644 --- a/gdb/target.c +++ b/gdb/target.c @@ -223,20 +223,20 @@ target_has_registers_1 (void) return 0; } -int -target_has_execution_1 (ptid_t the_ptid) +bool +target_has_execution_1 (inferior *inf) { for (target_ops *t = current_top_target (); t != NULL; t = t->beneath ()) - if (t->has_execution (the_ptid)) - return 1; + if (t->has_execution (inf)) + return true; - return 0; + return false; } int target_has_execution_current (void) { - return target_has_execution_1 (inferior_ptid); + return target_has_execution_1 (current_inferior ()); } /* This is used to implement the various target commands. */ diff --git a/gdb/target.h b/gdb/target.h index 4e2e75cb80..9a94227953 100644 --- a/gdb/target.h +++ b/gdb/target.h @@ -682,7 +682,7 @@ struct target_ops virtual bool has_memory () { return false; } virtual bool has_stack () { return false; } virtual bool has_registers () { return false; } - virtual bool has_execution (ptid_t) { return false; } + virtual bool has_execution (inferior *inf) { return false; } /* Control thread execution. */ virtual thread_control_capabilities get_thread_control_capabilities () @@ -1787,9 +1787,10 @@ extern int target_has_registers_1 (void); case this will become true after to_create_inferior or to_attach. */ -extern int target_has_execution_1 (ptid_t); +extern bool target_has_execution_1 (inferior *inf); -/* Like target_has_execution_1, but always passes inferior_ptid. */ +/* Like target_has_execution_1, but always passes + current_inferior(). */ extern int target_has_execution_current (void); diff --git a/gdb/tracefile.h b/gdb/tracefile.h index 8f9dc0e06d..9c7fdea729 100644 --- a/gdb/tracefile.h +++ b/gdb/tracefile.h @@ -127,7 +127,7 @@ public: bool has_memory () override; bool has_stack () override; bool has_registers () override; - bool has_execution (ptid_t) override { return false; } + bool has_execution (inferior *inf) override { return false; } bool thread_alive (ptid_t ptid) override; };