1 # Copyright
2002-2024 Free Software Foundation
, Inc.
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.
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.
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
/>.
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
>
20 # This file is part of the gdb testsuite
22 require allow_cplus_tests
25 # test running programs
28 standard_testfile .cc m
-static1.cc
30 include_file m
-static.h
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
38 if {[prepare_for_testing
"failed to prepare" $testfile \
39 [list $srcfile $srcfile2
] $flags
]} {
48 set non_dwarf
[expr
! [test_debug_format
"DWARF \[0-9\]"]]
50 # First
, run to after we
've constructed all the objects:
52 gdb_breakpoint [gdb_get_line_number "constructs-done"]
53 gdb_continue_to_breakpoint "end of constructors"
58 # simple object, static const bool
59 gdb_test "print test1.test" "\\$\[0-9\]* = true" "simple object, static const bool"
61 # simple object, static const int
62 gdb_test "print test1.key1" "\\$\[0-9\]* = 5" "simple object, static const int"
64 # simple object, static long
65 gdb_test "print test1.key2" "\\$\[0-9\]* = 77" "simple object, static long"
67 # simple object, static enum
68 gdb_test "print test1.value" "\\$\[0-9\]* = oriental" "simple object, static enum"
70 if { [is_aarch32_target] } {
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"
76 [multi_line_string_to_regexp \
77 "type = class single_constructor {" \
80 " single_constructor(void);" \
81 " ~single_constructor(void);" \
82 "} *(single_constructor * const)"]
83 gdb_test "ptype test5.single_constructor" $re \
84 "simple object instance, ptype constructor"
85 gdb_test "ptype single_constructor::single_constructor" $re \
86 "simple object class, ptype constructor"
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 destructor"
91 gdb_test "ptype test1.~gnu_obj_1" \
92 {type = void \*\(gnu_obj_1 \* const(, int)?\)} \
93 "simple object instance, ptype destructor"
95 gdb_test "print test1.'~gnu_obj_1
'" \
96 { = {void \*\(gnu_obj_1 \*( const)?(, int)?\)} 0x[0-9a-f]+ <gnu_obj_1::~gnu_obj_1\(\)>} \
97 "simple object instance, print quoted destructor"
99 gdb_test "ptype gnu_obj_1::'~gnu_obj_1
'" \
100 {type = void \*\(gnu_obj_1 \* const\)} \
101 "simple object class, ptype quoted destructor"
103 gdb_test "print test5.single_constructor" \
104 { = {void \(single_constructor \* const\)} 0x[0-9a-f]+ <single_constructor::single_constructor\(\)>} \
105 "simple object instance, print constructor"
106 gdb_test "ptype test5.single_constructor" \
107 {type = void \(single_constructor \* const\)} \
108 "simple object instance, ptype constructor"
109 gdb_test "ptype single_constructor::single_constructor" \
110 {type = void \(single_constructor \* const\)} \
111 "simple object class, ptype constructor"
113 gdb_test "print test1.~gnu_obj_1"\
114 { = {void \(gnu_obj_1 \* const(?:, int)?\)} 0x[0-9a-f]+ <gnu_obj_1::~gnu_obj_1\(\)>}\
115 "simple object instance, print destructor"
117 gdb_test "ptype test1.~gnu_obj_1"\
118 {type = void \(gnu_obj_1 \* const(?:, int)?\)}\
119 "simple object instance, ptype destructor"
121 gdb_test "print test1.'~gnu_obj_1
'" \
122 { = {void \(gnu_obj_1 \*( const)?(?:, int)?\)} 0x[0-9a-f]+ <gnu_obj_1::~gnu_obj_1\(\)>} \
123 "simple object instance, print quoted destructor"
125 gdb_test "ptype gnu_obj_1::'~gnu_obj_1
'" \
126 {type = void \(gnu_obj_1 \* const\)} \
127 "simple object class, ptype quoted destructor"
132 # derived template object, base static const bool
133 gdb_test "print test2.test" "\\$\[0-9\]* = true" "derived template object, base static const bool"
135 # derived template object, base static const int
136 gdb_test "print test2.key1" "\\$\[0-9\]* = 5" "derived template object, base static const int"
138 # derived template object, base static long
139 gdb_test "print test2.key2" "\\$\[0-9\]* = 77" "derived template object, base static long"
141 # derived template object, base static enum
142 gdb_test "print test2.value" "\\$\[0-9\].* = oriental" "derived template object, base static enum"
144 # derived template object, static enum
145 gdb_test "print test2.value_derived" "\\$\[0-9\].* = etruscan" "derived template object, static enum"
149 # template object, static derived template data member's base static const
bool
150 gdb_test
"print test3.data.test" "\\$\[0-9\].* = true" "template object, static const bool"
152 # template object
, static derived template data member
's base static const int
153 gdb_test "print test3.data.key1" "\\$\[0-9\].* = 5" "template object, static const int"
155 # template object, static derived template data member's base static long
156 gdb_test
"print test3.data.key2" "\\$\[0-9\].* = 77" "template object, static long"
158 # template object
, static derived template data member
's base static enum
159 gdb_test "print test3.data.value" "\\$\[0-9\].* = oriental" "template object, static enum"
161 # template object, static derived template data member's static enum
162 gdb_test
"print test3.data.value_derived" "\\$\[0-9\].* = etruscan" "template object, static derived enum"
167 # static const
int initialized in another file.
168 gdb_test
"print test4.elsewhere" "\\$\[0-9\].* = 221" "static const int initialized elsewhere"
170 # static const
int that nobody initializes. From PR gdb
/635.
171 if {[test_compiler_info
{gcc
-[0-3]-*}]
172 ||
[test_compiler_info
{gcc
-4-[0-4]-*}]} {
173 # There was an extra CU
-level DW_TAG_variable as DW_AT_declaration
174 # with DW_AT_name
= nowhere
175 # and DW_AT_MIPS_linkage_name
= _ZN9gnu_obj_47nowhereE .
178 gdb_test
"print test4.nowhere" "<optimized out>" "static const int initialized nowhere, print field"
179 gdb_test
"ptype test4.nowhere" "type = const int"
180 gdb_test
"print test4.nowhere.nowhere" "Attempt to extract a component of a value that is not a structure."
182 # Same
, but print the whole struct.
183 gdb_test
"print test4" "static nowhere = <optimized out>.*" "static const int initialized nowhere, whole struct"
185 # static const initialized in the class definition
, PR gdb
/11702.
186 if { $non_dwarf
} { setup_xfail
*-*-* }
187 gdb_test
"print test4.everywhere" "\\$\[0-9\].* = 317" "static const int initialized in class definition"
188 if { $non_dwarf
} { setup_xfail
*-*-* }
189 gdb_test
"print test4.somewhere" "\\$\[0-9\].* = 3.14\[0-9\]*" "static const float initialized in class definition"
191 # Also make sure static const members can be found via
"info var".
192 if { $non_dwarf
} { setup_xfail
*-*-* }
193 gdb_test
"info variable everywhere" \
195 {All variables matching regular expression
"everywhere":} \
197 "File (.*/)?m-static\[.\]h:" \
198 "$decimal:\tconst int gnu_obj_4::everywhere;"]
200 # Perhaps at some point test4 should also
include a test
for a static
201 # const
int that was initialized in the header file. But I
'm not sure
202 # that GDB's current behavior in such situations is either consistent
203 # across platforms or optimal
, so I
'm not including one now.
205 # Step into test1.method and examine the method-scoped static.
206 # This is a regression test for PR 9708.
207 gdb_test "step" "gnu_obj_1::method.*"
208 gdb_test "print svar" " = true"