This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFA/commit] Minor cleanup in breakpoint_thread_match


This is in preparation for adding handling of (Ada) task-specific
breakpoints in this routine.  I could have just modified the condition
inside the loop, but it was getting too nested for my taste, making
the condition hard to read.  So here's a cleanup that would provide
two improvements: readability, and computing of the ptid's thread-id
in a lazy way.  Most of the time, at least for myself, I don't use
thread-specific breakpoints, so might as well not compute the thread ID.

Reference: http://www.sourceware.org/ml/gdb-patches/2009-03/msg00551.html

2009-03-25  Joel Brobecker  <brobecker@adacore.com>

        * breakpoint.c (breakpoint_thread_match): Split a large condition
        into several smaller conditions.  No behavior change.

Tested on x86_64-linux. I made this change in a pretty procedural and
mechanical way.  But a second pair of eyes would be appreciated. Plus,
I'd like to know if others also prefer splitting this condition like
I did.

Thanks,
-- 
Joel
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 7e50342..6b88601 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -1893,20 +1893,28 @@ int
 breakpoint_thread_match (CORE_ADDR pc, ptid_t ptid)
 {
   const struct bp_location *bpt;
-  int thread;
-
-  thread = pid_to_thread_id (ptid);
-
+  /* The thread ID associated to PTID, computed lazily.  */
+  int thread = -1;
+  
   ALL_BP_LOCATIONS (bpt)
     {
       if (bpt->loc_type != bp_loc_software_breakpoint
 	  && bpt->loc_type != bp_loc_hardware_breakpoint)
 	continue;
 
-      if ((breakpoint_enabled (bpt->owner)
-	   || bpt->owner->enable_state == bp_permanent)
-	  && bpt->address == pc
-	  && (bpt->owner->thread == -1 || bpt->owner->thread == thread))
+      if (!breakpoint_enabled (bpt->owner)
+          && bpt->owner->enable_state != bp_permanent)
+        continue;
+
+      if (bpt->address != pc)
+        continue;
+
+      /* If this is a thread-specific breakpoint, and we haven't
+         computed the ptid's thread ID yet, compute it now.  */
+      if (bpt->owner->thread != -1 && thread == -1)
+        thread = pid_to_thread_id (ptid);
+
+      if (bpt->owner->thread == -1 || bpt->owner->thread == thread)
 	{
 	  if (overlay_debugging 
 	      && section_is_overlay (bpt->section) 

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]