Commit | Line | Data |
---|---|---|
6827a8f8 | 1 | # Test macro scoping. |
9b254dd1 | 2 | # Copyright 2002, 2007, 2008 Free Software Foundation, Inc. |
6827a8f8 JB |
3 | |
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 | |
e22f8b7c | 6 | # the Free Software Foundation; either version 3 of the License, or |
6827a8f8 | 7 | # (at your option) any later version. |
e22f8b7c | 8 | # |
6827a8f8 JB |
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. | |
e22f8b7c | 13 | # |
6827a8f8 | 14 | # You should have received a copy of the GNU General Public License |
e22f8b7c | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
6827a8f8 | 16 | |
6827a8f8 JB |
17 | if $tracelevel then { |
18 | strace $tracelevel | |
19 | } | |
20 | ||
21 | set prms_id 0 | |
22 | set bug_id 0 | |
23 | ||
d705c43c | 24 | set srcfile macscp1.c |
6827a8f8 | 25 | set testfile "macscp" |
87bdc959 | 26 | set objfile "macscp.o" |
6827a8f8 JB |
27 | set binfile ${objdir}/${subdir}/${testfile} |
28 | ||
d848e687 DJ |
29 | set options { debug } |
30 | ||
31 | get_compiler_info ${binfile} | |
32 | if [test_compiler_info gcc*] { | |
33 | lappend options additional_flags=-g3 | |
34 | } | |
35 | ||
87bdc959 TG |
36 | # Generate the intermediate object file. This is required by Darwin to |
37 | # have access to the .debug_macinfo section. | |
38 | if {[gdb_compile "${srcdir}/${subdir}/macscp1.c" "${objfile}" \ | |
39 | object $options] != "" | |
40 | || [gdb_compile "${objfile}" "${binfile}" executable $options] != "" } { | |
b60f0898 JB |
41 | untested macscp.exp |
42 | return -1 | |
6827a8f8 JB |
43 | } |
44 | ||
45 | gdb_exit | |
46 | gdb_start | |
47 | gdb_reinitialize_dir $srcdir/$subdir | |
48 | gdb_load ${binfile} | |
49 | ||
50 | ||
51 | # Ask GDB to show the current definition of MACRO, and return a list | |
52 | # describing the result. | |
53 | # | |
54 | # The return value has the form {FILE1 FILE2 ... DEF}, which means | |
55 | # that MACRO has the definition `DEF', and was defined in `FILE1', | |
56 | # which was included from `FILE2', included from ... . | |
57 | # | |
58 | # If GDB says that MACRO has no definition, return the string `undefined'. | |
59 | # | |
60 | # If GDB complains that it doesn't have any information about | |
61 | # preprocessor macro definitions, return the string `no-macro-info'. | |
62 | # | |
63 | # If expect times out waiting for GDB, we return the string `timeout'. | |
64 | # | |
65 | # If GDB's output doesn't otherwise match what we're expecting, we | |
66 | # return the empty string. | |
67 | ||
68 | proc info_macro {macro} { | |
69 | global gdb_prompt | |
70 | global decimal | |
71 | ||
72 | set filepat {macscp[0-9]+\.[ch]} | |
73 | set definition {} | |
74 | set location {} | |
75 | ||
76 | send_gdb "info macro ${macro}\n" | |
77 | ||
78 | set debug_me 0 | |
79 | ||
80 | if {$debug_me} {exp_internal 1} | |
81 | gdb_expect { | |
82 | -re "Defined at \[^\r\n\]*(${filepat}):${decimal}\[\r\n\]" { | |
83 | # `location' and `definition' should be empty when we see | |
84 | # this message. | |
85 | if {[llength $location] == 0 && [llength $definition] == 0} { | |
86 | set location $expect_out(1,string) | |
87 | exp_continue | |
88 | } else { | |
89 | # Exit this expect loop, with a result indicating failure. | |
90 | set definition {} | |
91 | } | |
92 | } | |
93 | -re "The symbol `${macro}' has no definition as a C/C\\+\\+ preprocessor macro\[^\r\n\]*\[\r\n\]" { | |
94 | # `location' and `definition' should be empty when we see | |
95 | # this message. | |
96 | if {[llength $location] == 0 && [llength $definition] == 0} { | |
97 | set definition undefined | |
98 | exp_continue | |
99 | } else { | |
100 | # Exit this expect loop, with a result indicating failure. | |
101 | set definition {} | |
102 | } | |
103 | } | |
104 | -re "^\[\r\n\]* included at \[^\r\n\]*(${filepat}):${decimal}\[\r\n\]" { | |
105 | # `location' should *not* be empty when we see this | |
106 | # message. It should have recorded at least the initial | |
107 | # `Defined at ' message (for definitions) or ` at' message | |
108 | # (for undefined symbols). | |
109 | if {[llength $location] != 0} { | |
110 | lappend location $expect_out(1,string) | |
111 | exp_continue | |
112 | } else { | |
113 | # Exit this expect loop, with a result indicating failure. | |
114 | set definition {} | |
115 | } | |
116 | } | |
117 | -re "^\[\r\n\]*at \[^\r\n\]*(${filepat}):${decimal}\[\r\n\]" { | |
118 | # This appears after a `has no definition' message. | |
119 | # `location' should be empty when we see it. | |
120 | if {[string compare $definition undefined] == 0 \ | |
121 | && [llength $location] == 0} { | |
122 | set location $expect_out(1,string) | |
123 | exp_continue | |
124 | } else { | |
125 | # Exit this expect loop, with a result indicating failure. | |
126 | set definition {} | |
127 | } | |
128 | } | |
129 | -re "#define ${macro} (\[^\r\n\]*)\[\r\n\]" { | |
130 | # `definition' should be empty when we see this message. | |
131 | if {[string compare $definition ""] == 0} { | |
132 | set definition $expect_out(1,string) | |
133 | exp_continue | |
134 | } else { | |
135 | # Exit this expect loop, with a result indicating failure. | |
136 | set definition {} | |
137 | } | |
138 | } | |
139 | -re "has no preprocessor macro information.*$gdb_prompt $" { | |
140 | set definition no-macro-info | |
141 | } | |
142 | -re "$gdb_prompt $" { | |
143 | # Exit the expect loop; let the existing value of `definition' | |
144 | # indicate failure or success. | |
145 | } | |
146 | timeout { | |
147 | set definition timeout | |
148 | } | |
149 | } | |
150 | if {$debug_me} {exp_internal 0} | |
151 | ||
152 | switch -exact -- $definition { | |
153 | no-macro-info { return no-macro-info } | |
154 | timeout { return timeout } | |
155 | undefined - | |
156 | default { | |
157 | if {[llength $location] >= 1} { | |
158 | return [concat $location [list $definition]] | |
159 | } else { | |
160 | return {} | |
161 | } | |
162 | } | |
163 | } | |
164 | } | |
165 | ||
166 | ||
167 | # Call info_macro to show the definition of MACRO. Expect a result of | |
168 | # EXPECTED. Use WHERE in pass/fail messages to identify the context. | |
169 | # Return non-zero if we should abort the entire test file, or zero if | |
170 | # we can continue. | |
171 | proc check_macro {macro expected where} { | |
172 | set func_def [info_macro $macro] | |
173 | if {[string compare $func_def $expected] == 0} { | |
174 | pass "info macro $macro $where" | |
175 | } else { | |
176 | switch -exact -- $func_def { | |
177 | no-macro-info { | |
178 | xfail "executable includes no macro debugging information" | |
179 | return 1 | |
180 | } | |
181 | timeout { | |
182 | fail "info macro $macro $where (timeout)" | |
183 | } | |
184 | default { | |
185 | fail "info macro $macro $where" | |
186 | } | |
187 | } | |
188 | } | |
189 | return 0 | |
190 | } | |
191 | ||
192 | ||
193 | # List the function FUNC, and then show the definition of MACRO, | |
194 | # expecting the result EXPECTED. | |
195 | proc list_and_check_macro {func macro expected} { | |
196 | gdb_test "list $func" ".*${func}.*" | |
197 | return [check_macro $macro $expected "after `list $func'"] | |
198 | } | |
199 | ||
200 | ||
201 | if {[list_and_check_macro main WHERE {macscp1.c {before macscp1_3}}]} { | |
202 | return 0 | |
203 | } | |
204 | list_and_check_macro macscp2_2 WHERE {macscp2.h macscp1.c {before macscp2_2}} | |
205 | list_and_check_macro macscp3_2 WHERE {macscp3.h macscp1.c {before macscp3_2}} | |
206 | ||
207 | ||
208 | # Although GDB's macro table structures distinguish between multiple | |
209 | # #inclusions of the same file, GDB's other structures don't. So the | |
210 | # `list' command here doesn't reliably select one #inclusion or the | |
211 | # other, even though it could. It would be nice to eventually change | |
212 | # GDB's structures to handle this correctly. | |
213 | gdb_test "list macscp4_2_from_macscp2" ".*macscp4_2_, MACSCP4_INCLUSION.*" | |
214 | switch -exact -- [info_macro WHERE] { | |
215 | {macscp4.h macscp2.h macscp1.c {before macscp4_2_..., from macscp2.h}} { | |
216 | pass "info macro WHERE after `list macscp_4_2_from_macscp2'" | |
217 | } | |
218 | {macscp4.h macscp3.h macscp1.c {before macscp4_2_..., from macscp3.h}} { | |
d848e687 | 219 | setup_kfail *-*-* "gdb/555" |
6827a8f8 JB |
220 | fail "info macro WHERE after `list macscp_4_2_from_macscp2' (gdb/555)" |
221 | } | |
222 | timeout { | |
223 | fail "info macro WHERE after `list macscp_4_2_from_macscp2' (timeout)" | |
224 | } | |
225 | default { fail "info macro WHERE after `list macscp_4_2_from_macscp2'" } | |
226 | } | |
227 | ||
228 | gdb_test "list macscp4_2_from_macscp3" ".*macscp4_2_, MACSCP4_INCLUSION.*" | |
229 | switch -exact -- [info_macro WHERE] { | |
230 | {macscp4.h macscp3.h macscp1.c {before macscp4_2_..., from macscp3.h}} { | |
231 | pass "info macro WHERE after `list macscp_4_2_from_macscp3'" | |
232 | } | |
233 | {macscp4.h macscp2.h macscp1.c {before macscp4_2_..., from macscp2.h}} { | |
d848e687 | 234 | setup_kfail *-*-* "gdb/555" |
6827a8f8 JB |
235 | fail "info macro WHERE after `list macscp_4_2_from_macscp3' (gdb/555)" |
236 | } | |
237 | timeout { | |
238 | fail "info macro WHERE after `list macscp_4_2_from_macscp3' (timeout)" | |
239 | } | |
240 | default { fail "info macro WHERE after `list macscp_4_2_from_macscp3'" } | |
241 | } | |
242 | ||
243 | ||
244 | #### Test the selection of the macro scope by the current frame. | |
245 | ||
246 | ### A table of functions, in the order they will be reached, which is | |
247 | ### also the order they appear in the preprocessed output. Each entry | |
248 | ### has the form {FUNCNAME WHERE KFAILWHERE}, where: | |
249 | ### - FUNCNAME is the name of the function, | |
250 | ### - WHERE is the definition we expect to see for the macro `WHERE', as | |
251 | ### returned by `info_macro', and | |
252 | ### - KFAILWHERE is an alternate definition which should be reported | |
253 | ### as a `known failure', due to GDB's inability to distinguish multiple | |
254 | ### #inclusions of the same file. | |
255 | ### KFAILWHERE may be omitted. | |
256 | ||
257 | set funcs { | |
258 | { | |
259 | macscp1_1 | |
260 | {macscp1.c {before macscp1_1}} | |
261 | } | |
262 | { | |
263 | macscp2_1 | |
264 | {macscp2.h macscp1.c {before macscp2_1}} | |
265 | } | |
266 | { | |
267 | macscp4_1_from_macscp2 | |
268 | {macscp4.h macscp2.h macscp1.c {before macscp4_1_..., from macscp2.h}} | |
269 | {macscp4.h macscp3.h macscp1.c {before macscp4_1_..., from macscp3.h}} | |
270 | } | |
271 | { | |
272 | macscp4_2_from_macscp2 | |
273 | {macscp4.h macscp2.h macscp1.c {before macscp4_2_..., from macscp2.h}} | |
274 | {macscp4.h macscp3.h macscp1.c {before macscp4_2_..., from macscp3.h}} | |
275 | } | |
276 | { | |
277 | macscp2_2 | |
278 | {macscp2.h macscp1.c {before macscp2_2}} | |
279 | } | |
280 | { | |
281 | macscp1_2 | |
282 | {macscp1.c {before macscp1_2}} | |
283 | } | |
284 | { | |
285 | macscp3_1 | |
286 | {macscp3.h macscp1.c {before macscp3_1}} | |
287 | } | |
288 | { | |
289 | macscp4_1_from_macscp3 | |
290 | {macscp4.h macscp3.h macscp1.c {before macscp4_1_..., from macscp3.h}} | |
291 | {macscp4.h macscp2.h macscp1.c {before macscp4_1_..., from macscp2.h}} | |
292 | } | |
293 | { | |
294 | macscp4_2_from_macscp3 | |
295 | {macscp4.h macscp3.h macscp1.c {before macscp4_2_..., from macscp3.h}} | |
296 | {macscp4.h macscp2.h macscp1.c {before macscp4_2_..., from macscp2.h}} | |
297 | } | |
298 | { | |
299 | macscp3_2 | |
300 | {macscp3.h macscp1.c {before macscp3_2}} | |
301 | } | |
302 | { | |
303 | macscp1_3 | |
304 | {macscp1.c {before macscp1_3}} | |
305 | } | |
306 | } | |
307 | ||
d848e687 DJ |
308 | proc maybe_kfail { func test_name } { |
309 | # We can't get the right scope info when we're stopped in | |
310 | # the macro4_ functions. | |
311 | if {[string match macscp4_* $func]} { | |
312 | kfail gdb/555 "$test_name" | |
313 | } else { | |
314 | fail "$test_name" | |
315 | } | |
316 | } | |
6827a8f8 JB |
317 | |
318 | # Start the program running. | |
319 | if {! [runto_main]} { | |
320 | fail "macro tests suppressed: couldn't run to main" | |
321 | return 0 | |
322 | } | |
323 | ||
324 | # Set a breakpoint on each of the functions. | |
325 | foreach func_entry $funcs { | |
326 | set func [lindex $func_entry 0] | |
327 | gdb_test "break $func" "Breakpoint.*" | |
328 | } | |
329 | ||
330 | # Run to each of the breakpoints and check the definition (or lack | |
331 | # thereof) of each macro. | |
332 | for {set i 0} {$i < [llength $funcs]} {incr i} { | |
333 | set func_entry [lindex $funcs $i] | |
334 | set func [lindex $func_entry 0] | |
335 | set expected [lindex $func_entry 1] | |
336 | set kfail_expected [lindex $func_entry 2] | |
337 | ||
338 | # Run to the breakpoint for $func. | |
339 | gdb_test "continue" "Breakpoint $decimal, $func .*" "continue to $func" | |
340 | ||
341 | # Check the macro WHERE. | |
342 | set result [info_macro WHERE] | |
343 | if {[string compare $result $expected] == 0} { | |
344 | pass "info macro WHERE stopped in $func" | |
345 | } elseif {[string compare $result $kfail_expected] == 0} { | |
d848e687 | 346 | setup_kfail *-*-* "gdb/555" |
6827a8f8 JB |
347 | fail "info macro WHERE stopped in $func (gdb/555)" |
348 | } elseif {[string compare $result timeout] == 0} { | |
349 | fail "info macro WHERE stopped in $func (timeout)" | |
350 | } else { | |
351 | fail "info macro WHERE stopped in $func" | |
352 | } | |
353 | ||
354 | # Check that the BEFORE_<func> macros for all prior functions are | |
355 | # #defined, and that those for all subsequent functions are not. | |
356 | for {set j 0} {$j < [llength $funcs]} {incr j} { | |
357 | if {$j != $i} { | |
358 | set func_j_entry [lindex $funcs $j] | |
359 | set func_j [lindex $func_j_entry 0] | |
360 | ||
361 | set before_macro "BEFORE_[string toupper $func_j]" | |
362 | set test_name \ | |
363 | "$before_macro defined/undefined when stopped at $func" | |
364 | set result [info_macro $before_macro] | |
365 | ||
6827a8f8 JB |
366 | if {$j < $i} { |
367 | if {[llength $result] >= 2 && \ | |
368 | [string compare [lindex $result end] {}] == 0} { | |
369 | pass $test_name | |
370 | } elseif {[string compare $result timeout] == 0} { | |
371 | fail "$test_name (timeout)" | |
372 | } else { | |
d848e687 | 373 | maybe_kfail $func "$test_name" |
6827a8f8 JB |
374 | } |
375 | } elseif {$j > $i} { | |
376 | switch -- [lindex $result end] { | |
377 | undefined { pass $test_name } | |
378 | timeout { fail "$test_name (timeout)" } | |
379 | default { | |
d848e687 | 380 | maybe_kfail $func "$test_name" |
6827a8f8 JB |
381 | } |
382 | } | |
383 | } | |
384 | ||
385 | set until_macro "UNTIL_[string toupper $func_j]" | |
386 | set test_name \ | |
387 | "$until_macro defined/undefined when stopped at $func" | |
388 | set result [info_macro $until_macro] | |
389 | ||
6827a8f8 JB |
390 | if {$j <= $i} { |
391 | switch -- [lindex $result end] { | |
392 | undefined { pass $test_name } | |
393 | timeout { fail "$test_name (timeout)" } | |
394 | default { | |
d848e687 | 395 | maybe_kfail $func "$test_name" |
6827a8f8 JB |
396 | } |
397 | } | |
398 | } elseif {$j > $i} { | |
399 | if {[llength $result] >= 2 && \ | |
400 | [string compare [lindex $result end] {}] == 0} { | |
401 | pass $test_name | |
402 | } elseif {[string compare $result timeout] == 0} { | |
403 | fail "$test_name (timeout)" | |
404 | } else { | |
d848e687 | 405 | maybe_kfail $func "$test_name" |
6827a8f8 JB |
406 | } |
407 | } | |
408 | } | |
409 | } | |
410 | } | |
d705c43c PA |
411 | |
412 | gdb_test "break [gdb_get_line_number "set breakpoint here"]" \ | |
413 | "Breakpoint.*at.* file .*, line.*" \ | |
414 | "breakpoint macscp_expr" | |
415 | ||
416 | gdb_test "continue" "foo = 0;.*" "continue to macsp_expr" | |
417 | ||
506800a9 TT |
418 | gdb_test "print MACRO_TO_EXPAND" \ |
419 | "No symbol \"MACRO_TO_EXPAND\" in current context\." \ | |
d705c43c PA |
420 | "print expression with macro before define." |
421 | ||
422 | gdb_test "next" "foo = 1;" "next to definition" | |
423 | ||
506800a9 | 424 | gdb_test "print MACRO_TO_EXPAND" \ |
d705c43c PA |
425 | " = 0" \ |
426 | "print expression with macro in scope." | |
427 | ||
506800a9 | 428 | gdb_test "macro define MACRO_TO_EXPAND 72" \ |
d7d9f01e TT |
429 | "" \ |
430 | "user macro override" | |
431 | ||
506800a9 | 432 | gdb_test "print MACRO_TO_EXPAND" \ |
d7d9f01e TT |
433 | " = 72" \ |
434 | "choose user macro" | |
435 | ||
506800a9 | 436 | gdb_test "macro undef MACRO_TO_EXPAND" \ |
d7d9f01e TT |
437 | "" \ |
438 | "remove user override" | |
439 | ||
506800a9 | 440 | gdb_test "print MACRO_TO_EXPAND" \ |
d7d9f01e TT |
441 | " = 0" \ |
442 | "print expression with macro after removing override" | |
443 | ||
d705c43c PA |
444 | gdb_test "next" "foo = 2;" "next to definition" |
445 | ||
506800a9 TT |
446 | gdb_test "print MACRO_TO_EXPAND" \ |
447 | "No symbol \"MACRO_TO_EXPAND\" in current context\." \ | |
d705c43c | 448 | "print expression with macro after undef." |
d7d9f01e | 449 | |
506800a9 | 450 | gdb_test "macro define MACRO_TO_EXPAND 5" \ |
d7d9f01e TT |
451 | "" \ |
452 | "basic macro define" | |
453 | ||
506800a9 | 454 | gdb_test "print MACRO_TO_EXPAND" \ |
d7d9f01e TT |
455 | " = 5" \ |
456 | "expansion of defined macro" | |
457 | ||
458 | gdb_test "macro list" \ | |
506800a9 | 459 | "macro define MACRO_TO_EXPAND 5" \ |
d7d9f01e TT |
460 | "basic macro list" |
461 | ||
506800a9 | 462 | gdb_test "macro define MACRO_TO_EXPAND(x) x" \ |
d7d9f01e TT |
463 | "" \ |
464 | "basic redefine, macro with args" | |
465 | ||
506800a9 | 466 | gdb_test "print MACRO_TO_EXPAND (7)" \ |
d7d9f01e TT |
467 | " = 7" \ |
468 | "expansion of macro with arguments" | |
469 | ||
506800a9 | 470 | gdb_test "macro undef MACRO_TO_EXPAND" \ |
d7d9f01e TT |
471 | "" \ |
472 | "basic macro undef" | |
473 | ||
506800a9 TT |
474 | gdb_test "print MACRO_TO_EXPAND" \ |
475 | "No symbol \"MACRO_TO_EXPAND\" in current context\." \ | |
d7d9f01e | 476 | "print expression with macro after user undef." |
ccb3ac8a | 477 | |
886a217c TT |
478 | # Regression test; this used to crash. |
479 | gdb_test "macro define" \ | |
480 | "usage: macro define.*" \ | |
481 | "macro define with no arguments" | |
482 | ||
483 | # Regression test; this used to crash. | |
484 | gdb_test "macro undef" \ | |
485 | "usage: macro undef.*" \ | |
486 | "macro undef with no arguments" | |
487 | ||
9a044a89 TT |
488 | # Completion tests. |
489 | ||
490 | # The macro FIFTY_SEVEN is in scope at this point. | |
491 | send_gdb "p FIFTY_\t" | |
492 | gdb_expect { | |
493 | -re "^p FIFTY_SEVEN $"\ | |
494 | { send_gdb "\n" | |
495 | gdb_expect { | |
496 | -re "^.* = 57.*$gdb_prompt $"\ | |
497 | { pass "complete 'p FIFTY_SEVEN'"} | |
498 | -re ".*$gdb_prompt $" { fail "complete 'p FIFTY_SEVEN'"} | |
499 | timeout {fail "(timeout) complete 'p FIFTY_SEVEN'"} | |
500 | } | |
501 | } | |
502 | -re ".*$gdb_prompt $" { fail "complete 'p FIFTY_SEVEN'" } | |
503 | timeout { fail "(timeout) complete 'p FIFTY_SEVEN' 2" } | |
504 | } | |
505 | ||
506 | # The macro TWENTY_THREE is not in scope. | |
507 | send_gdb "p TWENTY_\t" | |
508 | gdb_expect { | |
509 | -re "^p TWENTY_\\\x07$"\ | |
510 | { send_gdb "\n" | |
511 | gdb_expect { | |
512 | -re "No symbol \"TWENTY_\" in current context\\..*$gdb_prompt $"\ | |
513 | { pass "complete 'p TWENTY_'"} | |
514 | -re ".*$gdb_prompt $" { fail "complete 'p TWENTY_'"} | |
515 | timeout {fail "(timeout) complete 'p TWENTY_'"} | |
516 | } | |
517 | } | |
518 | -re ".*$gdb_prompt $" { fail "complete 'p TWENTY_'" } | |
519 | timeout { fail "(timeout) complete 'p TWENTY_' 2" } | |
520 | } | |
521 | ||
522 | # The macro FORTY_EIGHT was undefined and thus is not in scope. | |
523 | send_gdb "p FORTY_\t" | |
524 | gdb_expect { | |
525 | -re "^p FORTY_\\\x07$"\ | |
526 | { send_gdb "\n" | |
527 | gdb_expect { | |
528 | -re "No symbol \"FORTY_\" in current context\\..*$gdb_prompt $"\ | |
529 | { pass "complete 'p FORTY_'"} | |
530 | -re ".*$gdb_prompt $" { fail "complete 'p FORTY_'"} | |
531 | timeout {fail "(timeout) complete 'p FORTY_'"} | |
532 | } | |
533 | } | |
534 | -re ".*$gdb_prompt $" { fail "complete 'p FORTY_'" } | |
535 | timeout { fail "(timeout) complete 'p FORTY_' 2" } | |
536 | } | |
537 | ||
538 | gdb_test "macro define TWENTY_THREE 25" \ | |
539 | "" \ | |
540 | "defining TWENTY_THREE" | |
541 | ||
542 | # User-defined macros are always in scope. | |
543 | send_gdb "p TWENTY_\t" | |
544 | gdb_expect { | |
545 | -re "^p TWENTY_THREE $"\ | |
546 | { send_gdb "\n" | |
547 | gdb_expect { | |
548 | -re "^.* = 25.*$gdb_prompt $"\ | |
549 | { pass "complete 'p TWENTY_THREE'"} | |
550 | -re ".*$gdb_prompt $" { fail "complete 'p TWENTY_THREE'"} | |
551 | timeout {fail "(timeout) complete 'p TWENTY_THREE'"} | |
552 | } | |
553 | } | |
554 | -re ".*$gdb_prompt $" { fail "complete 'p TWENTY_THREE'" } | |
555 | timeout { fail "(timeout) complete 'p TWENTY_THREE' 2" } | |
556 | } | |
557 | ||
2fae03e8 TT |
558 | # Splicing tests. |
559 | ||
ccb3ac8a | 560 | gdb_test "macro expand SPLICE(x, y)" \ |
2fae03e8 TT |
561 | "expands to: xy" \ |
562 | "basic macro splicing" | |
563 | ||
564 | gdb_test "macro define robotinvasion 2010" \ | |
565 | "" \ | |
566 | "define splice helper" | |
567 | ||
568 | gdb_test "macro expand SPLICE(robot, invasion)" \ | |
569 | "expands to: *2010" \ | |
570 | "splicing plus expansion" | |
571 | ||
572 | # Varargs tests. | |
573 | ||
dcb1a1e2 | 574 | gdb_test "macro define va_c99(...) varfunc (fixedarg, __VA_ARGS__)" \ |
2fae03e8 TT |
575 | "" \ |
576 | "define first varargs helper" | |
577 | ||
dcb1a1e2 | 578 | gdb_test "macro define va2_c99(x, y, ...) varfunc (fixedarg, x, y, __VA_ARGS__)" \ |
2fae03e8 TT |
579 | "" \ |
580 | "define second varargs helper" | |
581 | ||
dcb1a1e2 | 582 | gdb_test "macro define va_gnu(args...) varfunc (fixedarg, args)" \ |
2fae03e8 TT |
583 | "" \ |
584 | "define third varargs helper" | |
585 | ||
dcb1a1e2 | 586 | gdb_test "macro define va2_gnu(args...) varfunc (fixedarg, ## args)" \ |
2fae03e8 TT |
587 | "" \ |
588 | "define fourth varargs helper" | |
589 | ||
590 | gdb_test "macro expand va_c99(one, two, three)" \ | |
dcb1a1e2 | 591 | "expands to: *varfunc \\(fixedarg, *one, two, three\\)" \ |
2fae03e8 TT |
592 | "c99 varargs expansion" |
593 | ||
594 | gdb_test "macro expand va_c99()" \ | |
dcb1a1e2 | 595 | "expands to: *varfunc \\(fixedarg, *\\)" \ |
2fae03e8 TT |
596 | "c99 varargs expansion without an argument" |
597 | ||
598 | gdb_test "macro expand va2_c99(one, two, three, four)" \ | |
dcb1a1e2 | 599 | "expands to: *varfunc \\(fixedarg, *one, two, three, four\\)" \ |
2fae03e8 TT |
600 | "c99 varargs expansion, multiple formal arguments" |
601 | ||
602 | gdb_test "macro expand va_gnu(one, two, three, four)" \ | |
dcb1a1e2 | 603 | "expands to: *varfunc \\(fixedarg, *one, two, three, four\\)" \ |
2fae03e8 TT |
604 | "gnu varargs expansion" |
605 | ||
606 | gdb_test "macro expand va_gnu()" \ | |
dcb1a1e2 | 607 | "expands to: *varfunc \\(fixedarg, *\\)" \ |
2fae03e8 TT |
608 | "gnu varargs expansion without an argument" |
609 | ||
610 | gdb_test "macro expand va2_gnu()" \ | |
dcb1a1e2 | 611 | "expands to: *varfunc \\(fixedarg\\)" \ |
2fae03e8 TT |
612 | "gnu varargs expansion special splicing without an argument" |
613 | ||
614 | # Stringification tests. | |
615 | ||
616 | gdb_test "macro define str(x) #x" \ | |
617 | "" \ | |
618 | "define stringification macro" | |
619 | ||
620 | gdb_test "macro define maude 5" \ | |
621 | "" \ | |
622 | "define first stringification helper" | |
623 | ||
624 | gdb_test "macro define xstr(x) str(x)" \ | |
625 | "" \ | |
626 | "define second stringification helper" | |
627 | ||
628 | gdb_test "print str(5)" \ | |
629 | " = \"5\"" \ | |
630 | "simple stringify" | |
631 | ||
632 | gdb_test "print str(hi bob)" \ | |
633 | " = \"hi bob\"" \ | |
634 | "stringify with one space" | |
635 | ||
636 | gdb_test "print str( hi bob )" \ | |
637 | " = \"hi bob\"" \ | |
638 | "stringify with many spaces" | |
639 | ||
640 | gdb_test "print str(hi \"bob\")" \ | |
641 | " = \"hi \\\\\"bob\\\\\"\"" \ | |
642 | "stringify with quotes" | |
643 | ||
644 | gdb_test "print str(hi \\bob\\)" \ | |
645 | " = \"hi \\\\\\\\bob\\\\\\\\\"" \ | |
646 | "stringify with backslashes" | |
647 | ||
648 | gdb_test "print str(maude)" \ | |
649 | " = \"maude\"" \ | |
650 | "stringify without substitution" | |
651 | ||
652 | gdb_test "print xstr(maude)" \ | |
653 | " = \"5\"" \ | |
654 | "stringify with substitution" |