This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [rfa/linux] Don't select an event LWP that wasn't resumed
- From: Daniel Jacobowitz <drow at false dot org>
- To: gdb-patches at sources dot redhat dot com
- Date: Sun, 27 Jul 2008 17:06:45 -0400
- Subject: Re: [rfa/linux] Don't select an event LWP that wasn't resumed
- References: <20050404040643.GA7531@nevyn.them.org>
On Mon, Apr 04, 2005 at 12:06:44AM -0400, Daniel Jacobowitz wrote:
> This patch improves testsuite results for schedlock.exp on platforms
> which use software single step. If we're trying to find which event
> to report, we should only look at LWPs with lp->resumed set. They may not
> have actually resumed, but they will correspond to the LWPs which infrun
> requested be resumed (even if they had pending status).
>
> Without this patch, we end up with five threads with pending SIGTRAPs in the
> portion of schedlock.exp which uses set scheduler-locking on. Then we
> resume a different thread, and eventually send it a Control-C. But in
> our next call to select_event_lwp, we select one of those threads with a
> pending SIGTRAP instead of th thread which was actually running.
Another patch from April 2005. I can no longer reproduce this failure
(I tried for several hours), but reading the code convinced me that
the patch is correct. We should only report events from threads that
have been resumed.
Tested on mips-linux and checked in, along with the testsuite changes
I used while trying to reproduce it.
--
Daniel Jacobowitz
CodeSourcery
2008-07-27 Daniel Jacobowitz <dan@codesourcery.com>
* linux-nat.c (count_events_callback, select_event_lwp_callback): Only
report events from resumed threads.
2008-07-27 Daniel Jacobowitz <dan@codesourcery.com>
* gdb.threads/schedlock.exp (get_args): Update to work for any
value of NUM.
(Top level): Report the number of threads that did not resume.
---
gdb/linux-nat.c | 8 ++++----
gdb/testsuite/gdb.threads/schedlock.exp | 23 +++++++++++++++++------
2 files changed, 21 insertions(+), 10 deletions(-)
Index: gdb-only/gdb/linux-nat.c
===================================================================
--- gdb-only.orig/gdb/linux-nat.c 2008-07-26 21:56:41.000000000 -0400
+++ gdb-only/gdb/linux-nat.c 2008-07-26 23:03:37.000000000 -0400
@@ -2319,8 +2319,8 @@ count_events_callback (struct lwp_info *
gdb_assert (count != NULL);
- /* Count only LWPs that have a SIGTRAP event pending. */
- if (lp->status != 0
+ /* Count only resumed LWPs that have a SIGTRAP event pending. */
+ if (lp->status != 0 && lp->resumed
&& WIFSTOPPED (lp->status) && WSTOPSIG (lp->status) == SIGTRAP)
(*count)++;
@@ -2347,8 +2347,8 @@ select_event_lwp_callback (struct lwp_in
gdb_assert (selector != NULL);
- /* Select only LWPs that have a SIGTRAP event pending. */
- if (lp->status != 0
+ /* Select only resumed LWPs that have a SIGTRAP event pending. */
+ if (lp->status != 0 && lp->resumed
&& WIFSTOPPED (lp->status) && WSTOPSIG (lp->status) == SIGTRAP)
if ((*selector)-- == 0)
return 1;
Index: gdb-only/gdb/testsuite/gdb.threads/schedlock.exp
===================================================================
--- gdb-only.orig/gdb/testsuite/gdb.threads/schedlock.exp 2008-07-26 20:46:42.000000000 -0400
+++ gdb-only/gdb/testsuite/gdb.threads/schedlock.exp 2008-07-26 23:04:10.000000000 -0400
@@ -45,14 +45,25 @@ if {[gdb_compile_pthreads "${srcdir}/${s
proc get_args { } {
global list_count
global gdb_prompt
+ global NUM
+
+ set pattern "(\[0-9\]+)"
+ for {set i 1} {[expr $i < $NUM]} {incr i} {
+ append pattern ", (\[0-9\]+)"
+ }
send_gdb "print args\n"
gdb_expect {
- -re "\\\$\[0-9\]+ = {(\[0-9\]+), (\[0-9\]+)}.*$gdb_prompt"
+ -re "\\\$\[0-9\]+ = {$pattern}.*$gdb_prompt"
{
set list_count [expr $list_count + 1]
pass "listed args ($list_count)"
- return [list $expect_out(1,string) $expect_out(2,string)]
+
+ set result ""
+ for {set i 1} {[expr $i <= $NUM]} {incr i} {
+ lappend result $expect_out($i,string)
+ }
+ return $result
}
-re "$gdb_prompt"
{
@@ -202,16 +213,16 @@ my_continue "initial"
set cont_args [get_args]
-set ok 1
+set bad 0
for {set i 0} {[expr $i < $NUM]} {set i [expr $i + 1]} {
if {[lindex $start_args $i] == [lindex $cont_args $i]} {
- set ok 0
+ incr bad
}
}
-if { $ok } {
+if { $bad == 0 } {
pass "all threads alive"
} else {
- fail "all threads alive"
+ fail "all threads alive ($bad/$NUM did not run)"
}
# We can't change threads, unfortunately, in current GDB. Use