* configure.in: Add config header.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.mi / mi-pthreads.exp
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 tests MI thread commands.
21 # Specifically, we are testing the MI command set and the console (in MI)
22 # command set ("interpreter-exec") and that the commands that are executed
23 # via these command pathways are properly executed. Console commands
24 # executed via MI should use MI output wrappers, MI event handlers, etc.
25
26 # This only works with native configurations
27 if {![isnative]} {
28 return
29 }
30
31 load_lib mi-support.exp
32 set MIFLAGS "-i=mi"
33
34 gdb_exit
35 if {[mi_gdb_start]} {
36 continue
37 }
38
39 # The procs below dealing with parsing cli/mi output for the threadlist
40 # is duplicated in gdb669.exp. Any changes here will probably need to
41 # be made there as well.
42
43 proc get_mi_thread_list {name} {
44 global expect_out
45
46 # MI will return a list of thread ids:
47 #
48 # -thread-list-ids
49 # ^done,thread-ids=[thread-id="1",thread-id="2",...],number-of-threads="N"
50 # (gdb)
51 mi_gdb_test "-thread-list-ids" \
52 {\^done,thread-ids={(thread-id="[0-9]+"(,)?)+},number-of-threads="[0-9]+"} \
53 "-thread_list_ids ($name)"
54
55 set thread_list {}
56 if {![regexp {thread-ids=\{(thread-id="[0-9]+"(,)?)*\}} $expect_out(buffer) threads]} {
57 fail "finding threads in MI output ($name)"
58 } else {
59 pass "finding threads in MI output ($name)"
60
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
68 }
69 }
70 }
71
72 return $thread_list
73 }
74
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} {
78 global expect_out
79
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)"
83 set mi_output $expect_out(buffer)
84
85 # GDB will return a list of thread ids and some more info:
86 #
87 # (gdb)
88 # -interpreter-exec console "info threads"
89 # ~" 4 Thread 2051 (LWP 7734) 0x401166b1 in __libc_nanosleep () at __libc_nanosleep:-1"
90 # ~" 3 Thread 1026 (LWP 7733) () at __libc_nanosleep:-1"
91 # ~" 2 Thread 2049 (LWP 7732) 0x401411f8 in __poll (fds=0x804bb24, nfds=1, timeout=2000) at ../sysdeps/unix/sysv/linux/poll.c:63"
92 # ~"* 1 Thread 1024 (LWP 7731) main (argc=1, argv=0xbfffdd94) at ../../../src/gdb/testsuite/gdb.mi/pthreads.c:160"
93 # FIXME: kseitz/2002-09-05: Don't use the hack-cli method.
94 mi_gdb_test "info threads" \
95 {.*(~".*"[\r\n]*)+.*} \
96 "info threads ($name)"
97 set console_output $expect_out(buffer)
98
99 # Make a list of all known threads to console (gdb's thread IDs)
100 set console_thread_list {}
101 foreach line [split $console_output \n] {
102 if {[string index $line 0] == "~"} {
103 # This is a line from the console; trim off "~", " ", "*", and "\""
104 set line [string trim $line ~\ \"\*]
105 if {[scan $line "%d" id] == 1} {
106 lappend console_thread_list $id
107 }
108 }
109 }
110
111 # Now find the result string from MI
112 set mi_result ""
113 foreach line [split $mi_output \n] {
114 if {[string range $line 0 4] == "^done"} {
115 set mi_result $line
116 }
117 }
118 if {$mi_result == ""} {
119 fail "finding MI result string ($name)"
120 } else {
121 pass "finding MI result string ($name)"
122 }
123
124 # Finally, extract the thread ids and compare them to the console
125 set num_mi_threads_str ""
126 if {![regexp {number-of-threads="[0-9]+"} $mi_result num_mi_threads_str]} {
127 fail "finding number of threads in MI output ($name)"
128 } else {
129 pass "finding number of threads in MI output ($name)"
130
131 # Extract the number of threads from the MI result
132 if {![scan $num_mi_threads_str {number-of-threads="%d"} num_mi_threads]} {
133 fail "got number of threads from MI ($name)"
134 } else {
135 pass "got number of threads from MI ($name)"
136
137 # Check if MI and console have same number of threads
138 if {$num_mi_threads != [llength $console_thread_list]} {
139 fail "console and MI have same number of threads ($name)"
140 } else {
141 pass "console and MI have same number of threads ($name)"
142
143 # Get MI thread list
144 set mi_thread_list [get_mi_thread_list $name]
145
146 # Check if MI and console have the same threads
147 set fails 0
148 foreach ct [lsort $console_thread_list] mt [lsort $mi_thread_list] {
149 if {$ct != $mt} {
150 incr fails
151 }
152 }
153 if {$fails > 0} {
154 fail "MI and console have same threads ($name)"
155
156 # Send a list of failures to the log
157 send_log "Console has thread ids: $console_thread_list\n"
158 send_log "MI has thread ids: $mi_thread_list\n"
159 } else {
160 pass "MI and console have same threads ($name)"
161 }
162 }
163 }
164 }
165 }
166
167 # This procedure tests the various thread commands in MI.
168 proc check_mi_thread_command_set {} {
169
170 mi_runto done_making_threads
171
172 set thread_list [get_mi_thread_list "in check_mi_thread_command_set"]
173
174 mi_gdb_test "-thread-select" \
175 {\^error,msg="mi_cmd_thread_select: USAGE: threadnum."} \
176 "check_mi_thread_command_set: -thread-select"
177
178 mi_gdb_test "-thread-select 123456789" \
179 {\^error,msg="Thread ID 123456789 not known\."} \
180 "check_mi_thread_command_set: -thread-select 123456789"
181
182 foreach thread $thread_list {
183 mi_gdb_test "-thread-select $thread" \
184 "\\^done,new-thread-id=\"$thread\",frame={.*},line=\"(-)?\[0-9\]+\",file=\".*\"" \
185 "check_mi_thread_command_set: -thread-select $thread"
186 }
187 }
188
189 #
190 # Start here
191 #
192 set testfile "pthreads"
193 set srcfile "$testfile.c"
194 set binfile "$objdir/$subdir/$testfile"
195
196 set options [list debug incdir=$subdir]
197 if {[gdb_compile_pthreads "$srcdir/$subdir/$srcfile" $binfile executable $options]
198 != "" } {
199 gdb_suppress_entire_file \
200 "Testcase compile failed, so all tests in this file will automatically fail."
201 }
202
203 mi_gdb_reinitialize_dir $srcdir/$subdir
204 mi_gdb_load $binfile
205
206 check_mi_thread_command_set
207
208 mi_gdb_exit
209
This page took 0.035174 seconds and 5 git commands to generate.