remove GetThreadBacktraceContext; GetBacktrace( x, NULL ) gets the current backtrace
This commit is contained in:
@@ -22,7 +22,7 @@ void GetSignalBacktraceContext( BacktraceContext *ctx, const ucontext_t *uc )
|
|||||||
ctx->pid = GetCurrentThreadId();
|
ctx->pid = GetCurrentThreadId();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GetCurrentBacktraceContext( BacktraceContext *ctx )
|
static void GetCurrentBacktraceContext( BacktraceContext *ctx )
|
||||||
{
|
{
|
||||||
register void *esp __asm__ ("esp");
|
register void *esp __asm__ ("esp");
|
||||||
ctx->esp = (long) esp;
|
ctx->esp = (long) esp;
|
||||||
@@ -30,18 +30,6 @@ void GetCurrentBacktraceContext( BacktraceContext *ctx )
|
|||||||
ctx->ebp = (long) __builtin_frame_address(0);
|
ctx->ebp = (long) __builtin_frame_address(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int GetThreadBacktraceContext( int ThreadID, BacktraceContext *ctx )
|
|
||||||
{
|
|
||||||
ctx->pid = ThreadID;
|
|
||||||
|
|
||||||
if( ThreadID != GetCurrentThreadId() )
|
|
||||||
return GetThreadContext( ThreadID, ctx );
|
|
||||||
|
|
||||||
GetCurrentBacktraceContext( ctx );
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static const char *itoa(unsigned n)
|
static const char *itoa(unsigned n)
|
||||||
{
|
{
|
||||||
static char ret[32];
|
static char ret[32];
|
||||||
@@ -293,16 +281,18 @@ void GetExceptionBacktraceContext( BacktraceContext *ctx, const ExceptionInforma
|
|||||||
ctx->FramePtr = (void *) exception->registerImage->R1.lo;
|
ctx->FramePtr = (void *) exception->registerImage->R1.lo;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GetCurrentBacktraceContext( BacktraceContext *ctx )
|
|
||||||
{
|
|
||||||
ctx->FramePtr = __builtin_return_address(2);
|
|
||||||
}
|
|
||||||
|
|
||||||
void InitializeBacktrace() { }
|
void InitializeBacktrace() { }
|
||||||
|
|
||||||
void GetBacktrace( const void **buf, size_t size, const BacktraceContext *ctx )
|
void GetBacktrace( const void **buf, size_t size, const BacktraceContext *ctx )
|
||||||
{
|
{
|
||||||
Frame *frame = (Frame *) ctx->FramePtr;
|
BacktraceContext CurrentCtx;
|
||||||
|
if( ctx == NULL )
|
||||||
|
{
|
||||||
|
ctx = &CurrentCtx;
|
||||||
|
CurrentCtx.FramePtr = (void *) __builtin_frame_address(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
const Frame *frame = (Frame *) ctx->FramePtr;
|
||||||
|
|
||||||
unsigned i = 0;
|
unsigned i = 0;
|
||||||
while( frame && i < size-1 ) // -1 for NULL
|
while( frame && i < size-1 ) // -1 for NULL
|
||||||
|
|||||||
@@ -28,9 +28,8 @@ void InitializeBacktrace();
|
|||||||
void GetBacktrace( const void **buf, size_t size, const BacktraceContext *ctx = NULL );
|
void GetBacktrace( const void **buf, size_t size, const BacktraceContext *ctx = NULL );
|
||||||
|
|
||||||
/* Set up a BacktraceContext to get a backtrace for a thread. ThreadID may
|
/* Set up a BacktraceContext to get a backtrace for a thread. ThreadID may
|
||||||
* be the current thread. */
|
* not be the current thread. */
|
||||||
int GetThreadBacktraceContext( int ThreadID, BacktraceContext *ctx );
|
bool GetThreadBacktraceContext( int ThreadID, BacktraceContext *ctx );
|
||||||
void GetCurrentBacktraceContext( BacktraceContext *ctx );
|
|
||||||
|
|
||||||
/* Set up a BacktraceContext to get a backtrace after receiving a signal, given
|
/* Set up a BacktraceContext to get a backtrace after receiving a signal, given
|
||||||
* a ucontext_t (see sigaction(2)). (This interface is UNIX-specific.) */
|
* a ucontext_t (see sigaction(2)). (This interface is UNIX-specific.) */
|
||||||
|
|||||||
@@ -292,6 +292,9 @@ static void RunCrashHandler( const CrashData *crash )
|
|||||||
|
|
||||||
/* Do this early, so functions called below don't end up on the backtrace. */
|
/* Do this early, so functions called below don't end up on the backtrace. */
|
||||||
const void *BacktracePointers[BACKTRACE_MAX_SIZE];
|
const void *BacktracePointers[BACKTRACE_MAX_SIZE];
|
||||||
|
if( crash->type == CrashData::FORCE_CRASH_THIS_THREAD )
|
||||||
|
GetBacktrace( BacktracePointers, BACKTRACE_MAX_SIZE, NULL );
|
||||||
|
else
|
||||||
GetBacktrace( BacktracePointers, BACKTRACE_MAX_SIZE, &crash->ctx );
|
GetBacktrace( BacktracePointers, BACKTRACE_MAX_SIZE, &crash->ctx );
|
||||||
|
|
||||||
/* We need to be very careful, since we're under crash conditions. Let's fork
|
/* We need to be very careful, since we're under crash conditions. Let's fork
|
||||||
@@ -333,7 +336,6 @@ void ForceCrashHandler( const char *reason )
|
|||||||
strncpy( crash.reason, reason, sizeof(crash.reason) );
|
strncpy( crash.reason, reason, sizeof(crash.reason) );
|
||||||
crash.reason[ sizeof(crash.reason)-1 ] = 0;
|
crash.reason[ sizeof(crash.reason)-1 ] = 0;
|
||||||
|
|
||||||
GetCurrentBacktraceContext( &crash.ctx );
|
|
||||||
RunCrashHandler( &crash );
|
RunCrashHandler( &crash );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ struct CrashData
|
|||||||
// FORCE_CRASH_DEADLOCK
|
// FORCE_CRASH_DEADLOCK
|
||||||
} type;
|
} type;
|
||||||
|
|
||||||
|
/* Everything except FORCE_CRASH_THIS_THREAD: */
|
||||||
BacktraceContext ctx;
|
BacktraceContext ctx;
|
||||||
|
|
||||||
/* FORCE_CRASH_DEADLOCK only: */
|
/* FORCE_CRASH_DEADLOCK only: */
|
||||||
|
|||||||
@@ -147,14 +147,14 @@ int ResumeThread( int ThreadID )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Get user_regs_struct for a thread. tid must not be the current thread.
|
/* Get a BacktraceContext for a thread. ThreadID must not be the current thread.
|
||||||
*
|
*
|
||||||
* tid() is a PID (from getpid) or a TID (from gettid). Note that this may have kernel compatibility
|
* tid() is a PID (from getpid) or a TID (from gettid). Note that this may have kernel compatibility
|
||||||
* problems, because NPTL is new and its interactions with ptrace() aren't well-defined.
|
* problems, because NPTL is new and its interactions with ptrace() aren't well-defined.
|
||||||
* If we're on a non-NPTL system, tid is a regular PID. */
|
* If we're on a non-NPTL system, tid is a regular PID. */
|
||||||
int GetThreadContext( int ThreadID, BacktraceContext *ctx )
|
bool GetThreadBacktraceContext( int ThreadID, BacktraceContext *ctx )
|
||||||
{
|
{
|
||||||
/* Can't GetThreadContext the current thread. */
|
/* Can't GetThreadBacktraceContext the current thread. */
|
||||||
ASSERT( ThreadID != GetCurrentThreadId() );
|
ASSERT( ThreadID != GetCurrentThreadId() );
|
||||||
|
|
||||||
/* Attach to the thread. */
|
/* Attach to the thread. */
|
||||||
@@ -187,7 +187,7 @@ int GetThreadContext( int ThreadID, BacktraceContext *ctx )
|
|||||||
ASSERT( ret == 0 );
|
ASSERT( ret == 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ctx->pid = ThreadID;
|
||||||
ctx->eip = regs.eip;
|
ctx->eip = regs.eip;
|
||||||
ctx->esp = regs.esp;
|
ctx->esp = regs.esp;
|
||||||
ctx->ebp = regs.ebp;
|
ctx->ebp = regs.ebp;
|
||||||
|
|||||||
Reference in New Issue
Block a user