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]

[PATCH] Disable thread specific breakpoints when thread dies


Hi,

The attached patch disables thread specific breakpoints if they are hit (in another thread) after the specific thread has died.

The rationale is that, once dead, the thread in question can never come back, and the breakpoint is then only a, potentially serious, performance drain. Even if another thread can be created with that ID it would not be appropriate to 'hit' the breakpoint.

The breakpoint is not deleted, only disabled. It may still be easily re-enabled when the program is re-run.

Is this OK?

Andrew Stubbs
2005-11-09  Andrew Stubbs  <andrew.stubbs@st.com>

	* breakpoint.c (breakpoint_thread_match): Disable thread specific
	breakpoints if we hit one after the thread has ceased to exist.

Index: src/gdb/breakpoint.c
===================================================================
--- src.orig/gdb/breakpoint.c	2005-05-29 04:13:17.000000000 +0100
+++ src/gdb/breakpoint.c	2005-11-01 13:49:40.000000000 +0000
@@ -1797,9 +1797,23 @@ breakpoint_thread_match (CORE_ADDR pc, p
 
       if ((breakpoint_enabled (bpt->owner)
 	   || bpt->owner->enable_state == bp_permanent)
-	  && bpt->address == pc
-	  && (bpt->owner->thread == -1 || bpt->owner->thread == thread))
+	  && bpt->address == pc)
 	{
+          /* Disable matched breakpoint if thread no longer exists: this
+	     prevents other tasks from hitting the breakpoint and improves
+	     performance.  */
+          if ((bpt->owner->thread != -1) && (bpt->owner->thread != thread))
+          {
+            if (!target_thread_alive(thread_id_to_pid(bpt->owner->thread)))
+              {
+                printf_filtered (
+		      "Breakpoint %d disabled as thread %d no longer alive.\n",
+		      bpt->owner->number, bpt->owner->thread);
+                disable_breakpoint(bpt->owner);
+              }
+            continue;  /* no need to consider this breakpoint any further */
+          }
+
 	  if (overlay_debugging 
 	      && section_is_overlay (bpt->section) 
 	      && !section_is_mapped (bpt->section))

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