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