Commit | Line | Data |
---|---|---|
c906108c SS |
1 | # Copyright (C) 1998 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 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 | ||
45 | set testfile "method" | |
46 | set srcfile ${testfile}.cc | |
47 | set binfile ${objdir}/${subdir}/${testfile} | |
48 | ||
49 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } { | |
50 | gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail." | |
51 | } | |
52 | ||
53 | ||
54 | ||
55 | gdb_exit | |
56 | gdb_start | |
57 | gdb_reinitialize_dir $srcdir/$subdir | |
58 | gdb_load ${binfile} | |
59 | ||
60 | ||
61 | # | |
62 | # set it up at a breakpoint so we can play with the variable values | |
63 | # | |
64 | if ![runto_main] then { | |
65 | perror "couldn't run to breakpoint" | |
66 | continue | |
67 | } | |
68 | ||
69 | send_gdb "break A::foo\n" | |
70 | gdb_expect { | |
71 | -re "Breakpoint \[0-9\]* at $hex.*file .*method.cc, line 38*\\.\r\n$gdb_prompt $" { | |
72 | pass "set breakpoint on A::foo" | |
73 | } | |
74 | -re ".*$gdb_prompt $" { fail "set breakpoint on A::foo" } | |
75 | timeout { fail "(timeout) set breakpoint on A::foo" } | |
76 | } | |
77 | ||
78 | send_gdb "continue\n" | |
79 | gdb_expect { | |
80 | -re "Continuing\\.\r\n\r\nBreakpoint \[0-9\]*, A::foo \\(this=$hex, arg=13\\) at .*method\\.cc:38\r\n38\[\t \]*x \\+= arg;\r\n$gdb_prompt $" { | |
81 | pass "continued and got breakpoint in A::foo" | |
82 | } | |
83 | -re ".*$gdb_prompt $" { fail "continuing and breaking in A::foo" } | |
84 | timeout { fail "(timeout) continue" } | |
85 | } | |
86 | ||
87 | # Check ability to access this-relative stuff. | |
88 | ||
89 | send_gdb "print x\n" | |
90 | gdb_expect { | |
91 | -re "\\$\[0-9\]* = 20\r\n$gdb_prompt $" { | |
92 | pass "access this-relative x (in foo)" | |
93 | } | |
94 | -re ".*$gdb_prompt $" { fail "print x (in foo)" } | |
95 | timeout { fail "(timeout) print x (in foo)" } | |
96 | } | |
97 | ||
98 | # Check access to this pointer | |
99 | ||
100 | send_gdb "print this\n" | |
101 | gdb_expect { | |
102 | -re "\\$\[0-9\]* = \\(A \\*\\) $hex\r\n$gdb_prompt $" { | |
103 | pass "print this (in foo)" | |
104 | } | |
105 | -re ".*$gdb_prompt $" { fail "print this (in foo)" } | |
106 | timeout { fail "(timeout) print this (in foo)" } | |
107 | } | |
108 | ||
109 | # Now do everything over again for A::bar, because sometimes processing one method | |
110 | # (the first one) is fine, but the second one's debug info gets munged beyond recognition. | |
111 | ||
112 | send_gdb "break A::bar\n" | |
113 | gdb_expect { | |
114 | -re "Breakpoint \[0-9\]* at $hex.*file .*method.cc, line 44\\.\r\n$gdb_prompt $" { | |
115 | pass "set breakpoint on A::bar" | |
116 | } | |
117 | -re ".*$gdb_prompt $" { fail "set breakpoint on A::bar" } | |
118 | timeout { fail "(timeout) set breakpoint on A::bar" } | |
119 | } | |
120 | ||
121 | send_gdb "continue\n" | |
122 | gdb_expect { | |
123 | -re "Continuing\\.\r\n\r\nBreakpoint \[0-9\]*, A::bar \\(this=$hex, arg=15\\) at .*method\\.cc:44\r\n44\[\t \]*return arg \\+ 2 \\* x;\r\n$gdb_prompt $" { | |
124 | pass "continued and got breakpoint in A::bar" | |
125 | } | |
126 | -re ".*$gdb_prompt $" { fail "continuing and breaking in A::bar" } | |
127 | timeout { fail "(timeout) continue" } | |
128 | } | |
129 | ||
130 | # Check ability to access this-relative stuff. | |
131 | ||
132 | send_gdb "print x\n" | |
133 | gdb_expect { | |
134 | -re "\\$\[0-9\]* = 33\r\n$gdb_prompt $" { | |
135 | pass "access this-relative x (in bar)" | |
136 | } | |
137 | -re ".*$gdb_prompt $" { fail "print x (in bar)" } | |
138 | timeout { fail "(timeout) print x (in bar)" } | |
139 | } | |
140 | ||
141 | # Check access to this pointer | |
142 | ||
143 | send_gdb "print this\n" | |
144 | gdb_expect { | |
145 | -re "\\$\[0-9\]* = \\(const class A \\*\\) $hex\r\n$gdb_prompt $" { | |
146 | pass "print this (in bar)" | |
147 | } | |
148 | -re ".*$gdb_prompt $" { fail "print this (in bar)" } | |
149 | timeout { fail "(timeout) print this (in bar)" } | |
150 | } | |
151 | ||
152 | # Check again with funk::getFunky (this is the original test case | |
153 | # for CHFts23426); sometimes having a constructor with no arguments | |
154 | # will nuke the debug info read in for other methods in the class. | |
155 | ||
156 | send_gdb "break funk::getFunky\n" | |
157 | gdb_expect { | |
158 | -re "Breakpoint \[0-9\]* at $hex.*file .*method.cc, line 20\\.\r\n$gdb_prompt $" { | |
159 | pass "set breakpoint on funk::getFunky" | |
160 | } | |
161 | -re ".*$gdb_prompt $" { fail "set breakpoint on funk::getfunky" } | |
162 | timeout { fail "(timeout) set breakpoint on funk::getfunky" } | |
163 | } | |
164 | ||
165 | send_gdb "continue\n" | |
166 | gdb_expect { | |
167 | -re "Continuing\\.\r\n\r\nBreakpoint \[0-9\]*, funk::getFunky \\(this=$hex, a=1, b=2\\) at .*method\\.cc:20\r\n20\[\t \]*res = a \\+ b - data_;\r\n$gdb_prompt $" { | |
168 | pass "continued and got breakpoint in funk::getfunky" | |
169 | } | |
170 | -re ".*$gdb_prompt $" { fail "continuing and breaking in funk::getfunky" } | |
171 | timeout { fail "(timeout) continue" } | |
172 | } | |
173 | ||
174 | # Check ability to access this-relative stuff. | |
175 | ||
176 | send_gdb "print data_\n" | |
177 | gdb_expect { | |
178 | -re "\\$\[0-9\]* = 33\r\n$gdb_prompt $" { | |
179 | pass "access this-relative data_ in getFunky" | |
180 | } | |
181 | -re ".*$gdb_prompt $" { fail "print data_ in getFunky" } | |
182 | timeout { fail "(timeout) print data_ in getFunky" } | |
183 | } | |
184 | ||
185 | # Check access to this pointer | |
186 | ||
187 | send_gdb "print this\n" | |
188 | gdb_expect { | |
189 | -re "\\$\[0-9\]* = \\(funk \\*\\) $hex\r\n$gdb_prompt $" { | |
190 | pass "print this in getFunky" | |
191 | } | |
192 | -re ".*$gdb_prompt $" { fail "print this in getfunky" } | |
193 | timeout { fail "(timeout) print this in getfunky" } | |
194 | } | |
195 | ||
196 | # Check access to local variable | |
197 | ||
198 | send_gdb "print res\n" | |
199 | gdb_expect { | |
7a292a7a | 200 | -re "\\$\[0-9\]* = .\[0-9\]*\r\n$gdb_prompt $" { |
c906108c SS |
201 | pass "print res in getFunky" |
202 | } | |
203 | -re ".*$gdb_prompt $" { fail "print res in getfunky" } | |
204 | timeout { fail "(timeout) print res in getfunky" } | |
205 | } | |
206 | ||
207 | ||
208 | # Check ptype of class -- should show const/volatile methods | |
209 | ||
210 | send_gdb "ptype A\n" | |
211 | gdb_expect { | |
212 | -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;\r\n\}\r\n$gdb_prompt $" { | |
213 | pass "ptype A" | |
214 | } | |
215 | -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 $" { | |
216 | pass "ptype A (HP aCC bug -- volatile not indicated)" | |
217 | } | |
218 | -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 $" { | |
219 | pass "ptype A" | |
220 | } | |
221 | -re ".*$gdb_prompt $" { fail "ptype A" } | |
222 | timeout { fail "(timeout) ptype A" } | |
223 | } | |
224 | ||
225 | send_gdb "cont\n" | |
226 | gdb_expect { | |
227 | -re "Continuing.\r\n\r\nProgram exited normally.\r\n$gdb_prompt $" { | |
228 | pass "finish program" | |
229 | } | |
230 | -re "$gdb_prompt $" { fail "finish program" } | |
231 | timeout { fail "(timeout) finish program" } | |
232 | } | |
233 |