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