2 # Copyright
2002 Free Software Foundation
, Inc.
4 # This
program is free software
; you can redistribute it and
/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation
; either version
2 of the License
, or
7 #
(at your option
) any later version.
9 # This
program is distributed in the hope that it will be useful
,
10 # but WITHOUT
ANY WARRANTY
; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License
for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this
program; if not
, write to the Free Software
16 # Foundation
, Inc.
, 59 Temple Place
- Suite
330, Boston
, MA
02111-1307, USA.
18 # Please email
any bugs
, comments
, and
/or additions to this file to
:
19 # bug
-gdb@prep.ai.mit.edu
29 set binfile $
{objdir
}/$
{subdir
}/$
{testfile
}
31 if {[gdb_compile
"${srcdir}/${subdir}/macscp1.c" "${binfile}" executable {debug}] != "" } {
32 gdb_suppress_entire_file
"Testcase compile failed, so all tests in this file will automatically fail."
37 gdb_reinitialize_dir $srcdir
/$subdir
41 # Ask GDB to
show the current definition of MACRO
, and
return a list
42 # describing the result.
44 # The
return value has the form
{FILE1 FILE2 ... DEF
}, which means
45 # that MACRO has the definition `DEF
', and was defined in `FILE1',
46 # which was included from `FILE2
', included from ... .
48 # If GDB says that MACRO has no definition, return the string `undefined'.
50 #
If GDB complains that it doesn
't have any information about
51 # preprocessor macro definitions, return the string `no-macro-info'.
53 #
If expect times out waiting
for GDB
, we
return the string `timeout
'.
55 # If GDB's output doesn
't otherwise match what we're expecting
, we
56 #
return the empty string.
58 proc info_macro
{macro
} {
62 set filepat
{macscp
[0-9]+\.
[ch
]}
66 send_gdb
"info macro ${macro}\n"
70 if {$debug_me
} {exp_internal
1}
72 -re
"Defined at \[^\r\n\]*(${filepat}):${decimal}\[\r\n\]" {
73 # `location
' and `definition' should be empty when we see
75 if {[llength $location
] == 0 && [llength $definition
] == 0} {
76 set location $expect_out
(1,string
)
79 # Exit this expect loop
, with a result indicating failure.
83 -re
"The symbol `${macro}' has no definition as a C/C\\+\\+ preprocessor macro\[^\r\n\]*\[\r\n\]" {
84 # `location
' and `definition' should be empty when we see
86 if {[llength $location
] == 0 && [llength $definition
] == 0} {
87 set definition undefined
90 # Exit this expect loop
, with a result indicating failure.
94 -re
"^\[\r\n\]* included at \[^\r\n\]*(${filepat}):${decimal}\[\r\n\]" {
95 # `location
' should *not* be empty when we see this
96 # message. It should have recorded at least the initial
97 # `Defined at ' message
(for definitions
) or ` at
' message
98 # (for undefined symbols).
99 if {[llength $location] != 0} {
100 lappend location $expect_out(1,string)
103 # Exit this expect loop, with a result indicating failure.
107 -re "^\[\r\n\]*at \[^\r\n\]*(${filepat}):${decimal}\[\r\n\]" {
108 # This appears after a `has no definition' message.
109 # `location
' should be empty when we see it.
110 if {[string compare $definition undefined] == 0 \
111 && [llength $location] == 0} {
112 set location $expect_out(1,string)
115 # Exit this expect loop, with a result indicating failure.
119 -re "#define ${macro} (\[^\r\n\]*)\[\r\n\]" {
120 # `definition' should be empty when we see this message.
121 if {[string compare $definition
""] == 0} {
122 set definition $expect_out
(1,string
)
125 # Exit this expect loop
, with a result indicating failure.
129 -re
"has no preprocessor macro information.*$gdb_prompt $" {
130 set definition no
-macro
-info
132 -re
"$gdb_prompt $" {
133 # Exit the expect loop
; let the existing value of `definition
'
134 # indicate failure or success.
137 set definition timeout
140 if {$debug_me} {exp_internal 0}
142 switch -exact -- $definition {
143 no-macro-info { return no-macro-info }
144 timeout { return timeout }
147 if {[llength $location] >= 1} {
148 return [concat $location [list $definition]]
157 # Call info_macro to show the definition of MACRO. Expect a result of
158 # EXPECTED. Use WHERE in pass/fail messages to identify the context.
159 # Return non-zero if we should abort the entire test file, or zero if
161 proc check_macro {macro expected where} {
162 set func_def [info_macro $macro]
163 if {[string compare $func_def $expected] == 0} {
164 pass "info macro $macro $where"
166 switch -exact -- $func_def {
168 xfail "executable includes no macro debugging information"
172 fail "info macro $macro $where (timeout)"
175 fail "info macro $macro $where"
183 # List the function FUNC, and then show the definition of MACRO,
184 # expecting the result EXPECTED.
185 proc list_and_check_macro {func macro expected} {
186 gdb_test "list $func" ".*${func}.*"
187 return [check_macro $macro $expected "after `list $func'"]
191 if {[list_and_check_macro main WHERE
{macscp1.c
{before macscp1_3
}}]} {
194 list_and_check_macro macscp2_2 WHERE
{macscp2.h macscp1.c
{before macscp2_2
}}
195 list_and_check_macro macscp3_2 WHERE
{macscp3.h macscp1.c
{before macscp3_2
}}
198 # Although GDB
's macro table structures distinguish between multiple
199 # #inclusions of the same file, GDB's other structures don
't. So the
200 # `list' command here doesn
't reliably select one #inclusion or the
201 # other, even though it could. It would be nice to eventually change
202 # GDB's structures to handle this correctly.
203 gdb_test
"list macscp4_2_from_macscp2" ".*macscp4_2_, MACSCP4_INCLUSION.*"
204 switch -exact
-- [info_macro WHERE
] {
205 {macscp4.h macscp2.h macscp1.c
{before macscp4_2_...
, from macscp2.h
}} {
206 pass
"info macro WHERE after `list macscp_4_2_from_macscp2'"
208 {macscp4.h macscp3.h macscp1.c
{before macscp4_2_...
, from macscp3.h
}} {
209 # setup_kfail
"gdb/555"
210 fail
"info macro WHERE after `list macscp_4_2_from_macscp2' (gdb/555)"
213 fail
"info macro WHERE after `list macscp_4_2_from_macscp2' (timeout)"
215 default
{ fail
"info macro WHERE after `list macscp_4_2_from_macscp2'" }
218 gdb_test
"list macscp4_2_from_macscp3" ".*macscp4_2_, MACSCP4_INCLUSION.*"
219 switch -exact
-- [info_macro WHERE
] {
220 {macscp4.h macscp3.h macscp1.c
{before macscp4_2_...
, from macscp3.h
}} {
221 pass
"info macro WHERE after `list macscp_4_2_from_macscp3'"
223 {macscp4.h macscp2.h macscp1.c
{before macscp4_2_...
, from macscp2.h
}} {
224 # setup_kfail
"gdb/555"
225 fail
"info macro WHERE after `list macscp_4_2_from_macscp3' (gdb/555)"
228 fail
"info macro WHERE after `list macscp_4_2_from_macscp3' (timeout)"
230 default
{ fail
"info macro WHERE after `list macscp_4_2_from_macscp3'" }
234 #### Test the selection of the macro scope by the current frame.
236 ### A table of functions
, in the order they will be reached
, which is
237 ### also the order they appear in the preprocessed output. Each entry
238 ### has the form
{FUNCNAME WHERE KFAILWHERE
}, where
:
239 ###
- FUNCNAME is the
name of the function
,
240 ###
- WHERE is the definition we expect to see
for the macro `WHERE
', as
241 ### returned by `info_macro', and
242 ###
- KFAILWHERE is an alternate definition which should be reported
243 ### as a `known failure
', due to GDB's inability to distinguish multiple
244 ### #inclusions of the same file.
245 ### KFAILWHERE may be omitted.
250 {macscp1.c
{before macscp1_1
}}
254 {macscp2.h macscp1.c
{before macscp2_1
}}
257 macscp4_1_from_macscp2
258 {macscp4.h macscp2.h macscp1.c
{before macscp4_1_...
, from macscp2.h
}}
259 {macscp4.h macscp3.h macscp1.c
{before macscp4_1_...
, from macscp3.h
}}
262 macscp4_2_from_macscp2
263 {macscp4.h macscp2.h macscp1.c
{before macscp4_2_...
, from macscp2.h
}}
264 {macscp4.h macscp3.h macscp1.c
{before macscp4_2_...
, from macscp3.h
}}
268 {macscp2.h macscp1.c
{before macscp2_2
}}
272 {macscp1.c
{before macscp1_2
}}
276 {macscp3.h macscp1.c
{before macscp3_1
}}
279 macscp4_1_from_macscp3
280 {macscp4.h macscp3.h macscp1.c
{before macscp4_1_...
, from macscp3.h
}}
281 {macscp4.h macscp2.h macscp1.c
{before macscp4_1_...
, from macscp2.h
}}
284 macscp4_2_from_macscp3
285 {macscp4.h macscp3.h macscp1.c
{before macscp4_2_...
, from macscp3.h
}}
286 {macscp4.h macscp2.h macscp1.c
{before macscp4_2_...
, from macscp2.h
}}
290 {macscp3.h macscp1.c
{before macscp3_2
}}
294 {macscp1.c
{before macscp1_3
}}
299 # Start the
program running.
300 if {! [runto_main
]} {
301 fail
"macro tests suppressed: couldn't run to main"
305 #
Set a breakpoint
on each of the functions.
306 foreach func_entry $funcs
{
307 set func
[lindex $func_entry
0]
308 gdb_test
"break $func" "Breakpoint.*"
311 # Run to each of the breakpoints and check the definition
(or lack
312 # thereof
) of each macro.
313 for {set i
0} {$i
< [llength $funcs
]} {incr i
} {
314 set func_entry
[lindex $funcs $i
]
315 set func
[lindex $func_entry
0]
316 set expected
[lindex $func_entry
1]
317 set kfail_expected
[lindex $func_entry
2]
319 # Run to the breakpoint
for $func.
320 gdb_test
"continue" "Breakpoint $decimal, $func .*" "continue to $func"
322 # Check the macro WHERE.
323 set result
[info_macro WHERE
]
324 if {[string compare $result $expected
] == 0} {
325 pass
"info macro WHERE stopped in $func"
326 } elseif
{[string compare $result $kfail_expected
] == 0} {
327 # setup_kfail
"gdb/555"
328 fail
"info macro WHERE stopped in $func (gdb/555)"
329 } elseif
{[string compare $result timeout
] == 0} {
330 fail
"info macro WHERE stopped in $func (timeout)"
332 fail
"info macro WHERE stopped in $func"
335 # Check that the BEFORE_
<func
> macros
for all prior functions are
336 # #defined
, and that those
for all subsequent functions are not.
337 for {set j
0} {$j
< [llength $funcs
]} {incr j
} {
339 set func_j_entry
[lindex $funcs $j
]
340 set func_j
[lindex $func_j_entry
0]
342 set before_macro
"BEFORE_[string toupper $func_j]"
344 "$before_macro defined/undefined when stopped at $func"
345 set result
[info_macro $before_macro
]
347 # We can
't get the right scope info when we're stopped in
348 # the macro4_ functions.
349 if {[string match macscp4_
* $func
]} {
350 # setup_kfail
"gdb/555"
351 set test_name
"$test_name (gdb/555)"
354 if {[llength $result
] >= 2 && \
355 [string compare
[lindex $result end
] {}] == 0} {
357 } elseif
{[string compare $result timeout
] == 0} {
358 fail
"$test_name (timeout)"
363 switch -- [lindex $result end
] {
364 undefined
{ pass $test_name
}
365 timeout
{ fail
"$test_name (timeout)" }
372 set until_macro
"UNTIL_[string toupper $func_j]"
374 "$until_macro defined/undefined when stopped at $func"
375 set result
[info_macro $until_macro
]
377 # We can
't get the right scope info when we're stopped in
378 # the macro4_ functions.
379 if {[string match macscp4_
* $func
]} {
380 # setup_kfail
"gdb/555"
381 set test_name
"$test_name (gdb/555)"
384 switch -- [lindex $result end
] {
385 undefined
{ pass $test_name
}
386 timeout
{ fail
"$test_name (timeout)" }
392 if {[llength $result
] >= 2 && \
393 [string compare
[lindex $result end
] {}] == 0} {
395 } elseif
{[string compare $result timeout
] == 0} {
396 fail
"$test_name (timeout)"