OSDN Git Service

gdb/testsuite/
[pf3gnuchains/pf3gnuchains4x.git] / gdb / testsuite / gdb.cp / m-static.exp
1 # Copyright 2002, 2004, 2007, 2008, 2009, 2010, 2011
2 # Free Software Foundation, Inc.
3
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
17 # Tests for member static data
18 # 2002-05-13  Benjamin Kosnik  <bkoz@redhat.com>
19 # 2002-08-22  David Carlton <carlton@math.stanford.edu>
20
21 # This file is part of the gdb testsuite
22
23 if $tracelevel then {
24         strace $tracelevel
25         }
26
27 if { [skip_cplus_tests] } { continue }
28
29 #
30 # test running programs
31 #
32
33 set testfile "m-static"
34 set srcfile  "${testfile}.cc"
35 set srcfile1 "${testfile}1.cc"
36 set objfile  "${testfile}.o"
37 set objfile1 "${testfile}1.o"
38 set binfile  "${objdir}/${subdir}/${testfile}"
39
40 if  { [gdb_compile "$srcdir/$subdir/$srcfile" "$objdir/$subdir/$objfile" object {debug c++}] != "" } {
41      untested m-static.exp
42      return -1
43 }
44
45 if  { [gdb_compile "$srcdir/$subdir/$srcfile1" "$objdir/$subdir/$objfile1" object {debug c++}] != "" } {
46      untested m-static.exp
47      return -1
48 }
49
50 if { [gdb_compile "$objdir/$subdir/$objfile $objdir/$subdir/$objfile1" "${binfile}" executable {debug c++}] != "" } {
51      untested m-static.exp
52      return -1
53 }
54
55 if [get_compiler_info $binfile] {
56     return -1
57 }
58
59 gdb_exit
60 gdb_start
61 gdb_reinitialize_dir $srcdir/$subdir
62 gdb_load ${binfile}
63
64 if ![runto_main] then {
65     perror "couldn't run to breakpoint"
66     continue
67 }
68
69 get_debug_format
70 set non_dwarf [expr ! [test_debug_format "DWARF 2"]]
71
72 # First, run to after we've constructed all the objects:
73
74 gdb_breakpoint [gdb_get_line_number "constructs-done"]
75 gdb_continue_to_breakpoint "end of constructors"
76
77
78 # One.
79
80 # simple object, static const bool
81 gdb_test "print test1.test" "\\$\[0-9\]* = true" "simple object, static const bool"
82
83 # simple object, static const int
84 gdb_test "print test1.key1" "\\$\[0-9\]* = 5" "simple object, static const int"
85
86 # simple object, static long
87 gdb_test "print test1.key2" "\\$\[0-9\]* = 77" "simple object, static long"
88
89 # simple object, static enum
90 gdb_test "print test1.value" "\\$\[0-9\]* = oriental" "simple object, static enum"
91
92 # Two.
93
94 # derived template object, base static const bool
95 gdb_test "print test2.test" "\\$\[0-9\]* = true" "derived template object, base static const bool"
96
97 # derived template object, base static const int
98 gdb_test "print test2.key1" "\\$\[0-9\]* = 5" "derived template object, base static const int"
99
100 # derived template object, base static long
101 gdb_test "print test2.key2" "\\$\[0-9\]* = 77" "derived template object, base static long"
102
103 # derived template object, base static enum
104 gdb_test "print test2.value" "\\$\[0-9\].* = oriental" "derived template object, base static enum"
105
106 # derived template object, static enum
107 gdb_test "print test2.value_derived" "\\$\[0-9\].* = etruscan" "derived template object, static enum"
108
109 # Three.
110
111 # template object, static derived template data member's base static const bool
112 gdb_test "print test3.data.test" "\\$\[0-9\].* = true" "template object, static const bool"
113
114 # template object, static derived template data member's base static const int
115 gdb_test "print test3.data.key1" "\\$\[0-9\].* = 5" "template object, static const int"
116
117 # template object, static derived template data member's base static long
118 gdb_test "print test3.data.key2" "\\$\[0-9\].* = 77" "template object, static long"
119
120 # template object, static derived template data member's base static enum
121 gdb_test "print test3.data.value" "\\$\[0-9\].* = oriental" "template object, static enum"
122
123 #  template object, static derived template data member's static enum
124 gdb_test "print test3.data.value_derived" "\\$\[0-9\].* = etruscan" "template object, static derived enum"
125
126 # 2002-08-16
127 # Four.
128
129 # static const int initialized in another file.
130 gdb_test "print test4.elsewhere" "\\$\[0-9\].* = 221" "static const int initialized elsewhere"
131
132 # static const int that nobody initializes.  From PR gdb/635.
133 if {[test_compiler_info {gcc-[0-3]-*}]
134     || [test_compiler_info {gcc-4-[0-4]-*}]} {
135     # There was an extra CU-level DW_TAG_variable as DW_AT_declaration
136     # with DW_AT_name = nowhere
137     # and DW_AT_MIPS_linkage_name = _ZN9gnu_obj_47nowhereE .
138     setup_xfail *-*-*
139 }
140 gdb_test "print test4.nowhere" "field nowhere is nonexistent or has been optimized out" "static const int initialized nowhere"
141
142 # static const initialized in the class definition, PR gdb/11702.
143 if { $non_dwarf } { setup_xfail *-*-* }
144 gdb_test "print test4.everywhere" "\\$\[0-9\].* = 317" "static const int initialized in class definition"
145 if { $non_dwarf } { setup_xfail *-*-* }
146 gdb_test "print test4.somewhere" "\\$\[0-9\].* = 3.14\[0-9\]*" "static const float initialized in class definition"
147
148 # Also make sure static const members can be found via "info var".
149 if { $non_dwarf } { setup_xfail *-*-* }
150 gdb_test "info variable everywhere" "File .*/m-static\[.\]h.*const int gnu_obj_4::everywhere;" "info variable everywhere"
151
152 # Perhaps at some point test4 should also include a test for a static
153 # const int that was initialized in the header file.  But I'm not sure
154 # that GDB's current behavior in such situations is either consistent
155 # across platforms or optimal, so I'm not including one now.
156
157 # Step into test1.method and examine the method-scoped static.
158 # This is a regression test for PR 9708.
159 gdb_test "step" "gnu_obj_1::method.*"
160 gdb_test "print svar" " = true"
161
162 gdb_exit
163 return 0