From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by sourceware.org (Postfix) with ESMTPS id A1116385B1B0 for ; Mon, 12 Dec 2022 15:06:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A1116385B1B0 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id DF10833750; Mon, 12 Dec 2022 15:06:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1670857609; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=WtykBRIkAYW6zA0/0JDgqjlihJusD+MiNRvsWL4j1I4=; b=MFbrMoIqlu/C/sUFZ6rA/shE8wLq5N1uRbnDtnogqqb1rVdWJQObBmm4lF5+XxM1bmoDVf Y7W4gT8YcDjV6Of09fSqdMoQgDzSo4db/rd9fFDwpfjuIAdLkntoNbZJGCIjUVdfzb14a1 o1zWgZ2V/rW2WnJpC6tOHMshiOFInKw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1670857609; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=WtykBRIkAYW6zA0/0JDgqjlihJusD+MiNRvsWL4j1I4=; b=/HOgTxifDEA66+1APDDucefQdgXA3L3PTP3uRjDQc/37OsHY3yMrCg49EYe87Hm85weQ74 +7zi0eJTcGuSMtCA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id C6DFC13456; Mon, 12 Dec 2022 15:06:49 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id wgGeLolDl2NUWQAAMHmgww (envelope-from ); Mon, 12 Dec 2022 15:06:49 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Cc: Ulrich Weigand Subject: [PATCH] [gdb/tdep] Fix s390_linux_nat_target::stopped_by_watchpoint Date: Mon, 12 Dec 2022 16:06:49 +0100 Message-Id: <20221212150649.10289-1-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.5 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 autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On s390x-linux, I run into: ... (gdb) continue^M Continuing.^M breakpoint.c:5784: internal-error: bpstat_stop_status_nowatch: \ Assertion `!target_stopped_by_watchpoint ()' failed.^M A problem internal to GDB has been detected,^M further debugging may prove unreliable.^M FAIL: gdb.threads/watchpoint-fork.exp: parent: singlethreaded: \ breakpoint after the first fork (GDB internal error) ... What happens is the follow: - a watchpoint event triggers - the event is processed, s390_linux_nat_target::stopped_by_watchpoint is called and it returns true, as expected - the watchpoint event is reported by gdb, and gdb stops - we issue a continue command - a fork event triggers - the event is processed, and during processing that event s390_linux_nat_target::stopped_by_watchpoint is called again, and returns true - the assertion fails, because the function is expected to return false The function s390_linux_nat_target::stopped_by_watchpoint returns true the second time, because it looks at the exact same data that was looked at when it was called the first time, and that data hasn't changed. There's code in the same function that intends to prevent that from happening: ... /* Do not report this watchpoint again. */ memset (&per_lowcore, 0, sizeof (per_lowcore)); if (ptrace (PTRACE_POKEUSR_AREA, s390_inferior_tid (), &parea, 0) < 0) perror_with_name (_("Couldn't clear watchpoint status")); ... and that probably used to work for older kernels, but no longer does since linux kernel commit 5e9a26928f55 ("[S390] ptrace cleanup"). Fix this by copying this: ... siginfo_t siginfo; if (!linux_nat_get_siginfo (inferior_ptid, &siginfo)) return false; if (siginfo.si_signo != SIGTRAP || (siginfo.si_code & 0xffff) != TRAP_HWBKPT) return false; ... from aarch64_linux_nat_target::stopped_data_address and remove the obsolete watchpoint status clearing code. Tested on s390x-linux. --- gdb/s390-linux-nat.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/gdb/s390-linux-nat.c b/gdb/s390-linux-nat.c index 96833e804e9..f85e8941655 100644 --- a/gdb/s390-linux-nat.c +++ b/gdb/s390-linux-nat.c @@ -673,6 +673,13 @@ s390_linux_nat_target::stopped_by_watchpoint () if (state->watch_areas.empty ()) return false; + siginfo_t siginfo; + if (!linux_nat_get_siginfo (inferior_ptid, &siginfo)) + return false; + if (siginfo.si_signo != SIGTRAP + || (siginfo.si_code & 0xffff) != TRAP_HWBKPT) + return false; + parea.len = sizeof (per_lowcore); parea.process_addr = (addr_t) & per_lowcore; parea.kernel_addr = offsetof (struct user_regs_struct, per_info.lowcore); @@ -682,14 +689,6 @@ s390_linux_nat_target::stopped_by_watchpoint () bool result = (per_lowcore.perc_storage_alteration == 1 && per_lowcore.perc_store_real_address == 0); - if (result) - { - /* Do not report this watchpoint again. */ - memset (&per_lowcore, 0, sizeof (per_lowcore)); - if (ptrace (PTRACE_POKEUSR_AREA, s390_inferior_tid (), &parea, 0) < 0) - perror_with_name (_("Couldn't clear watchpoint status")); - } - return result; } -- 2.26.2