From 37d42d300b0fb5b616d9019a36bb04976a592e41 Mon Sep 17 00:00:00 2001 From: castano Date: Tue, 29 May 2007 10:53:03 +0000 Subject: [PATCH] Get instruction pointer correctly on Darwin. --- src/nvcore/Debug.cpp | 71 +++++++++++++++++++++----------------------- 1 file changed, 34 insertions(+), 37 deletions(-) diff --git a/src/nvcore/Debug.cpp b/src/nvcore/Debug.cpp index 2edbd0f..98b139c 100644 --- a/src/nvcore/Debug.cpp +++ b/src/nvcore/Debug.cpp @@ -164,51 +164,48 @@ namespace static void * callerAddress(void * secret) { # if NV_OS_DARWIN && NV_CPU_PPC - return NULL; + ucontext_t * ucp = (ucontext_t *)secret; + return (void *) ucp->uc_mcontext->ss.srr0; # elif NV_OS_DARWIN && NV_CPU_X86 - return NULL; + ucontext_t * ucp = (ucontext_t *)secret; + return (void *) ucp->uc_mcontext->ss.eip; # elif NV_CPU_X86_64 - ucontext_t * uc = (ucontext_t *)secret; - return (void *)uc->uc_mcontext.gregs[REG_RIP]; + // #define REG_RIP REG_INDEX(rip) // seems to be 16 + ucontext_t * ucp = (ucontext_t *)secret; + return (void *)ucp->uc_mcontext.gregs[REG_RIP]; # elif NV_CPU_X86 - ucontext_t * uc = (ucontext_t *)secret; - return (void *)uc->uc_mcontext.gregs[REG_EIP]; + ucontext_t * ucp = (ucontext_t *)secret; + return (void *)ucp->uc_mcontext.gregs[REG_EIP]; // 14 # elif NV_CPU_PPC - ucontext_t* uc = (ucontext_t*) secret; - return (void*) uc->uc_mcontext.regs->nip; + ucontext_t * ucp = (ucontext_t *)secret; + return (void *) ucp->uc_mcontext.regs->nip; #else return NULL; #endif - // From http://www.miriamruiz.es/weblog/?p=14 - - // #elif defined(__hppa__) - // ucontext_t* uc = (ucontext_t*) secret; - // pnt = (void*) uc->uc_mcontext.sc_iaoq[0] & ~0×3UL ; - // #elif defined(__sparc__) - // struct sigcontext* sc = (struct sigcontext*) secret; - // #if __WORDSIZE == 64 - // pnt = (void*) scp->sigc_regs.tpc ; - // #else - // pnt = (void*) scp->si_regs.pc ; - // #endif - + // How to obtain the instruction pointers in different platforms, from mlton's source code. + // http://mlton.org/ + // OpenBSD && NetBSD + // ucp->sc_eip + // FreeBSD: + // ucp->uc_mcontext.mc_eip + // HPUX: + // ucp->uc_link + // Solaris: + // ucp->uc_mcontext.gregs[REG_PC] + // Linux hppa: + // uc->uc_mcontext.sc_iaoq[0] & ~0×3UL + // Linux sparc: + // ((struct sigcontext*) secret)->sigc_regs.tpc + // Linux sparc64: + // ((struct sigcontext*) secret)->si_regs.pc + // potentially correct for other archs: - // alpha: ucp->m_context.sc_pc - // arm: ucp->m_context.ctx.arm_pc - // ia64: ucp->m_context.sc_ip & ~0×3UL - // mips: ucp->m_context.sc_pc - // s390: ucp->m_context.sregs->regs.psw.addr - - // #ifndef EIP - // #define EIP 14 - // #endif - - // #if (defined (__x86_64__)) - // #ifndef REG_RIP - // #define REG_RIP REG_INDEX(rip) /* seems to be 16 */ - // #endif - // #endif + // Linux alpha: ucp->m_context.sc_pc + // Linux arm: ucp->m_context.ctx.arm_pc + // Linux ia64: ucp->m_context.sc_ip & ~0×3UL + // Linux mips: ucp->m_context.sc_pc + // Linux s390: ucp->m_context.sregs->regs.psw.addr } static void nvSigHandler(int sig, siginfo_t *info, void *secret) @@ -471,7 +468,7 @@ void debug::enableSigHandler() struct sigaction sa; sa.sa_sigaction = nvSigHandler; sigemptyset (&sa.sa_mask); - sa.sa_flags = SA_RESTART | SA_SIGINFO; + sa.sa_flags = SA_ONSTACK | SA_RESTART | SA_SIGINFO; sigaction(SIGSEGV, &sa, &s_old_sigsegv); sigaction(SIGTRAP, &sa, &s_old_sigtrap);