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