From patchwork Wed Nov 29 20:33:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 80987 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id ACA773881874 for ; Wed, 29 Nov 2023 20:33:50 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by sourceware.org (Postfix) with ESMTPS id 3BCC33861845 for ; Wed, 29 Nov 2023 20:33:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3BCC33861845 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 3BCC33861845 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701290011; cv=none; b=RUWij85dJuIF73Jje/LD1tyjgU9+N/MQLyqgH/7uvKQKaIp/vC3/t9wFyIPCfmXL6A/lbx36/ijSNjl9S+ryt9NzkxIbsQVVtRVL9ldxluplPf/0+bMs151E4e/3NiWAqJjhSuzTfNBuY7ZYiXQqBrGozxUOhFI8TBsWKCm2tow= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701290011; c=relaxed/simple; bh=z3xlq285WScYRIxbW+rn8f3Gj85zE1clp7m13yRTIbE=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=T9TDMYrQacxKEVTR9rQTtzseVtStf6pzqQgkucD9KHRoBgHb01p3cVcUEtvaXSBmd9jFN+kDqaa20tKS7743QRFr+/USAzvljqvxYeKl4OY2N/MhqIhRHb8sDE7YsrNeBsU4tkHpnhD3gWveTj/BcLSthlisdSmKshjO6T91m3I= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id E17821F892 for ; Wed, 29 Nov 2023 20:33:28 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id C7BBA1388B for ; Wed, 29 Nov 2023 20:33:28 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id ELM0LxigZ2U5QQAAD6G6ig (envelope-from ) for ; Wed, 29 Nov 2023 20:33:28 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [RFC 1/4] [gdb/tdep] Add dummy amd64_software_single_step Date: Wed, 29 Nov 2023 21:33:23 +0100 Message-Id: <20231129203326.11952-1-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 X-Spamd-Bar: ++++++++++++ Authentication-Results: smtp-out2.suse.de; dkim=none; dmarc=fail reason="No valid SPF, No valid DKIM" header.from=suse.de (policy=none); spf=softfail (smtp-out2.suse.de: 2a07:de40:b281:104:10:150:64:97 is neither permitted nor denied by domain of tdevries@suse.de) smtp.mailfrom=tdevries@suse.de X-Rspamd-Server: rspamd2 X-Spamd-Result: default: False [12.28 / 50.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; ARC_NA(0.00)[]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; R_MISSING_CHARSET(2.50)[]; MIME_GOOD(-0.10)[text/plain]; PREVIOUSLY_DELIVERED(0.00)[gdb-patches@sourceware.org]; BROKEN_CONTENT_TYPE(1.50)[]; R_SPF_SOFTFAIL(4.60)[~all]; RCPT_COUNT_ONE(0.00)[1]; RCVD_COUNT_THREE(0.00)[3]; TO_DN_NONE(0.00)[]; MX_GOOD(-0.01)[]; NEURAL_SPAM_LONG(3.49)[0.998]; MID_CONTAINS_FROM(1.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(2.20)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%]; DMARC_POLICY_SOFTFAIL(0.10)[suse.de : No valid SPF, No valid DKIM,none] X-Spam-Score: 12.28 X-Rspamd-Queue-Id: E17821F892 X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org The documentation of gdbarch_software_single_step states: ... Return a vector of addresses on which the software single step breakpoints should be inserted. NULL means software single step is not used. ... Add a dummy amd64_software_single_step, returning an empty vector. As per the documentation, this shouldn't have any effect. However, there are regressions. The reason for these regressions is the use of gdbarch_software_single_step_p: ... bool gdbarch_software_single_step_p (struct gdbarch *gdbarch) { gdb_assert (gdbarch != NULL); return gdbarch->software_single_step != NULL; } ... which simply tests for the presence of the hook, and which returns true instead of false after adding amd64_software_single_step. Fix this by introducing a software_single_step_p which follows the logic of insert_single_step_breakpoints, and using this instead of gdbarch_software_single_step_p. This leaves gdbarch_software_single_step_p used only in: - software_single_step_p, and - of gdbarch_displaced_step_hw_singlestep. In the latter case, software_single_step_p doesn't work well, so instead use a amd64_displaced_step_hw_singlestep always returning true. Tested on x86_64-linux. --- gdb/amd64-tdep.c | 15 +++++++++++++++ gdb/breakpoint.c | 15 +++++++++++++++ gdb/breakpoint.h | 2 ++ gdb/infrun.c | 2 +- gdb/linux-nat.c | 4 ++-- gdb/record-full.c | 4 ++-- 6 files changed, 37 insertions(+), 5 deletions(-) base-commit: 35efddd5a12bbe514ff3870ec67a0357774fbe04 diff --git a/gdb/amd64-tdep.c b/gdb/amd64-tdep.c index e6feee677b3..85721bbadf4 100644 --- a/gdb/amd64-tdep.c +++ b/gdb/amd64-tdep.c @@ -3158,6 +3158,18 @@ amd64_in_indirect_branch_thunk (struct gdbarch *gdbarch, CORE_ADDR pc) AMD64_RIP_REGNUM); } +static std::vector +amd64_software_single_step (struct regcache *regcache) +{ + return {}; +} + +static bool +amd64_displaced_step_hw_singlestep (gdbarch *) +{ + return true; +} + void amd64_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch, const target_desc *default_tdesc) @@ -3329,6 +3341,9 @@ amd64_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch, amd64_in_indirect_branch_thunk); register_amd64_ravenscar_ops (gdbarch); + + set_gdbarch_software_single_step (gdbarch, amd64_software_single_step); + set_gdbarch_displaced_step_hw_singlestep (gdbarch, amd64_displaced_step_hw_singlestep); } /* Initialize ARCH for x86-64, no osabi. */ diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index 699919e32b3..60e795e1849 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -13945,6 +13945,21 @@ insert_single_step_breakpoint (struct gdbarch *gdbarch, update_global_location_list (UGLL_INSERT); } +bool +software_single_step_p (struct gdbarch *gdbarch) +{ + if (!gdbarch_software_single_step_p (gdbarch)) + return false; + + regcache *regcache = get_thread_regcache (inferior_thread ()); + std::vector next_pcs; + + next_pcs = gdbarch_software_single_step (gdbarch, regcache); + + return !next_pcs.empty (); +} + + /* Insert single step breakpoints according to the current state. */ int diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h index feb798224c0..20b1eb23b83 100644 --- a/gdb/breakpoint.h +++ b/gdb/breakpoint.h @@ -1815,6 +1815,8 @@ extern void insert_single_step_breakpoint (struct gdbarch *, const address_space *, CORE_ADDR); +extern bool software_single_step_p (struct gdbarch *gdbarch); + /* Insert all software single step breakpoints for the current frame. Return true if any software single step breakpoints are inserted, otherwise, return false. */ diff --git a/gdb/infrun.c b/gdb/infrun.c index 45c1b4a79bb..f7f76737c40 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -2366,7 +2366,7 @@ maybe_software_singlestep (struct gdbarch *gdbarch) bool hw_step = true; if (execution_direction == EXEC_FORWARD - && gdbarch_software_single_step_p (gdbarch)) + && software_single_step_p (gdbarch)) hw_step = !insert_single_step_breakpoints (gdbarch); return hw_step; diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c index 737e0f7bda6..9954750fc84 100644 --- a/gdb/linux-nat.c +++ b/gdb/linux-nat.c @@ -490,8 +490,8 @@ linux_nat_target::follow_fork (inferior *child_inf, ptid_t child_ptid, /* Note that we consult the parent's architecture instead of the child's because there's no inferior for the child at this point. */ - if (!gdbarch_software_single_step_p (target_thread_architecture - (parent_ptid))) + if (!software_single_step_p (target_thread_architecture + (parent_ptid))) { int status; diff --git a/gdb/record-full.c b/gdb/record-full.c index 2fc9e433ca8..023e9cb7b26 100644 --- a/gdb/record-full.c +++ b/gdb/record-full.c @@ -1074,7 +1074,7 @@ record_full_target::resume (ptid_t ptid, int step, enum gdb_signal signal) if (!step) { /* This is not hard single step. */ - if (!gdbarch_software_single_step_p (gdbarch)) + if (!software_single_step_p (gdbarch)) { /* This is a normal continue. */ step = 1; @@ -1249,7 +1249,7 @@ record_full_wait_1 (struct target_ops *ops, process_stratum_target *proc_target = current_inferior ()->process_target (); - if (gdbarch_software_single_step_p (gdbarch)) + if (software_single_step_p (gdbarch)) { /* Try to insert the software single step breakpoint. If insert success, set step to 0. */