public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] gdb: cleanup around some set_momentary_breakpoint_at_pc calls
@ 2023-04-03 14:11 Andrew Burgess
  0 siblings, 0 replies; only message in thread
From: Andrew Burgess @ 2023-04-03 14:11 UTC (permalink / raw)
  To: gdb-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=60a13bbcdfb0ce008a77563cea0c34c830d7b170

commit 60a13bbcdfb0ce008a77563cea0c34c830d7b170
Author: Andrew Burgess <aburgess@redhat.com>
Date:   Thu Mar 16 11:13:44 2023 +0000

    gdb: cleanup around some set_momentary_breakpoint_at_pc calls
    
    I noticed a couple of places in infrun.c where we call
    set_momentary_breakpoint_at_pc, and then set the newly created
    breakpoint's thread field, these are in:
    
      insert_exception_resume_breakpoint
      insert_exception_resume_from_probe
    
    Function set_momentary_breakpoint_at_pc calls
    set_momentary_breakpoint, which always creates the breakpoint as
    thread-specific for the current inferior_thread().
    
    The two insert_* functions mentioned above take an arbitrary
    thread_info* as an argument and set the breakpoint::thread to hold the
    thread number of that arbitrary thread.
    
    However, the insert_* functions store the breakpoint pointer within
    the current inferior_thread(), so we know that the thread being passed
    in must be the currently selected thread.
    
    What this means is that we can:
    
      1. Assert that the thread being passed in is the currently selected
      thread, and
    
      2. No longer adjust the breakpoint::thread field, this will already
      have been set correctly be calling set_momentary_breakpoint_at_pc.
    
    There should be no user visible changes after this commit.

Diff:
---
 gdb/infrun.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/gdb/infrun.c b/gdb/infrun.c
index 8a8439f6da5..87141117dfe 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -8190,6 +8190,9 @@ insert_exception_resume_breakpoint (struct thread_info *tp,
 	  infrun_debug_printf ("exception resume at %lx",
 			       (unsigned long) handler);
 
+	  /* set_momentary_breakpoint_at_pc creates a thread-specific
+	     breakpoint for the current inferior thread.  */
+	  gdb_assert (tp == inferior_thread ());
 	  bp = set_momentary_breakpoint_at_pc (get_frame_arch (frame),
 					       handler,
 					       bp_exception_resume).release ();
@@ -8197,8 +8200,7 @@ insert_exception_resume_breakpoint (struct thread_info *tp,
 	  /* set_momentary_breakpoint_at_pc invalidates FRAME.  */
 	  frame = nullptr;
 
-	  bp->thread = tp->global_num;
-	  inferior_thread ()->control.exception_resume_breakpoint = bp;
+	  tp->control.exception_resume_breakpoint = bp;
 	}
     }
   catch (const gdb_exception_error &e)
@@ -8228,10 +8230,12 @@ insert_exception_resume_from_probe (struct thread_info *tp,
   infrun_debug_printf ("exception resume at %s",
 		       paddress (probe->objfile->arch (), handler));
 
+  /* set_momentary_breakpoint_at_pc creates a thread-specific breakpoint
+     for the current inferior thread.  */
+  gdb_assert (tp == inferior_thread ());
   bp = set_momentary_breakpoint_at_pc (get_frame_arch (frame),
 				       handler, bp_exception_resume).release ();
-  bp->thread = tp->global_num;
-  inferior_thread ()->control.exception_resume_breakpoint = bp;
+  tp->control.exception_resume_breakpoint = bp;
 }
 
 /* This is called when an exception has been intercepted.  Check to

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-04-03 14:11 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-03 14:11 [binutils-gdb] gdb: cleanup around some set_momentary_breakpoint_at_pc calls Andrew Burgess

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