run copyright.sh for 2011.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.objc / basicclass.exp
CommitLineData
7b6bb8da 1# Copyright 2003, 2004, 2006, 2007, 2008, 2009, 2010, 2011
4c38e0a4 2# Free Software Foundation, Inc.
130cacce
AF
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
130cacce 7# (at your option) any later version.
e22f8b7c 8#
130cacce
AF
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#
130cacce 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/>.
130cacce
AF
16
17# This file was written by Adam Fedor (fedor@gnu.org)
18
19if $tracelevel then {
20 strace $tracelevel
21}
22
23set testfile "basicclass"
24set srcfile ${testfile}.m
25set binfile ${objdir}/${subdir}/${testfile}
26
27#
28# Objective-C program compilation isn't standard. We need to figure out
29# which libraries to link in. Most of the time it uses pthread
30#
31if {[gdb_compile_objc "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug ]] != "" } {
6e25beaf 32 return -1
130cacce
AF
33}
34
35#
36# Deduce language of main()
37#
38
39proc deduce_language_of_main {} {
40 global gdb_prompt
41
42 # See what language gdb thinks main() is, prior to reading full symbols.
43 # I think this fails for COFF targets.
44 send_gdb "show language\n"
45 gdb_expect {
46 -re ".* source language is \"auto; currently objective-c\".*$gdb_prompt $" {
47 pass "deduced language is Objective-C, before full symbols"
48 }
49 -re ".*$gdb_prompt $" {
50 fail "source language not correct for Objective-C (psymtabs only)"
51 return
52 }
53 timeout {
54 fail "can't show language (timeout)"
55 return
56 }
57 }
58
59 runto_main
60
61 # See if our idea of the language has changed.
62
63 send_gdb "show language\n"
64 gdb_expect {
65 -re ".* source language is \"auto; currently objective-c\".*$gdb_prompt $" {
66 pass "deduced language is Objective-C, after full symbols"
67 }
68 -re ".*$gdb_prompt $" {
69 fail "source language not correct for Objective-C (full symbols)"
70 return
71 }
72 timeout {
73 fail "can't show language (timeout)"
74 return
75 }
76 }
77}
78
79proc do_objc_tests {} {
130cacce
AF
80 global subdir
81 global objdir
82 global srcdir
83 global binfile
84 global gdb_prompt
85
130cacce
AF
86
87 # Start with a fresh gdb.
88
89 gdb_exit
90 gdb_start
91 gdb_reinitialize_dir $srcdir/$subdir
92 gdb_load $binfile
93
94 deduce_language_of_main
95}
96
97do_objc_tests
98
99#
100# Breakpoint tests
101#
0f73703c
UW
102
103# Disable pending breakpoint query to avoid timeouts
104# if Obj-C symbols cannot be found
105gdb_test "set breakpoint pending off" "" "set breakpoint pending"
106
130cacce
AF
107gdb_test "break doIt" \
108 "Breakpoint.*at.* file .*$srcfile, line.29.*" \
109 "breakpoint method"
110
111gdb_test "break takeArg:" \
112 "Breakpoint.*at.* file .*$srcfile, line.34.*" \
113 "breakpoint method with colon"
114
115gdb_test "break newWithArg:" \
116 "Breakpoint.*at.* file .*$srcfile, line.22.*" \
117 "breakpoint class method with colon"
118
119#
120# Continue until breakpoint (test re-setting breakpoint)
121#
122gdb_test continue \
123 "Continuing\\..*Breakpoint \[0-9\]+, -.BasicClass takeArg:. \\(self=.*, _cmd=.*, arg=.*\\) at .*$srcfile:34.*" \
124 "continue until method breakpoint"
125
126#
127# Test resetting breakpoints when re-running program
128#
83f66e8f 129gdb_run_cmd
130cacce 130gdb_expect {
83f66e8f 131 -re "Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$srcfile:.*$gdb_prompt $"\
130cacce
AF
132 { pass "resetting breakpoints when rerunning" }
133 -re ".*$gdb_prompt $" { fail "resetting breakpoints when rerunning" }
134 timeout { fail "resetting breakpoints when rerunning" }
135}
136
137#
138# Continue until breakpoint (test re-setting breakpoint)
139#
140gdb_test continue \
141 "Continuing\\..*Breakpoint \[0-9\]+, -.BasicClass takeArg:. \\(self=.*, _cmd=.*, arg=.*\\) at .*$srcfile:34.*" \
142 "continue until method breakpoint"
143
144#
145# Test printing objects
146#
147gdb_test "print object" \
148 "\\$\[0-9\] = .*0x0" \
149 " print an ivar of self"
150
151gdb_test "print self" \
152 "\\$\[0-9\] = \\(.*BasicClass \\*\\) 0x\[0-9a-f\]+" \
153 " print self"
154
155gdb_test "print \*self" \
2fa63963 156 "\\$\[0-9\] = \{{?isa = 0x\[0-9a-f\]+}?, object = 0x0\}" \
130cacce
AF
157 " print contents of self"
158
159#
160# Break in a category
161#
162gdb_test "break hiddenMethod" \
163 "Breakpoint.*at.* file .*$srcfile, line.61." \
164 "breakpoint in category method"
165
166
167#
168# Continue until breakpoint (test re-setting category breakpoint)
169#
170gdb_test continue \
171 "Continuing\\..*Breakpoint \[0-9\]+, -.BasicClass\\(Private\\) hiddenMethod. \\(self=.*, _cmd=.*\\) at .*$srcfile:61.*" \
172 "continue until category method"
173
174#
175# Test calling Objective-C methods
176#
177gdb_test "print \[self printHi\]" \
62f4b920 178 "Hi.*\\$\[0-9\] = \\(.*objc_object \\*\\) 0x\[0-9a-f\]+" \
130cacce
AF
179 "Call an Objective-C method with no arguments"
180
181gdb_test "print \[self printNumber: 42\]" \
182 "42.*\\$\[0-9\] = 43" \
183 "Call an Objective-C method with one argument"
184
185#
186# Test printing the object description
187#
188gdb_test "print-object object" \
189 "BasicClass gdb test object" \
190 "Use of the print-object command"
191
192gdb_test "po self" \
193 "BasicClass gdb test object" \
194 "Use of the po (print-object) command"
195
196
This page took 0.788226 seconds and 4 git commands to generate.