From: Tankut Baris Aktemur <tankutbaris.aktemur@amd.com>
To: <gdb-patches@sourceware.org>, <lancelot.six@amd.com>
Cc: <simon.marchi@efficios.com>
Subject: [PATCH] gdb, amdgpu: report SIGSEGV instead of SIGTRAP
Date: Tue, 29 Sep 2026 16:31:25 +0200 [thread overview]
Message-ID: <20260929143125.1098582-1-tankutbaris.aktemur@amd.com> (raw)
By default, segfaults on the AMD GPU target are imprecise: they are
reported *after* the actual segfaulting instruction (and in practice,
several other instructions) has been executed. If there is a
breakpoint placed after the segfaulting statement, segfault should be
reported instead of a breakpoint hit. Achieve this by setting the
`imprecise_pagefault_reporting` gdbarch field to true.
Tested on gfx1201.
Bug: AIROCGDB-662
---
gdb/amdgpu-tdep.c | 6 +++++
gdb/gdbarch_components.py | 1 -
.../precise-memory-warning-sigsegv.cpp | 1 +
.../precise-memory-warning-sigsegv.exp | 23 +++++++++++++++++--
4 files changed, 28 insertions(+), 3 deletions(-)
diff --git a/gdb/amdgpu-tdep.c b/gdb/amdgpu-tdep.c
index b0d6023a410..d1407af16bd 100644
--- a/gdb/amdgpu-tdep.c
+++ b/gdb/amdgpu-tdep.c
@@ -1270,6 +1270,12 @@ amdgpu_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
set_gdbarch_decr_pc_after_break (gdbarch, pc_adjust);
+ /* Pagefaults are reported imprecisely. If we receive a SIGSEGV on
+ an instruction where there is already a breakpoint, we tell GDB
+ to not convert the signal to a breakpoint hit, but to continue
+ treating it as SIGSEGV. */
+ set_gdbarch_imprecise_pagefault_reporting (gdbarch, true);
+
return gdbarch_u.release ();
}
diff --git a/gdb/gdbarch_components.py b/gdb/gdbarch_components.py
index 604c37f3832..f2ad61e5a23 100644
--- a/gdb/gdbarch_components.py
+++ b/gdb/gdbarch_components.py
@@ -2816,5 +2816,4 @@ non-executable stack).
name="imprecise_pagefault_reporting",
predefault="false",
invalid=False,
- unused=True,
)
diff --git a/gdb/testsuite/gdb.rocm/precise-memory-warning-sigsegv.cpp b/gdb/testsuite/gdb.rocm/precise-memory-warning-sigsegv.cpp
index 2510e4381bf..db0f06b364e 100644
--- a/gdb/testsuite/gdb.rocm/precise-memory-warning-sigsegv.cpp
+++ b/gdb/testsuite/gdb.rocm/precise-memory-warning-sigsegv.cpp
@@ -24,6 +24,7 @@ kernel ()
{
int *p = nullptr;
*p = 1;
+ int x = 42; /* Break here. */
}
int
diff --git a/gdb/testsuite/gdb.rocm/precise-memory-warning-sigsegv.exp b/gdb/testsuite/gdb.rocm/precise-memory-warning-sigsegv.exp
index 460d14a2b30..755fc0a7a56 100644
--- a/gdb/testsuite/gdb.rocm/precise-memory-warning-sigsegv.exp
+++ b/gdb/testsuite/gdb.rocm/precise-memory-warning-sigsegv.exp
@@ -29,8 +29,7 @@ if {[build_executable "failed to prepare" $testfile $srcfile {debug hip}]} {
}
proc do_test { } {
- clean_restart
- gdb_load $::binfile
+ clean_restart $::testfile
with_rocm_gpu_lock {
if {![runto_main]} {
@@ -41,6 +40,26 @@ proc do_test { } {
gdb_test "continue" \
"SIGSEGV, Segmentation fault.*Warning: precise memory violation signal reporting is not enabled.*"
}
+
+ clean_restart $::testfile
+
+ with_rocm_gpu_lock {
+ if {![runto_main]} {
+ return
+ }
+
+ with_test_prefix "with-breakpoint" {
+ gdb_test_no_output "set amdgpu precise-memory off"
+
+ # Define a breakpoint right after the line that would
+ # cause segfault. SIGSEGV should be reported, not a
+ # breakpoint hit.
+ gdb_breakpoint [gdb_get_line_number "Break here"] -allow-pending
+
+ gdb_test "continue" \
+ "SIGSEGV, Segmentation fault.*Warning: precise memory violation signal reporting is not enabled.*"
+ }
+ }
}
do_test
--
2.53.0
reply other threads:[~2026-09-29 14:32 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20260929143125.1098582-1-tankutbaris.aktemur@amd.com \
--to=tankutbaris.aktemur@amd.com \
--cc=gdb-patches@sourceware.org \
--cc=lancelot.six@amd.com \
--cc=simon.marchi@efficios.com \
/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