Merge fixes from trunk.
This commit is contained in:
parent
73288eb24b
commit
f167b79cfd
|
@ -28,7 +28,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if NV_OS_LINUX && defined(HAVE_EXECINFO_H)
|
#if NV_OS_LINUX && defined(HAVE_EXECINFO_H)
|
||||||
# include <execinfo.h>
|
# include <execinfo.h> // backtrace
|
||||||
# if NV_CC_GNUC // defined(HAVE_CXXABI_H)
|
# if NV_CC_GNUC // defined(HAVE_CXXABI_H)
|
||||||
# include <cxxabi.h>
|
# include <cxxabi.h>
|
||||||
# endif
|
# endif
|
||||||
|
@ -39,6 +39,13 @@
|
||||||
# include <sys/types.h>
|
# include <sys/types.h>
|
||||||
# include <sys/sysctl.h> // sysctl
|
# include <sys/sysctl.h> // sysctl
|
||||||
# include <ucontext.h>
|
# include <ucontext.h>
|
||||||
|
# undef HAVE_EXECINFO_H
|
||||||
|
# if defined(HAVE_EXECINFO_H) // only after OSX 10.5
|
||||||
|
# include <execinfo.h> // backtrace
|
||||||
|
# if NV_CC_GNUC // defined(HAVE_CXXABI_H)
|
||||||
|
# include <cxxabi.h>
|
||||||
|
# endif
|
||||||
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <stdexcept> // std::runtime_error
|
#include <stdexcept> // std::runtime_error
|
||||||
|
@ -128,6 +135,10 @@ namespace
|
||||||
|
|
||||||
#if defined(HAVE_EXECINFO_H) // NV_OS_LINUX
|
#if defined(HAVE_EXECINFO_H) // NV_OS_LINUX
|
||||||
|
|
||||||
|
static bool nvHasStackTrace() {
|
||||||
|
return backtrace != NULL;
|
||||||
|
}
|
||||||
|
|
||||||
static void nvPrintStackTrace(void * trace[], int size, int start=0) {
|
static void nvPrintStackTrace(void * trace[], int size, int start=0) {
|
||||||
char ** string_array = backtrace_symbols(trace, size);
|
char ** string_array = backtrace_symbols(trace, size);
|
||||||
|
|
||||||
|
@ -166,13 +177,26 @@ namespace
|
||||||
|
|
||||||
static void * callerAddress(void * secret)
|
static void * callerAddress(void * secret)
|
||||||
{
|
{
|
||||||
# if NV_OS_DARWIN && NV_CPU_PPC
|
# if NV_OS_DARWIN
|
||||||
|
# if defined(_STRUCT_MCONTEXT)
|
||||||
|
# if NV_CPU_PPC
|
||||||
|
ucontext_t * ucp = (ucontext_t *)secret;
|
||||||
|
return (void *) ucp->uc_mcontext->__ss.__srr0;
|
||||||
|
# elif NV_CPU_X86
|
||||||
|
ucontext_t * ucp = (ucontext_t *)secret;
|
||||||
|
return (void *) ucp->uc_mcontext->__ss.__eip;
|
||||||
|
# endif
|
||||||
|
# else
|
||||||
|
# if NV_CPU_PPC
|
||||||
ucontext_t * ucp = (ucontext_t *)secret;
|
ucontext_t * ucp = (ucontext_t *)secret;
|
||||||
return (void *) ucp->uc_mcontext->ss.srr0;
|
return (void *) ucp->uc_mcontext->ss.srr0;
|
||||||
# elif NV_OS_DARWIN && NV_CPU_X86
|
# elif NV_CPU_X86
|
||||||
ucontext_t * ucp = (ucontext_t *)secret;
|
ucontext_t * ucp = (ucontext_t *)secret;
|
||||||
return (void *) ucp->uc_mcontext->ss.eip;
|
return (void *) ucp->uc_mcontext->ss.eip;
|
||||||
# elif NV_CPU_X86_64
|
# endif
|
||||||
|
# endif
|
||||||
|
# else
|
||||||
|
# if NV_CPU_X86_64
|
||||||
// #define REG_RIP REG_INDEX(rip) // seems to be 16
|
// #define REG_RIP REG_INDEX(rip) // seems to be 16
|
||||||
ucontext_t * ucp = (ucontext_t *)secret;
|
ucontext_t * ucp = (ucontext_t *)secret;
|
||||||
return (void *)ucp->uc_mcontext.gregs[REG_RIP];
|
return (void *)ucp->uc_mcontext.gregs[REG_RIP];
|
||||||
|
@ -182,8 +206,7 @@ namespace
|
||||||
# elif NV_CPU_PPC
|
# elif NV_CPU_PPC
|
||||||
ucontext_t * ucp = (ucontext_t *)secret;
|
ucontext_t * ucp = (ucontext_t *)secret;
|
||||||
return (void *) ucp->uc_mcontext.regs->nip;
|
return (void *) ucp->uc_mcontext.regs->nip;
|
||||||
# else
|
# endif
|
||||||
return NULL;
|
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
// How to obtain the instruction pointers in different platforms, from mlton's source code.
|
// How to obtain the instruction pointers in different platforms, from mlton's source code.
|
||||||
|
@ -228,7 +251,8 @@ namespace
|
||||||
}
|
}
|
||||||
|
|
||||||
# if defined(HAVE_EXECINFO_H)
|
# if defined(HAVE_EXECINFO_H)
|
||||||
|
if (nvHasStackTrace()) // in case of weak linking
|
||||||
|
{
|
||||||
void * trace[64];
|
void * trace[64];
|
||||||
int size = backtrace(trace, 64);
|
int size = backtrace(trace, 64);
|
||||||
|
|
||||||
|
@ -238,7 +262,7 @@ namespace
|
||||||
}
|
}
|
||||||
|
|
||||||
nvPrintStackTrace(trace, size, 1);
|
nvPrintStackTrace(trace, size, 1);
|
||||||
|
}
|
||||||
# endif // defined(HAVE_EXECINFO_H)
|
# endif // defined(HAVE_EXECINFO_H)
|
||||||
|
|
||||||
exit(0);
|
exit(0);
|
||||||
|
@ -373,9 +397,12 @@ namespace
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
# if defined(HAVE_EXECINFO_H)
|
# if defined(HAVE_EXECINFO_H)
|
||||||
|
if (nvHasStackTrace())
|
||||||
|
{
|
||||||
void * trace[64];
|
void * trace[64];
|
||||||
int size = backtrace(trace, 64);
|
int size = backtrace(trace, 64);
|
||||||
nvPrintStackTrace(trace, size, 3);
|
nvPrintStackTrace(trace, size, 3);
|
||||||
|
}
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
// Exit cleanly.
|
// Exit cleanly.
|
||||||
|
@ -422,9 +449,12 @@ void NV_CDECL nvDebug(const char *msg, ...)
|
||||||
void debug::dumpInfo()
|
void debug::dumpInfo()
|
||||||
{
|
{
|
||||||
#if !NV_OS_WIN32 && defined(HAVE_SIGNAL_H) && defined(HAVE_EXECINFO_H)
|
#if !NV_OS_WIN32 && defined(HAVE_SIGNAL_H) && defined(HAVE_EXECINFO_H)
|
||||||
|
if (nvHasStackTrace())
|
||||||
|
{
|
||||||
void * trace[64];
|
void * trace[64];
|
||||||
int size = backtrace(trace, 64);
|
int size = backtrace(trace, 64);
|
||||||
nvPrintStackTrace(trace, size, 1);
|
nvPrintStackTrace(trace, size, 1);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,8 +2,7 @@
|
||||||
#error "Do not include this file directly."
|
#error "Do not include this file directly."
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <stdlib.h> // uint8_t, int8_t, ...
|
#include <stdint.h> // uint8_t, int8_t, ...
|
||||||
|
|
||||||
|
|
||||||
// Function linkage
|
// Function linkage
|
||||||
#define DLL_IMPORT
|
#define DLL_IMPORT
|
||||||
|
|
|
@ -19,7 +19,9 @@
|
||||||
|
|
||||||
// Set standard function names.
|
// Set standard function names.
|
||||||
#define snprintf _snprintf
|
#define snprintf _snprintf
|
||||||
|
#if _MSC_VER < 1500
|
||||||
# define vsnprintf _vsnprintf
|
# define vsnprintf _vsnprintf
|
||||||
|
#endif
|
||||||
#define vsscanf _vsscanf
|
#define vsscanf _vsscanf
|
||||||
#define chdir _chdir
|
#define chdir _chdir
|
||||||
#define getcwd _getcwd
|
#define getcwd _getcwd
|
||||||
|
|
|
@ -24,7 +24,7 @@ __forceinline void nvPrefetch(const void * mem)
|
||||||
#else // NV_CC_MSVC
|
#else // NV_CC_MSVC
|
||||||
|
|
||||||
// do nothing in other case.
|
// do nothing in other case.
|
||||||
#define piPrefetch(ptr)
|
#define nvPrefetch(ptr)
|
||||||
|
|
||||||
#endif // NV_CC_MSVC
|
#endif // NV_CC_MSVC
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user