Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Muhammad Waqas <mwaqas@codesourcery.com>
To: Pedro Alves <palves@redhat.com>
Cc: Tom Tromey <tromey@redhat.com>, Yao Qi <yao@codesourcery.com>,
	<gdb-patches@sourceware.org>
Subject: Re: [PATCH with testcase] Bug 11568 - delete thread-specific breakpoint on the thread exit
Date: Fri, 23 Aug 2013 05:31:00 -0000	[thread overview]
Message-ID: <5216F37D.9090009@codesourcery.com> (raw)
In-Reply-To: <521646F5.1010509@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 6233 bytes --]

On 08/22/2013 10:14 PM, Pedro Alves wrote:
> I'm having trouble applying this patch as well.
> Could you resend it please?
> 
>> Sorry for this. Please find the patch in attachment as well.
>> Thanks.

gdb/ChangeLog

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

	PR gdb/11568
	* breakpoint.c (remove_threaded_breakpoints): New function.
	* breakpoint.c (_initialize_breakpoint): function
        remove_threaded_breakpoints registers with thread_exit.

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	23 Aug 2013 05:15:34 -0000
@@ -2928,6 +2928,24 @@ remove_breakpoints (void)
   return val;
 }

+/* Used when a thread exits, it will remove breakpoints which
+   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)
+       {
+         b->disposition = disp_del_at_next_stop;
+         b->number = 0;
+       }
+    }
+}
+
 /* Remove breakpoints of process PID.  */

 int
@@ -16568,4 +16586,5 @@ agent-printf \"printf format string\", a
   automatic_hardware_breakpoints = 1;

   observer_attach_about_to_proceed (breakpoint_about_to_proceed);
+  observer_attach_thread_exit (remove_threaded_breakpoints);
 }

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.


Index: thread-specific-bp.c
===================================================================
RCS file: thread-specific-bp.c
diff -N thread-specific-bp.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ thread-specific-bp.c	23 Aug 2013 04:54:21 -0000
@@ -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*/
+}

Index: thread-specific-bp.exp
===================================================================
RCS file: thread-specific-bp.exp
diff -N thread-specific-bp.exp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ thread-specific-bp.exp	23 Aug 2013 04:54:46 -0000
@@ -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 id of thread
+	    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"
+
+    send_gdb "continue\n"
+    gdb_expect 10 {
+	-re "(?:Breakpoint|Temporary breakpoint) .* (at|in) .*\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.*$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"

[-- Attachment #2: breakpoint.c.thread.patch --]
[-- Type: text/x-patch, Size: 1039 bytes --]

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	23 Aug 2013 05:15:34 -0000
@@ -2928,6 +2928,24 @@ remove_breakpoints (void)
   return val;
 }
 
+/* Used when a thread exits, it will remove breakpoints which
+   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)
+       {
+         b->disposition = disp_del_at_next_stop;
+         b->number = 0;
+       }
+    }
+}
+
 /* Remove breakpoints of process PID.  */
 
 int
@@ -16568,4 +16586,5 @@ agent-printf \"printf format string\", a
   automatic_hardware_breakpoints = 1;
 
   observer_attach_about_to_proceed (breakpoint_about_to_proceed);
+  observer_attach_thread_exit (remove_threaded_breakpoints);
 }

[-- Attachment #3: thread-spacific-bp.c.patch --]
[-- Type: text/x-patch, Size: 1282 bytes --]

Index: thread-specific-bp.c
===================================================================
RCS file: thread-specific-bp.c
diff -N thread-specific-bp.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ thread-specific-bp.c	23 Aug 2013 04:54:21 -0000
@@ -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*/
+}

[-- Attachment #4: thread-spacific-bp.exp.patch --]
[-- Type: text/x-patch, Size: 3268 bytes --]

Index: thread-specific-bp.exp
===================================================================
RCS file: thread-specific-bp.exp
diff -N thread-specific-bp.exp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ thread-specific-bp.exp	23 Aug 2013 04:54:46 -0000
@@ -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 id of thread
+	    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"
+    
+    send_gdb "continue\n"
+    gdb_expect 10 {
+	-re "(?:Breakpoint|Temporary breakpoint) .* (at|in) .*\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.*$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"

  reply	other threads:[~2013-08-23  5:31 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-29  7:29 Muhammad Waqas
2013-07-29  9:21 ` Yao Qi
2013-07-29 11:42   ` Muhammad Waqas
2013-07-29 14:18     ` Yao Qi
2013-07-30 10:34       ` Muhammad Waqas
2013-07-31  2:41         ` Yao Qi
2013-08-01 10:51           ` Pedro Alves
2013-08-01 10:59             ` Yao Qi
2013-08-01 11:27               ` Pedro Alves
2013-08-01 12:10                 ` Yao Qi
2013-08-01 11:57         ` Pedro Alves
2013-08-01 12:44           ` Muhammad Waqas
2013-08-02  9:45             ` Pedro Alves
2013-08-05 12:01               ` Muhammad Waqas
2013-08-05 13:57                 ` Tom Tromey
2013-08-06  6:12                   ` Muhammad Waqas
2013-08-22  9:42                     ` Muhammad Waqas
2013-08-22 17:14                       ` Pedro Alves
2013-08-23  5:31                         ` Muhammad Waqas [this message]
2013-08-27 11:31                         ` Muhammad Waqas
2013-08-27 19:02                           ` Pedro Alves
2013-08-27 19:06                             ` Pedro Alves
2013-08-28 12:26                             ` Muhammad Waqas
2013-08-30 16:28                               ` Pedro Alves
2013-09-02  4:06                                 ` Muhammad Waqas
2013-09-02  8:39                                   ` Pedro Alves
2013-09-02  9:46                                     ` Muhammad Waqas
2013-09-02 10:24                                       ` Pedro Alves
2013-09-02 10:32                                         ` Muhammad Waqas
2013-09-02 10:48                                           ` Pedro Alves
2013-09-02 16:46                               ` Pedro Alves
2013-09-02 16:52                                 ` [PATCH] PR gdb/11568 - delete thread-specific breakpoints on " Pedro Alves
2013-09-09 16:07                                   ` Tom Tromey
2013-09-17 19:36                                     ` Pedro Alves
2013-09-19 14:48                                       ` [COMMIT PATCH] Fix regressions caused by thread-specific breakpoint deletion. (was: Re: [PATCH] PR gdb/11568 - delete thread-specific breakpoints on thread exit) Pedro Alves
2013-08-28 12:26                             ` [PATCH with testcase] Bug 11568 - delete thread-specific breakpoint on the thread exit Muhammad Waqas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5216F37D.9090009@codesourcery.com \
    --to=mwaqas@codesourcery.com \
    --cc=gdb-patches@sourceware.org \
    --cc=palves@redhat.com \
    --cc=tromey@redhat.com \
    --cc=yao@codesourcery.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox