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