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]

Re: [PATCH with testcase] Bug 11568 - delete thread-specific breakpoint on the thread exit


2013-08-05  Muhammad Waqas <mwaqas@codesourcery.com>

	PR gdb/11568
	* breakpoint.c (remove_threaded_breakpoints): New function.
	(_initialize_breakpoint): Attach remove_threaded_breakpoints
	as thread_exit observer.

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

	PR gdb/11568
	* gdb.thread/thread-specific-bp.c: New file.
	* gdb.thread/thread-specific-bp.exp: New file.
---
 gdb/breakpoint.c                                 |   26 ++++++
 gdb/testsuite/gdb.threads/thread-specific-bp.c   |   33 ++++++++
 gdb/testsuite/gdb.threads/thread-specific-bp.exp |   98 ++++++++++++++++++++++
 3 files changed, 157 insertions(+)
 create mode 100644 gdb/testsuite/gdb.threads/thread-specific-bp.c
 create mode 100644 gdb/testsuite/gdb.threads/thread-specific-bp.exp

diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 44bb7a8..724d847 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -2928,6 +2928,31 @@ remove_breakpoints (void)
   return val;
 }
 
+/* When a thread exits, remove breakpoints that are related to
+   that thread.  */
+
+static void
+remove_threaded_breakpoints (struct thread_info *tp, int silent)
+{
+  struct breakpoint *b, *b_tmp;
+
+  ALL_BREAKPOINTS_SAFE (b, b_tmp)
+    {
+      if (b->thread == tp->num)
+	{
+         int tmp = b->number;
+         b->disposition = disp_del_at_next_stop;
+         /* Hide it from the user.  */
+         b->number = 0;
+
+         printf_filtered (_("Breakpoint %d deleted\
+because thread %d has been exited\non which this  \
+breakpoint is valid.\n"),
+			  tmp,tp->num);
+       }
+    }
+}
+
 /* Remove breakpoints of process PID.  */
 
 int
@@ -16587,4 +16612,5 @@ agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
   automatic_hardware_breakpoints = 1;
 
   observer_attach_about_to_proceed (breakpoint_about_to_proceed);
+  observer_attach_thread_exit (remove_threaded_breakpoints);
 }
diff --git a/gdb/testsuite/gdb.threads/thread-specific-bp.c b/gdb/testsuite/gdb.threads/thread-specific-bp.c
new file mode 100644
index 0000000..474d667
--- /dev/null
+++ b/gdb/testsuite/gdb.threads/thread-specific-bp.c
@@ -0,0 +1,33 @@
+/* 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 <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; /*set break here*/
+}
diff --git a/gdb/testsuite/gdb.threads/thread-specific-bp.exp b/gdb/testsuite/gdb.threads/thread-specific-bp.exp
new file mode 100644
index 0000000..013bfcd
--- /dev/null
+++ b/gdb/testsuite/gdb.threads/thread-specific-bp.exp
@@ -0,0 +1,98 @@
+# 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/>.
+#
+# Verify that a thread-specific breakpoint is deleted when the
+# corresponding thread is gone.
+
+standard_testfile
+
+if {[gdb_compile_pthreads \
+	 "${srcdir}/${subdir}/${srcfile}" \
+	 "${binfile}" executable {debug} ] != "" } {
+    return -1
+}
+
+clean_restart ${binfile}
+
+proc check_threaded_breakpoint {mode} {
+    with_test_prefix "$mode" {
+	global gdb_prompt
+	gdb_breakpoint "start"
+	gdb_continue_to_breakpoint "start"
+	set thre 0
+
+	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 thread's id.
+		set thre $expect_out(1,string)
+	    }
+	}
+	gdb_breakpoint "main thread $thre"
+	gdb_test "info break" ".*breakpoint.*thread $thre" "Breakpoint set"
+	gdb_breakpoint [gdb_get_line_number "set break here"]
+
+	# 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_test "thread $thre" "Switching to thread $thre.*" "Thread $thre selected"
+	set full_name "continue to breakpoint: set break here"
+
+	gdb_test_multiple "continue" "$full_name" {
+	    -re "(?:Breakpoint) .* (at) .*\r\n$gdb_prompt $" {
+		pass $full_name
+	    }
+	    -re ".*$gdb_prompt $" {
+		fail $full_name
+	    }
+	    timeout {
+      		send_gdb "thread 1\n"
+		exp_continue
+	    }
+	}
+
+	set test "thread-specific breakpoint is deleted"
+	gdb_test_multiple "info breakpoint" $test {
+	    -re "thread $thre\n$gdb_prompt $" {
+		fail $test
+	    }
+	    -re "$gdb_prompt $" {
+		pass $test
+	    }
+	}
+    }
+}
+
+if ![runto_main] {
+    untested "could not run to main"
+    return -1
+}
+
+# Testing in all stop mode.
+check_threaded_breakpoint "All stop"
+
+clean_restart ${binfile}
+
+gdb_test "set target-async on" ".*" "Set async mode"
+gdb_test "set non-stop on" ".*" "Set non stop mode"
+
+if ![runto_main] {
+    untested "could not run to main"
+    return -1
+}
+
+# Testing in non-stop with async mode.
+check_threaded_breakpoint "non-stop with async"
-- 
1.7.9.5


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