* target.h (struct target_ops) <to_has_execution>: Add ptid_t
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.cp / method.exp
CommitLineData
7b6bb8da 1# Copyright 1998, 1999, 2001, 2002, 2003, 2004, 2007, 2008, 2009, 2010, 2011
6aba47ca 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
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
32if $tracelevel then {
33 strace $tracelevel
34 }
35
36#
37# test running programs
38#
c906108c 39
d4f3574e
SS
40if { [skip_cplus_tests] } { continue }
41
c906108c
SS
42set testfile "method"
43set srcfile ${testfile}.cc
44set binfile ${objdir}/${subdir}/${testfile}
45
46if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
b60f0898
JB
47 untested method.exp
48 return -1
c906108c
SS
49}
50
a0b3c4fd
JM
51if [get_compiler_info $binfile "c++"] {
52 return -1
53}
c906108c
SS
54
55gdb_exit
56gdb_start
57gdb_reinitialize_dir $srcdir/$subdir
58gdb_load ${binfile}
59
60
61#
62# set it up at a breakpoint so we can play with the variable values
63#
64if ![runto_main] then {
65 perror "couldn't run to breakpoint"
66 continue
67}
68
f18dabd2
MC
69gdb_test "break A::foo" \
70 "Breakpoint \[0-9\]* at $hex.*file .*method.cc, line 38\\."
c906108c 71
f18dabd2
MC
72gdb_test "continue" \
73 "Continuing\\.\r\n\r\nBreakpoint \[0-9\]*, A::foo(\\(int\\)|) \\(this=$hex, arg=13\\) at .*method\\.cc:38\r\n38\[\t \]*x \\+= arg;" \
74 "continue to A::foo"
c906108c
SS
75
76# Check ability to access this-relative stuff.
77
f18dabd2
MC
78gdb_test "print x" \
79 "\\$\[0-9\]* = 20" \
80 "print x in A::foo"
c906108c
SS
81
82# Check access to this pointer
83
f18dabd2
MC
84gdb_test "print this" \
85 "\\$\[0-9\]* = \\((class |)A *\\* *(const|)\\) $hex" \
86 "print this in A::foo"
c906108c
SS
87
88# Now do everything over again for A::bar, because sometimes processing one method
89# (the first one) is fine, but the second one's debug info gets munged beyond recognition.
90
f18dabd2
MC
91gdb_test "break A::bar" \
92 "Breakpoint \[0-9\]* at $hex.*file .*method.cc, line 44\\."
c906108c 93
f18dabd2 94gdb_test "continue" \
c9f2c8a3 95 "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 96 "continue to A::bar"
c906108c
SS
97
98# Check ability to access this-relative stuff.
99
f18dabd2
MC
100gdb_test "print x" \
101 "\\$\[0-9\]* = 33" \
102 "print x in A::bar"
c906108c
SS
103
104# Check access to this pointer
105
3a63e3f9
MC
106get_debug_format
107
f8d3bf8f
MS
108gdb_test_multiple "print this" "print this in A::bar" {
109 -re "\\$\[0-9\]* = \\(const (class |)A *\\* *(const|)\\) $hex\r\n$gdb_prompt $" {
110 pass "print this in A::bar"
111 }
112 -re "\\$\[0-9\]* = \\((class |)A *\\* *(const|)\\) $hex\r\n$gdb_prompt $" {
113 # gcc versions up to 3.0.4 with -gstabs+ do not emit "const"
114 # indicators, so the output is "A *". It should be "const A
115 # *" or "const A * const".
116 setup_xfail_format "stabs"
117 fail "print this in A::bar (missing const)"
118 }
119 -re "\\$\[0-9\]* = \\(const (class |)\{\\.\\.\\.\} *\\* *(const|)\\) $hex\r\n$gdb_prompt $" {
120 # gcc versions gcc-3_1-branch%20020404 and HEAD%20020404 with -gstabs+
121 # produce good stabs, but gdb prints "const class {...} *" const.
122 # This is PR gdb/277.
123 # setup_kfail "gdb/277"
124 fail "print this in A::bar (gdb/277)"
125 }
3a63e3f9 126}
c906108c
SS
127
128# Check again with funk::getFunky (this is the original test case
129# for CHFts23426); sometimes having a constructor with no arguments
130# will nuke the debug info read in for other methods in the class.
131
f18dabd2
MC
132gdb_test "break 21" \
133 "Breakpoint \[0-9\]* at $hex.*file .*method.cc, line 21\\."
c906108c 134
f18dabd2
MC
135gdb_test "continue" \
136 "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;" \
137 "continue to 21"
c906108c
SS
138
139# Check ability to access this-relative stuff.
140
f18dabd2
MC
141gdb_test "print data_" \
142 "\\$\[0-9\]* = 33" \
143 "print data_ in funk::getFunky"
c906108c
SS
144
145# Check access to this pointer
146
f18dabd2
MC
147gdb_test "print this" \
148 "\\$\[0-9\]* = \\((class |)funk *\\* *(const|)\\) $hex" \
149 "print this in funk::getFunky"
c906108c
SS
150
151# Check access to local variable
152
f18dabd2
MC
153gdb_test "print res" \
154 "\\$\[0-9\]* = -30" \
155 "print res in funk::getFunky"
c906108c
SS
156
157# Check ptype of class -- should show const/volatile methods
158
f8d3bf8f
MS
159gdb_test_multiple "ptype A" "ptype A" {
160 -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 $" {
161 pass "ptype A"
162 }
163 -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 $" {
164 pass "ptype A"
165 }
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\[ \]*A & operator=\\(A const ?&\\);\r\n\[ \]*A\\(A const ?&\\);\r\n\[ \]*A\\((void|)\\);\r\n\}\r\n$gdb_prompt $" {
167 pass "ptype A"
168 }
169 -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 $" {
170 pass "ptype A (HP aCC bug -- volatile not indicated)"
171 }
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;\r\n\}\r\n$gdb_prompt $" {
173 pass "ptype A"
174 }
c906108c
SS
175}
176
f8d3bf8f 177gdb_test_multiple "cont" "finish program" {
e71019a1 178 -re "Continuing.\r\n\r\nProgram exited normally.*$gdb_prompt $" {
f1c47eb2
MS
179 pass "finish program"
180 }
181 -re "Continuing.* EXIT code 0.*Program exited normally.*$gdb_prompt $" {
182 pass "finish program (exit wrapper)"
183 }
f1c47eb2
MS
184}
185
This page took 1.018403 seconds and 4 git commands to generate.