aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.c++/method.exp
blob: b3c725cfa70ade908592d40c922523b7550227e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
# Copyright (C) 1998, 1999 Free Software Foundation, Inc.

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  

# Please email any bugs, comments, and/or additions to this file to:
# bug-gdb@prep.ai.mit.edu

# tests for misc. C++ method stuff
# Written by Satish Pai <pai@apollo.hp.com> 1997-07-08

# This file is part of the gdb testsuite

# This tests:
# 0. method arguments are correct
# 1. access to class data members inside method scopes
# 2. correct param types for methods in ptype.
# 3. const and volatile methods

# (#0 and #1 above relate to an HP specific problem -- GDB must correctly
# integrate FPARAM symbols in HP debug info into the local var list
# for the function or method's block.)

if $tracelevel then {
        strace $tracelevel
        }

#
# test running programs
#
set prms_id 0
set bug_id 0

if { [skip_cplus_tests] } { continue }

set testfile "method"
set srcfile ${testfile}.cc
set binfile ${objdir}/${subdir}/${testfile}

if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
     gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
}

if [get_compiler_info $binfile "c++"] {
  return -1
}

gdb_exit
gdb_start
gdb_reinitialize_dir $srcdir/$subdir
gdb_load ${binfile}


#
# set it up at a breakpoint so we can play with the variable values
#
if ![runto_main] then {
    perror "couldn't run to breakpoint"
    continue
}

send_gdb "break A::foo\n"
gdb_expect {
   -re "Breakpoint \[0-9\]* at $hex.*file .*method.cc, line 38*\\.\r\n$gdb_prompt $" {
       pass "set breakpoint on A::foo"
   }
   -re ".*$gdb_prompt $" { fail "set breakpoint on A::foo" }
   timeout { fail "(timeout) set breakpoint on A::foo" }
}

send_gdb "continue\n"
gdb_expect {
   -re "Continuing\\.\r\n\r\nBreakpoint \[0-9\]*, A::foo \\(this=$hex, arg=13\\) at .*method\\.cc:38\r\n38\[\t \]*x \\+= arg;\r\n$gdb_prompt $" {
      pass "continued and got breakpoint in A::foo"
   }
   -re ".*$gdb_prompt $" { fail "continuing and breaking in A::foo" }
   timeout { fail "(timeout) continue" }
}

# Check ability to access this-relative stuff.

send_gdb "print x\n"
gdb_expect {
   -re "\\$\[0-9\]* = 20\r\n$gdb_prompt $" {
       pass "access this-relative x (in foo)"
   }
   -re ".*$gdb_prompt $" { fail "print x (in foo)" } 
   timeout { fail "(timeout) print x (in foo)" }
}

# Check access to this pointer       

send_gdb "print this\n"
gdb_expect {
   -re "\\$\[0-9\]* = \\(A \\*\\) $hex\r\n$gdb_prompt $" {
       pass "print this (in foo)"
   }
   -re ".*$gdb_prompt $" { fail "print this (in foo)" }
   timeout { fail "(timeout) print this (in foo)" }
}

# Now do everything over again for A::bar, because sometimes processing one method
# (the first one) is fine, but the second one's debug info gets munged beyond recognition.

send_gdb "break A::bar\n"
gdb_expect {
   -re "Breakpoint \[0-9\]* at $hex.*file .*method.cc, line 44\\.\r\n$gdb_prompt $" {
       pass "set breakpoint on A::bar"
   }
   -re ".*$gdb_prompt $" { fail "set breakpoint on A::bar" }
   timeout { fail "(timeout) set breakpoint on A::bar" }
}

send_gdb "continue\n"
gdb_expect {
   -re "Continuing\\.\r\n\r\nBreakpoint \[0-9\]*, A::bar \\(this=$hex, arg=15\\) at .*method\\.cc:44\r\n44\[\t \]*return arg \\+ 2 \\* x;\r\n$gdb_prompt $" {
      pass "continued and got breakpoint in A::bar"
   }
   -re ".*$gdb_prompt $" { fail "continuing and breaking in A::bar" }
   timeout { fail "(timeout) continue" }
}

# Check ability to access this-relative stuff.

send_gdb "print x\n"
gdb_expect {
   -re "\\$\[0-9\]* = 33\r\n$gdb_prompt $" {
       pass "access this-relative x (in bar)"
   }
   -re ".*$gdb_prompt $" { fail "print x (in bar)" }
   timeout { fail "(timeout) print x (in bar)" }
}

# Check access to this pointer       

send_gdb "print this\n"
gdb_expect {
   -re "\\$\[0-9\]* = \\(const class A \\*\\) $hex\r\n$gdb_prompt $" {
     global gcc_compiled
     if {$gcc_compiled} {
       xfail "print this (in bar)"
     } else {
       pass "print this (in bar)"
     }
   }
   -re "\\$\[0-9\]* = \\(A \\*\\) $hex\r\n$gdb_prompt $" {
     global gcc_compiled
     if {$gcc_compiled} {
       pass "print this (in bar)"
     } else {
       xfail "print this (in bar)"
     }
   }
   -re ".*$gdb_prompt $" { fail "print this (in bar)" }
   timeout { fail "(timeout) print this (in bar)" }
}

# Check again with funk::getFunky (this is the original test case
# for CHFts23426); sometimes having a constructor with no arguments
# will nuke the debug info read in for other methods in the class.

send_gdb "break funk::getFunky\n"
gdb_expect {
   -re "Breakpoint \[0-9\]* at $hex.*file .*method.cc, line 20\\.\r\n$gdb_prompt $" {
       pass "set breakpoint on funk::getFunky"
   }
   -re ".*$gdb_prompt $" { fail "set breakpoint on funk::getfunky" }
   timeout { fail "(timeout) set breakpoint on funk::getfunky" }
}

send_gdb "continue\n"
gdb_expect {
   -re "Continuing\\.\r\n\r\nBreakpoint \[0-9\]*, funk::getFunky \\(this=$hex, a=1, b=2\\) at .*method\\.cc:20\r\n20\[\t \]*res = a \\+ b - data_;\r\n$gdb_prompt $" {
      pass "continued and got breakpoint in funk::getfunky"
   }
   -re ".*$gdb_prompt $" { fail "continuing and breaking in funk::getfunky" }
   timeout { fail "(timeout) continue" }
}

# Check ability to access this-relative stuff.

send_gdb "print data_\n"
gdb_expect {
   -re "\\$\[0-9\]* = 33\r\n$gdb_prompt $" {
       pass "access this-relative data_ in getFunky"
   }
   -re ".*$gdb_prompt $" { fail "print data_ in getFunky" }
   timeout { fail "(timeout) print data_ in getFunky" }
}

# Check access to this pointer       

send_gdb "print this\n"
gdb_expect {
   -re "\\$\[0-9\]* = \\(funk \\*\\) $hex\r\n$gdb_prompt $" {
       pass "print this in getFunky"
   }
   -re ".*$gdb_prompt $" { fail "print this in getfunky" }
   timeout { fail "(timeout) print this in getfunky" }
}

# Check access to local variable

send_gdb "print res\n"
gdb_expect {
   -re "\\$\[0-9\]* = .\[0-9\]*\r\n$gdb_prompt $" {
       pass "print res in getFunky"
   }
   -re ".*$gdb_prompt $" { fail "print res in getfunky" }
   timeout { fail "(timeout) print res in getfunky" }
}


# Check ptype of class -- should show const/volatile methods

send_gdb "ptype A\n"
gdb_expect {
   -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;\r\n\}\r\n$gdb_prompt $" {
      pass "ptype A"
   }
   -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 $" {
      pass "ptype A (HP aCC bug -- volatile not indicated)"
   }
   -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 $" {
      pass "ptype A"
   }
   -re ".*$gdb_prompt $" { fail "ptype A" }
   timeout { fail "(timeout) ptype A" }
}

send_gdb "cont\n"
gdb_expect {
    -re "Continuing.\r\n\r\nProgram exited normally.\r\n$gdb_prompt $" {
        pass "finish program"
    }
    -re "$gdb_prompt $" { fail "finish program"  }
    timeout { fail "(timeout) finish program"  }
}