1 # Copyright 2002, 2003, 2004 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 2 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, write to the Free Software
15 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-gdb@prep.ai.mit.edu
20 # This file checks for the bug gdb/669, where the console
21 # command "info threads" and the MI command "-thread-list-ids"
22 # return different threads in the system.
24 # This only works with native configurations
29 load_lib mi-support.exp
37 # The procs below are all stolen from mi-pthreads.exp. Any updates
38 # should also be made to the procs there.
40 proc get_mi_thread_list {name} {
43 # MI will return a list of thread ids:
46 # ^done,thread-ids=[thread-id="1",thread-id="2",...],number-of-threads="N"
48 mi_gdb_test "-thread-list-ids" \
49 {\^done,thread-ids={(thread-id="[0-9]+"(,)?)+},number-of-threads="[0-9]+"} \
50 "-thread_list_ids ($name)"
53 if {[info exists expect_out(buffer)]} {
54 set output $expect_out(buffer)
57 if {![regexp {thread-ids=\{(thread-id="[0-9]+"(,)?)*\}} $output threads]} {
58 fail "finding threads in MI output ($name)"
60 pass "finding threads in MI output ($name)"
62 # Make list of console threads
63 set start [expr {[string first \{ $threads] + 1}]
64 set end [expr {[string first \} $threads] - 1}]
65 set threads [string range $threads $start $end]
66 foreach thread [split $threads ,] {
67 if {[scan $thread {thread-id="%d"} num]} {
68 lappend thread_list $num
76 # Check that MI and the console know of the same threads.
77 # Appends NAME to all test names.
78 proc check_mi_and_console_threads {name} {
81 mi_gdb_test "-thread-list-ids" \
82 {\^done,thread-ids={(thread-id="[0-9]+"(,)*)+},number-of-threads="[0-9]+"} \
83 "-thread-list-ids ($name)"
85 if {[info exists expect_out(buffer)]} {
86 set mi_output $expect_out(buffer)
89 # GDB will return a list of thread ids and some more info:
92 # -interpreter-exec console "info threads"
93 # ~" 4 Thread 2051 (LWP 7734) 0x401166b1 in __libc_nanosleep () at __libc_nanosleep:-1"
94 # ~" 3 Thread 1026 (LWP 7733) () at __libc_nanosleep:-1"
95 # ~" 2 Thread 2049 (LWP 7732) 0x401411f8 in __poll (fds=0x804bb24, nfds=1, timeout=2000) at ../sysdeps/unix/sysv/linux/poll.c:63"
96 # ~"* 1 Thread 1024 (LWP 7731) main (argc=1, argv=0xbfffdd94) at ../../../src/gdb/testsuite/gdb.mi/pthreads.c:160"
97 # FIXME: kseitz/2002-09-05: Don't use the hack-cli method.
98 mi_gdb_test "info threads" \
99 {.*(~".*"[\r\n]*)+.*} \
100 "info threads ($name)"
101 set console_output {}
102 if {[info exists expect_out(buffer)]} {
103 set console_output $expect_out(buffer)
106 # Make a list of all known threads to console (gdb's thread IDs)
107 set console_thread_list {}
108 foreach line [split $console_output \n] {
109 if {[string index $line 0] == "~"} {
110 # This is a line from the console; trim off "~", " ", "*", and "\""
111 set line [string trim $line ~\ \"\*]
112 if {[scan $line "%d" id] == 1} {
113 lappend console_thread_list $id
118 # Now find the result string from MI
120 foreach line [split $mi_output \n] {
121 if {[string range $line 0 4] == "^done"} {
125 if {$mi_result == ""} {
126 fail "finding MI result string ($name)"
128 pass "finding MI result string ($name)"
131 # Finally, extract the thread ids and compare them to the console
132 set num_mi_threads_str ""
133 if {![regexp {number-of-threads="[0-9]+"} $mi_result num_mi_threads_str]} {
134 fail "finding number of threads in MI output ($name)"
136 pass "finding number of threads in MI output ($name)"
138 # Extract the number of threads from the MI result
139 if {![scan $num_mi_threads_str {number-of-threads="%d"} num_mi_threads]} {
140 fail "got number of threads from MI ($name)"
142 pass "got number of threads from MI ($name)"
144 # Check if MI and console have same number of threads
145 if {$num_mi_threads != [llength $console_thread_list]} {
146 fail "console and MI have same number of threads ($name)"
148 pass "console and MI have same number of threads ($name)"
151 set mi_thread_list [get_mi_thread_list $name]
153 # Check if MI and console have the same threads
155 foreach ct [lsort $console_thread_list] mt [lsort $mi_thread_list] {
161 fail "MI and console have same threads ($name)"
163 # Send a list of failures to the log
164 send_log "Console has thread ids: $console_thread_list\n"
165 send_log "MI has thread ids: $mi_thread_list\n"
167 pass "MI and console have same threads ($name)"
177 set testfile "pthreads"
178 set srcfile "$testfile.c"
179 set binfile "$objdir/$subdir/gdb669-$testfile"
181 set options [list debug incdir=$objdir]
182 if {[gdb_compile_pthreads "$srcdir/$subdir/$srcfile" $binfile executable $options] != "" } {
186 mi_gdb_reinitialize_dir $srcdir/$subdir
190 check_mi_and_console_threads "at main"
192 for {set i 0} {$i < 4} {incr i} {
193 mi_next "next, try $i"
194 check_mi_and_console_threads "try $i"