public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] gdb: avoid conversion of SIGSEGV to SIGTRAP on user breakpoints
@ 2024-10-02 14:10 Klaus Gerlicher
  2024-10-04  9:22 ` Andrew Burgess
  2024-11-06 14:24 ` Andrew Burgess
  0 siblings, 2 replies; 9+ messages in thread
From: Klaus Gerlicher @ 2024-10-02 14:10 UTC (permalink / raw)
  To: gdb-patches

From: "Gerlicher, Klaus" <klaus.gerlicher@intel.com>

GDB converts signals GDB_SIGNAL_ILL, GDB_SIGNAL_SEGV and GDB_SIGNAL_EMT to
GDB_SIGNAL_SEGV if a breakpoint is inserted at the fault location.  If, due
to imprecise page fault reporting, a breakpoint is at the same address as
the fault address, this signal would always be reported as GDB_SIGNAL_TRAP.

Limit the check for a breakpoint at the current PC to internal breakpoints.
Internal breakpoints have a number less than or equal to zero.
---
 gdb/breakpoint.c | 18 ++++++++++++++++++
 gdb/breakpoint.h |  5 +++++
 gdb/infrun.c     |  8 +++++---
 3 files changed, 28 insertions(+), 3 deletions(-)

diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index b80b3522dcb..09526fa557f 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -4569,6 +4569,24 @@ hardware_watchpoint_inserted_in_range (const address_space *aspace,
 
 /* See breakpoint.h.  */
 
+bool
+internal_breakpoint_inserted_here_p (const address_space *aspace,
+				     CORE_ADDR pc)
+{
+  for (bp_location *bl : all_bp_locations_at_addr (pc))
+    {
+      if (bl->owner == nullptr || user_breakpoint_p (bl->owner))
+	continue;
+
+      if (bp_location_inserted_here_p (bl, aspace, pc))
+	return true;
+    }
+
+  return false;
+}
+
+/* See breakpoint.h.  */
+
 bool
 is_catchpoint (struct breakpoint *b)
 {
diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h
index cef1d727ed2..6134b546f4e 100644
--- a/gdb/breakpoint.h
+++ b/gdb/breakpoint.h
@@ -1499,6 +1499,11 @@ extern int hardware_watchpoint_inserted_in_range (const address_space *,
 						  CORE_ADDR addr,
 						  ULONGEST len);
 
+/* Returns true if any non-user breakpoints are present and inserted
+   at ADDR.  Internal breakpoints have a number less than or equal to zero.  */
+extern bool internal_breakpoint_inserted_here_p (const address_space *aspace,
+						 CORE_ADDR addr);
+
 /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the
    same breakpoint location.  In most targets, this can only be true
    if ASPACE1 matches ASPACE2.  On targets that have global
diff --git a/gdb/infrun.c b/gdb/infrun.c
index 4ca15450afe..af9c6d291b7 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -6135,7 +6135,8 @@ handle_inferior_event (struct execution_control_state *ecs)
      when we're trying to execute a breakpoint instruction on a
      non-executable stack.  This happens for call dummy breakpoints
      for architectures like SPARC that place call dummies on the
-     stack.  */
+     stack.  Note that only internal breakpoints must be used for this
+     check.  */
   if (ecs->ws.kind () == TARGET_WAITKIND_STOPPED
       && (ecs->ws.sig () == GDB_SIGNAL_ILL
 	  || ecs->ws.sig () == GDB_SIGNAL_SEGV
@@ -6143,8 +6144,9 @@ handle_inferior_event (struct execution_control_state *ecs)
     {
       struct regcache *regcache = get_thread_regcache (ecs->event_thread);
 
-      if (breakpoint_inserted_here_p (ecs->event_thread->inf->aspace.get (),
-				      regcache_read_pc (regcache)))
+      if (internal_breakpoint_inserted_here_p (
+	    ecs->event_thread->inf->aspace.get (),
+	    regcache_read_pc (regcache)))
 	{
 	  infrun_debug_printf ("Treating signal as SIGTRAP");
 	  ecs->ws.set_stopped (GDB_SIGNAL_TRAP);
-- 
2.34.1

Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de
Managing Directors: Sean Fennelly, Jeffrey Schneiderman, Tiffany Doon Silva
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928


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

end of thread, other threads:[~2024-11-07  7:46 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-10-02 14:10 [PATCH] gdb: avoid conversion of SIGSEGV to SIGTRAP on user breakpoints Klaus Gerlicher
2024-10-04  9:22 ` Andrew Burgess
2024-10-08  7:03   ` Gerlicher, Klaus
2024-10-22 11:50     ` [PING][PATCH] " Gerlicher, Klaus
2024-11-05 11:09       ` [PING V2][PATCH] " Gerlicher, Klaus
2024-11-05 14:30     ` [PATCH] " Andrew Burgess
2024-11-05 16:22       ` Gerlicher, Klaus
2024-11-06 14:24 ` Andrew Burgess
2024-11-07  7:45   ` Gerlicher, Klaus

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).