1 # Copyright 2003-2014 Free Software Foundation, Inc.
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.
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.
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/>.
16 # This file was written by Adam Fedor (fedor@gnu.org)
21 # Objective-C program compilation isn't standard. We need to figure out
22 # which libraries to link in. Most of the time it uses pthread
24 if {[gdb_compile_objc "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug ]] != "" } {
29 # Deduce language of main()
32 proc deduce_language_of_main {} {
35 # See what language gdb thinks main() is, prior to reading full symbols.
36 # I think this fails for COFF targets.
37 send_gdb "show language\n"
39 -re ".* source language is \"auto; currently objective-c\".*$gdb_prompt $" {
40 pass "deduced language is Objective-C, before full symbols"
42 -re ".*$gdb_prompt $" {
43 fail "source language not correct for Objective-C (psymtabs only)"
47 fail "can't show language (timeout)"
54 # See if our idea of the language has changed.
56 send_gdb "show language\n"
58 -re ".* source language is \"auto; currently objective-c\".*$gdb_prompt $" {
59 pass "deduced language is Objective-C, after full symbols"
61 -re ".*$gdb_prompt $" {
62 fail "source language not correct for Objective-C (full symbols)"
66 fail "can't show language (timeout)"
72 proc do_objc_tests {} {
79 # Start with a fresh gdb.
83 gdb_reinitialize_dir $srcdir/$subdir
86 deduce_language_of_main
95 # Disable pending breakpoint query to avoid timeouts
96 # if Obj-C symbols cannot be found
97 gdb_test "set breakpoint pending off" "" "set breakpoint pending"
99 gdb_test "break doIt" \
100 "Breakpoint.*at.* file .*$srcfile, line.29.*" \
103 gdb_test "break takeArg:" \
104 "Breakpoint.*at.* file .*$srcfile, line.34.*" \
105 "breakpoint method with colon"
107 gdb_test "break newWithArg:" \
108 "Breakpoint.*at.* file .*$srcfile, line.22.*" \
109 "breakpoint class method with colon"
112 # Continue until breakpoint (test re-setting breakpoint)
115 "Continuing\\..*Breakpoint \[0-9\]+, -.BasicClass takeArg:. \\(self=.*, _cmd=.*, arg=.*\\) at .*$srcfile:34.*" \
116 "continue until method breakpoint"
119 # Test resetting breakpoints when re-running program
123 -re "Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$srcfile:.*$gdb_prompt $"\
124 { pass "resetting breakpoints when rerunning" }
125 -re ".*$gdb_prompt $" { fail "resetting breakpoints when rerunning" }
126 timeout { fail "resetting breakpoints when rerunning" }
130 # Continue until breakpoint (test re-setting breakpoint)
133 "Continuing\\..*Breakpoint \[0-9\]+, -.BasicClass takeArg:. \\(self=.*, _cmd=.*, arg=.*\\) at .*$srcfile:34.*" \
134 "continue until method breakpoint"
137 # Test printing objects
139 gdb_test "print object" \
140 "\\$\[0-9\] = .*0x0" \
141 " print an ivar of self"
143 gdb_test "print self" \
144 "\\$\[0-9\] = \\(.*BasicClass \\*\\) 0x\[0-9a-f\]+" \
147 gdb_test "print \*self" \
148 "\\$\[0-9\] = \{{?isa = 0x\[0-9a-f\]+( <.*>)?}?, object = 0x0\}" \
149 " print contents of self"
152 # Break in a category
154 gdb_test "break hiddenMethod" \
155 "Breakpoint.*at.* file .*$srcfile, line.61." \
156 "breakpoint in category method"
160 # Continue until breakpoint (test re-setting category breakpoint)
163 "Continuing\\..*Breakpoint \[0-9\]+, -.BasicClass\\(Private\\) hiddenMethod. \\(self=.*, _cmd=.*\\) at .*$srcfile:61.*" \
164 "continue until category method"
167 # Test calling Objective-C methods
169 gdb_test "print \[self printHi\]" \
170 "Hi.*\\$\[0-9\] = \\(.*objc_object \\*\\) 0x\[0-9a-f\]+" \
171 "Call an Objective-C method with no arguments"
173 gdb_test "print \[self printNumber: 42\]" \
174 "42.*\\$\[0-9\] = 43" \
175 "Call an Objective-C method with one argument"
178 # Test printing the object description
180 gdb_test "print-object object" \
181 "BasicClass gdb test object" \
182 "Use of the print-object command"
185 "BasicClass gdb test object" \
186 "Use of the po (print-object) command"