]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.cp/m-static.exp
run copyright.sh for 2011.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.cp / m-static.exp
1 # Copyright 2002, 2004, 2007, 2008, 2009, 2010, 2011
2 # Free Software Foundation, Inc.
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
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
8 #
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.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17 # Tests for member static data
18 # 2002-05-13 Benjamin Kosnik <bkoz@redhat.com>
19 # 2002-08-22 David Carlton <carlton@math.stanford.edu>
20
21 # This file is part of the gdb testsuite
22
23 if $tracelevel then {
24 strace $tracelevel
25 }
26
27 if { [skip_cplus_tests] } { continue }
28
29 #
30 # test running programs
31 #
32
33 set testfile "m-static"
34 set srcfile "${testfile}.cc"
35 set srcfile1 "${testfile}1.cc"
36 set objfile "${testfile}.o"
37 set objfile1 "${testfile}1.o"
38 set binfile "${objdir}/${subdir}/${testfile}"
39
40 if { [gdb_compile "$srcdir/$subdir/$srcfile" "$objdir/$subdir/$objfile" object {debug c++}] != "" } {
41 untested m-static.exp
42 return -1
43 }
44
45 if { [gdb_compile "$srcdir/$subdir/$srcfile1" "$objdir/$subdir/$objfile1" object {debug c++}] != "" } {
46 untested m-static.exp
47 return -1
48 }
49
50 if { [gdb_compile "$objdir/$subdir/$objfile $objdir/$subdir/$objfile1" "${binfile}" executable {debug c++}] != "" } {
51 untested m-static.exp
52 return -1
53 }
54
55 gdb_exit
56 gdb_start
57 gdb_reinitialize_dir $srcdir/$subdir
58 gdb_load ${binfile}
59
60 if ![runto_main] then {
61 perror "couldn't run to breakpoint"
62 continue
63 }
64
65 get_debug_format
66 set non_dwarf [expr ! [test_debug_format "DWARF 2"]]
67
68 # First, run to after we've constructed all the objects:
69
70 gdb_breakpoint [gdb_get_line_number "constructs-done"]
71 gdb_continue_to_breakpoint "end of constructors"
72
73
74 # One.
75
76 # simple object, static const bool
77 gdb_test "print test1.test" "\\$\[0-9\]* = true" "simple object, static const bool"
78
79 # simple object, static const int
80 gdb_test "print test1.key1" "\\$\[0-9\]* = 5" "simple object, static const int"
81
82 # simple object, static long
83 gdb_test "print test1.key2" "\\$\[0-9\]* = 77" "simple object, static long"
84
85 # simple object, static enum
86 gdb_test "print test1.value" "\\$\[0-9\]* = oriental" "simple object, static enum"
87
88 # Two.
89
90 # derived template object, base static const bool
91 gdb_test "print test2.test" "\\$\[0-9\]* = true" "derived template object, base static const bool"
92
93 # derived template object, base static const int
94 gdb_test "print test2.key1" "\\$\[0-9\]* = 5" "derived template object, base static const int"
95
96 # derived template object, base static long
97 gdb_test "print test2.key2" "\\$\[0-9\]* = 77" "derived template object, base static long"
98
99 # derived template object, base static enum
100 gdb_test "print test2.value" "\\$\[0-9\].* = oriental" "derived template object, base static enum"
101
102 # derived template object, static enum
103 gdb_test "print test2.value_derived" "\\$\[0-9\].* = etruscan" "derived template object, static enum"
104
105 # Three.
106
107 # template object, static derived template data member's base static const bool
108 gdb_test "print test3.data.test" "\\$\[0-9\].* = true" "template object, static const bool"
109
110 # template object, static derived template data member's base static const int
111 gdb_test "print test3.data.key1" "\\$\[0-9\].* = 5" "template object, static const int"
112
113 # template object, static derived template data member's base static long
114 gdb_test "print test3.data.key2" "\\$\[0-9\].* = 77" "template object, static long"
115
116 # template object, static derived template data member's base static enum
117 gdb_test "print test3.data.value" "\\$\[0-9\].* = oriental" "template object, static enum"
118
119 # template object, static derived template data member's static enum
120 gdb_test "print test3.data.value_derived" "\\$\[0-9\].* = etruscan" "template object, static derived enum"
121
122 # 2002-08-16
123 # Four.
124
125 # static const int initialized in another file.
126 gdb_test "print test4.elsewhere" "\\$\[0-9\].* = 221" "static const int initialized elsewhere"
127
128 # static const int that nobody initializes. From PR gdb/635.
129 gdb_test "print test4.nowhere" "field nowhere is nonexistent or has been optimized out" "static const int initialized nowhere"
130
131 # static const initialized in the class definition, PR gdb/11702.
132 if { $non_dwarf } { setup_xfail *-*-* }
133 gdb_test "print test4.everywhere" "\\$\[0-9\].* = 317" "static const int initialized in class definition"
134 if { $non_dwarf } { setup_xfail *-*-* }
135 gdb_test "print test4.somewhere" "\\$\[0-9\].* = 3.14\[0-9\]*" "static const float initialized in class definition"
136
137 # Also make sure static const members can be found via "info var".
138 if { $non_dwarf } { setup_xfail *-*-* }
139 gdb_test "info variable everywhere" "File .*/m-static\[.\]h.*const int gnu_obj_4::everywhere;" "info variable everywhere"
140
141 # Perhaps at some point test4 should also include a test for a static
142 # const int that was initialized in the header file. But I'm not sure
143 # that GDB's current behavior in such situations is either consistent
144 # across platforms or optimal, so I'm not including one now.
145
146 # Step into test1.method and examine the method-scoped static.
147 # This is a regression test for PR 9708.
148 gdb_test "step" "gnu_obj_1::method.*"
149 gdb_test "print svar" " = true"
150
151 gdb_exit
152 return 0