gdb, amdgpu: report SIGSEGV instead of SIGTRAP
Checks
| Context |
Check |
Description |
| linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 |
success
|
Build passed
|
| linaro-tcwg-bot/tcwg_gdb_build--master-arm |
success
|
Build passed
|
| linaro-tcwg-bot/tcwg_gdb_check--master-arm |
fail
|
Patch failed to apply
|
Commit Message
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(-)
Comments
On 9/29/26 10:31 AM, Tankut Baris Aktemur wrote:
> 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.*"
> + }
> + }
I think this should use
foreach_with_prefix with_breakpoint {yes no} {
...
}
and then only set the breakpoint if $with_breakpoint is yes.
Otherwise, LGTM.
Approved-By: Simon Marchi <simon.marchi@efficios.com>
Simon
@@ -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 ();
}
@@ -2816,5 +2816,4 @@ non-executable stack).
name="imprecise_pagefault_reporting",
predefault="false",
invalid=False,
- unused=True,
)
@@ -24,6 +24,7 @@ kernel ()
{
int *p = nullptr;
*p = 1;
+ int x = 42; /* Break here. */
}
int
@@ -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