]>
Commit | Line | Data |
---|---|---|
6aba47ca DJ |
1 | # Copyright 1998, 1999, 2001, 2002, 2003, 2004, 2007 |
2 | # Free Software Foundation, Inc. | |
c906108c SS |
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 2 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, write to the Free Software | |
16 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
17 | ||
c906108c SS |
18 | # tests for misc. C++ method stuff |
19 | # Written by Satish Pai <pai@apollo.hp.com> 1997-07-08 | |
20 | ||
21 | # This file is part of the gdb testsuite | |
22 | ||
23 | # This tests: | |
24 | # 0. method arguments are correct | |
25 | # 1. access to class data members inside method scopes | |
26 | # 2. correct param types for methods in ptype. | |
27 | # 3. const and volatile methods | |
28 | ||
29 | # (#0 and #1 above relate to an HP specific problem -- GDB must correctly | |
30 | # integrate FPARAM symbols in HP debug info into the local var list | |
31 | # for the function or method's block.) | |
32 | ||
33 | if $tracelevel then { | |
34 | strace $tracelevel | |
35 | } | |
36 | ||
37 | # | |
38 | # test running programs | |
39 | # | |
40 | set prms_id 0 | |
41 | set bug_id 0 | |
42 | ||
d4f3574e SS |
43 | if { [skip_cplus_tests] } { continue } |
44 | ||
c906108c SS |
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++}] != "" } { | |
b60f0898 JB |
50 | untested method.exp |
51 | return -1 | |
c906108c SS |
52 | } |
53 | ||
a0b3c4fd JM |
54 | if [get_compiler_info $binfile "c++"] { |
55 | return -1 | |
56 | } | |
c906108c SS |
57 | |
58 | gdb_exit | |
59 | gdb_start | |
60 | gdb_reinitialize_dir $srcdir/$subdir | |
61 | gdb_load ${binfile} | |
62 | ||
63 | ||
64 | # | |
65 | # set it up at a breakpoint so we can play with the variable values | |
66 | # | |
67 | if ![runto_main] then { | |
68 | perror "couldn't run to breakpoint" | |
69 | continue | |
70 | } | |
71 | ||
f18dabd2 MC |
72 | gdb_test "break A::foo" \ |
73 | "Breakpoint \[0-9\]* at $hex.*file .*method.cc, line 38\\." | |
c906108c | 74 | |
f18dabd2 MC |
75 | gdb_test "continue" \ |
76 | "Continuing\\.\r\n\r\nBreakpoint \[0-9\]*, A::foo(\\(int\\)|) \\(this=$hex, arg=13\\) at .*method\\.cc:38\r\n38\[\t \]*x \\+= arg;" \ | |
77 | "continue to A::foo" | |
c906108c SS |
78 | |
79 | # Check ability to access this-relative stuff. | |
80 | ||
f18dabd2 MC |
81 | gdb_test "print x" \ |
82 | "\\$\[0-9\]* = 20" \ | |
83 | "print x in A::foo" | |
c906108c SS |
84 | |
85 | # Check access to this pointer | |
86 | ||
f18dabd2 MC |
87 | gdb_test "print this" \ |
88 | "\\$\[0-9\]* = \\((class |)A *\\* *(const|)\\) $hex" \ | |
89 | "print this in A::foo" | |
c906108c SS |
90 | |
91 | # Now do everything over again for A::bar, because sometimes processing one method | |
92 | # (the first one) is fine, but the second one's debug info gets munged beyond recognition. | |
93 | ||
f18dabd2 MC |
94 | gdb_test "break A::bar" \ |
95 | "Breakpoint \[0-9\]* at $hex.*file .*method.cc, line 44\\." | |
c906108c | 96 | |
f18dabd2 | 97 | gdb_test "continue" \ |
c9f2c8a3 | 98 | "Continuing\\.\r\n\r\nBreakpoint \[0-9\]*, A::bar(|\\(int\\) const| const) \\(this=$hex, arg=15\\) at .*method\\.cc:44\r\n44\[\t \]*return arg \\+ 2 \\* x;" \ |
f18dabd2 | 99 | "continue to A::bar" |
c906108c SS |
100 | |
101 | # Check ability to access this-relative stuff. | |
102 | ||
f18dabd2 MC |
103 | gdb_test "print x" \ |
104 | "\\$\[0-9\]* = 33" \ | |
105 | "print x in A::bar" | |
c906108c SS |
106 | |
107 | # Check access to this pointer | |
108 | ||
3a63e3f9 MC |
109 | get_debug_format |
110 | ||
111 | send_gdb "print this\n" | |
112 | gdb_expect { | |
113 | -re "\\$\[0-9\]* = \\(const (class |)A *\\* *(const|)\\) $hex\r\n$gdb_prompt $" { | |
114 | pass "print this in A::bar" | |
115 | } | |
116 | -re "\\$\[0-9\]* = \\((class |)A *\\* *(const|)\\) $hex\r\n$gdb_prompt $" { | |
117 | # gcc versions up to 3.0.4 with -gstabs+ do not emit "const" indicators, | |
118 | # so the output is "A *". It should be "const A *" or "const A * const". | |
119 | setup_xfail_format "stabs" | |
120 | fail "print this in A::bar (missing const)" | |
121 | } | |
122 | -re "\\$\[0-9\]* = \\(const (class |)\{\\.\\.\\.\} *\\* *(const|)\\) $hex\r\n$gdb_prompt $" { | |
123 | # gcc versions gcc-3_1-branch%20020404 and HEAD%20020404 with -gstabs+ | |
124 | # produce good stabs, but gdb prints "const class {...} *" const. | |
125 | # This is PR gdb/277. | |
a805a116 MC |
126 | # setup_kfail "gdb/277" |
127 | fail "print this in A::bar (gdb/277)" | |
3a63e3f9 MC |
128 | } |
129 | -re ".*$gdb_prompt $" { fail "print this in A::bar" } | |
130 | timeout { fail "(timeout) print this in A::bar" } | |
131 | } | |
c906108c SS |
132 | |
133 | # Check again with funk::getFunky (this is the original test case | |
134 | # for CHFts23426); sometimes having a constructor with no arguments | |
135 | # will nuke the debug info read in for other methods in the class. | |
136 | ||
f18dabd2 MC |
137 | gdb_test "break 21" \ |
138 | "Breakpoint \[0-9\]* at $hex.*file .*method.cc, line 21\\." | |
c906108c | 139 | |
f18dabd2 MC |
140 | gdb_test "continue" \ |
141 | "Continuing\\.\r\n\r\nBreakpoint \[0-9\]*, funk::getFunky(\\(int, int\\)|) \\(this=$hex, a=1, b=2\\) at .*method\\.cc:21\r\n21\[\t \]*data_ = res;" \ | |
142 | "continue to 21" | |
c906108c SS |
143 | |
144 | # Check ability to access this-relative stuff. | |
145 | ||
f18dabd2 MC |
146 | gdb_test "print data_" \ |
147 | "\\$\[0-9\]* = 33" \ | |
148 | "print data_ in funk::getFunky" | |
c906108c SS |
149 | |
150 | # Check access to this pointer | |
151 | ||
f18dabd2 MC |
152 | gdb_test "print this" \ |
153 | "\\$\[0-9\]* = \\((class |)funk *\\* *(const|)\\) $hex" \ | |
154 | "print this in funk::getFunky" | |
c906108c SS |
155 | |
156 | # Check access to local variable | |
157 | ||
f18dabd2 MC |
158 | gdb_test "print res" \ |
159 | "\\$\[0-9\]* = -30" \ | |
160 | "print res in funk::getFunky" | |
c906108c SS |
161 | |
162 | # Check ptype of class -- should show const/volatile methods | |
163 | ||
164 | send_gdb "ptype A\n" | |
165 | gdb_expect { | |
3e36a0f4 DJ |
166 | -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 $" { |
167 | pass "ptype A" | |
168 | } | |
5178b9d6 | 169 | -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 |
170 | pass "ptype A" |
171 | } | |
44ffb27c MC |
172 | -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\[ \]*A & operator=\\(A const ?&\\);\r\n\[ \]*A\\(A const ?&\\);\r\n\[ \]*A\\((void|)\\);\r\n\}\r\n$gdb_prompt $" { |
173 | pass "ptype A" | |
174 | } | |
c906108c SS |
175 | -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 $" { |
176 | pass "ptype A (HP aCC bug -- volatile not indicated)" | |
177 | } | |
178 | -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 $" { | |
179 | pass "ptype A" | |
180 | } | |
181 | -re ".*$gdb_prompt $" { fail "ptype A" } | |
182 | timeout { fail "(timeout) ptype A" } | |
183 | } | |
184 | ||
f1c47eb2 MS |
185 | send_gdb "cont\n" |
186 | gdb_expect { | |
e71019a1 | 187 | -re "Continuing.\r\n\r\nProgram exited normally.*$gdb_prompt $" { |
f1c47eb2 MS |
188 | pass "finish program" |
189 | } | |
190 | -re "Continuing.* EXIT code 0.*Program exited normally.*$gdb_prompt $" { | |
191 | pass "finish program (exit wrapper)" | |
192 | } | |
193 | -re ".*$gdb_prompt $" { fail "finish program" } | |
194 | default:{ fail "finish program (timeout)" } | |
195 | } | |
196 |