From f270c76a2e27ffde1e7b0c80dc44e59d7f149a1d Mon Sep 17 00:00:00 2001 From: Rene Gollent Date: Sun, 28 Jul 2013 18:59:36 -0400 Subject: [PATCH] Debugger: Cleanups. ResolvePICFunctionAddress() needs to restore the CPUState object back to how it was when it was originally passed in. Fixes various issues that would occur as a result. --- src/apps/debugger/arch/x86/ArchitectureX86.cpp | 1 - src/apps/debugger/arch/x86_64/ArchitectureX8664.cpp | 9 +++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/apps/debugger/arch/x86/ArchitectureX86.cpp b/src/apps/debugger/arch/x86/ArchitectureX86.cpp index 0955446019..b0bec17137 100644 --- a/src/apps/debugger/arch/x86/ArchitectureX86.cpp +++ b/src/apps/debugger/arch/x86/ArchitectureX86.cpp @@ -605,7 +605,6 @@ ArchitectureX86::ResolvePICFunctionAddress(target_addr_t instructionAddress, // will actually have taken us to its corresponding PLT slot. // in such a case, look at the disassembled jump to determine // where to find the actual function address. - state->SetInstructionPointer(instructionAddress); InstructionInfo info; if (GetInstructionInfo(instructionAddress, info, state) != B_OK) { return B_BAD_VALUE; diff --git a/src/apps/debugger/arch/x86_64/ArchitectureX8664.cpp b/src/apps/debugger/arch/x86_64/ArchitectureX8664.cpp index a234cfe1bf..0922808fc1 100644 --- a/src/apps/debugger/arch/x86_64/ArchitectureX8664.cpp +++ b/src/apps/debugger/arch/x86_64/ArchitectureX8664.cpp @@ -625,6 +625,7 @@ status_t ArchitectureX8664::ResolvePICFunctionAddress(target_addr_t instructionAddress, CpuState* state, target_addr_t& _targetAddress) { + target_addr_t previousIP = state->InstructionPointer(); // if the function in question is position-independent, the call // will actually have taken us to its corresponding PLT slot. // in such a case, look at the disassembled jump to determine @@ -638,8 +639,10 @@ ArchitectureX8664::ResolvePICFunctionAddress(target_addr_t instructionAddress, // after this instruction (where it would be during actual // execution), and recalculate the target address of the jump state->SetInstructionPointer(info.Address() + info.Size()); - if (GetInstructionInfo(info.Address(), info, state) != B_OK) - return B_BAD_VALUE; + status_t result = GetInstructionInfo(info.Address(), info, state); + state->SetInstructionPointer(previousIP); + if (result != B_OK) + return result; target_addr_t subroutineAddress; ssize_t bytesRead = fTeamMemory->ReadMemory(info.TargetAddress(), @@ -650,8 +653,6 @@ ArchitectureX8664::ResolvePICFunctionAddress(target_addr_t instructionAddress, _targetAddress = subroutineAddress; return B_OK; - - return B_BAD_VALUE; }