Re: INT3 not calling SIGTRAP handler?
site_archiver@lists.apple.com Delivered-To: darwin-dev@lists.apple.com i: 31 i: 32 i: 33 i: 34 i: 35 test-mach-exception.c:100: failed assertion `flag == 0' Abort trap #include <stdio.h> #include <stdlib.h> #include <signal.h> #include <stdarg.h> #include <pthread.h> #include <assert.h> #if defined(__MACH__) #include <mach/mach_types.h> #include <mach/sync_policy.h> #endif thread_port_t main_thread; int exception_count = 0; int flag = 0; 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) { kern_return_t ret; exception_count++; flag = 0; return KERN_SUCCESS; } void * exception_handler_proc(void *arg) { extern boolean_t exc_server(); mach_port_t p = (mach_port_t) arg; mach_msg_server(exc_server, 2048, p, 0); abort(); } mach_port_t setup_mach_exception_port() { static mach_port_t exception_port = MACH_PORT_NULL; kern_return_t ret; pthread_attr_t attr; pthread_t returned_thread = (pthread_t) 0; pthread_attr_init(&attr); ret = mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_RECEIVE, &exception_port); fprintf(stderr, "mach_port_allocate ret: %d\n", ret); ret = mach_port_insert_right(mach_task_self(), exception_port, exception_port, MACH_MSG_TYPE_MAKE_SEND); fprintf(stderr, "mach_port_insert_right ret: %d\n", ret); ret = thread_set_exception_ports(main_thread, EXC_MASK_BREAKPOINT, exception_port, EXCEPTION_DEFAULT, MACHINE_THREAD_STATE); fprintf(stderr, "thread_set_exception_ports ret: %d\n", ret); pthread_create(&returned_thread, &attr, exception_handler_proc, (void*) exception_port); return exception_port; } void test_trap() { #if defined(__i386__) __asm__ __volatile__ ( "int3\n\t"); #elif defined(__ppc__) __asm__ __volatile__ ( "twle r1,r1\n\t"); #endif } int main(int argc, char** argv) { main_thread = mach_thread_self(); mach_port_t port = setup_mach_exception_port(); int i=0; for(i=0; i < 1000; i++) { flag = 1; test_trap(); assert(flag == 0); fprintf(stderr, " i: %d\n", i); } fprintf(stderr, "Exception count: %d\n", exception_count); return 0; } _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-dev mailing list (Darwin-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-dev/site_archiver%40lists.appl... And, here's a version that tries to work around the problem by using mach exceptions, but the problem persists. Perhaps I'm doing something wrong in the mach exception code, but, like in the SIGTRAP case, it works most of the time, except when it doesn't, e.g.: This email sent to site_archiver@lists.apple.com
participants (1)
-
Cyrus Harmon