From d013f698cc3c243aa64ffc9a54b0cb17a6ede65a Mon Sep 17 00:00:00 2001 From: joerg Date: Sat, 26 Apr 2014 23:17:38 +0000 Subject: [PATCH] Use the return address register from the CIE. Based on patch from Nick Kledzik. --- sys/lib/libunwind/DwarfInstructions.hpp | 5 +---- sys/lib/libunwind/DwarfParser.hpp | 3 ++- sys/lib/libunwind/Registers.hpp | 13 ------------- 3 files changed, 3 insertions(+), 18 deletions(-) diff --git a/sys/lib/libunwind/DwarfInstructions.hpp b/sys/lib/libunwind/DwarfInstructions.hpp index 9f7279190723..56fe8466e2f2 100644 --- a/sys/lib/libunwind/DwarfInstructions.hpp +++ b/sys/lib/libunwind/DwarfInstructions.hpp @@ -48,9 +48,6 @@ private: const typename CFI_Parser::RegisterLocation &); static int lastRestoreReg(const R &) { return R::LAST_RESTORE_REG; } - static bool isReturnAddressRegister(int regno, const R &) { - return regno == R::RETURN_REG; - } static pint_t getCFA(A &addressSpace, const typename CFI_Parser::PrologInfo &prolog, @@ -139,7 +136,7 @@ step_result DwarfInstructions::stepWithDwarf(A &addressSpace, pint_t pc, for (int i = 0; i <= lastRestoreReg(newRegisters); ++i) { if (prolog.savedRegisters[i].location == CFI_Parser::kRegisterUnused) continue; - if (isReturnAddressRegister(i, registers)) + if (i == (int)cieInfo.returnAddressRegister) returnAddress = getSavedRegister(addressSpace, registers, cfa, prolog.savedRegisters[i]); else if (registers.validRegister(i)) diff --git a/sys/lib/libunwind/DwarfParser.hpp b/sys/lib/libunwind/DwarfParser.hpp index ba1ec13a1948..509f6d57f158 100644 --- a/sys/lib/libunwind/DwarfParser.hpp +++ b/sys/lib/libunwind/DwarfParser.hpp @@ -43,6 +43,7 @@ public: uint8_t personalityOffsetInCIE; bool isSignalFrame; bool fdesHaveAugmentationData; + uint8_t returnAddressRegister; }; /// Information about an FDE (Frame Description Entry) @@ -238,7 +239,7 @@ bool CFI_Parser::parseCIE(A &addressSpace, pint_t cie, // Parse data alignment factor cieInfo->dataAlignFactor = addressSpace.getSLEB128(p, cieContentEnd); // Parse return address register - addressSpace.getULEB128(p, cieContentEnd); + cieInfo->returnAddressRegister = (uint8_t)addressSpace.getULEB128(p, cieContentEnd); // Parse augmentation data based on augmentation string. if (addressSpace.get8(strStart) == 'z') { // parse augmentation data length diff --git a/sys/lib/libunwind/Registers.hpp b/sys/lib/libunwind/Registers.hpp index 08612646a501..7e6b0d71f025 100644 --- a/sys/lib/libunwind/Registers.hpp +++ b/sys/lib/libunwind/Registers.hpp @@ -34,7 +34,6 @@ public: enum { LAST_REGISTER = REGNO_X86_EIP, LAST_RESTORE_REG = REGNO_X86_EIP, - RETURN_REG = REGNO_X86_EIP, RETURN_OFFSET = 0, }; @@ -100,7 +99,6 @@ public: enum { LAST_REGISTER = REGNO_X86_64_RIP, LAST_RESTORE_REG = REGNO_X86_64_RIP, - RETURN_REG = REGNO_X86_64_RIP, RETURN_OFFSET = 0, }; @@ -169,7 +167,6 @@ public: enum { LAST_REGISTER = REGNO_PPC32_V31, LAST_RESTORE_REG = REGNO_PPC32_V31, - RETURN_REG = REGNO_PPC32_LR, RETURN_OFFSET = 0, }; @@ -258,7 +255,6 @@ public: enum { LAST_REGISTER = REGNO_ARM32_D31, LAST_RESTORE_REG = REGNO_ARM32_SPSR, - RETURN_REG = REGNO_ARM32_SPSR, RETURN_OFFSET = 0, }; @@ -328,7 +324,6 @@ public: enum { LAST_REGISTER = REGNO_VAX_PSW, LAST_RESTORE_REG = REGNO_VAX_PSW, - RETURN_REG = REGNO_VAX_R15, RETURN_OFFSET = 0, }; @@ -400,7 +395,6 @@ public: enum { LAST_REGISTER = REGNO_M68K_FP7, LAST_RESTORE_REG = REGNO_M68K_FP7, - RETURN_REG = REGNO_M68K_PC, RETURN_OFFSET = 0, }; @@ -477,7 +471,6 @@ public: enum { LAST_REGISTER = REGNO_SH3_PR, LAST_RESTORE_REG = REGNO_SH3_PR, - RETURN_REG = REGNO_SH3_PR, RETURN_OFFSET = 0, }; @@ -542,7 +535,6 @@ public: enum { LAST_REGISTER = REGNO_SPARC64_PC, LAST_RESTORE_REG = REGNO_SPARC64_PC, - RETURN_REG = REGNO_SPARC64_R15, RETURN_OFFSET = 8, }; typedef uint64_t reg_t; @@ -606,7 +598,6 @@ public: enum { LAST_REGISTER = REGNO_SPARC_PC, LAST_RESTORE_REG = REGNO_SPARC_PC, - RETURN_REG = REGNO_SPARC_R15, RETURN_OFFSET = 8, }; typedef uint32_t reg_t; @@ -672,7 +663,6 @@ public: enum { LAST_REGISTER = REGNO_ALPHA_F30, LAST_RESTORE_REG = REGNO_ALPHA_F30, - RETURN_REG = REGNO_ALPHA_R26, RETURN_OFFSET = 0, }; typedef uint32_t reg_t; @@ -740,7 +730,6 @@ public: enum { LAST_REGISTER = REGNO_HPPA_FR31H, LAST_RESTORE_REG = REGNO_HPPA_FR31H, - RETURN_REG = REGNO_HPPA_R2, RETURN_OFFSET = -3, // strictly speaking, this is a mask }; @@ -812,7 +801,6 @@ public: enum { LAST_REGISTER = REGNO_MIPS_F31, LAST_RESTORE_REG = REGNO_MIPS_F31, - RETURN_REG = REGNO_MIPS_R31, RETURN_OFFSET = 0, }; @@ -884,7 +872,6 @@ public: enum { LAST_REGISTER = REGNO_MIPS64_F31, LAST_RESTORE_REG = REGNO_MIPS64_F31, - RETURN_REG = REGNO_MIPS64_R31, RETURN_OFFSET = 0, };