Commit | Line | Data |
---|---|---|
0b302171 JB |
1 | # Copyright 1998-1999, 2001-2004, 2007-2012 Free Software Foundation, |
2 | # 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 | |
e22f8b7c | 6 | # the Free Software Foundation; either version 3 of the License, or |
c906108c | 7 | # (at your option) any later version. |
e22f8b7c | 8 | # |
c906108c SS |
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. | |
e22f8b7c | 13 | # |
c906108c | 14 | # You should have received a copy of the GNU General Public License |
e22f8b7c | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
c906108c | 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 | ||
c906108c SS |
32 | # |
33 | # test running programs | |
34 | # | |
c906108c | 35 | |
d4f3574e SS |
36 | if { [skip_cplus_tests] } { continue } |
37 | ||
f5f3a911 | 38 | standard_testfile .cc |
c906108c | 39 | |
4c93b1db | 40 | if [get_compiler_info "c++"] { |
a0b3c4fd JM |
41 | return -1 |
42 | } | |
c906108c | 43 | |
f5f3a911 TT |
44 | if {[prepare_for_testing $testfile.exp $testfile $srcfile {debug c++}]} { |
45 | return -1 | |
46 | } | |
c906108c SS |
47 | |
48 | # | |
49 | # set it up at a breakpoint so we can play with the variable values | |
50 | # | |
51 | if ![runto_main] then { | |
52 | perror "couldn't run to breakpoint" | |
53 | continue | |
54 | } | |
55 | ||
f18dabd2 MC |
56 | gdb_test "break A::foo" \ |
57 | "Breakpoint \[0-9\]* at $hex.*file .*method.cc, line 38\\." | |
c906108c | 58 | |
f18dabd2 MC |
59 | gdb_test "continue" \ |
60 | "Continuing\\.\r\n\r\nBreakpoint \[0-9\]*, A::foo(\\(int\\)|) \\(this=$hex, arg=13\\) at .*method\\.cc:38\r\n38\[\t \]*x \\+= arg;" \ | |
61 | "continue to A::foo" | |
c906108c SS |
62 | |
63 | # Check ability to access this-relative stuff. | |
64 | ||
f18dabd2 MC |
65 | gdb_test "print x" \ |
66 | "\\$\[0-9\]* = 20" \ | |
67 | "print x in A::foo" | |
c906108c SS |
68 | |
69 | # Check access to this pointer | |
70 | ||
f18dabd2 MC |
71 | gdb_test "print this" \ |
72 | "\\$\[0-9\]* = \\((class |)A *\\* *(const|)\\) $hex" \ | |
73 | "print this in A::foo" | |
c906108c SS |
74 | |
75 | # Now do everything over again for A::bar, because sometimes processing one method | |
76 | # (the first one) is fine, but the second one's debug info gets munged beyond recognition. | |
77 | ||
f18dabd2 MC |
78 | gdb_test "break A::bar" \ |
79 | "Breakpoint \[0-9\]* at $hex.*file .*method.cc, line 44\\." | |
c906108c | 80 | |
f18dabd2 | 81 | gdb_test "continue" \ |
c9f2c8a3 | 82 | "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 | 83 | "continue to A::bar" |
c906108c SS |
84 | |
85 | # Check ability to access this-relative stuff. | |
86 | ||
f18dabd2 MC |
87 | gdb_test "print x" \ |
88 | "\\$\[0-9\]* = 33" \ | |
89 | "print x in A::bar" | |
c906108c SS |
90 | |
91 | # Check access to this pointer | |
92 | ||
3a63e3f9 MC |
93 | get_debug_format |
94 | ||
f8d3bf8f MS |
95 | gdb_test_multiple "print this" "print this in A::bar" { |
96 | -re "\\$\[0-9\]* = \\(const (class |)A *\\* *(const|)\\) $hex\r\n$gdb_prompt $" { | |
97 | pass "print this in A::bar" | |
98 | } | |
99 | -re "\\$\[0-9\]* = \\((class |)A *\\* *(const|)\\) $hex\r\n$gdb_prompt $" { | |
100 | # gcc versions up to 3.0.4 with -gstabs+ do not emit "const" | |
101 | # indicators, so the output is "A *". It should be "const A | |
102 | # *" or "const A * const". | |
103 | setup_xfail_format "stabs" | |
104 | fail "print this in A::bar (missing const)" | |
105 | } | |
106 | -re "\\$\[0-9\]* = \\(const (class |)\{\\.\\.\\.\} *\\* *(const|)\\) $hex\r\n$gdb_prompt $" { | |
107 | # gcc versions gcc-3_1-branch%20020404 and HEAD%20020404 with -gstabs+ | |
108 | # produce good stabs, but gdb prints "const class {...} *" const. | |
109 | # This is PR gdb/277. | |
110 | # setup_kfail "gdb/277" | |
111 | fail "print this in A::bar (gdb/277)" | |
112 | } | |
3a63e3f9 | 113 | } |
c906108c SS |
114 | |
115 | # Check again with funk::getFunky (this is the original test case | |
116 | # for CHFts23426); sometimes having a constructor with no arguments | |
117 | # will nuke the debug info read in for other methods in the class. | |
118 | ||
f18dabd2 MC |
119 | gdb_test "break 21" \ |
120 | "Breakpoint \[0-9\]* at $hex.*file .*method.cc, line 21\\." | |
c906108c | 121 | |
f18dabd2 MC |
122 | gdb_test "continue" \ |
123 | "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;" \ | |
124 | "continue to 21" | |
c906108c SS |
125 | |
126 | # Check ability to access this-relative stuff. | |
127 | ||
f18dabd2 MC |
128 | gdb_test "print data_" \ |
129 | "\\$\[0-9\]* = 33" \ | |
130 | "print data_ in funk::getFunky" | |
c906108c SS |
131 | |
132 | # Check access to this pointer | |
133 | ||
f18dabd2 MC |
134 | gdb_test "print this" \ |
135 | "\\$\[0-9\]* = \\((class |)funk *\\* *(const|)\\) $hex" \ | |
136 | "print this in funk::getFunky" | |
c906108c SS |
137 | |
138 | # Check access to local variable | |
139 | ||
f18dabd2 MC |
140 | gdb_test "print res" \ |
141 | "\\$\[0-9\]* = -30" \ | |
142 | "print res in funk::getFunky" | |
c906108c SS |
143 | |
144 | # Check ptype of class -- should show const/volatile methods | |
145 | ||
f8d3bf8f MS |
146 | gdb_test_multiple "ptype A" "ptype A" { |
147 | -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 $" { | |
148 | pass "ptype A" | |
149 | } | |
150 | -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 $" { | |
151 | pass "ptype A" | |
152 | } | |
153 | -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 $" { | |
154 | pass "ptype A" | |
155 | } | |
156 | -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 $" { | |
157 | pass "ptype A (HP aCC bug -- volatile not indicated)" | |
158 | } | |
159 | -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 $" { | |
160 | pass "ptype A" | |
161 | } | |
c906108c SS |
162 | } |
163 | ||
f8d3bf8f | 164 | gdb_test_multiple "cont" "finish program" { |
fda326dd | 165 | -re "Continuing.\r\n$inferior_exited_re normally.*$gdb_prompt $" { |
f1c47eb2 MS |
166 | pass "finish program" |
167 | } | |
fda326dd | 168 | -re "Continuing.* EXIT code 0.*$inferior_exited_re normally.*$gdb_prompt $" { |
f1c47eb2 MS |
169 | pass "finish program (exit wrapper)" |
170 | } | |
f1c47eb2 MS |
171 | } |
172 |