1 # Copyright
2002, 2003, 2004, 2005 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 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.
26 # This only works with native configurations
31 load_lib mi
-support.exp
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.
43 proc get_mi_thread_list
{name} {
46 # MI will
return a list of thread ids
:
49 # ^done
,thread
-ids
=[thread
-id
="1",thread-id="2",...],number-of-threads="N"
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)"
56 if {[info exists expect_out
(buffer
)]} {
57 set output $expect_out
(buffer
)
61 if {![regexp
{thread
-ids
=\
{(thread
-id
="[0-9]+"(,)?)*\}} $output threads]} {
62 fail
"finding threads in MI output ($name)"
64 pass
"finding threads in MI output ($name)"
66 # Make list of console threads
67 set start
[expr
{[string first \
{ $threads
] + 1}]
68 set end
[expr
{[string first \
} $threads
] - 1}]
69 set threads
[string range $threads $start $end
]
70 foreach thread
[split $threads
,] {
71 if {[scan $thread
{thread
-id
="%d"} num]} {
72 lappend thread_list $num
80 # Check that MI and the console know of the same threads.
81 # Appends
NAME to all test names.
82 proc check_mi_and_console_threads
{name} {
85 mi_gdb_test
"-thread-list-ids" \
86 {\^done
,thread
-ids
={(thread
-id
="[0-9]+"(,)*)+},number-of-threads="[0-9]+"} \
87 "-thread-list-ids ($name)"
89 if {[info exists expect_out
(buffer
)]} {
90 set mi_output $expect_out
(buffer
)
93 # GDB will
return a list of thread ids and some more
info:
96 #
-interpreter
-exec console
"info threads"
97 # ~
" 4 Thread 2051 (LWP 7734) 0x401166b1 in __libc_nanosleep () at __libc_nanosleep:-1"
98 # ~
" 3 Thread 1026 (LWP 7733) () at __libc_nanosleep:-1"
99 # ~
" 2 Thread 2049 (LWP 7732) 0x401411f8 in __poll (fds=0x804bb24, nfds=1, timeout=2000) at ../sysdeps/unix/sysv/linux/poll.c:63"
100 # ~
"* 1 Thread 1024 (LWP 7731) main (argc=1, argv=0xbfffdd94) at ../../../src/gdb/testsuite/gdb.mi/pthreads.c:160"
101 # FIXME
: kseitz
/2002-09-05: Don
't use the hack-cli method.
102 mi_gdb_test "info threads" \
103 {.*(~".*"[\r\n]*)+.*} \
104 "info threads ($name)"
105 set console_output {}
106 if {[info exists $expect_out(buffer)]} {
107 set console_output $expect_out(buffer)
110 # Make a list of all known threads to console (gdb's thread IDs
)
111 set console_thread_list
{}
112 foreach line
[split $console_output
\n] {
113 if {[string index $line
0] == "~"} {
114 # This is a line from the console
; trim
off "~", " ", "*", and "\""
115 set line
[string trim $line ~\
\"\
*]
116 if {[scan $line
"%d" id] == 1} {
117 lappend console_thread_list $id
122 # Now find the result string from MI
124 foreach line
[split $mi_output
\n] {
125 if {[string range $line
0 4] == "^done"} {
129 if {$mi_result
== ""} {
130 fail
"finding MI result string ($name)"
132 pass
"finding MI result string ($name)"
135 # Finally
, extract the thread ids and compare them to the console
136 set num_mi_threads_str
""
137 if {![regexp
{number
-of
-threads
="[0-9]+"} $mi_result num_mi_threads_str]} {
138 fail
"finding number of threads in MI output ($name)"
140 pass
"finding number of threads in MI output ($name)"
142 # Extract the number of threads from the MI result
143 if {![scan $num_mi_threads_str
{number
-of
-threads
="%d"} num_mi_threads]} {
144 fail
"got number of threads from MI ($name)"
146 pass
"got number of threads from MI ($name)"
148 # Check
if MI and console have same number of threads
149 if {$num_mi_threads
!= [llength $console_thread_list
]} {
150 fail
"console and MI have same number of threads ($name)"
152 pass
"console and MI have same number of threads ($name)"
155 set mi_thread_list
[get_mi_thread_list $
name]
157 # Check
if MI and console have the same threads
159 foreach ct
[lsort $console_thread_list
] mt
[lsort $mi_thread_list
] {
165 fail
"MI and console have same threads ($name)"
167 # Send a list of failures to the
log
168 send_log
"Console has thread ids: $console_thread_list\n"
169 send_log
"MI has thread ids: $mi_thread_list\n"
171 pass
"MI and console have same threads ($name)"
178 # This procedure tests the various thread commands in MI.
179 proc check_mi_thread_command_set
{} {
181 mi_runto done_making_threads
183 set thread_list
[get_mi_thread_list
"in check_mi_thread_command_set"]
185 mi_gdb_test
"-thread-select" \
186 {\^error
,msg
="mi_cmd_thread_select: USAGE: threadnum."} \
187 "check_mi_thread_command_set: -thread-select"
189 mi_gdb_test
"-thread-select 123456789" \
190 {&.
*\^error
,msg
="Thread ID 123456789 not known\."} \
191 "check_mi_thread_command_set: -thread-select 123456789"
193 foreach thread $thread_list
{
194 # line and file are optional.
195 # many of the threads are blocked in libc calls
,
196 # and many people have libc
's with no symbols.
197 mi_gdb_test "-thread-select $thread" \
198 "\\^done,new-thread-id=\"$thread\",frame={.*}(,line=\"(-)?\[0-9\]+\",file=\".*\")?" \
199 "check_mi_thread_command_set: -thread-select $thread"
206 set testfile "pthreads"
207 set srcfile "$testfile.c"
208 set binfile "$objdir/$subdir/mi-$testfile"
210 set options [list debug incdir=$objdir]
211 if {[gdb_compile_pthreads "$srcdir/$subdir/$srcfile" $binfile executable $options] != "" } {
215 mi_gdb_reinitialize_dir $srcdir/$subdir
218 check_mi_thread_command_set