This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH] fix Bug 11568 - delete thread-specific breakpoint on the thread exit
- From: Waqas Jamil <waqas dot jamil47 at gmail dot com>
- To: gdb-patches at sourceware dot org
- Date: Mon, 22 Jul 2013 13:55:37 +0500
- Subject: [PATCH] fix Bug 11568 - delete thread-specific breakpoint on the thread exit
Hi
I have read the Bug about thread-specific breakpoint on the thread exit
thread at link
http://sourceware.org/bugzilla/show_bug.cgi?id=11568
I found the problem is GDB not checking about the user created thread
related breakpoints which are exited so I am posting the patch.
Before Changing Output of test run
(gdb) b start
Breakpoint 1 at 0x4005bc: file 11568.c, line 5.
(gdb) r
Starting program: /home/waqas/gdb/bugs/a.out
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/
libthread_db.so.1".
[New Thread 0x7ffff77fd700 (LWP 29010)]
[Switching to Thread 0x7ffff77fd700 (LWP 29010)]
Breakpoint 1, start (arg=0x0) at 11568.c:5
5 return NULL;
(gdb) info thread
Id Target Id Frame
* 2 Thread 0x7ffff77fd700 (LWP 29010) "a.out" start (arg=0x0) at
11568.c:5
1 Thread 0x7ffff7fdf700 (LWP 29009) "a.out" 0x00007ffff7bc6148 in
pthread_join () from /lib/x86_64-linux-gnu/
libpthread.so.0
(gdb) b 13
Note: breakpoint 3 also set at pc 0x4005f7.
Breakpoint 4 at 0x4005f7: file 11568.c, line 13.
(gdb) c
Continuing.
[Thread 0x7ffff77fd700 (LWP 29010) exited]
[Switching to Thread 0x7ffff7fdf700 (LWP 29009)]
Breakpoint 3, main () at 11568.c:13
13 return 0; /* line 13 */
(gdb) info break
Num Type Disp Enb Address What
1 breakpoint keep y 0x00000000004005bc in start at 11568.c:5
breakpoint already hit 1 time
3 breakpoint keep y 0x00000000004005f7 in main at 11568.c:13
breakpoint already hit 1 time
4 breakpoint keep y 0x00000000004005f7 in main at 11568.c:13
breakpoint already hit 1 time
(gdb) info thread
Id Target Id Frame
* 1 Thread 0x7ffff7fdf700 (LWP 29009) "a.out" main () at 11568.c:13
so breakpoint still exist but thread exited it should be removed as
watchpoint on local variable removed
After Changing in breakpoint.c:breakpoint_auto_delete
--- gdb/breakpoint.c 2013-04-25 13:15:34.000000000 +0500
+++ ./breakpoint.c 2013-07-22 11:53:43.156686242 +0500
@@ -12099,6 +12099,14 @@ 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);
+ }
+ }
}
}
form above you can see I check if the thread with breakpoint if it is user
created and it is not alive delete the break point on that thread
Output is
(gdb) break start
Breakpoint 1 at 0x4005bc: file 11568.c, line 5.
(gdb) r
Starting program: /home/waqas/gdb/bugs/a.out
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/
libthread_db.so.1".
[New Thread 0x7ffff77fd700 (LWP 2590)]
[Switching to Thread 0x7ffff77fd700 (LWP 2590)]
Breakpoint 1, start (arg=0x0) at 11568.c:5
5 return NULL;
(gdb) b main thread 2
Breakpoint 2 at 0x4005cb: file 11568.c, line 11.
(gdb) b 13
Breakpoint 3 at 0x4005f7: file 11568.c, line 13.
(gdb) info break
Num Type Disp Enb Address What
1 breakpoint keep y 0x00000000004005bc in start at 11568.c:5
breakpoint already hit 1 time
2 breakpoint keep y 0x00000000004005cb in main
at 11568.c:11 thread 2
stop only in thread 2
3 breakpoint keep y 0x00000000004005f7 in main at 11568.c:13
(gdb) info thread
Id Target Id Frame
* 2 Thread 0x7ffff77fd700 (LWP 2590) "a.out" start (arg=0x0) at 11568.c:5
1 Thread 0x7ffff7fdf700 (LWP 2586) "a.out" 0x00007ffff7bc6148 in
pthread_join () from /lib/x86_64-linux-gnu/libpthread.so.0
(gdb) c
Continuing.
[Thread 0x7ffff77fd700 (LWP 2590) exited]
[Switching to Thread 0x7ffff7fdf700 (LWP 2586)]
Breakpoint 3, main () at 11568.c:13
13 return 0; /* line 13 */
(gdb) info break
Num Type Disp Enb Address What
1 breakpoint keep y 0x00000000004005bc in start at 11568.c:5
breakpoint already hit 1 time
3 breakpoint keep y 0x00000000004005f7 in main at 11568.c:13
breakpoint already hit 1 time
(gdb) info thread
Id Target Id Frame
* 1 Thread 0x7ffff7fdf700 (LWP 2586) "a.out" main () at 11568.c:13