From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id YgaCFSyqYmb4bSkAWB0awg (envelope-from ) for ; Fri, 07 Jun 2024 02:35:24 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=TVEIg4/h; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=NGXXu6qz; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=TVEIg4/h; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=NGXXu6qz; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 467D61E0C1; Fri, 7 Jun 2024 02:35:24 -0400 (EDT) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 04E1F1E030 for ; Fri, 7 Jun 2024 02:35:21 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 49AF2399C085 for ; Fri, 7 Jun 2024 06:35:21 +0000 (GMT) Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2a07:de40:b251:101:10:150:64:2]) by sourceware.org (Postfix) with ESMTPS id D72B738DC2EA for ; Fri, 7 Jun 2024 06:35:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D72B738DC2EA 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 D72B738DC2EA Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a07:de40:b251:101:10:150:64:2 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1717742102; cv=none; b=EEt+yrAF8aI7HHxA5zoqLUfVsvexBRI9urSGofr/3rD+3iRe2BiqeGqR7W/FMCHVefw7Ryj1ayIUf+Ay/NeAkl1wSyRXnZYS/rXU+Jfm6FDTFoQgmr2xm2ojoLeNMmwjtmqXNDEIoX2cZHNKsXkkiClgdxK+bxfFxpwSwRTY1QA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1717742102; c=relaxed/simple; bh=aYoYTxuAqdOKfpohomHXp5Vgj63jNAH9ONcq+pFEoeg=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:From: To:Subject:Date:Message-Id:MIME-Version; b=PF/m+Qhyd7jcXzhqP/zLr8ZvPx+7uGjYwKtUi93SRqnnsb6S+xjrMdfUKYtTcLWRo4s7AZvjDBgXjj49cprIoWkO8JZArEY9kSXMy6GguGJuABLLV9KgCwapS3dO421/HyoOCzu0eUD/Y4Uerm7xBkHwHuRn7FjZS9/cfqxoD98= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from imap1.dmz-prg2.suse.org (unknown [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 61D841FB81 for ; Fri, 7 Jun 2024 06:34:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1717742099; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=uAEWoN9TL22kv5n0ZFdas4w8lhVpYeN9MFrxepQAMRo=; b=TVEIg4/hfeM+CO0weFOg1rSlQoZmM5TbTcQeXEY+gUWNA37Fb85WpOAsS8d9lEtpjjMdfw jRXehShjwE0Sl3hasdfoL6eRqMKLrQSUmVJDCGcrNG6x632+YmUMbjh8uUi3AvWlpgXKJc KQ9KAKYuI/LXcBLP7HUrYcuE5AH73d8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1717742099; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=uAEWoN9TL22kv5n0ZFdas4w8lhVpYeN9MFrxepQAMRo=; b=NGXXu6qz7vvjYhRwOXgRv24lrUU+VQtjs4tLhJanjb4w6VR7VWuxokRpymcGgQPcHiMQ76 5y2EbCdmm6UiwKAQ== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1717742099; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=uAEWoN9TL22kv5n0ZFdas4w8lhVpYeN9MFrxepQAMRo=; b=TVEIg4/hfeM+CO0weFOg1rSlQoZmM5TbTcQeXEY+gUWNA37Fb85WpOAsS8d9lEtpjjMdfw jRXehShjwE0Sl3hasdfoL6eRqMKLrQSUmVJDCGcrNG6x632+YmUMbjh8uUi3AvWlpgXKJc KQ9KAKYuI/LXcBLP7HUrYcuE5AH73d8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1717742099; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=uAEWoN9TL22kv5n0ZFdas4w8lhVpYeN9MFrxepQAMRo=; b=NGXXu6qz7vvjYhRwOXgRv24lrUU+VQtjs4tLhJanjb4w6VR7VWuxokRpymcGgQPcHiMQ76 5y2EbCdmm6UiwKAQ== 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 3EEBD133F3 for ; Fri, 7 Jun 2024 06:34:59 +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 wm3aDROqYmbeZQAAD6G6ig (envelope-from ) for ; Fri, 07 Jun 2024 06:34:59 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH] [gdb/tdep] Fix gdb.base/watchpoint-running on {arm, ppc64le}-linux Date: Fri, 7 Jun 2024 08:35:25 +0200 Message-Id: <20240607063525.9887-1-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Score: -2.79 X-Spam-Level: X-Spamd-Result: default: False [-2.79 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.19)[-0.964]; MIME_GOOD(-0.10)[text/plain]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; ARC_NA(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; TO_DN_NONE(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[gdb-patches@sourceware.org]; RCVD_TLS_ALL(0.00)[] X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, 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+public-inbox=simark.ca@sourceware.org When running test-case gdb.base/watchpoint-running on ppc64le-linux, we get: ... (gdb) watch global_var^M warning: Error when detecting the debug register interface. \ Debug registers will be unavailable.^M Watchpoint 2: global_var^M (gdb) FAIL: $exp: all-stop: hardware: watch global_var FAIL: $exp: all-stop: hardware: watchpoint hit (timeout) ... The problem is that ppc_linux_dreg_interface::detect fails to detect the hardware watchpoint interface, because the calls to ptrace return with errno set to ESRCH. This is a feature of ptrace: if a call is done while the tracee is not ptrace-stopped, it returns ESRCH. Indeed, in the test-case "watch global_var" is executed while the inferior is running, and that triggers the first call to ppc_linux_dreg_interface::detect. And because the detection failure is cached, subsequent attempts at setting hardware watchpoints will also fail, even if the tracee is ptrace-stopped. Fix this by calling target_can_use_hardware_watchpoint from linux_init_ptrace_procfs, which is called from both: - linux_nat_target::post_attach, and - linux_nat_target::post_startup_inferior. By fixing this here, we also fix the same problem for arm-linux. Tested on ppc64le-linux and arm-linux. PR tdep/31834 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31834 PR tdep/31705 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31705 --- gdb/linux-nat.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c index c95d420d416..d8b5a99269b 100644 --- a/gdb/linux-nat.c +++ b/gdb/linux-nat.c @@ -454,6 +454,18 @@ linux_init_ptrace_procfs (pid_t pid, int attached) linux_ptrace_init_warnings (); linux_proc_init_warnings (); proc_mem_file_is_writable (); + + /* Some targets (for instance ppc and arm) may call ptrace to answer a + target_can_use_hardware_watchpoint query, and cache the result. However, + the ptrace call will fail with errno ESRCH if the tracee is not + ptrace-stopped, making the query fail. And if the caching mechanism does + not disregard an ESRCH result, all subsequent queries will also fail. + Call it now, where we known the tracee is ptrace-stopped. + + Other targets (for instance aarch64) do the relevant ptrace call and + caching in their implementation of post_attach and post_startup_inferior, + in which case this call is expected to have no effect. */ + target_can_use_hardware_watchpoint (bp_hardware_watchpoint, 1, 0); } linux_nat_target::~linux_nat_target () base-commit: f9478936896ada7786e8d68622f6e6ff78b97b0d -- 2.35.3