本文整理汇总了C++中StackFrame::SetReturnAddress方法的典型用法代码示例。如果您正苦于以下问题:C++ StackFrame::SetReturnAddress方法的具体用法?C++ StackFrame::SetReturnAddress怎么用?C++ StackFrame::SetReturnAddress使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StackFrame
的用法示例。
在下文中一共展示了StackFrame::SetReturnAddress方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: new
//.........这里部分代码省略.........
// return address on the stack, though.
// If the function is not frameless and we're at the top frame we need
// to check whether the prologue has not been executed (completely) or
// we're already after the epilogue.
if (isTopFrame) {
uint64 stack = 0;
if (hasPrologue) {
if (rip < function->Address() + kFunctionPrologueSize) {
// The prologue has not been executed yet, i.e. there's no
// stack frame yet. Get the return address from the stack.
stack = cpuState->IntRegisterValue(X86_64_REGISTER_RSP);
if (rip > function->Address()) {
// The "push %rbp" has already been executed.
stack += 8;
}
} else {
// Not in the function prologue, but maybe after the
// epilogue. The epilogue is a single "pop %rbp", so we
// check whether the current instruction is already a
// "ret".
uint8 code[1];
if (fTeamMemory->ReadMemory(rip, &code, 1) == 1
&& code[0] == 0xc3) {
stack = cpuState->IntRegisterValue(
X86_64_REGISTER_RSP);
}
}
} else {
// Check if the instruction pointer is at a readable location.
// If it isn't, then chances are we got here via a bogus
// function pointer, and the prologue hasn't actually been
// executed. In such a case, what we need is right at the top
// of the stack.
uint8 data[1];
if (fTeamMemory->ReadMemory(rip, &data, 1) != 1)
stack = cpuState->IntRegisterValue(X86_64_REGISTER_RSP);
}
if (stack != 0) {
uint64 address;
if (fTeamMemory->ReadMemory(stack, &address, 8) == 8) {
returnAddress = address;
previousFramePointer = framePointer;
framePointer = 0;
readStandardFrame = false;
frameType = STACK_FRAME_TYPE_FRAMELESS;
}
}
}
}
// create the stack frame
StackFrameDebugInfo* stackFrameDebugInfo
= new(std::nothrow) NoOpStackFrameDebugInfo;
if (stackFrameDebugInfo == NULL)
return B_NO_MEMORY;
BReference<StackFrameDebugInfo> stackFrameDebugInfoReference(
stackFrameDebugInfo, true);
StackFrame* frame = new(std::nothrow) StackFrame(frameType, cpuState,
framePointer, rip, stackFrameDebugInfo);
if (frame == NULL)
return B_NO_MEMORY;
BReference<StackFrame> frameReference(frame, true);
status_t error = frame->Init();
if (error != B_OK)
return error;
// read the previous frame and return address, if this is a standard frame
if (readStandardFrame) {
uint64 frameData[2];
if (framePointer != 0
&& fTeamMemory->ReadMemory(framePointer, frameData, 16) == 16) {
previousFramePointer = frameData[0];
returnAddress = frameData[1];
}
}
// create the CPU state, if we have any info
CpuStateX8664* previousCpuState = NULL;
if (returnAddress != 0) {
// prepare the previous CPU state
previousCpuState = new(std::nothrow) CpuStateX8664;
if (previousCpuState == NULL)
return B_NO_MEMORY;
previousCpuState->SetIntRegister(X86_64_REGISTER_RBP,
previousFramePointer);
previousCpuState->SetIntRegister(X86_64_REGISTER_RIP, returnAddress);
frame->SetPreviousCpuState(previousCpuState);
}
frame->SetReturnAddress(returnAddress);
_frame = frameReference.Detach();
_previousCpuState = previousCpuState;
return B_OK;
}