Commit | Line | Data |
---|---|---|
6aba47ca | 1 | # Copyright 2002, 2003, 2004, 2005, 2007 Free Software Foundation, Inc. |
2fcf52f0 AC |
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 | |
e22f8b7c | 5 | # the Free Software Foundation; either version 3 of the License, or |
2fcf52f0 | 6 | # (at your option) any later version. |
e22f8b7c | 7 | # |
2fcf52f0 AC |
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. | |
e22f8b7c | 12 | # |
2fcf52f0 | 13 | # You should have received a copy of the GNU General Public License |
e22f8b7c | 14 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
2fcf52f0 AC |
15 | |
16 | # Please email any bugs, comments, and/or additions to this file to: | |
17 | # bug-gdb@prep.ai.mit.edu | |
18 | ||
19 | # This file tests MI thread commands. | |
20 | # Specifically, we are testing the MI command set and the console (in MI) | |
21 | # command set ("interpreter-exec") and that the commands that are executed | |
22 | # via these command pathways are properly executed. Console commands | |
23 | # executed via MI should use MI output wrappers, MI event handlers, etc. | |
24 | ||
25 | # This only works with native configurations | |
26 | if {![isnative]} { | |
27 | return | |
28 | } | |
29 | ||
30 | load_lib mi-support.exp | |
31 | set MIFLAGS "-i=mi2" | |
32 | ||
33 | gdb_exit | |
34 | if {[mi_gdb_start]} { | |
35 | continue | |
36 | } | |
37 | ||
38 | # The procs below dealing with parsing cli/mi output for the threadlist | |
39 | # is duplicated in gdb669.exp. Any changes here will probably need to | |
40 | # be made there as well. | |
41 | ||
42 | proc get_mi_thread_list {name} { | |
43 | global expect_out | |
44 | ||
45 | # MI will return a list of thread ids: | |
46 | # | |
47 | # -thread-list-ids | |
48 | # ^done,thread-ids=[thread-id="1",thread-id="2",...],number-of-threads="N" | |
49 | # (gdb) | |
50 | mi_gdb_test "-thread-list-ids" \ | |
51 | {\^done,thread-ids={(thread-id="[0-9]+"(,)?)+},number-of-threads="[0-9]+"} \ | |
52 | "-thread_list_ids ($name)" | |
53 | ||
54 | set output {} | |
55 | if {[info exists expect_out(buffer)]} { | |
56 | set output $expect_out(buffer) | |
57 | } | |
58 | ||
59 | set thread_list {} | |
60 | if {![regexp {thread-ids=\{(thread-id="[0-9]+"(,)?)*\}} $output threads]} { | |
61 | fail "finding threads in MI output ($name)" | |
62 | } else { | |
63 | pass "finding threads in MI output ($name)" | |
64 | ||
65 | # Make list of console threads | |
66 | set start [expr {[string first \{ $threads] + 1}] | |
67 | set end [expr {[string first \} $threads] - 1}] | |
68 | set threads [string range $threads $start $end] | |
69 | foreach thread [split $threads ,] { | |
70 | if {[scan $thread {thread-id="%d"} num]} { | |
71 | lappend thread_list $num | |
72 | } | |
73 | } | |
74 | } | |
75 | ||
76 | return $thread_list | |
77 | } | |
78 | ||
79 | # Check that MI and the console know of the same threads. | |
80 | # Appends NAME to all test names. | |
81 | proc check_mi_and_console_threads {name} { | |
82 | global expect_out | |
83 | ||
84 | mi_gdb_test "-thread-list-ids" \ | |
85 | {\^done,thread-ids={(thread-id="[0-9]+"(,)*)+},number-of-threads="[0-9]+"} \ | |
86 | "-thread-list-ids ($name)" | |
87 | set mi_output {} | |
88 | if {[info exists expect_out(buffer)]} { | |
89 | set mi_output $expect_out(buffer) | |
90 | } | |
91 | ||
92 | # GDB will return a list of thread ids and some more info: | |
93 | # | |
94 | # (gdb) | |
95 | # -interpreter-exec console "info threads" | |
96 | # ~" 4 Thread 2051 (LWP 7734) 0x401166b1 in __libc_nanosleep () at __libc_nanosleep:-1" | |
97 | # ~" 3 Thread 1026 (LWP 7733) () at __libc_nanosleep:-1" | |
98 | # ~" 2 Thread 2049 (LWP 7732) 0x401411f8 in __poll (fds=0x804bb24, nfds=1, timeout=2000) at ../sysdeps/unix/sysv/linux/poll.c:63" | |
99 | # ~"* 1 Thread 1024 (LWP 7731) main (argc=1, argv=0xbfffdd94) at ../../../src/gdb/testsuite/gdb.mi/pthreads.c:160" | |
100 | # FIXME: kseitz/2002-09-05: Don't use the hack-cli method. | |
101 | mi_gdb_test "info threads" \ | |
102 | {.*(~".*"[\r\n]*)+.*} \ | |
103 | "info threads ($name)" | |
104 | set console_output {} | |
105 | if {[info exists $expect_out(buffer)]} { | |
106 | set console_output $expect_out(buffer) | |
107 | } | |
108 | ||
109 | # Make a list of all known threads to console (gdb's thread IDs) | |
110 | set console_thread_list {} | |
111 | foreach line [split $console_output \n] { | |
112 | if {[string index $line 0] == "~"} { | |
113 | # This is a line from the console; trim off "~", " ", "*", and "\"" | |
114 | set line [string trim $line ~\ \"\*] | |
115 | if {[scan $line "%d" id] == 1} { | |
116 | lappend console_thread_list $id | |
117 | } | |
118 | } | |
119 | } | |
120 | ||
121 | # Now find the result string from MI | |
122 | set mi_result "" | |
123 | foreach line [split $mi_output \n] { | |
124 | if {[string range $line 0 4] == "^done"} { | |
125 | set mi_result $line | |
126 | } | |
127 | } | |
128 | if {$mi_result == ""} { | |
129 | fail "finding MI result string ($name)" | |
130 | } else { | |
131 | pass "finding MI result string ($name)" | |
132 | } | |
133 | ||
134 | # Finally, extract the thread ids and compare them to the console | |
135 | set num_mi_threads_str "" | |
136 | if {![regexp {number-of-threads="[0-9]+"} $mi_result num_mi_threads_str]} { | |
137 | fail "finding number of threads in MI output ($name)" | |
138 | } else { | |
139 | pass "finding number of threads in MI output ($name)" | |
140 | ||
141 | # Extract the number of threads from the MI result | |
142 | if {![scan $num_mi_threads_str {number-of-threads="%d"} num_mi_threads]} { | |
143 | fail "got number of threads from MI ($name)" | |
144 | } else { | |
145 | pass "got number of threads from MI ($name)" | |
146 | ||
147 | # Check if MI and console have same number of threads | |
148 | if {$num_mi_threads != [llength $console_thread_list]} { | |
149 | fail "console and MI have same number of threads ($name)" | |
150 | } else { | |
151 | pass "console and MI have same number of threads ($name)" | |
152 | ||
153 | # Get MI thread list | |
154 | set mi_thread_list [get_mi_thread_list $name] | |
155 | ||
156 | # Check if MI and console have the same threads | |
157 | set fails 0 | |
158 | foreach ct [lsort $console_thread_list] mt [lsort $mi_thread_list] { | |
159 | if {$ct != $mt} { | |
160 | incr fails | |
161 | } | |
162 | } | |
163 | if {$fails > 0} { | |
164 | fail "MI and console have same threads ($name)" | |
165 | ||
166 | # Send a list of failures to the log | |
167 | send_log "Console has thread ids: $console_thread_list\n" | |
168 | send_log "MI has thread ids: $mi_thread_list\n" | |
169 | } else { | |
170 | pass "MI and console have same threads ($name)" | |
171 | } | |
172 | } | |
173 | } | |
174 | } | |
175 | } | |
176 | ||
177 | # This procedure tests the various thread commands in MI. | |
178 | proc check_mi_thread_command_set {} { | |
179 | ||
180 | mi_runto done_making_threads | |
181 | ||
182 | set thread_list [get_mi_thread_list "in check_mi_thread_command_set"] | |
183 | ||
184 | mi_gdb_test "-thread-select" \ | |
185 | {\^error,msg="mi_cmd_thread_select: USAGE: threadnum."} \ | |
186 | "check_mi_thread_command_set: -thread-select" | |
187 | ||
188 | mi_gdb_test "-thread-select 123456789" \ | |
39fb8e9e | 189 | {&.*\^error,msg="Thread ID 123456789 not known\."} \ |
2fcf52f0 AC |
190 | "check_mi_thread_command_set: -thread-select 123456789" |
191 | ||
192 | foreach thread $thread_list { | |
193 | # line and file are optional. | |
194 | # many of the threads are blocked in libc calls, | |
195 | # and many people have libc's with no symbols. | |
196 | mi_gdb_test "-thread-select $thread" \ | |
197 | "\\^done,new-thread-id=\"$thread\",frame={.*}(,line=\"(-)?\[0-9\]+\",file=\".*\")?" \ | |
198 | "check_mi_thread_command_set: -thread-select $thread" | |
199 | } | |
200 | } | |
201 | ||
202 | # | |
203 | # Start here | |
204 | # | |
205 | set testfile "pthreads" | |
206 | set srcfile "$testfile.c" | |
19ac3974 | 207 | set binfile "$objdir/$subdir/mi2-$testfile" |
2fcf52f0 AC |
208 | |
209 | set options [list debug incdir=$objdir] | |
210 | if {[gdb_compile_pthreads "$srcdir/$subdir/$srcfile" $binfile executable $options] != "" } { | |
211 | return -1 | |
212 | } | |
213 | ||
214 | mi_gdb_reinitialize_dir $srcdir/$subdir | |
215 | mi_gdb_load $binfile | |
216 | ||
217 | check_mi_thread_command_set | |
218 | ||
219 | mi_gdb_exit | |
220 |