Created
September 11, 2015 23:28
-
-
Save bazhenovc/9b7bc0e2cb6d5a35646e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// GetFramePointer (ASM) | |
.globl GetFramePointer | |
GetFramePointer: | |
mov rp, fp | |
mov pc, lr | |
// Walk the stack | |
struct FramePointer | |
{ | |
pointer_t FP; | |
pointer_t SP; | |
pointer_t LR; | |
pointer_t PC; | |
}; | |
static void GetSymbolName(pointer_t ptr, AsciiString& outString) | |
{ | |
pointer_t addressList[] = { ptr, NULL }; | |
uint8_t** symbolList = backtrace_symbols(addressList, 1); | |
outString = AsciiString::FromCString(symbolList[0]); | |
} | |
static void GetCallStack(uint32_t depth, DynamicArray<AsciiString>& outCallStack) | |
{ | |
pointer_t top = GetFramePointer(); | |
for (uint32_t i = 0; i < depth; ++i) { | |
FramePointer* frame = reinterpret_cast<FramePointer*>(top) - sizeof(FramePointer); | |
AsciiString symbolName; | |
if (i == 0) GetSymbolName(frame->PC, symbolName); | |
if (frame->FP != 0) GetSymbolName(frame->LR, symbolName); | |
else GetSymbolName(frame->PC, symbolName); | |
outCallStack.Add(symbolName); | |
top = frame->FP; | |
if (!ValidateFramePointer(top)) | |
break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment