diff options
author | Adam Fedor <fedor@gnu.org> | 2003-05-01 01:09:51 +0000 |
---|---|---|
committer | Adam Fedor <fedor@gnu.org> | 2003-05-01 01:09:51 +0000 |
commit | 130cacceca840fe1b78c6a1f67c37f6bab3f7fc6 (patch) | |
tree | 6a13bdcc70d03e09468bbd424425ba2f68756772 /gdb/testsuite/gdb.objc | |
parent | 10a9829174397471ff95856c94aac352190ca7b9 (diff) | |
download | gdb-130cacceca840fe1b78c6a1f67c37f6bab3f7fc6.zip gdb-130cacceca840fe1b78c6a1f67c37f6bab3f7fc6.tar.gz gdb-130cacceca840fe1b78c6a1f67c37f6bab3f7fc6.tar.bz2 |
* Makefile.in (ALL_SUBDIRS): Add gdb.objc
* configure.in (AC_OUTPUT): Add gdb.objc/Makefile
* gdb.objc/Makefile.in, gdb.objc/basicclass.exp,
gdb.objc/basicclass.m: : New files
* lib/gdb.exp (gdb_compile_objc): New procedure.
Diffstat (limited to 'gdb/testsuite/gdb.objc')
-rw-r--r-- | gdb/testsuite/gdb.objc/Makefile.in | 22 | ||||
-rw-r--r-- | gdb/testsuite/gdb.objc/basicclass.exp | 199 | ||||
-rw-r--r-- | gdb/testsuite/gdb.objc/basicclass.m | 81 |
3 files changed, 302 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.objc/Makefile.in b/gdb/testsuite/gdb.objc/Makefile.in new file mode 100644 index 0000000..381e48a --- /dev/null +++ b/gdb/testsuite/gdb.objc/Makefile.in @@ -0,0 +1,22 @@ +VPATH = @srcdir@ +srcdir = @srcdir@ + +EXECUTABLES = basicclass + +all: + @echo "Nothing to be done for all..." + +info: +install-info: +dvi: +install: +uninstall: force +installcheck: +check: + +clean mostlyclean: + -rm -f *~ *.o *.ci + -rm -f core ${EXECUTABLES} + +distclean maintainer-clean realclean: clean + -rm -f Makefile config.status config.log diff --git a/gdb/testsuite/gdb.objc/basicclass.exp b/gdb/testsuite/gdb.objc/basicclass.exp new file mode 100644 index 0000000..44b709e --- /dev/null +++ b/gdb/testsuite/gdb.objc/basicclass.exp @@ -0,0 +1,199 @@ +# Copyright 2003 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. + +# This file was written by Adam Fedor (fedor@gnu.org) + +if $tracelevel then { + strace $tracelevel +} + +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 ]] != "" } { + gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail." +} + +# +# 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 prms_id + global bug_id + global subdir + global objdir + global srcdir + global binfile + global gdb_prompt + + set prms_id 0 + set bug_id 0 + + # 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 +# +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 +# +send_gdb "run\n" +gdb_expect { + -re "The program .* has been started already.*y or n. $" { + send_gdb "y\n" + exp_continue + } + -re "Starting program.*Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$srcfile:.*$gdb_prompt $"\ + { 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" \ + "\\$\[0-9\] = \{isa = 0x\[0-9a-f\]+, object = 0x0\}" \ + " 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\]" \ + "Hi.*\\$\[0-9\] = \[0-9\]+" \ + "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" + + diff --git a/gdb/testsuite/gdb.objc/basicclass.m b/gdb/testsuite/gdb.objc/basicclass.m new file mode 100644 index 0000000..0de12db --- /dev/null +++ b/gdb/testsuite/gdb.objc/basicclass.m @@ -0,0 +1,81 @@ +#include <objc/Object.h> + +@interface BasicClass: Object +{ + id object; +} ++ newWithArg: arg; +- doIt; +- takeArg: arg; +- printHi; +- (int) printNumber: (int)number; +- (const char *) myDescription; +@end + +@interface BasicClass (Private) +- hiddenMethod; +@end + +@implementation BasicClass ++ newWithArg: arg +{ + id obj = [self new]; + [obj takeArg: arg]; + return obj; +} + +- doIt +{ + return self; +} + +- takeArg: arg +{ + object = arg; + [self hiddenMethod]; + return self; +} + +- printHi +{ + printf("Hi\n"); + return self; +} + +- (int) printNumber: (int)number +{ + printf("%d\n", number); + return number+1; +} + +- (const char *) myDescription +{ + return "BasicClass gdb test object"; +} + +@end + +@implementation BasicClass (Private) +- hiddenMethod +{ + return self; +} +@end + +int main (int argc, const char *argv[]) +{ + id obj; + obj = [BasicClass new]; + [obj takeArg: obj]; + return 0; +} + +const char *_NSPrintForDebugger(id object) +{ + /* This is not really what _NSPrintForDebugger should do, but it + is a simple test if gdb can call this function */ + if (object && [object respondsTo: @selector(myDescription)]) + return [object myDescription]; + + return NULL; +} |