OSDN Git Service

Copyright year update in most files of the GDB Project.
[pf3gnuchains/pf3gnuchains4x.git] / gdb / testsuite / gdb.cp / m-static.exp
1 # Copyright 2002, 2004, 2007-2012 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 $tracelevel then {
23         strace $tracelevel
24         }
25
26 if { [skip_cplus_tests] } { continue }
27
28 #
29 # test running programs
30 #
31
32 set testfile "m-static"
33 set srcfile  "${testfile}.cc"
34 set srcfile1 "${testfile}1.cc"
35 set objfile  "${testfile}.o"
36 set objfile1 "${testfile}1.o"
37 set binfile  "${objdir}/${subdir}/${testfile}"
38
39 if  { [gdb_compile "$srcdir/$subdir/$srcfile" "$objdir/$subdir/$objfile" object {debug c++}] != "" } {
40      untested m-static.exp
41      return -1
42 }
43
44 if  { [gdb_compile "$srcdir/$subdir/$srcfile1" "$objdir/$subdir/$objfile1" object {debug c++}] != "" } {
45      untested m-static.exp
46      return -1
47 }
48
49 if { [gdb_compile "$objdir/$subdir/$objfile $objdir/$subdir/$objfile1" "${binfile}" executable {debug c++}] != "" } {
50      untested m-static.exp
51      return -1
52 }
53
54 if [get_compiler_info $binfile] {
55     return -1
56 }
57
58 gdb_exit
59 gdb_start
60 gdb_reinitialize_dir $srcdir/$subdir
61 gdb_load ${binfile}
62
63 if ![runto_main] then {
64     perror "couldn't run to breakpoint"
65     continue
66 }
67
68 get_debug_format
69 set non_dwarf [expr ! [test_debug_format "DWARF 2"]]
70
71 # First, run to after we've constructed all the objects:
72
73 gdb_breakpoint [gdb_get_line_number "constructs-done"]
74 gdb_continue_to_breakpoint "end of constructors"
75
76
77 # One.
78
79 # simple object, static const bool
80 gdb_test "print test1.test" "\\$\[0-9\]* = true" "simple object, static const bool"
81
82 # simple object, static const int
83 gdb_test "print test1.key1" "\\$\[0-9\]* = 5" "simple object, static const int"
84
85 # simple object, static long
86 gdb_test "print test1.key2" "\\$\[0-9\]* = 77" "simple object, static long"
87
88 # simple object, static enum
89 gdb_test "print test1.value" "\\$\[0-9\]* = oriental" "simple object, static enum"
90
91 # Two.
92
93 # derived template object, base static const bool
94 gdb_test "print test2.test" "\\$\[0-9\]* = true" "derived template object, base static const bool"
95
96 # derived template object, base static const int
97 gdb_test "print test2.key1" "\\$\[0-9\]* = 5" "derived template object, base static const int"
98
99 # derived template object, base static long
100 gdb_test "print test2.key2" "\\$\[0-9\]* = 77" "derived template object, base static long"
101
102 # derived template object, base static enum
103 gdb_test "print test2.value" "\\$\[0-9\].* = oriental" "derived template object, base static enum"
104
105 # derived template object, static enum
106 gdb_test "print test2.value_derived" "\\$\[0-9\].* = etruscan" "derived template object, static enum"
107
108 # Three.
109
110 # template object, static derived template data member's base static const bool
111 gdb_test "print test3.data.test" "\\$\[0-9\].* = true" "template object, static const bool"
112
113 # template object, static derived template data member's base static const int
114 gdb_test "print test3.data.key1" "\\$\[0-9\].* = 5" "template object, static const int"
115
116 # template object, static derived template data member's base static long
117 gdb_test "print test3.data.key2" "\\$\[0-9\].* = 77" "template object, static long"
118
119 # template object, static derived template data member's base static enum
120 gdb_test "print test3.data.value" "\\$\[0-9\].* = oriental" "template object, static enum"
121
122 #  template object, static derived template data member's static enum
123 gdb_test "print test3.data.value_derived" "\\$\[0-9\].* = etruscan" "template object, static derived enum"
124
125 # 2002-08-16
126 # Four.
127
128 # static const int initialized in another file.
129 gdb_test "print test4.elsewhere" "\\$\[0-9\].* = 221" "static const int initialized elsewhere"
130
131 # static const int that nobody initializes.  From PR gdb/635.
132 if {[test_compiler_info {gcc-[0-3]-*}]
133     || [test_compiler_info {gcc-4-[0-4]-*}]} {
134     # There was an extra CU-level DW_TAG_variable as DW_AT_declaration
135     # with DW_AT_name = nowhere
136     # and DW_AT_MIPS_linkage_name = _ZN9gnu_obj_47nowhereE .
137     setup_xfail *-*-*
138 }
139 gdb_test "print test4.nowhere" "field nowhere is nonexistent or has been optimized out" "static const int initialized nowhere"
140
141 # static const initialized in the class definition, PR gdb/11702.
142 if { $non_dwarf } { setup_xfail *-*-* }
143 gdb_test "print test4.everywhere" "\\$\[0-9\].* = 317" "static const int initialized in class definition"
144 if { $non_dwarf } { setup_xfail *-*-* }
145 gdb_test "print test4.somewhere" "\\$\[0-9\].* = 3.14\[0-9\]*" "static const float initialized in class definition"
146
147 # Also make sure static const members can be found via "info var".
148 if { $non_dwarf } { setup_xfail *-*-* }
149 gdb_test "info variable everywhere" "File .*/m-static\[.\]h.*const int gnu_obj_4::everywhere;" "info variable everywhere"
150
151 # Perhaps at some point test4 should also include a test for a static
152 # const int that was initialized in the header file.  But I'm not sure
153 # that GDB's current behavior in such situations is either consistent
154 # across platforms or optimal, so I'm not including one now.
155
156 # Step into test1.method and examine the method-scoped static.
157 # This is a regression test for PR 9708.
158 gdb_test "step" "gnu_obj_1::method.*"
159 gdb_test "print svar" " = true"
160
161 gdb_exit
162 return 0