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