2012-01-04 08:17:56 +00:00
|
|
|
# Copyright 2003-2004, 2006-2012 Free Software Foundation, Inc.
|
2003-05-01 01:09:51 +00:00
|
|
|
|
|
|
|
# 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
|
2007-08-23 18:14:19 +00:00
|
|
|
# the Free Software Foundation; either version 3 of the License, or
|
2003-05-01 01:09:51 +00:00
|
|
|
# (at your option) any later version.
|
2007-08-23 18:14:19 +00:00
|
|
|
#
|
2003-05-01 01:09:51 +00:00
|
|
|
# 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.
|
2007-08-23 18:14:19 +00:00
|
|
|
#
|
2003-05-01 01:09:51 +00:00
|
|
|
# You should have received a copy of the GNU General Public License
|
2007-08-23 18:14:19 +00:00
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2003-05-01 01:09:51 +00:00
|
|
|
|
|
|
|
# This file was written by Adam Fedor (fedor@gnu.org)
|
|
|
|
|
|
|
|
set testfile "basicclass"
|
|
|
|
set srcfile ${testfile}.m
|
|
|
|
set binfile ${objdir}/${subdir}/${testfile}
|
|
|
|
|
|
|
|
#
|
|
|
|
# Objective-C program compilation isn't standard. We need to figure out
|
|
|
|
# which libraries to link in. Most of the time it uses pthread
|
|
|
|
#
|
|
|
|
if {[gdb_compile_objc "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug ]] != "" } {
|
2003-06-23 20:20:31 +00:00
|
|
|
return -1
|
2003-05-01 01:09:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# Deduce language of main()
|
|
|
|
#
|
|
|
|
|
|
|
|
proc deduce_language_of_main {} {
|
|
|
|
global gdb_prompt
|
|
|
|
|
|
|
|
# See what language gdb thinks main() is, prior to reading full symbols.
|
|
|
|
# I think this fails for COFF targets.
|
|
|
|
send_gdb "show language\n"
|
|
|
|
gdb_expect {
|
|
|
|
-re ".* source language is \"auto; currently objective-c\".*$gdb_prompt $" {
|
|
|
|
pass "deduced language is Objective-C, before full symbols"
|
|
|
|
}
|
|
|
|
-re ".*$gdb_prompt $" {
|
|
|
|
fail "source language not correct for Objective-C (psymtabs only)"
|
|
|
|
return
|
|
|
|
}
|
|
|
|
timeout {
|
|
|
|
fail "can't show language (timeout)"
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
runto_main
|
|
|
|
|
|
|
|
# See if our idea of the language has changed.
|
|
|
|
|
|
|
|
send_gdb "show language\n"
|
|
|
|
gdb_expect {
|
|
|
|
-re ".* source language is \"auto; currently objective-c\".*$gdb_prompt $" {
|
|
|
|
pass "deduced language is Objective-C, after full symbols"
|
|
|
|
}
|
|
|
|
-re ".*$gdb_prompt $" {
|
|
|
|
fail "source language not correct for Objective-C (full symbols)"
|
|
|
|
return
|
|
|
|
}
|
|
|
|
timeout {
|
|
|
|
fail "can't show language (timeout)"
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
proc do_objc_tests {} {
|
|
|
|
global subdir
|
|
|
|
global objdir
|
|
|
|
global srcdir
|
|
|
|
global binfile
|
|
|
|
global gdb_prompt
|
|
|
|
|
|
|
|
|
|
|
|
# Start with a fresh gdb.
|
|
|
|
|
|
|
|
gdb_exit
|
|
|
|
gdb_start
|
|
|
|
gdb_reinitialize_dir $srcdir/$subdir
|
|
|
|
gdb_load $binfile
|
|
|
|
|
|
|
|
deduce_language_of_main
|
|
|
|
}
|
|
|
|
|
|
|
|
do_objc_tests
|
|
|
|
|
|
|
|
#
|
|
|
|
# Breakpoint tests
|
|
|
|
#
|
2009-09-29 19:02:22 +00:00
|
|
|
|
|
|
|
# Disable pending breakpoint query to avoid timeouts
|
|
|
|
# if Obj-C symbols cannot be found
|
|
|
|
gdb_test "set breakpoint pending off" "" "set breakpoint pending"
|
|
|
|
|
2003-05-01 01:09:51 +00:00
|
|
|
gdb_test "break doIt" \
|
|
|
|
"Breakpoint.*at.* file .*$srcfile, line.29.*" \
|
|
|
|
"breakpoint method"
|
|
|
|
|
|
|
|
gdb_test "break takeArg:" \
|
|
|
|
"Breakpoint.*at.* file .*$srcfile, line.34.*" \
|
|
|
|
"breakpoint method with colon"
|
|
|
|
|
|
|
|
gdb_test "break newWithArg:" \
|
|
|
|
"Breakpoint.*at.* file .*$srcfile, line.22.*" \
|
|
|
|
"breakpoint class method with colon"
|
|
|
|
|
|
|
|
#
|
|
|
|
# Continue until breakpoint (test re-setting breakpoint)
|
|
|
|
#
|
|
|
|
gdb_test continue \
|
|
|
|
"Continuing\\..*Breakpoint \[0-9\]+, -.BasicClass takeArg:. \\(self=.*, _cmd=.*, arg=.*\\) at .*$srcfile:34.*" \
|
|
|
|
"continue until method breakpoint"
|
|
|
|
|
|
|
|
#
|
|
|
|
# Test resetting breakpoints when re-running program
|
|
|
|
#
|
2004-02-08 03:56:15 +00:00
|
|
|
gdb_run_cmd
|
2003-05-01 01:09:51 +00:00
|
|
|
gdb_expect {
|
2004-02-08 03:56:15 +00:00
|
|
|
-re "Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$srcfile:.*$gdb_prompt $"\
|
2003-05-01 01:09:51 +00:00
|
|
|
{ pass "resetting breakpoints when rerunning" }
|
|
|
|
-re ".*$gdb_prompt $" { fail "resetting breakpoints when rerunning" }
|
|
|
|
timeout { fail "resetting breakpoints when rerunning" }
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# Continue until breakpoint (test re-setting breakpoint)
|
|
|
|
#
|
|
|
|
gdb_test continue \
|
|
|
|
"Continuing\\..*Breakpoint \[0-9\]+, -.BasicClass takeArg:. \\(self=.*, _cmd=.*, arg=.*\\) at .*$srcfile:34.*" \
|
|
|
|
"continue until method breakpoint"
|
|
|
|
|
|
|
|
#
|
|
|
|
# Test printing objects
|
|
|
|
#
|
|
|
|
gdb_test "print object" \
|
|
|
|
"\\$\[0-9\] = .*0x0" \
|
|
|
|
" print an ivar of self"
|
|
|
|
|
|
|
|
gdb_test "print self" \
|
|
|
|
"\\$\[0-9\] = \\(.*BasicClass \\*\\) 0x\[0-9a-f\]+" \
|
|
|
|
" print self"
|
|
|
|
|
|
|
|
gdb_test "print \*self" \
|
2012-05-18 15:31:42 +00:00
|
|
|
"\\$\[0-9\] = \{{?isa = 0x\[0-9a-f\]+( <.*>)?}?, object = 0x0\}" \
|
2003-05-01 01:09:51 +00:00
|
|
|
" print contents of self"
|
|
|
|
|
|
|
|
#
|
|
|
|
# Break in a category
|
|
|
|
#
|
|
|
|
gdb_test "break hiddenMethod" \
|
|
|
|
"Breakpoint.*at.* file .*$srcfile, line.61." \
|
|
|
|
"breakpoint in category method"
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# Continue until breakpoint (test re-setting category breakpoint)
|
|
|
|
#
|
|
|
|
gdb_test continue \
|
|
|
|
"Continuing\\..*Breakpoint \[0-9\]+, -.BasicClass\\(Private\\) hiddenMethod. \\(self=.*, _cmd=.*\\) at .*$srcfile:61.*" \
|
|
|
|
"continue until category method"
|
|
|
|
|
|
|
|
#
|
|
|
|
# Test calling Objective-C methods
|
|
|
|
#
|
|
|
|
gdb_test "print \[self printHi\]" \
|
2004-02-18 04:22:02 +00:00
|
|
|
"Hi.*\\$\[0-9\] = \\(.*objc_object \\*\\) 0x\[0-9a-f\]+" \
|
2003-05-01 01:09:51 +00:00
|
|
|
"Call an Objective-C method with no arguments"
|
|
|
|
|
|
|
|
gdb_test "print \[self printNumber: 42\]" \
|
|
|
|
"42.*\\$\[0-9\] = 43" \
|
|
|
|
"Call an Objective-C method with one argument"
|
|
|
|
|
|
|
|
#
|
|
|
|
# Test printing the object description
|
|
|
|
#
|
|
|
|
gdb_test "print-object object" \
|
|
|
|
"BasicClass gdb test object" \
|
|
|
|
"Use of the print-object command"
|
|
|
|
|
|
|
|
gdb_test "po self" \
|
|
|
|
"BasicClass gdb test object" \
|
|
|
|
"Use of the po (print-object) command"
|
|
|
|
|
|
|
|
|