rename eip/ebp/esp -> ip/bp/sp, since it's used for x86-64 too (rip/rbp/rsp)
This commit is contained in:
@@ -299,42 +299,42 @@ static void do_backtrace( const void **buf, size_t size, const BacktraceContext
|
|||||||
get_readable_ranges( g_ExecutableBegin, g_ExecutableEnd, 1024, READABLE_ONLY|EXECUTABLE_ONLY );
|
get_readable_ranges( g_ExecutableBegin, g_ExecutableEnd, 1024, READABLE_ONLY|EXECUTABLE_ONLY );
|
||||||
|
|
||||||
/* Find the stack memory blocks. */
|
/* Find the stack memory blocks. */
|
||||||
g_StackBlock1 = find_address( ctx->esp, g_ReadableBegin, g_ReadableEnd );
|
g_StackBlock1 = find_address( ctx->sp, g_ReadableBegin, g_ReadableEnd );
|
||||||
g_StackBlock2 = find_address( SavedStackPointer, g_ReadableBegin, g_ReadableEnd );
|
g_StackBlock2 = find_address( SavedStackPointer, g_ReadableBegin, g_ReadableEnd );
|
||||||
|
|
||||||
/* Put eip at the top of the backtrace. */
|
/* Put eip at the top of the backtrace. */
|
||||||
/* XXX: We want EIP even if it's not valid, but we can't put NULL on the
|
/* XXX: We want EIP even if it's not valid, but we can't put NULL on the
|
||||||
* list, since it's NULL-terminated. Hmm. */
|
* list, since it's NULL-terminated. Hmm. */
|
||||||
unsigned i=0;
|
unsigned i=0;
|
||||||
if( i < size-1 && ctx->eip ) // -1 for NULL
|
if( i < size-1 && ctx->ip ) // -1 for NULL
|
||||||
buf[i++] = ctx->eip;
|
buf[i++] = ctx->ip;
|
||||||
|
|
||||||
/* If we did a CALL to an invalid address (eg. call a NULL callback), then
|
/* If we did a CALL to an invalid address (eg. call a NULL callback), then
|
||||||
* we won't have a stack frame for the function that called it (since the
|
* we won't have a stack frame for the function that called it (since the
|
||||||
* stack frame is set up by the called function), but if esp hasn't been
|
* stack frame is set up by the called function), but if esp hasn't been
|
||||||
* changed after the CALL, the return address will be esp[0]. Grab it. */
|
* changed after the CALL, the return address will be esp[0]. Grab it. */
|
||||||
if( IsOnStack( ctx->esp ) )
|
if( IsOnStack( ctx->sp ) )
|
||||||
{
|
{
|
||||||
const void *p = ((const void **) ctx->esp)[0];
|
const void *p = ((const void **) ctx->sp)[0];
|
||||||
if( IsExecutableAddress( p ) && PointsToValidCall( p ) && i < size-1 ) // -1 for NULL
|
if( IsExecutableAddress( p ) && PointsToValidCall( p ) && i < size-1 ) // -1 for NULL
|
||||||
buf[i++] = p;
|
buf[i++] = p;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
/* ebp is usually the frame pointer. */
|
/* ebp is usually the frame pointer. */
|
||||||
const StackFrame *frame = (StackFrame *) ctx->ebp;
|
const StackFrame *frame = (StackFrame *) ctx->bp;
|
||||||
|
|
||||||
/* If ebp doesn't point to a valid stack frame, we're probably in
|
/* If ebp doesn't point to a valid stack frame, we're probably in
|
||||||
* -fomit-frame-pointer code. Ignore it; use esp instead. It probably
|
* -fomit-frame-pointer code. Ignore it; use esp instead. It probably
|
||||||
* won't point to a stack frame, but it should at least give us a starting
|
* won't point to a stack frame, but it should at least give us a starting
|
||||||
* point in the stack. */
|
* point in the stack. */
|
||||||
if( !IsValidFrame( frame ) )
|
if( !IsValidFrame( frame ) )
|
||||||
frame = (StackFrame *) ctx->esp;
|
frame = (StackFrame *) ctx->sp;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Actually, let's just use esp. Even if ebp points to a valid stack frame, there might be
|
/* Actually, let's just use esp. Even if ebp points to a valid stack frame, there might be
|
||||||
* -fomit-frame-pointer calls in front of it, and we want to get those. */
|
* -fomit-frame-pointer calls in front of it, and we want to get those. */
|
||||||
const StackFrame *frame = (StackFrame *) ctx->esp;
|
const StackFrame *frame = (StackFrame *) ctx->sp;
|
||||||
|
|
||||||
while( i < size-1 ) // -1 for NULL
|
while( i < size-1 ) // -1 for NULL
|
||||||
{
|
{
|
||||||
@@ -368,9 +368,9 @@ static void do_backtrace( const void **buf, size_t size, const BacktraceContext
|
|||||||
|
|
||||||
void GetSignalBacktraceContext( BacktraceContext *ctx, const ucontext_t *uc )
|
void GetSignalBacktraceContext( BacktraceContext *ctx, const ucontext_t *uc )
|
||||||
{
|
{
|
||||||
ctx->eip = (void *) uc->uc_mcontext.gregs[REG_EIP];
|
ctx->ip = (void *) uc->uc_mcontext.gregs[REG_EIP];
|
||||||
ctx->ebp = (void *) uc->uc_mcontext.gregs[REG_EBP];
|
ctx->bp = (void *) uc->uc_mcontext.gregs[REG_EBP];
|
||||||
ctx->esp = (void *) uc->uc_mcontext.gregs[REG_ESP];
|
ctx->sp = (void *) uc->uc_mcontext.gregs[REG_ESP];
|
||||||
ctx->pid = GetCurrentThreadId();
|
ctx->pid = GetCurrentThreadId();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -383,9 +383,9 @@ void GetBacktrace( const void **buf, size_t size, const BacktraceContext *ctx )
|
|||||||
{
|
{
|
||||||
ctx = &CurrentCtx;
|
ctx = &CurrentCtx;
|
||||||
|
|
||||||
CurrentCtx.eip = NULL;
|
CurrentCtx.ip = NULL;
|
||||||
CurrentCtx.ebp = __builtin_frame_address(0);
|
CurrentCtx.bp = __builtin_frame_address(0);
|
||||||
CurrentCtx.esp = __builtin_frame_address(0);
|
CurrentCtx.sp = __builtin_frame_address(0);
|
||||||
CurrentCtx.pid = GetCurrentThreadId();
|
CurrentCtx.pid = GetCurrentThreadId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
struct BacktraceContext
|
struct BacktraceContext
|
||||||
{
|
{
|
||||||
#if defined(LINUX)
|
#if defined(LINUX)
|
||||||
const void *eip, *ebp, *esp;
|
const void *ip, *bp, *sp;
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -223,13 +223,13 @@ bool GetThreadBacktraceContext( uint64_t ThreadID, BacktraceContext *ctx )
|
|||||||
|
|
||||||
ctx->pid = pid_t(ThreadID);
|
ctx->pid = pid_t(ThreadID);
|
||||||
#if defined(CPU_X86_64)
|
#if defined(CPU_X86_64)
|
||||||
ctx->eip = (void *) regs.rip;
|
ctx->ip = (void *) regs.rip;
|
||||||
ctx->ebp = (void *) regs.rbp;
|
ctx->bp = (void *) regs.rbp;
|
||||||
ctx->esp = (void *) regs.rsp;
|
ctx->sp = (void *) regs.rsp;
|
||||||
#elif defined(CPU_X86)
|
#elif defined(CPU_X86)
|
||||||
ctx->eip = (void *) regs.eip;
|
ctx->ip = (void *) regs.eip;
|
||||||
ctx->ebp = (void *) regs.ebp;
|
ctx->bp = (void *) regs.ebp;
|
||||||
ctx->esp = (void *) regs.esp;
|
ctx->sp = (void *) regs.esp;
|
||||||
#else
|
#else
|
||||||
#error GetThreadBacktraceContext: which arch?
|
#error GetThreadBacktraceContext: which arch?
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user