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