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] Bug fix PR gdb/11568 - delete thread-specific breakpoint on the thread exit


Hi

This patch remove thread-specific breakpoints on thread exit, please
review it and thanks to Yao for correction in testcase.
Workaround is simple, I have just added code snippet in a function
breakpoint_auto_delete which check if thread specific breakpoints is
on a thread which is exited, if there is any it will be deleted.

ChangLog

2013-07-24  Muhammad Waqas  <mwaqas@codesourcery.com>

	PR gdb/11568
	* breakpoint.c (breakpoint_auto_delete): Remove thread related
	breakpoints if threads are exited.

Index: breakpoint.c
===================================================================
RCS file: /cvs/src/src/gdb/breakpoint.c,v
retrieving revision 1.773
diff -u -p -r1.773 breakpoint.c
--- breakpoint.c	24 Jul 2013 19:50:32 -0000	1.773
+++ breakpoint.c	1 Aug 2013 05:41:58 -0000
@@ -11941,6 +11941,17 @@ breakpoint_auto_delete (bpstat bs)
   {
     if (b->disposition == disp_del_at_next_stop)
       delete_breakpoint (b);
+    else if (b->thread > 0)
+      {
+	/* If breakpoint relates to user created thread Check if it's
+	   not alive then delete it.  */
+	struct thread_info *tp = find_thread_id (b->thread);
+
+	if (tp != NULL && (tp->state == THREAD_EXITED
+			    || !target_thread_alive (tp->ptid)))
+	  delete_breakpoint(b);
+
+      }
   }
 }
testsuite/ChangeLog

2013-07-24  Muhammad Waqas  <mwaqas@codesourccery.com>
	    Jan Kratochvil  <jan.kartochvil@redhat.com>

	*gdb.thread/thread-specific-bp.c: Newfile.
	*gdb.thread/thread-specific-bp.exp: Newfile.

Index: testsuite/gdb.threads/thread-specific-bp.c
===================================================================
RCS file: testsuite/gdb.threads/thread-specific-bp.c
diff -N testsuite/gdb.threads/thread-specific-bp.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ testsuite/gdb.threads/thread-specific-bp.c	1 Aug 2013 05:42:00 -0000
@@ -0,0 +1,34 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2013 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include <stdio.h>
+#include <pthread.h>
+
+static void *
+start (void *arg)
+{
+  return NULL;
+}
+
+int
+main (void)
+{
+  pthread_t thread;
+  pthread_create (&thread, NULL, start, NULL);
+  pthread_join (thread, NULL);
+  return 0; /*line # 13*/
+}
Index: testsuite/gdb.threads/thread-specific-bp.exp
===================================================================
RCS file: testsuite/gdb.threads/thread-specific-bp.exp
diff -N testsuite/gdb.threads/thread-specific-bp.exp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ testsuite/gdb.threads/thread-specific-bp.exp	1 Aug 2013 05:42:00 -0000
@@ -0,0 +1,59 @@
+# Copyright (C) 2013 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# This file was written by Muhammad Waqas <mwaqas@codesourcery.com>
+#
+#This test verfiy that Breakpoint on a spacific thread is deleted
+
+standard_testfile
+
+if {[gdb_compile_pthreads \
+	 "${srcdir}/${subdir}/${srcfile}" \
+	 "${binfile}" executable {debug} ] != "" } {
+    return -1
+}
+
+clean_restart ${binfile}
+if [runto main] then {
+
+    gdb_breakpoint "start"
+    gdb_continue_to_breakpoint "start"
+    gdb_test_multiple "info threads" "get thread 1 id" {
+	-re "(\[0-9\]+)(\[^\n\r\]*Thread\[^\n\r\]*start.*)($gdb_prompt $)" {
+	    pass "thread created"
+	}
+    }
+    # get the id of thread
+    set thre $expect_out(1,string)
+    gdb_breakpoint [gdb_get_line_number "line # 13"]
+
+    # Force GDB to update its knowledge on existing threads when this
+    # breakpoint is hit.  Otherwise, GDB doesn't realize thread $thre
+    # has exited and doesn't remove the thread specific breakpoint.
+    gdb_test "commands\ninfo threads\nend" "End with.*" "add breakpoint commands"
+    gdb_breakpoint "main thread $thre"
+    gdb_test "info break" ".*breakpoint.*(thread $thre)" "Breakpoint set"
+    gdb_test "thread $thre" "Switching to thread $thre.*" "Thread $thre selected"
+    gdb_continue_to_breakpoint "line # 13"
+    set test "thread-specific breakpoint is deleted"
+    gdb_test_multiple "info breakpoint" $test {
+    	-re "thread $thre.*$gdb_prompt $" {
+	    fail $test
+    	}
+    	-re "$gdb_prompt $" {
+	    pass $test
+    	}
+    }
+}


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