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