diff --git a/device/plugins/native_daemon/include/utilities.h b/device/plugins/native_daemon/include/utilities.h index e5bd4b4aeb84b39f17fc2a04e18fd9d707077ed2..ac309af0ae3b574dd861461f08470e045b832b28 100644 --- a/device/plugins/native_daemon/include/utilities.h +++ b/device/plugins/native_daemon/include/utilities.h @@ -316,6 +316,7 @@ bool PowerOfTwo(int n); #endif int32_t GetProcessPid(const std::string& processName); bool IsArkJsFile(const std::string& filepath); +uintptr_t StripPac(uintptr_t inAddr, uintptr_t pacMask); } // namespace NativeDaemon } // namespace Developtools } // namespace OHOS diff --git a/device/plugins/native_daemon/src/stack_preprocess.cpp b/device/plugins/native_daemon/src/stack_preprocess.cpp index 1ff686758f7c7bb7eeb8a3edca3a8a04011d4e6b..4151f7aae5c77d3ae32cd849b1fde668fa8fb22e 100644 --- a/device/plugins/native_daemon/src/stack_preprocess.cpp +++ b/device/plugins/native_daemon/src/stack_preprocess.cpp @@ -745,12 +745,7 @@ void StackPreprocess::SetEventFrame(const RawStackPtr& rawStack, std::vector& callFrames, uint64_t napiIndex) { - #if defined(__aarch64__) - uintptr_t pacMask = 0xFFFFFF8000000000; -#else - uintptr_t pacMask = 0; -#endif - CallFrame& jsCallFrame = callFrames_.emplace_back(0 & (~pacMask)); + CallFrame& jsCallFrame = callFrames_.emplace_back(0); jsCallFrame.symbolName_ = tagName; jsCallFrame.isJsFrame_ = true; jsCallFrame.needReport_ |= CALL_FRAME_REPORT; @@ -1533,17 +1528,12 @@ void StackPreprocess::FinishReport() void StackPreprocess::FillFpNativeIp(RawStackPtr& rawData) { -#if defined(__aarch64__) - uintptr_t pacMask = 0xFFFFFF8000000000; -#else - uintptr_t pacMask = 0; -#endif uint64_t* fpIp = reinterpret_cast(rawData->data); for (uint8_t idx = 0; idx < rawData->fpDepth ; ++idx) { if (fpIp[idx] == 0) { break; } - callFrames_.emplace_back(fpIp[idx] & (~pacMask)); + callFrames_.emplace_back(StripPac(fpIp[idx], 0)); } } @@ -1607,12 +1597,7 @@ void StackPreprocess::FillFpJsData(RawStackPtr& rawData) void StackPreprocess::FillDwarfErrorStack() { -#if defined(__aarch64__) - uintptr_t pacMask = 0xFFFFFF8000000000; -#else - uintptr_t pacMask = 0; -#endif - CallFrame& jsCallFrame = callFrames_.emplace_back(0 & (~pacMask)); + CallFrame& jsCallFrame = callFrames_.emplace_back(0); jsCallFrame.symbolName_ = "UnwindErrorDwarf"; jsCallFrame.isJsFrame_ = true; jsCallFrame.needReport_ |= CALL_FRAME_REPORT; diff --git a/device/plugins/native_daemon/src/utilities.cpp b/device/plugins/native_daemon/src/utilities.cpp index c89e26dbc9675d3a9c0c11c658e1b2710993a3f9..8cf8655454db17ec30b97b73f292d4d9fb6d5c7c 100644 --- a/device/plugins/native_daemon/src/utilities.cpp +++ b/device/plugins/native_daemon/src/utilities.cpp @@ -514,6 +514,26 @@ bool IsArkJsFile(const std::string& filepath) StringStartsWith(filepath, "[anon:ArkTS Code") || StringEndsWith(filepath, ".abc") || StringEndsWith(filepath, ".hqf")); } + +uintptr_t StripPac(uintptr_t inAddr, uintptr_t pacMask) +{ + uintptr_t outAddr = inAddr; +#if defined(__aarch64__) + if (outAddr != 0) { + if (pacMask != 0) { + outAddr &= ~pacMask; + } else { + register uint64_t x30 __asm("x30") = inAddr; + asm("hint 0x7" : "+r"(x30)); + outAddr = x30; + } + if (outAddr != inAddr) { + HLOGM("Strip pac in addr: %lx, out addr: %lx", (uint64_t)inAddr, (uint64_t)outAddr); + } + } +#endif + return outAddr; +} } // namespace NativeDaemon } // namespace Developtools } // namespace OHOS