65661713ff3862bab7f8521f19d20d63e06340ae
[external/binutils.git] / gdb / testsuite / gdb.cp / m-static.exp
1 # Copyright 2002-2018 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 # Tests for member static data
17 # 2002-05-13  Benjamin Kosnik  <bkoz@redhat.com>
18 # 2002-08-22  David Carlton <carlton@math.stanford.edu>
19
20 # This file is part of the gdb testsuite
21
22 if { [skip_cplus_tests] } { continue }
23
24 #
25 # test running programs
26 #
27
28 standard_testfile .cc m-static1.cc
29
30 if [get_compiler_info] {
31     return -1
32 }
33
34 if {[prepare_for_testing "failed to prepare" $testfile \
35          [list $srcfile $srcfile2] {debug c++}]} {
36     return -1
37 }
38
39 if ![runto_main] then {
40     perror "couldn't run to breakpoint"
41     continue
42 }
43
44 get_debug_format
45 set non_dwarf [expr ! [test_debug_format "DWARF 2"]]
46
47 # First, run to after we've constructed all the objects:
48
49 gdb_breakpoint [gdb_get_line_number "constructs-done"]
50 gdb_continue_to_breakpoint "end of constructors"
51
52
53 # One.
54
55 # simple object, static const bool
56 gdb_test "print test1.test" "\\$\[0-9\]* = true" "simple object, static const bool"
57
58 # simple object, static const int
59 gdb_test "print test1.key1" "\\$\[0-9\]* = 5" "simple object, static const int"
60
61 # simple object, static long
62 gdb_test "print test1.key2" "\\$\[0-9\]* = 77" "simple object, static long"
63
64 # simple object, static enum
65 gdb_test "print test1.value" "\\$\[0-9\]* = oriental" "simple object, static enum"
66
67 if { [is_aarch32_target] } {
68     gdb_test "print test5.single_constructor" \
69         { = {single_constructor \*\(single_constructor \* const\)} 0x[0-9a-f]+ <single_constructor::single_constructor\(\)>} \
70         "simple object instance, print constructor"
71     gdb_test "ptype test5.single_constructor" \
72         {type = class single_constructor {\r\n  public:\r\n    single_constructor\(void\);\r\n    ~single_constructor\(\);\r\n} \*\(single_constructor \* const\)} \
73         "simple object instance, ptype constructor"
74     gdb_test "ptype single_constructor::single_constructor" \
75         {type = class single_constructor {\r\n  public:\r\n    single_constructor\(void\);\r\n    ~single_constructor\(\);\r\n} \*\(single_constructor \* const\)} \
76         "simple object class, ptype constructor"
77
78     gdb_test "print test1.~gnu_obj_1" \
79         { = {void \*\(gnu_obj_1 \* const, int\)} 0x[0-9a-f]+ <gnu_obj_1::~gnu_obj_1\(\)>} \
80         "simple object instance, print destructor"
81     gdb_test "ptype test1.~gnu_obj_1" \
82         {type = void \*\(gnu_obj_1 \* const, int\)} \
83         "simple object instance, ptype destructor"
84
85     gdb_test "print test1.'~gnu_obj_1'" \
86         { = {void \*\(gnu_obj_1 \*( const)?, int\)} 0x[0-9a-f]+ <gnu_obj_1::~gnu_obj_1\(\)>} \
87         "simple object instance, print quoted destructor"
88
89     gdb_test "ptype gnu_obj_1::'~gnu_obj_1'" \
90         {type = void \*\(gnu_obj_1 \* const\)} \
91         "simple object class, ptype quoted destructor"
92 } else {
93     gdb_test "print test5.single_constructor" \
94         { = {void \(single_constructor \* const\)} 0x[0-9a-f]+ <single_constructor::single_constructor\(\)>} \
95         "simple object instance, print constructor"
96     gdb_test "ptype test5.single_constructor" \
97         {type = void \(single_constructor \* const\)} \
98         "simple object instance, ptype constructor"
99     gdb_test "ptype single_constructor::single_constructor" \
100         {type = void \(single_constructor \* const\)} \
101         "simple object class, ptype constructor"
102
103     gdb_test "print test1.~gnu_obj_1" \
104         { = {void \(gnu_obj_1 \* const, int\)} 0x[0-9a-f]+ <gnu_obj_1::~gnu_obj_1\(\)>} \
105         "simple object instance, print destructor"
106     gdb_test "ptype test1.~gnu_obj_1" \
107         {type = void \(gnu_obj_1 \* const, int\)} \
108         "simple object instance, ptype destructor"
109
110     gdb_test "print test1.'~gnu_obj_1'" \
111         { = {void \(gnu_obj_1 \*( const)?, int\)} 0x[0-9a-f]+ <gnu_obj_1::~gnu_obj_1\(\)>} \
112         "simple object instance, print quoted destructor"
113
114     gdb_test "ptype gnu_obj_1::'~gnu_obj_1'" \
115         {type = void \(gnu_obj_1 \* const\)} \
116         "simple object class, ptype quoted destructor"
117 }
118
119 # Two.
120
121 # derived template object, base static const bool
122 gdb_test "print test2.test" "\\$\[0-9\]* = true" "derived template object, base static const bool"
123
124 # derived template object, base static const int
125 gdb_test "print test2.key1" "\\$\[0-9\]* = 5" "derived template object, base static const int"
126
127 # derived template object, base static long
128 gdb_test "print test2.key2" "\\$\[0-9\]* = 77" "derived template object, base static long"
129
130 # derived template object, base static enum
131 gdb_test "print test2.value" "\\$\[0-9\].* = oriental" "derived template object, base static enum"
132
133 # derived template object, static enum
134 gdb_test "print test2.value_derived" "\\$\[0-9\].* = etruscan" "derived template object, static enum"
135
136 # Three.
137
138 # template object, static derived template data member's base static const bool
139 gdb_test "print test3.data.test" "\\$\[0-9\].* = true" "template object, static const bool"
140
141 # template object, static derived template data member's base static const int
142 gdb_test "print test3.data.key1" "\\$\[0-9\].* = 5" "template object, static const int"
143
144 # template object, static derived template data member's base static long
145 gdb_test "print test3.data.key2" "\\$\[0-9\].* = 77" "template object, static long"
146
147 # template object, static derived template data member's base static enum
148 gdb_test "print test3.data.value" "\\$\[0-9\].* = oriental" "template object, static enum"
149
150 #  template object, static derived template data member's static enum
151 gdb_test "print test3.data.value_derived" "\\$\[0-9\].* = etruscan" "template object, static derived enum"
152
153 # 2002-08-16
154 # Four.
155
156 # static const int initialized in another file.
157 gdb_test "print test4.elsewhere" "\\$\[0-9\].* = 221" "static const int initialized elsewhere"
158
159 # static const int that nobody initializes.  From PR gdb/635.
160 if {[test_compiler_info {gcc-[0-3]-*}]
161     || [test_compiler_info {gcc-4-[0-4]-*}]} {
162     # There was an extra CU-level DW_TAG_variable as DW_AT_declaration
163     # with DW_AT_name = nowhere
164     # and DW_AT_MIPS_linkage_name = _ZN9gnu_obj_47nowhereE .
165     setup_xfail *-*-*
166 }
167 gdb_test "print test4.nowhere" "<optimized out>" "static const int initialized nowhere (print field)"
168
169 # Same, but print the whole struct.
170 gdb_test "print test4" "static nowhere = <optimized out>.*" "static const int initialized nowhere (whole struct)"
171
172 # static const initialized in the class definition, PR gdb/11702.
173 if { $non_dwarf } { setup_xfail *-*-* }
174 gdb_test "print test4.everywhere" "\\$\[0-9\].* = 317" "static const int initialized in class definition"
175 if { $non_dwarf } { setup_xfail *-*-* }
176 gdb_test "print test4.somewhere" "\\$\[0-9\].* = 3.14\[0-9\]*" "static const float initialized in class definition"
177
178 # Also make sure static const members can be found via "info var".
179 if { $non_dwarf } { setup_xfail *-*-* }
180 gdb_test "info variable everywhere" "File .*/m-static\[.\]h.*const int gnu_obj_4::everywhere;" "info variable everywhere"
181
182 # Perhaps at some point test4 should also include a test for a static
183 # const int that was initialized in the header file.  But I'm not sure
184 # that GDB's current behavior in such situations is either consistent
185 # across platforms or optimal, so I'm not including one now.
186
187 # Step into test1.method and examine the method-scoped static.
188 # This is a regression test for PR 9708.
189 gdb_test "step" "gnu_obj_1::method.*"
190 gdb_test "print svar" " = true"
191
192 gdb_exit
193 return 0