1 # Copyright 2002, 2003, 2004, 2007 Free Software Foundation, Inc.
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 # Please email any bugs, comments, and/or additions to this file to:
17 # bug-gdb@prep.ai.mit.edu
19 # This file checks for the bug gdb/669, where the console
20 # command "info threads" and the MI command "-thread-list-ids"
21 # return different threads in the system.
23 # This only works with native configurations
28 load_lib mi-support.exp
36 # The procs below are all stolen from mi-pthreads.exp. Any updates
37 # should also be made to the procs there.
39 proc get_mi_thread_list {name} {
42 # MI will return a list of thread ids:
45 # ^done,thread-ids=[thread-id="1",thread-id="2",...],number-of-threads="N"
47 mi_gdb_test "-thread-list-ids" \
48 {\^done,thread-ids={(thread-id="[0-9]+"(,)?)+},number-of-threads="[0-9]+"} \
49 "-thread_list_ids ($name)"
52 if {[info exists expect_out(buffer)]} {
53 set output $expect_out(buffer)
56 if {![regexp {thread-ids=\{(thread-id="[0-9]+"(,)?)*\}} $output threads]} {
57 fail "finding threads in MI output ($name)"
59 pass "finding threads in MI output ($name)"
61 # Make list of console threads
62 set start [expr {[string first \{ $threads] + 1}]
63 set end [expr {[string first \} $threads] - 1}]
64 set threads [string range $threads $start $end]
65 foreach thread [split $threads ,] {
66 if {[scan $thread {thread-id="%d"} num]} {
67 lappend thread_list $num
75 # Check that MI and the console know of the same threads.
76 # Appends NAME to all test names.
77 proc check_mi_and_console_threads {name} {
80 mi_gdb_test "-thread-list-ids" \
81 {\^done,thread-ids={(thread-id="[0-9]+"(,)*)+},number-of-threads="[0-9]+"} \
82 "-thread-list-ids ($name)"
84 if {[info exists expect_out(buffer)]} {
85 set mi_output $expect_out(buffer)
88 # GDB will return a list of thread ids and some more info:
91 # -interpreter-exec console "info threads"
92 # ~" 4 Thread 2051 (LWP 7734) 0x401166b1 in __libc_nanosleep () at __libc_nanosleep:-1"
93 # ~" 3 Thread 1026 (LWP 7733) () at __libc_nanosleep:-1"
94 # ~" 2 Thread 2049 (LWP 7732) 0x401411f8 in __poll (fds=0x804bb24, nfds=1, timeout=2000) at ../sysdeps/unix/sysv/linux/poll.c:63"
95 # ~"* 1 Thread 1024 (LWP 7731) main (argc=1, argv=0xbfffdd94) at ../../../src/gdb/testsuite/gdb.mi/pthreads.c:160"
96 # FIXME: kseitz/2002-09-05: Don't use the hack-cli method.
97 mi_gdb_test "info threads" \
98 {.*(~".*"[\r\n]*)+.*} \
99 "info threads ($name)"
100 set console_output {}
101 if {[info exists expect_out(buffer)]} {
102 set console_output $expect_out(buffer)
105 # Make a list of all known threads to console (gdb's thread IDs)
106 set console_thread_list {}
107 foreach line [split $console_output \n] {
108 if {[string index $line 0] == "~"} {
109 # This is a line from the console; trim off "~", " ", "*", and "\""
110 set line [string trim $line ~\ \"\*]
111 if {[scan $line "%d" id] == 1} {
112 lappend console_thread_list $id
117 # Now find the result string from MI
119 foreach line [split $mi_output \n] {
120 if {[string range $line 0 4] == "^done"} {
124 if {$mi_result == ""} {
125 fail "finding MI result string ($name)"
127 pass "finding MI result string ($name)"
130 # Finally, extract the thread ids and compare them to the console
131 set num_mi_threads_str ""
132 if {![regexp {number-of-threads="[0-9]+"} $mi_result num_mi_threads_str]} {
133 fail "finding number of threads in MI output ($name)"
135 pass "finding number of threads in MI output ($name)"
137 # Extract the number of threads from the MI result
138 if {![scan $num_mi_threads_str {number-of-threads="%d"} num_mi_threads]} {
139 fail "got number of threads from MI ($name)"
141 pass "got number of threads from MI ($name)"
143 # Check if MI and console have same number of threads
144 if {$num_mi_threads != [llength $console_thread_list]} {
145 fail "console and MI have same number of threads ($name)"
147 pass "console and MI have same number of threads ($name)"
150 set mi_thread_list [get_mi_thread_list $name]
152 # Check if MI and console have the same threads
154 foreach ct [lsort $console_thread_list] mt [lsort $mi_thread_list] {
160 fail "MI and console have same threads ($name)"
162 # Send a list of failures to the log
163 send_log "Console has thread ids: $console_thread_list\n"
164 send_log "MI has thread ids: $mi_thread_list\n"
166 pass "MI and console have same threads ($name)"
176 set testfile "pthreads"
177 set srcfile "$testfile.c"
178 set binfile "$objdir/$subdir/gdb669-$testfile"
180 set options [list debug incdir=$objdir]
181 if {[gdb_compile_pthreads "$srcdir/$subdir/$srcfile" $binfile executable $options] != "" } {
186 check_mi_and_console_threads "at main"
188 for {set i 0} {$i < 4} {incr i} {
189 mi_next "next, try $i"
190 check_mi_and_console_threads "try $i"