Last active
December 17, 2015 16:59
-
-
Save rtsisyk/5643301 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Compile with: gcc gcc-objective-c-exceptions.m -fobjc-exceptions -o test -lobjc */ | |
#include <stdio.h> | |
#include <stdlib.h> | |
#import <objc/runtime.h> | |
@interface Object { | |
Class isa; | |
} | |
+ (id) alloc; | |
- (id) init; | |
- (void) free; | |
@end | |
@implementation Object | |
+ (id) alloc | |
{ | |
return class_createInstance(self, 0); | |
} | |
- (id) init | |
{ | |
return self; | |
} | |
- (void) free | |
{ | |
object_dispose(self); | |
} | |
@end | |
@interface Frob: Object | |
@end | |
@implementation Frob: Object | |
@end | |
int proc() { | |
@throw [[Frob alloc] init]; | |
} | |
int foo() | |
{ | |
@try { | |
return proc(); | |
} | |
@catch (Frob *) { | |
printf("Catch(Frob *)\n"); | |
return 0; | |
} | |
@catch (Object *) { | |
printf("Catch(Object *)\n"); | |
return 0; | |
} | |
@catch (id) { | |
printf("Catch(id)\n"); | |
return 0; | |
} | |
} | |
int main(void) | |
{ | |
foo(); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
roman@work:~$ gcc -v | |
Using built-in specs. | |
COLLECT_GCC=gcc | |
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.7/lto-wrapper | |
Target: x86_64-linux-gnu | |
Configured with: ../src/configure -v --with-pkgversion='Debian 4.7.2-5' --with-bugurl=file:///usr/share/doc/gcc-4.7/README.Bugs --enable-languages=c,c++,go,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.7 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.7 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin --enable-objc-gc --with-arch-32=i586 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu | |
Thread model: posix | |
gcc version 4.7.2 (Debian 4.7.2-5) | |
roman@work:~$ gcc gcc-objective-c-exceptions.m -fobjc-exceptions -o test -lobjc | |
roman@work:~$ gdb ./test | |
GNU gdb (GDB) 7.4.1-debian | |
Copyright (C) 2012 Free Software Foundation, Inc. | |
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> | |
This is free software: you are free to change and redistribute it. | |
There is NO WARRANTY, to the extent permitted by law. Type "show copying" | |
and "show warranty" for details. | |
This GDB was configured as "x86_64-linux-gnu". | |
For bug reporting instructions, please see: | |
<http://www.gnu.org/software/gdb/bugs/>... | |
Reading symbols from test...(no debugging symbols found)...done. | |
(gdb) r | |
Starting program: test | |
Program received signal SIGSEGV, Segmentation fault. | |
__objc_responds_to (sel=<optimized out>, object=0x601340) at /home/packages/gcc/4.7/w/gcc-4.7-4.7.2/src/libobjc/sendmsg.c:398 | |
398 res = sarray_get_safe (dtable, (size_t) sel->sel_id); | |
(gdb) bt | |
#0 __objc_responds_to (sel=<optimized out>, object=0x601340) at /home/packages/gcc/4.7/w/gcc-4.7-4.7.2/src/libobjc/sendmsg.c:398 | |
#1 __objc_forward (object=0x601340, sel=0x6016a0, args=0x7fffffffe010) at /home/packages/gcc/4.7/w/gcc-4.7-4.7.2/src/libobjc/sendmsg.c:905 | |
#2 0x00007ffff7bd24ed in __objc_word_forward (rcv=<optimized out>, op=<optimized out>) | |
at /home/packages/gcc/4.7/w/gcc-4.7-4.7.2/src/libobjc/sendmsg.c:844 | |
#3 0x0000000000400a7c in proc () | |
#4 0x0000000000400ab0 in foo () | |
#5 0x0000000000400b1b in main () |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[buildslave@localhost objc-exception-bug]$ gcc -v | |
Using built-in specs. | |
COLLECT_GCC=/usr/bin/gcc | |
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.7.2/lto-wrapper | |
Target: x86_64-redhat-linux | |
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --disable-build-with-cxx --disable-build-poststage1-with-cxx --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --enable-java-awt=gtk --disable-dssi --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib --with-ppl --with-cloog --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux | |
Thread model: posix | |
gcc version 4.7.2 20121109 (Red Hat 4.7.2-8) (GCC) | |
[buildslave@localhost objc-exception-bug]$ gcc -fobjc-exceptions gcc-objective-c-exceptions.m -o test -lobjc | |
[buildslave@localhost objc-exception-bug]$ gdb ./test | |
rGNU gdb (GDB) Fedora (7.5.1-38.fc18) | |
Copyright (C) 2012 Free Software Foundation, Inc. | |
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> | |
This is free software: you are free to change and redistribute it. | |
There is NO WARRANTY, to the extent permitted by law. Type "show copying" | |
and "show warranty" for details. | |
This GDB was configured as "x86_64-redhat-linux-gnu". | |
For bug reporting instructions, please see: | |
<http://www.gnu.org/software/gdb/bugs/>... | |
Reading symbols from /home/buildslave/objc-exception-bug/test...(no debugging symbols found)...done. | |
(gdb) r | |
Starting program: /home/buildslave/objc-exception-bug/test | |
Program received signal SIGSEGV, Segmentation fault. | |
__objc_responds_to (sel=<optimized out>, object=0x602120 <_OBJC_Class_Frob>) at /usr/src/debug/gcc-4.7.2-20121109/libobjc/sendmsg.c:398 | |
398 res = sarray_get_safe (dtable, (size_t) sel->sel_id); | |
(gdb) bt | |
#0 __objc_responds_to (sel=<optimized out>, object=0x602120 <_OBJC_Class_Frob>) at /usr/src/debug/gcc-4.7.2-20121109/libobjc/sendmsg.c:398 | |
#1 __objc_forward (object=0x602120 <_OBJC_Class_Frob>, sel=0x602480 <_OBJC_SELECTOR_TABLE>, args=0x7fffffffe330) | |
at /usr/src/debug/gcc-4.7.2-20121109/libobjc/sendmsg.c:905 | |
#2 0x00007ffff7de6cfd in __objc_word_forward (rcv=<optimized out>, op=<optimized out>) at /usr/src/debug/gcc-4.7.2-20121109/libobjc/sendmsg.c:844 | |
#3 0x0000000000400a2c in proc () | |
#4 0x0000000000400a60 in foo () | |
#5 0x0000000000400acb in main () |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment