* configure.in: Add config header.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.mi / gdb669.exp
CommitLineData
d1a2f204
KS
1# Copyright 2002 Free Software Foundation, Inc.
2
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.
7#
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.
12#
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.
16
17# Please email any bugs, comments, and/or additions to this file to:
18# bug-gdb@prep.ai.mit.edu
19
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.
23
24# This only works with native configurations
25if {![isnative]} {
26 return
27}
28
29load_lib mi-support.exp
30set MIFLAGS "-i=mi"
31
32gdb_exit
33if {[mi_gdb_start]} {
34 continue
35}
36
37# The procs below are all stolen from mi-pthreads.exp. Any updates
38# should also be made to the procs there.
39
40proc get_mi_thread_list {name} {
41 global expect_out
42
43 # MI will return a list of thread ids:
44 #
45 # -thread-list-ids
46 # ^done,thread-ids=[thread-id="1",thread-id="2",...],number-of-threads="N"
47 # (gdb)
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)"
51
52 set thread_list {}
53 if {![regexp {thread-ids=\{(thread-id="[0-9]+"(,)?)*\}} $expect_out(buffer) threads]} {
54 fail "finding threads in MI output ($name)"
55 } else {
56 pass "finding threads in MI output ($name)"
57
58 # Make list of console threads
59 set start [expr {[string first \{ $threads] + 1}]
60 set end [expr {[string first \} $threads] - 1}]
61 set threads [string range $threads $start $end]
62 foreach thread [split $threads ,] {
63 if {[scan $thread {thread-id="%d"} num]} {
64 lappend thread_list $num
65 }
66 }
67 }
68
69 return $thread_list
70}
71
72# Check that MI and the console know of the same threads.
73# Appends NAME to all test names.
74proc check_mi_and_console_threads {name} {
75 global expect_out
76
77 mi_gdb_test "-thread-list-ids" \
78 {\^done,thread-ids={(thread-id="[0-9]+"(,)*)+},number-of-threads="[0-9]+"} \
79 "-thread-list-ids ($name)"
80 set mi_output $expect_out(buffer)
81
82 # GDB will return a list of thread ids and some more info:
83 #
84 # (gdb)
85 # -interpreter-exec console "info threads"
86 # ~" 4 Thread 2051 (LWP 7734) 0x401166b1 in __libc_nanosleep () at __libc_nanosleep:-1"
87 # ~" 3 Thread 1026 (LWP 7733) () at __libc_nanosleep:-1"
88 # ~" 2 Thread 2049 (LWP 7732) 0x401411f8 in __poll (fds=0x804bb24, nfds=1, timeout=2000) at ../sysdeps/unix/sysv/linux/poll.c:63"
89 # ~"* 1 Thread 1024 (LWP 7731) main (argc=1, argv=0xbfffdd94) at ../../../src/gdb/testsuite/gdb.mi/pthreads.c:160"
90 # FIXME: kseitz/2002-09-05: Don't use the hack-cli method.
91 mi_gdb_test "info threads" \
92 {.*(~".*"[\r\n]*)+.*} \
93 "info threads ($name)"
94 set console_output $expect_out(buffer)
95
96 # Make a list of all known threads to console (gdb's thread IDs)
97 set console_thread_list {}
98 foreach line [split $console_output \n] {
99 if {[string index $line 0] == "~"} {
100 # This is a line from the console; trim off "~", " ", "*", and "\""
101 set line [string trim $line ~\ \"\*]
102 if {[scan $line "%d" id] == 1} {
103 lappend console_thread_list $id
104 }
105 }
106 }
107
108 # Now find the result string from MI
109 set mi_result ""
110 foreach line [split $mi_output \n] {
111 if {[string range $line 0 4] == "^done"} {
112 set mi_result $line
113 }
114 }
115 if {$mi_result == ""} {
116 fail "finding MI result string ($name)"
117 } else {
118 pass "finding MI result string ($name)"
119 }
120
121 # Finally, extract the thread ids and compare them to the console
122 set num_mi_threads_str ""
123 if {![regexp {number-of-threads="[0-9]+"} $mi_result num_mi_threads_str]} {
124 fail "finding number of threads in MI output ($name)"
125 } else {
126 pass "finding number of threads in MI output ($name)"
127
128 # Extract the number of threads from the MI result
129 if {![scan $num_mi_threads_str {number-of-threads="%d"} num_mi_threads]} {
130 fail "got number of threads from MI ($name)"
131 } else {
132 pass "got number of threads from MI ($name)"
133
134 # Check if MI and console have same number of threads
135 if {$num_mi_threads != [llength $console_thread_list]} {
136 fail "console and MI have same number of threads ($name)"
137 } else {
138 pass "console and MI have same number of threads ($name)"
139
140 # Get MI thread list
141 set mi_thread_list [get_mi_thread_list $name]
142
143 # Check if MI and console have the same threads
144 set fails 0
145 foreach ct [lsort $console_thread_list] mt [lsort $mi_thread_list] {
146 if {$ct != $mt} {
147 incr fails
148 }
149 }
150 if {$fails > 0} {
151 fail "MI and console have same threads ($name)"
152
153 # Send a list of failures to the log
154 send_log "Console has thread ids: $console_thread_list\n"
155 send_log "MI has thread ids: $mi_thread_list\n"
156 } else {
157 pass "MI and console have same threads ($name)"
158 }
159 }
160 }
161 }
162}
163
164#
165# Start here
166#
167set testfile "pthreads"
168set srcfile "$testfile.c"
169set binfile "$objdir/$subdir/$testfile"
170
171set options [list debug incdir=$subdir]
172if {[gdb_compile_pthreads "$srcdir/$subdir/$srcfile" $binfile executable $options]
173 != "" } {
174 gdb_suppress_entire_file \
175 "Testcase compile failed, so all tests in this file will automatically fail."
176}
177
178mi_gdb_reinitialize_dir $srcdir/$subdir
179mi_gdb_load $binfile
180
181mi_run_to_main
182check_mi_and_console_threads "at main"
183
184for {set i 0} {$i < 4} {incr i} {
185 mi_next "next, try $i"
186 check_mi_and_console_threads "try $i"
187}
188
189mi_gdb_exit
190
This page took 0.032504 seconds and 4 git commands to generate.