Reapply fix for gdb.cp/var-tag.exp C++ failures.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.cp / var-tag.exp
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"
31
32 if {$lang == "c++"} {
33 set opt_underlying "(: unsigned int )?"
34 } else {
35 set opt_underlying ""
36 set ptypefmt "type = (class|enum|union|struct) %s $opt_underlying{.*}"
37
38 with_test_prefix $lang {
39 gdb_test_no_output "set language $lang"
40 gdb_test "ptype C" "type = class C {.*}"
41 gdb_test "print E" "= a"
42 gdb_test "ptype E" "type = enum E $opt_underlying{.*}"
43 gdb_test "print S" "= {<No data fields>}"
44 gdb_test "ptype S" "type = struct S {.*}"
45 gdb_test "print U" "= {.*}"
46 gdb_test "ptype U" "type = union U {.*}"
47 gdb_test "print cc" "= {.*}"
48 gdb_test "ptype cc" "type = class CC {.*}"
49 gdb_test "print CC" [format $invalid_print "CC"]
50 gdb_test "ptype CC" [format $ptypefmt "CC"]
51 gdb_test "print ss" "= {<No data fields>}"
52 gdb_test "ptype ss" "type = struct SS {.*}"
53 gdb_test "print SS" [format $invalid_print "SS"]
54 gdb_test "ptype SS" [format $ptypefmt "SS"]
55 gdb_test "print ee" "= .*"
56 gdb_test "ptype ee" "type = enum EE $opt_underlying{.*}"
57 gdb_test "print EE" [format $invalid_print "EE"]
58 gdb_test "ptype EE" [format $ptypefmt "EE"]
59 gdb_test "print uu" "= {.*}"
60 gdb_test "ptype uu" "type = union UU {.*}"
61 gdb_test "print UU" [format $invalid_print "UU"]
62 gdb_test "ptype UU" [format $ptypefmt "UU"]
63
64 # These tests exercise lookup of symbols using the "quick fns" API.
65 # Each of them is in a separate CU as once its CU is expanded,
66 # we're no longer using the quick fns API.
67 gdb_test "print E2" "= a2"
68 gdb_test "ptype E2" "type = enum E2 {.*}"
69 gdb_test "print S2" "= {<No data fields>}"
70 gdb_test "ptype S2" "type = struct S2 {.*}"
71 gdb_test "print U2" "= {.*}"
72 gdb_test "ptype U2" "type = union U2 {.*}"
73 }
74 }
75
76 # First test expressions when there is no context.
77 with_test_prefix "before start" {
78 do_global_tests c++
79 do_global_tests c
80 }
81
82 # Run to main and test again.
83 if {![runto_main]} {
84 perror "couldn't run to main"
85 continue
86 }
87
88 with_test_prefix "in main" {
89 do_global_tests c++
90 do_global_tests c
91 }
92
93 # Run to C::f and test again.
94 gdb_breakpoint "C::f"
95 gdb_continue_to_breakpoint "continue to C::f"
96 with_test_prefix "in C::f" {
97 do_global_tests c++
98 do_global_tests c
99 }
100
101 # Another hard-to-guess-the-users-intent bug...
102 # It would be really nice if we could query the user!
103 with_test_prefix "global collision" {
104 gdb_test_no_output "set language c++"
105 setup_kfail "c++/16463" "*-*-*"
106 gdb_test "print global" "= 3"
107
108 # ... with a simple workaround:
109 gdb_test "print ::global" "= 3"
110 }
This page took 0.032867 seconds and 5 git commands to generate.