Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH] gdb, amdgpu: report SIGSEGV instead of SIGTRAP
@ 2026-09-29 14:31 Tankut Baris Aktemur
  2026-09-29 17:25 ` Simon Marchi
  0 siblings, 1 reply; 2+ messages in thread
From: Tankut Baris Aktemur @ 2026-09-29 14:31 UTC (permalink / raw)
  To: gdb-patches, lancelot.six; +Cc: simon.marchi

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] gdb, amdgpu: report SIGSEGV instead of SIGTRAP
  2026-09-29 14:31 [PATCH] gdb, amdgpu: report SIGSEGV instead of SIGTRAP Tankut Baris Aktemur
@ 2026-09-29 17:25 ` Simon Marchi
  0 siblings, 0 replies; 2+ messages in thread
From: Simon Marchi @ 2026-09-29 17:25 UTC (permalink / raw)
  To: Tankut Baris Aktemur, gdb-patches, lancelot.six

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-09-29 17:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-29 14:31 [PATCH] gdb, amdgpu: report SIGSEGV instead of SIGTRAP Tankut Baris Aktemur
2026-09-29 17:25 ` Simon Marchi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox