]>
Commit | Line | Data |
---|---|---|
1d506c26 | 1 | # Copyright 2002-2024 Free Software Foundation, Inc. |
258093ca MC |
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 | |
e22f8b7c | 5 | # the Free Software Foundation; either version 3 of the License, or |
258093ca | 6 | # (at your option) any later version. |
e22f8b7c | 7 | # |
258093ca MC |
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. | |
e22f8b7c | 12 | # |
258093ca | 13 | # You should have received a copy of the GNU General Public License |
e22f8b7c | 14 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
258093ca MC |
15 | |
16 | # Tests for member static data | |
17 | # 2002-05-13 Benjamin Kosnik <bkoz@redhat.com> | |
e70d6e3f | 18 | # 2002-08-22 David Carlton <carlton@math.stanford.edu> |
258093ca MC |
19 | |
20 | # This file is part of the gdb testsuite | |
21 | ||
0b94d2b9 | 22 | require allow_cplus_tests |
258093ca MC |
23 | |
24 | # | |
25 | # test running programs | |
26 | # | |
258093ca | 27 | |
f5f3a911 | 28 | standard_testfile .cc m-static1.cc |
258093ca | 29 | |
722c4596 TV |
30 | include_file m-static.h |
31 | ||
8f5d31b8 TV |
32 | set flags [list debug c++] |
33 | if { [test_compiler_info gcc-*] && [gcc_major_version] >= 10 } { | |
34 | # Work around PR gcc/101452. | |
35 | lappend flags additional_flags=-fno-eliminate-unused-debug-types | |
36 | } | |
37 | ||
5b362f04 | 38 | if {[prepare_for_testing "failed to prepare" $testfile \ |
8f5d31b8 | 39 | [list $srcfile $srcfile2] $flags]} { |
f5f3a911 TT |
40 | return -1 |
41 | } | |
258093ca | 42 | |
95701cae | 43 | if {![runto_main]} { |
cdd42066 | 44 | return |
258093ca MC |
45 | } |
46 | ||
254e6b9e | 47 | get_debug_format |
d184a3c1 | 48 | set non_dwarf [expr ! [test_debug_format "DWARF \[0-9\]"]] |
254e6b9e | 49 | |
e70d6e3f DC |
50 | # First, run to after we've constructed all the objects: |
51 | ||
52 | gdb_breakpoint [gdb_get_line_number "constructs-done"] | |
53 | gdb_continue_to_breakpoint "end of constructors" | |
54 | ||
55 | ||
258093ca | 56 | # One. |
258093ca MC |
57 | |
58 | # simple object, static const bool | |
59 | gdb_test "print test1.test" "\\$\[0-9\]* = true" "simple object, static const bool" | |
60 | ||
61 | # simple object, static const int | |
62 | gdb_test "print test1.key1" "\\$\[0-9\]* = 5" "simple object, static const int" | |
63 | ||
64 | # simple object, static long | |
65 | gdb_test "print test1.key2" "\\$\[0-9\]* = 77" "simple object, static long" | |
66 | ||
67 | # simple object, static enum | |
68 | gdb_test "print test1.value" "\\$\[0-9\]* = oriental" "simple object, static enum" | |
69 | ||
e3465b24 | 70 | if { [is_aarch32_target] } { |
f4059ef3 WN |
71 | gdb_test "print test5.single_constructor" \ |
72 | { = {single_constructor \*\(single_constructor \* const\)} 0x[0-9a-f]+ <single_constructor::single_constructor\(\)>} \ | |
73 | "simple object instance, print constructor" | |
74 | gdb_test "ptype test5.single_constructor" \ | |
ec3b243d | 75 | {type = class single_constructor {\r\n public:\r\n single_constructor\(void\);\r\n ~single_constructor\(\);\r\n} \*\(single_constructor \* const\)} \ |
f4059ef3 WN |
76 | "simple object instance, ptype constructor" |
77 | gdb_test "ptype single_constructor::single_constructor" \ | |
ec3b243d | 78 | {type = class single_constructor {\r\n public:\r\n single_constructor\(void\);\r\n ~single_constructor\(\);\r\n} \*\(single_constructor \* const\)} \ |
f4059ef3 WN |
79 | "simple object class, ptype constructor" |
80 | ||
81 | gdb_test "print test1.~gnu_obj_1" \ | |
82 | { = {void \*\(gnu_obj_1 \* const, int\)} 0x[0-9a-f]+ <gnu_obj_1::~gnu_obj_1\(\)>} \ | |
83 | "simple object instance, print destructor" | |
84 | gdb_test "ptype test1.~gnu_obj_1" \ | |
85 | {type = void \*\(gnu_obj_1 \* const, int\)} \ | |
86 | "simple object instance, ptype destructor" | |
87 | ||
88 | gdb_test "print test1.'~gnu_obj_1'" \ | |
89 | { = {void \*\(gnu_obj_1 \*( const)?, int\)} 0x[0-9a-f]+ <gnu_obj_1::~gnu_obj_1\(\)>} \ | |
90 | "simple object instance, print quoted destructor" | |
91 | ||
92 | gdb_test "ptype gnu_obj_1::'~gnu_obj_1'" \ | |
93 | {type = void \*\(gnu_obj_1 \* const\)} \ | |
94 | "simple object class, ptype quoted destructor" | |
95 | } else { | |
96 | gdb_test "print test5.single_constructor" \ | |
97 | { = {void \(single_constructor \* const\)} 0x[0-9a-f]+ <single_constructor::single_constructor\(\)>} \ | |
98 | "simple object instance, print constructor" | |
99 | gdb_test "ptype test5.single_constructor" \ | |
100 | {type = void \(single_constructor \* const\)} \ | |
101 | "simple object instance, ptype constructor" | |
102 | gdb_test "ptype single_constructor::single_constructor" \ | |
103 | {type = void \(single_constructor \* const\)} \ | |
104 | "simple object class, ptype constructor" | |
105 | ||
f2f2eb6b BL |
106 | gdb_test "print test1.~gnu_obj_1"\ |
107 | { = {void \(gnu_obj_1 \* const(?:, int)?\)} 0x[0-9a-f]+ <gnu_obj_1::~gnu_obj_1\(\)>}\ | |
f4059ef3 | 108 | "simple object instance, print destructor" |
f2f2eb6b BL |
109 | |
110 | gdb_test "ptype test1.~gnu_obj_1"\ | |
111 | {type = void \(gnu_obj_1 \* const(?:, int)?\)}\ | |
f4059ef3 WN |
112 | "simple object instance, ptype destructor" |
113 | ||
114 | gdb_test "print test1.'~gnu_obj_1'" \ | |
f2f2eb6b | 115 | { = {void \(gnu_obj_1 \*( const)?(?:, int)?\)} 0x[0-9a-f]+ <gnu_obj_1::~gnu_obj_1\(\)>} \ |
f4059ef3 WN |
116 | "simple object instance, print quoted destructor" |
117 | ||
118 | gdb_test "ptype gnu_obj_1::'~gnu_obj_1'" \ | |
119 | {type = void \(gnu_obj_1 \* const\)} \ | |
120 | "simple object class, ptype quoted destructor" | |
121 | } | |
e234dfaf | 122 | |
258093ca | 123 | # Two. |
258093ca MC |
124 | |
125 | # derived template object, base static const bool | |
126 | gdb_test "print test2.test" "\\$\[0-9\]* = true" "derived template object, base static const bool" | |
127 | ||
128 | # derived template object, base static const int | |
129 | gdb_test "print test2.key1" "\\$\[0-9\]* = 5" "derived template object, base static const int" | |
130 | ||
131 | # derived template object, base static long | |
132 | gdb_test "print test2.key2" "\\$\[0-9\]* = 77" "derived template object, base static long" | |
133 | ||
134 | # derived template object, base static enum | |
135 | gdb_test "print test2.value" "\\$\[0-9\].* = oriental" "derived template object, base static enum" | |
136 | ||
137 | # derived template object, static enum | |
138 | gdb_test "print test2.value_derived" "\\$\[0-9\].* = etruscan" "derived template object, static enum" | |
139 | ||
140 | # Three. | |
258093ca MC |
141 | |
142 | # template object, static derived template data member's base static const bool | |
143 | gdb_test "print test3.data.test" "\\$\[0-9\].* = true" "template object, static const bool" | |
144 | ||
145 | # template object, static derived template data member's base static const int | |
146 | gdb_test "print test3.data.key1" "\\$\[0-9\].* = 5" "template object, static const int" | |
147 | ||
148 | # template object, static derived template data member's base static long | |
149 | gdb_test "print test3.data.key2" "\\$\[0-9\].* = 77" "template object, static long" | |
150 | ||
151 | # template object, static derived template data member's base static enum | |
152 | gdb_test "print test3.data.value" "\\$\[0-9\].* = oriental" "template object, static enum" | |
153 | ||
154 | # template object, static derived template data member's static enum | |
155 | gdb_test "print test3.data.value_derived" "\\$\[0-9\].* = etruscan" "template object, static derived enum" | |
156 | ||
e70d6e3f DC |
157 | # 2002-08-16 |
158 | # Four. | |
159 | ||
160 | # static const int initialized in another file. | |
161 | gdb_test "print test4.elsewhere" "\\$\[0-9\].* = 221" "static const int initialized elsewhere" | |
162 | ||
163 | # static const int that nobody initializes. From PR gdb/635. | |
46fc714c JK |
164 | if {[test_compiler_info {gcc-[0-3]-*}] |
165 | || [test_compiler_info {gcc-4-[0-4]-*}]} { | |
166 | # There was an extra CU-level DW_TAG_variable as DW_AT_declaration | |
167 | # with DW_AT_name = nowhere | |
168 | # and DW_AT_MIPS_linkage_name = _ZN9gnu_obj_47nowhereE . | |
169 | setup_xfail *-*-* | |
170 | } | |
686d4def | 171 | gdb_test "print test4.nowhere" "<optimized out>" "static const int initialized nowhere (print field)" |
c2e0e465 SM |
172 | gdb_test "ptype test4.nowhere" "type = const int" |
173 | gdb_test "print test4.nowhere.nowhere" "Attempt to extract a component of a value that is not a structure." | |
686d4def PA |
174 | |
175 | # Same, but print the whole struct. | |
176 | gdb_test "print test4" "static nowhere = <optimized out>.*" "static const int initialized nowhere (whole struct)" | |
e70d6e3f | 177 | |
254e6b9e DE |
178 | # static const initialized in the class definition, PR gdb/11702. |
179 | if { $non_dwarf } { setup_xfail *-*-* } | |
180 | gdb_test "print test4.everywhere" "\\$\[0-9\].* = 317" "static const int initialized in class definition" | |
181 | if { $non_dwarf } { setup_xfail *-*-* } | |
182 | gdb_test "print test4.somewhere" "\\$\[0-9\].* = 3.14\[0-9\]*" "static const float initialized in class definition" | |
183 | ||
184 | # Also make sure static const members can be found via "info var". | |
185 | if { $non_dwarf } { setup_xfail *-*-* } | |
722c4596 TV |
186 | gdb_test "info variable everywhere" \ |
187 | [multi_line \ | |
9ed6d741 TV |
188 | {All variables matching regular expression "everywhere":} \ |
189 | "" \ | |
722c4596 | 190 | "File (.*/)?m-static\[.\]h:" \ |
9ed6d741 | 191 | "$decimal:\tconst int gnu_obj_4::everywhere;"] |
254e6b9e | 192 | |
e70d6e3f DC |
193 | # Perhaps at some point test4 should also include a test for a static |
194 | # const int that was initialized in the header file. But I'm not sure | |
195 | # that GDB's current behavior in such situations is either consistent | |
196 | # across platforms or optimal, so I'm not including one now. | |
197 | ||
1c809c68 TT |
198 | # Step into test1.method and examine the method-scoped static. |
199 | # This is a regression test for PR 9708. | |
200 | gdb_test "step" "gnu_obj_1::method.*" | |
201 | gdb_test "print svar" " = true" | |
202 | ||
258093ca | 203 | gdb_exit |