Commit | Line | Data |
---|---|---|
b6ba6518 | 1 | # Copyright 1998, 1999 Free Software Foundation, Inc. |
c906108c SS |
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 2 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, write to the Free Software | |
15 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
16 | ||
17 | # Please email any bugs, comments, and/or additions to this file to: | |
18 | # bug-gdb@prep.ai.mit.edu | |
19 | ||
20 | # tests for misc. C++ method stuff | |
21 | # Written by Satish Pai <pai@apollo.hp.com> 1997-07-08 | |
22 | ||
23 | # This file is part of the gdb testsuite | |
24 | ||
25 | # This tests: | |
26 | # 0. method arguments are correct | |
27 | # 1. access to class data members inside method scopes | |
28 | # 2. correct param types for methods in ptype. | |
29 | # 3. const and volatile methods | |
30 | ||
31 | # (#0 and #1 above relate to an HP specific problem -- GDB must correctly | |
32 | # integrate FPARAM symbols in HP debug info into the local var list | |
33 | # for the function or method's block.) | |
34 | ||
35 | if $tracelevel then { | |
36 | strace $tracelevel | |
37 | } | |
38 | ||
39 | # | |
40 | # test running programs | |
41 | # | |
42 | set prms_id 0 | |
43 | set bug_id 0 | |
44 | ||
d4f3574e SS |
45 | if { [skip_cplus_tests] } { continue } |
46 | ||
c906108c SS |
47 | set testfile "method" |
48 | set srcfile ${testfile}.cc | |
49 | set binfile ${objdir}/${subdir}/${testfile} | |
50 | ||
51 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } { | |
52 | gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail." | |
53 | } | |
54 | ||
a0b3c4fd JM |
55 | if [get_compiler_info $binfile "c++"] { |
56 | return -1 | |
57 | } | |
c906108c SS |
58 | |
59 | gdb_exit | |
60 | gdb_start | |
61 | gdb_reinitialize_dir $srcdir/$subdir | |
62 | gdb_load ${binfile} | |
63 | ||
64 | ||
65 | # | |
66 | # set it up at a breakpoint so we can play with the variable values | |
67 | # | |
68 | if ![runto_main] then { | |
69 | perror "couldn't run to breakpoint" | |
70 | continue | |
71 | } | |
72 | ||
73 | send_gdb "break A::foo\n" | |
74 | gdb_expect { | |
75 | -re "Breakpoint \[0-9\]* at $hex.*file .*method.cc, line 38*\\.\r\n$gdb_prompt $" { | |
76 | pass "set breakpoint on A::foo" | |
77 | } | |
78 | -re ".*$gdb_prompt $" { fail "set breakpoint on A::foo" } | |
79 | timeout { fail "(timeout) set breakpoint on A::foo" } | |
80 | } | |
81 | ||
82 | send_gdb "continue\n" | |
83 | gdb_expect { | |
5178b9d6 | 84 | -re "Continuing\\.\r\n\r\nBreakpoint \[0-9\]*, A::foo(\\(int\\)|) \\(this=$hex, arg=13\\) at .*method\\.cc:38\r\n38\[\t \]*x \\+= arg;\r\n$gdb_prompt $" { |
c906108c SS |
85 | pass "continued and got breakpoint in A::foo" |
86 | } | |
87 | -re ".*$gdb_prompt $" { fail "continuing and breaking in A::foo" } | |
88 | timeout { fail "(timeout) continue" } | |
89 | } | |
90 | ||
91 | # Check ability to access this-relative stuff. | |
92 | ||
93 | send_gdb "print x\n" | |
94 | gdb_expect { | |
95 | -re "\\$\[0-9\]* = 20\r\n$gdb_prompt $" { | |
96 | pass "access this-relative x (in foo)" | |
97 | } | |
98 | -re ".*$gdb_prompt $" { fail "print x (in foo)" } | |
99 | timeout { fail "(timeout) print x (in foo)" } | |
100 | } | |
101 | ||
102 | # Check access to this pointer | |
103 | ||
104 | send_gdb "print this\n" | |
105 | gdb_expect { | |
106 | -re "\\$\[0-9\]* = \\(A \\*\\) $hex\r\n$gdb_prompt $" { | |
107 | pass "print this (in foo)" | |
108 | } | |
109 | -re ".*$gdb_prompt $" { fail "print this (in foo)" } | |
110 | timeout { fail "(timeout) print this (in foo)" } | |
111 | } | |
112 | ||
113 | # Now do everything over again for A::bar, because sometimes processing one method | |
114 | # (the first one) is fine, but the second one's debug info gets munged beyond recognition. | |
115 | ||
116 | send_gdb "break A::bar\n" | |
117 | gdb_expect { | |
118 | -re "Breakpoint \[0-9\]* at $hex.*file .*method.cc, line 44\\.\r\n$gdb_prompt $" { | |
119 | pass "set breakpoint on A::bar" | |
120 | } | |
121 | -re ".*$gdb_prompt $" { fail "set breakpoint on A::bar" } | |
122 | timeout { fail "(timeout) set breakpoint on A::bar" } | |
123 | } | |
124 | ||
125 | send_gdb "continue\n" | |
126 | gdb_expect { | |
5178b9d6 | 127 | -re "Continuing\\.\r\n\r\nBreakpoint \[0-9\]*, A::bar(\\(int\\) const|) \\(this=$hex, arg=15\\) at .*method\\.cc:44\r\n44\[\t \]*return arg \\+ 2 \\* x;\r\n$gdb_prompt $" { |
c906108c SS |
128 | pass "continued and got breakpoint in A::bar" |
129 | } | |
130 | -re ".*$gdb_prompt $" { fail "continuing and breaking in A::bar" } | |
131 | timeout { fail "(timeout) continue" } | |
132 | } | |
133 | ||
134 | # Check ability to access this-relative stuff. | |
135 | ||
136 | send_gdb "print x\n" | |
137 | gdb_expect { | |
138 | -re "\\$\[0-9\]* = 33\r\n$gdb_prompt $" { | |
139 | pass "access this-relative x (in bar)" | |
140 | } | |
141 | -re ".*$gdb_prompt $" { fail "print x (in bar)" } | |
142 | timeout { fail "(timeout) print x (in bar)" } | |
143 | } | |
144 | ||
145 | # Check access to this pointer | |
146 | ||
147 | send_gdb "print this\n" | |
148 | gdb_expect { | |
149 | -re "\\$\[0-9\]* = \\(const class A \\*\\) $hex\r\n$gdb_prompt $" { | |
a0b3c4fd JM |
150 | global gcc_compiled |
151 | if {$gcc_compiled} { | |
152 | xfail "print this (in bar)" | |
153 | } else { | |
154 | pass "print this (in bar)" | |
155 | } | |
156 | } | |
157 | -re "\\$\[0-9\]* = \\(A \\*\\) $hex\r\n$gdb_prompt $" { | |
158 | global gcc_compiled | |
159 | if {$gcc_compiled} { | |
c906108c | 160 | pass "print this (in bar)" |
a0b3c4fd JM |
161 | } else { |
162 | xfail "print this (in bar)" | |
163 | } | |
c906108c SS |
164 | } |
165 | -re ".*$gdb_prompt $" { fail "print this (in bar)" } | |
166 | timeout { fail "(timeout) print this (in bar)" } | |
167 | } | |
168 | ||
169 | # Check again with funk::getFunky (this is the original test case | |
170 | # for CHFts23426); sometimes having a constructor with no arguments | |
171 | # will nuke the debug info read in for other methods in the class. | |
172 | ||
173 | send_gdb "break funk::getFunky\n" | |
174 | gdb_expect { | |
175 | -re "Breakpoint \[0-9\]* at $hex.*file .*method.cc, line 20\\.\r\n$gdb_prompt $" { | |
176 | pass "set breakpoint on funk::getFunky" | |
177 | } | |
178 | -re ".*$gdb_prompt $" { fail "set breakpoint on funk::getfunky" } | |
179 | timeout { fail "(timeout) set breakpoint on funk::getfunky" } | |
180 | } | |
181 | ||
182 | send_gdb "continue\n" | |
183 | gdb_expect { | |
5178b9d6 | 184 | -re "Continuing\\.\r\n\r\nBreakpoint \[0-9\]*, funk::getFunky(\\(int, int\\)|) \\(this=$hex, a=1, b=2\\) at .*method\\.cc:20\r\n20\[\t \]*res = a \\+ b - data_;\r\n$gdb_prompt $" { |
c906108c SS |
185 | pass "continued and got breakpoint in funk::getfunky" |
186 | } | |
187 | -re ".*$gdb_prompt $" { fail "continuing and breaking in funk::getfunky" } | |
188 | timeout { fail "(timeout) continue" } | |
189 | } | |
190 | ||
191 | # Check ability to access this-relative stuff. | |
192 | ||
193 | send_gdb "print data_\n" | |
194 | gdb_expect { | |
195 | -re "\\$\[0-9\]* = 33\r\n$gdb_prompt $" { | |
196 | pass "access this-relative data_ in getFunky" | |
197 | } | |
198 | -re ".*$gdb_prompt $" { fail "print data_ in getFunky" } | |
199 | timeout { fail "(timeout) print data_ in getFunky" } | |
200 | } | |
201 | ||
202 | # Check access to this pointer | |
203 | ||
204 | send_gdb "print this\n" | |
205 | gdb_expect { | |
206 | -re "\\$\[0-9\]* = \\(funk \\*\\) $hex\r\n$gdb_prompt $" { | |
207 | pass "print this in getFunky" | |
208 | } | |
209 | -re ".*$gdb_prompt $" { fail "print this in getfunky" } | |
210 | timeout { fail "(timeout) print this in getfunky" } | |
211 | } | |
212 | ||
213 | # Check access to local variable | |
214 | ||
215 | send_gdb "print res\n" | |
216 | gdb_expect { | |
7a292a7a | 217 | -re "\\$\[0-9\]* = .\[0-9\]*\r\n$gdb_prompt $" { |
c906108c SS |
218 | pass "print res in getFunky" |
219 | } | |
220 | -re ".*$gdb_prompt $" { fail "print res in getfunky" } | |
221 | timeout { fail "(timeout) print res in getfunky" } | |
222 | } | |
223 | ||
224 | ||
225 | # Check ptype of class -- should show const/volatile methods | |
226 | ||
227 | send_gdb "ptype A\n" | |
228 | gdb_expect { | |
3e36a0f4 DJ |
229 | -re "type = class A \{\r\n\[ \]*public:\r\n\[ \]*int x;\r\n\[ \]*int y;\r\n\r\n\[ \]*int foo\\(int\\);\r\n\[ \]*int bar\\(int\\) const;\r\n\[ \]*int baz\\(int, char\\) volatile;\r\n\[ \]*int qux\\(int, float\\) (const volatile|volatile const);\r\n\}\r\n$gdb_prompt $" { |
230 | pass "ptype A" | |
231 | } | |
5178b9d6 | 232 | -re "type = class A \{\r\n\[ \]*public:\r\n\[ \]*int x;\r\n\[ \]*int y;\r\n\r\n\[ \]*A & operator=\\(A const ?&\\);\r\n\[ \]*A\\(A const ?&\\);\r\n\[ \]*A\\((void|)\\);\r\n\[ \]*int foo\\(int\\);\r\n\[ \]*int bar\\(int\\) const;\r\n\[ \]*int baz\\(int, char\\) volatile;\r\n\[ \]*int qux\\(int, float\\) (const volatile|volatile const);\r\n\}\r\n$gdb_prompt $" { |
c906108c SS |
233 | pass "ptype A" |
234 | } | |
235 | -re "type = class A \{\r\n\[ \]*public:\r\n\[ \]*int x;\r\n\[ \]*int y;\r\n\r\n\[ \]*int foo\\(int\\);\r\n\[ \]*int bar\\(int\\) const;\r\n\[ \]*int baz\\(int, char\\);\r\n\[ \]*int qux\\(int, float\\) const;\r\n\}\r\n$gdb_prompt $" { | |
236 | pass "ptype A (HP aCC bug -- volatile not indicated)" | |
237 | } | |
238 | -re "type = class A \{\r\n\[ \]*public:\r\n\[ \]*int x;\r\n\[ \]*int y;\r\n\r\n\[ \]*int foo\\(int\\);\r\n\[ \]*int bar\\(int\\) const;\r\n\[ \]*int baz\\(int, char\\) volatile;\r\n\[ \]*int qux\\(int, float\\) const volatile;\r\n\}\r\n$gdb_prompt $" { | |
239 | pass "ptype A" | |
240 | } | |
241 | -re ".*$gdb_prompt $" { fail "ptype A" } | |
242 | timeout { fail "(timeout) ptype A" } | |
243 | } | |
244 | ||
245 | send_gdb "cont\n" | |
246 | gdb_expect { | |
247 | -re "Continuing.\r\n\r\nProgram exited normally.\r\n$gdb_prompt $" { | |
248 | pass "finish program" | |
249 | } | |
250 | -re "$gdb_prompt $" { fail "finish program" } | |
251 | timeout { fail "(timeout) finish program" } | |
252 | } | |
253 |