From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.baldwin.cx (unknown [IPv6:2607:f138:0:13::2]) by sourceware.org (Postfix) with ESMTPS id 4FFF03858406 for ; Tue, 1 Mar 2022 00:24:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4FFF03858406 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=FreeBSD.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=FreeBSD.org Received: from ralph.com (ralph.baldwin.cx [66.234.199.215]) by mail.baldwin.cx (Postfix) with ESMTPSA id 93F901A84C72 for ; Mon, 28 Feb 2022 19:24:29 -0500 (EST) From: John Baldwin To: gdb-patches@sourceware.org Subject: [RFC PATCH 03/12] x86-nat: Add x86_lookup_debug_reg_state. Date: Mon, 28 Feb 2022 16:24:10 -0800 Message-Id: <20220301002419.5122-4-jhb@FreeBSD.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220301002419.5122-1-jhb@FreeBSD.org> References: <20220301002419.5122-1-jhb@FreeBSD.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.6.4 (mail.baldwin.cx [0.0.0.0]); Mon, 28 Feb 2022 19:24:29 -0500 (EST) X-Virus-Scanned: clamav-milter 0.103.1 at mail.baldwin.cx X-Virus-Status: Clean X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_SOFTFAIL, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 01 Mar 2022 00:24:31 -0000 This function returns nullptr if debug register state does not yet exist for a given process rather than creating new state. --- gdb/x86-nat.c | 21 +++++++++++++++++---- gdb/x86-nat.h | 5 +++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/gdb/x86-nat.c b/gdb/x86-nat.c index cb323393e82..974a37853d9 100644 --- a/gdb/x86-nat.c +++ b/gdb/x86-nat.c @@ -47,17 +47,30 @@ static std::unordered_map> x86_debug_process_state; -/* Get debug registers state for process PID. */ +/* See x86-nat.h. */ struct x86_debug_reg_state * -x86_debug_reg_state (pid_t pid) +x86_lookup_debug_reg_state (pid_t pid) { auto it = x86_debug_process_state.find (pid); if (it != x86_debug_process_state.end ()) return it->second.get (); - struct x86_debug_reg_state *state = XCNEW (struct x86_debug_reg_state); - x86_debug_process_state.emplace (pid, state); + return nullptr; +} + +/* Get debug registers state for process PID. */ + +struct x86_debug_reg_state * +x86_debug_reg_state (pid_t pid) +{ + struct x86_debug_reg_state *state = x86_lookup_debug_reg_state (pid); + + if (state == nullptr) + { + state = XCNEW (struct x86_debug_reg_state); + x86_debug_process_state.emplace (pid, state); + } return state; } diff --git a/gdb/x86-nat.h b/gdb/x86-nat.h index 913291a2305..d9c2a3f6e14 100644 --- a/gdb/x86-nat.h +++ b/gdb/x86-nat.h @@ -40,6 +40,11 @@ extern void x86_set_debug_register_length (int len); extern void x86_cleanup_dregs (void); +/* Return the debug register state for process PID. If no existing + state is found for this process, return nullptr. */ + +struct x86_debug_reg_state *x86_lookup_debug_reg_state (pid_t pid); + /* Called whenever GDB is no longer debugging process PID. It deletes data structures that keep track of debug register state. */ -- 2.34.1