]>
Commit | Line | Data |
---|---|---|
ee93cd5e KS |
1 | # Copyright 2014, 2015 Free Software Foundation, Inc. |
2 | ||
3 | # This program is free software; you can redistribute it and/or modify | |
4 | # it under the terms of the GNU General Public License as published by | |
5 | # the Free Software Foundation; either version 3 of the License, or | |
6 | # (at your option) any later version. | |
7 | # | |
8 | # This program is distributed in the hope that it will be useful, | |
9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 | # GNU General Public License for more details. | |
12 | # | |
13 | # You should have received a copy of the GNU General Public License | |
14 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
15 | ||
16 | # This file is part of the gdb testsuite | |
17 | ||
18 | # Test expressions in which variable names shadow tag names. | |
19 | ||
20 | if {[skip_cplus_tests]} { continue } | |
21 | ||
22 | standard_testfile var-tag.cc var-tag-2.cc var-tag-3.cc var-tag-4.cc | |
23 | ||
24 | if {[prepare_for_testing $testfile.exp $testfile \ | |
25 | [list $srcfile $srcfile2 $srcfile3 $srcfile4] {debug c++}]} { | |
26 | return -1 | |
27 | } | |
28 | ||
29 | proc do_global_tests {lang} { | |
30 | set invalid_print "Attempt to use a type name as an expression" | |
4bc4d428 SL |
31 | |
32 | if {$lang == "c++"} { | |
938d3bf2 | 33 | set opt_underlying "(: unsigned (int|short|char) )?" |
4bc4d428 SL |
34 | } else { |
35 | set opt_underlying "" | |
032a0fca | 36 | } |
4bc4d428 | 37 | set ptypefmt "type = (class|enum|union|struct) %s $opt_underlying{.*}" |
ee93cd5e KS |
38 | |
39 | with_test_prefix $lang { | |
40 | gdb_test_no_output "set language $lang" | |
41 | gdb_test "ptype C" "type = class C {.*}" | |
42 | gdb_test "print E" "= a" | |
4bc4d428 | 43 | gdb_test "ptype E" "type = enum E $opt_underlying{.*}" |
ee93cd5e KS |
44 | gdb_test "print S" "= {<No data fields>}" |
45 | gdb_test "ptype S" "type = struct S {.*}" | |
46 | gdb_test "print U" "= {.*}" | |
47 | gdb_test "ptype U" "type = union U {.*}" | |
48 | gdb_test "print cc" "= {.*}" | |
49 | gdb_test "ptype cc" "type = class CC {.*}" | |
50 | gdb_test "print CC" [format $invalid_print "CC"] | |
51 | gdb_test "ptype CC" [format $ptypefmt "CC"] | |
52 | gdb_test "print ss" "= {<No data fields>}" | |
53 | gdb_test "ptype ss" "type = struct SS {.*}" | |
54 | gdb_test "print SS" [format $invalid_print "SS"] | |
55 | gdb_test "ptype SS" [format $ptypefmt "SS"] | |
56 | gdb_test "print ee" "= .*" | |
4bc4d428 | 57 | gdb_test "ptype ee" "type = enum EE $opt_underlying{.*}" |
ee93cd5e KS |
58 | gdb_test "print EE" [format $invalid_print "EE"] |
59 | gdb_test "ptype EE" [format $ptypefmt "EE"] | |
60 | gdb_test "print uu" "= {.*}" | |
61 | gdb_test "ptype uu" "type = union UU {.*}" | |
62 | gdb_test "print UU" [format $invalid_print "UU"] | |
63 | gdb_test "ptype UU" [format $ptypefmt "UU"] | |
64 | ||
65 | # These tests exercise lookup of symbols using the "quick fns" API. | |
66 | # Each of them is in a separate CU as once its CU is expanded, | |
67 | # we're no longer using the quick fns API. | |
68 | gdb_test "print E2" "= a2" | |
032a0fca | 69 | gdb_test "ptype E2" "type = enum E2 $opt_underlying{.*}" |
ee93cd5e KS |
70 | gdb_test "print S2" "= {<No data fields>}" |
71 | gdb_test "ptype S2" "type = struct S2 {.*}" | |
72 | gdb_test "print U2" "= {.*}" | |
73 | gdb_test "ptype U2" "type = union U2 {.*}" | |
74 | } | |
75 | } | |
76 | ||
77 | # First test expressions when there is no context. | |
78 | with_test_prefix "before start" { | |
79 | do_global_tests c++ | |
80 | do_global_tests c | |
81 | } | |
82 | ||
83 | # Run to main and test again. | |
84 | if {![runto_main]} { | |
85 | perror "couldn't run to main" | |
86 | continue | |
87 | } | |
88 | ||
89 | with_test_prefix "in main" { | |
90 | do_global_tests c++ | |
91 | do_global_tests c | |
92 | } | |
93 | ||
94 | # Run to C::f and test again. | |
95 | gdb_breakpoint "C::f" | |
96 | gdb_continue_to_breakpoint "continue to C::f" | |
97 | with_test_prefix "in C::f" { | |
98 | do_global_tests c++ | |
99 | do_global_tests c | |
100 | } | |
101 | ||
102 | # Another hard-to-guess-the-users-intent bug... | |
103 | # It would be really nice if we could query the user! | |
104 | with_test_prefix "global collision" { | |
105 | gdb_test_no_output "set language c++" | |
106 | setup_kfail "c++/16463" "*-*-*" | |
107 | gdb_test "print global" "= 3" | |
108 | ||
109 | # ... with a simple workaround: | |
110 | gdb_test "print ::global" "= 3" | |
111 | } |