From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Cc: Ulrich Weigand <Ulrich.Weigand@de.ibm.com>
Subject: [PATCH] [gdb/tdep] Fix s390_linux_nat_target::stopped_by_watchpoint
Date: Mon, 12 Dec 2022 16:06:49 +0100 [thread overview]
Message-ID: <20221212150649.10289-1-tdevries@suse.de> (raw)
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
next reply other threads:[~2022-12-12 15:06 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-12 15:06 Tom de Vries [this message]
2022-12-13 15:17 ` Ulrich Weigand
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221212150649.10289-1-tdevries@suse.de \
--to=tdevries@suse.de \
--cc=Ulrich.Weigand@de.ibm.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).