| |||
| [Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] |
| Hi, all, I install my exception port in my application, but when I link the dynamic library with 10.4 SDK, the exception handler can't work well, but when I delete "-isysroot /Developer/SDKs/MacOSX10.4u.sdk -mmacosx-version-min=10.4" in makefile, my exception handler will be called and the Crash Report works well. Is it an apple bug? Following my sample code: -------------------------makefile------------------------------------ all: test libtest2.dylib libtest2.dylib: test2.c gcc -isysroot /Developer/SDKs/MacOSX10.4u.sdk -mmacosx-version-min=10.4 -dynamiclib test2.c -o libtest2.dylib test: libtest2.dylib test.c gcc -isysroot /Developer/SDKs/MacOSX10.4u.sdk -mmacosx-version-min=10.4 -L. -ltest2 test.c -o test --------------------------test.c----------------------------------------- #include <pthread.h> extern void SetMyExceptionHandler(); extern void crash_thread_proc(void* data); int main(int argc, char* argv[]) { SetMyExceptionHandler(); pthread_t returned_thread; pthread_create(&returned_thread, NULL, crash_thread_proc,NULL); while (1) {} return 0; } --------------------test2.c---------------------------- #include <Carbon/Carbon.h> #include <stdio.h> #include <stdlib.h> #include <signal.h> #include <stdarg.h> #include <pthread.h> #include <assert.h> #include <mach/mach.h> void *exception_handler(void *arg) { extern boolean_t exc_server(); mach_port_t port = (mach_port_t) arg; mach_msg_server(exc_server, 2048, port, 0); abort(); // without this GCC complains (it doesn't know that mach_msg_server never returns) } void setup_mach_exception_port() { static mach_port_t exception_port = MACH_PORT_NULL; mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_RECEIVE, &exception_port); mach_port_insert_right(mach_task_self(), exception_port, exception_port, MACH_MSG_TYPE_MAKE_SEND); task_set_exception_ports(mach_task_self(), EXC_MASK_ALL, exception_port, EXCEPTION_DEFAULT, MACHINE_THREAD_STATE); pthread_t returned_thread; pthread_create(&returned_thread, NULL, exception_handler, (void*) exception_port); } void test_crash() { char *obj = NULL; *obj = "foo"; } struct macosx_exception_info { exception_mask_t masks[EXC_TYPES_COUNT]; mach_port_t ports[EXC_TYPES_COUNT]; exception_behavior_t behaviors[EXC_TYPES_COUNT]; thread_state_flavor_t flavors[EXC_TYPES_COUNT]; mach_msg_type_number_t count; }; struct macosx_exception_info info; kern_return_t macosx_save_exception_ports (task_t task, struct macosx_exception_info *info) { kern_return_t kret; info->count = (sizeof (info->ports) / sizeof (info->ports[0])); kret = task_get_exception_ports (task, EXC_MASK_ALL, info->masks, &info->count, info->ports, info->behaviors, info->flavors); if (kret != KERN_SUCCESS) return kret; return KERN_SUCCESS; } kern_return_t macosx_restore_exception_ports (task_t task, struct macosx_exception_info *info) { int i; kern_return_t kret; for (i = 0; i < info->count; i++) { kret = task_set_exception_ports (task, info->masks[i], info->ports[i], info->behaviors[i], info->flavors[i]); if (kret != KERN_SUCCESS) return kret; } return KERN_SUCCESS; } kern_return_t catch_exception_raise(mach_port_t exception_port, mach_port_t thread, mach_port_t task, exception_type_t exception, exception_data_t code_vector, mach_msg_type_number_t code_count) { fprintf(stderr, "catch_exception_raise %d\n", exception); macosx_restore_exception_ports(mach_task_self(),&info); return KERN_SUCCESS; // loops infinitely... } void crash_thread_proc(void* data) { test_crash(); } void SetMyExceptionHandler() { extern kern_return_t catch_exception_raise(mach_port_t exception_port, mach_port_t thread, mach_port_t task, exception_type_t exception, exception_data_t code_vector, mach_msg_type_number_t code_count) ; static int i = 0; if ( i == 0 ) { i = 1; macosx_save_exception_ports(mach_task_self(), &info); setup_mach_exception_port(); printf("Set Exception Handler\n"); } } |
_______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-dev/email@hidden This email sent to email@hidden
| Home | Archives | FAQ | Terms/Conditions | Contact | RSS | Lists | About |
Visit the Apple Store online or at retail locations.
1-800-MY-APPLE
Contact Apple | Terms of Use | Privacy Policy
Copyright © 2007 Apple Inc. All rights reserved.