This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH]13217 thread apply all detach throws a SEGFAULT
- From: "Bilal, Muhammad" <Muhammad_Bilal at mentor dot com>
- To: Tom Tromey <tromey at redhat dot com>, "eliz at gnu dot org" <eliz at gnu dot org>, "brobecker at adacore dot com" <brobecker at adacore dot com>, "dje at google dot com" <dje at google dot com>, "jan dot kratochvil at redhat dot com" <jan dot kratochvil at redhat dot com>, "gdb-patches at sourceware dot org" <gdb-patches at sourceware dot org>
- Date: Mon, 14 Jan 2013 13:38:22 +0000
- Subject: [PATCH]13217 thread apply all detach throws a SEGFAULT
- References: <97B73E257CC18646B0B5D3DD77DCBDD158E8FD@EU-MBX-02.mgc.mentorg.com>
Hi,
I worked on bug#13217 "thread apply all detach throws a SEGFAULT " of gdb
and fixed this problem by making a Patch.
I am upstreaming of it
Actually when command "thread apply all detach" is applied then the function thread_apply_command (char *tidlist, int from_tty) in thread.c:1179 called a function init_thread_list (void)in thread.c:140
which makes the 'thread_list' struck to null so when for (tp = thread_list; tp; tp = tp->next) loop in thread_apply_command (char *tidlist, int from_tty) in thread.c:1179 iterates 2nd time it throws a segmentation fault when try to access the bogus value of
thread_list
so i have fixed this problem
I have written the test case for it also
I have worked on gdb-7.5.50.20121127 snapshot
1)
gdb/thread.c
diff -u thread.c new_thread.c > change_thread.c
------------PATCH---------------------------------------
--- thread.c 2012-07-27 05:52:36.000000000 +0500
+++ new_thread.c 2013-01-02 12:06:51.876346782 +0500
@@ -1203,6 +1203,8 @@
execute_command (cmd, from_tty);
strcpy (cmd, saved_cmd); /* Restore exact command used
previously. */
+ if(thread_list == NULL)
+ break;
}
do_cleanups (old_chain);
2)
gdb/testsuit/gdb.thread
-----------------------------------test------------------------------------
--- threadapply.exp 2013-01-14 16:30:25.000000000 +0500
+++ new_threadapply.exp 2013-01-14 16:39:07.000000000 +0500
@@ -63,3 +63,4 @@
gdb_test "up" ".*in main.*" "go up in the stack frame"
gdb_test "thread apply all print 1" "Thread ..*\\\$\[0-9]+ = 1.*Thread ..*\\\$\[0-9]+ = 1.*Thread ..*\\\$\[0-9]+ = 1.*Thread ..*\\\$\[0-9]+ = 1.*Thread ..*\\\$\[0-9]+ = 1.*Thread ..*\\\$\[0-9]+ = 1" "run a simple print command on all threads"
gdb_test "down" "#0.*thread_function.*" "go down and check selected frame"
+gdb_test "thread apply all detach" "Thread.*\nDetaching from.*" "detaching from all threads"
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
please review it and add me sourceware.org
thanks
Bilal