PR gdb/15827
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.cp / var-tag.exp
1 # Copyright 2014 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 .cc
23
24 if {[prepare_for_testing $testfile.exp $testfile $srcfile {debug c++}]} {
25 return -1
26 }
27
28 proc do_global_tests {lang} {
29 if {$lang == "c"} {
30 set invalid_print "No symbol \"%s\" in current context."
31 set ptypefmt $invalid_print
32 } else {
33 set invalid_print "Attempt to use a type name as an expression"
34 set ptypefmt "type = (class|enum|union|struct) %s {.*}"
35 }
36
37 with_test_prefix $lang {
38 gdb_test_no_output "set language $lang"
39 gdb_test "ptype C" "type = class C {.*}"
40 gdb_test "print E" "= a"
41 gdb_test "ptype E" "type = enum E {.*}"
42 gdb_test "print S" "= {<No data fields>}"
43 gdb_test "ptype S" "type = struct S {.*}"
44 gdb_test "print U" "= {.*}"
45 gdb_test "ptype U" "type = union U {.*}"
46 gdb_test "print cc" "= {.*}"
47 gdb_test "ptype cc" "type = class CC {.*}"
48 gdb_test "print CC" [format $invalid_print "CC"]
49 gdb_test "ptype CC" [format $ptypefmt "CC"]
50 gdb_test "print ss" "= {<No data fields>}"
51 gdb_test "ptype ss" "type = struct SS {.*}"
52 gdb_test "print SS" [format $invalid_print "SS"]
53 gdb_test "ptype SS" [format $ptypefmt "SS"]
54 gdb_test "print ee" "= .*"
55 gdb_test "ptype ee" "type = enum EE {.*}"
56 gdb_test "print EE" [format $invalid_print "EE"]
57 gdb_test "ptype EE" [format $ptypefmt "EE"]
58 gdb_test "print uu" "= {.*}"
59 gdb_test "ptype uu" "type = union UU {.*}"
60 gdb_test "print UU" [format $invalid_print "UU"]
61 gdb_test "ptype UU" [format $ptypefmt "UU"]
62 }
63 }
64
65 # First test expressions when there is no context.
66 with_test_prefix "before start" {
67 do_global_tests c++
68 do_global_tests c
69 }
70
71 # Run to main and test again.
72 if {![runto_main]} {
73 perror "couldn't run to main"
74 continue
75 }
76
77 with_test_prefix "in main" {
78 do_global_tests c++
79 do_global_tests c
80 }
81
82 # Finally run to C::f and test again
83 gdb_breakpoint "C::f"
84 gdb_continue_to_breakpoint "continue to C::f"
85 with_test_prefix "in C::f" {
86 do_global_tests c++
87 do_global_tests c
88 }
89
90 # Another hard-to-guess-the-users-intent bug...
91 # It would be really nice if we could query the user!
92 with_test_prefix "global collision" {
93 gdb_test_no_output "set language c++"
94 setup_kfail "c++/16463" "*-*-*"
95 gdb_test "print global" "= 3"
96
97 # ... with a simple workaround:
98 gdb_test "print ::global" "= 3"
99 }
This page took 0.030983 seconds and 4 git commands to generate.