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