diff --git a/interfaces/innerkits/unwinder/include/thread_context.h b/interfaces/innerkits/unwinder/include/thread_context.h index 68af5b80552465bedf652ad7067033c5a36214b7..359f6897445537759654e022f9e0ef1db27f6d83 100644 --- a/interfaces/innerkits/unwinder/include/thread_context.h +++ b/interfaces/innerkits/unwinder/include/thread_context.h @@ -101,7 +101,7 @@ public: LocalThreadContextMix& operator=(const LocalThreadContextMix&) = delete; static LocalThreadContextMix& GetInstance(); void ReleaseCollectThreadContext(); - bool CollectThreadContext(int32_t tid); + bool CollectThreadContext(int32_t tid, bool needMaps = false); bool CheckStatusValidate(int status, int32_t tid); bool GetSelfStackRangeInSignal(); void CopyRegister(void *context); diff --git a/interfaces/innerkits/unwinder/src/unwind_local/thread_context.cpp b/interfaces/innerkits/unwinder/src/unwind_local/thread_context.cpp index b41bd3770aa6591e2f5cc1f1037eeb2502bf6d74..4b0fe5bdfade764cc9ecd9f455d6626c331f6a60 100644 --- a/interfaces/innerkits/unwinder/src/unwind_local/thread_context.cpp +++ b/interfaces/innerkits/unwinder/src/unwind_local/thread_context.cpp @@ -298,9 +298,11 @@ NO_SANITIZE LocalThreadContextMix& LocalThreadContextMix::GetInstance() return instance; } -bool LocalThreadContextMix::CollectThreadContext(int32_t tid) +bool LocalThreadContextMix::CollectThreadContext(int32_t tid, bool needMaps) { - maps_ = DfxMaps::Create(); + if (needMaps) { + maps_ = DfxMaps::Create(); + } StartCollectThreadContext(tid); InitSignalHandler(); if (!SignalRequestThread(tid)) { diff --git a/interfaces/innerkits/unwinder/unwinder.cpp b/interfaces/innerkits/unwinder/unwinder.cpp index b603d213749abdf8595df6b4f1e332635d4a4651..64825c739cc4789dfd1134e305f58c2310a250c4 100644 --- a/interfaces/innerkits/unwinder/unwinder.cpp +++ b/interfaces/innerkits/unwinder/unwinder.cpp @@ -563,8 +563,8 @@ bool Unwinder::Impl::UnwindLocalWithTid(const pid_t tid, size_t maxFrameNum, siz return false; } DFXLOGD("UnwindLocalWithTid:: tid: %{public}d", tid); - auto threadContext = LocalThreadContext::GetInstance().CollectThreadContext(tid); #if defined(__aarch64__) + auto threadContext = LocalThreadContext::GetInstance().CollectThreadContext(tid); if (threadContext != nullptr && threadContext->frameSz > 0) { pcs_.clear(); for (size_t i = 0; i < threadContext->frameSz; i++) { @@ -575,41 +575,7 @@ bool Unwinder::Impl::UnwindLocalWithTid(const pid_t tid, size_t maxFrameNum, siz } return false; #else - if (threadContext == nullptr || threadContext->ctx == nullptr) { - DFXLOGW("Failed to get thread context of tid(%{public}d)", tid); - LocalThreadContext::GetInstance().ReleaseThread(tid); - return false; - } - if (regs_ == nullptr) { - regs_ = DfxRegs::CreateFromUcontext(*(threadContext->ctx)); - } else { - regs_->SetFromUcontext(*(threadContext->ctx)); - } - uintptr_t stackBottom = 1; - uintptr_t stackTop = static_cast(-1); - if (tid == getpid()) { - if (!GetMainStackRangeInner(stackBottom, stackTop)) { - return false; - } - } else if (!LocalThreadContext::GetInstance().GetStackRange(tid, stackBottom, stackTop)) { - DFXLOGE("Failed to get stack range with tid(%{public}d), err(%{public}d)", tid, errno); - return false; - } - if (stackBottom == 0 || stackTop == 0) { - DFXLOGE("Invalid stack range, err(%{public}d)", errno); - return false; - } - DFXLOGU("[%{public}d]: stackBottom: %{public}" PRIx64 ", stackTop: %{public}" PRIx64 "", __LINE__, - (uint64_t)stackBottom, (uint64_t)stackTop); - context_.pid = UNWIND_TYPE_LOCAL; - context_.regs = regs_; - context_.maps = maps_; - context_.stackCheck = false; - context_.stackBottom = stackBottom; - context_.stackTop = stackTop; - auto ret = Unwind(&context_, maxFrameNum, skipFrameNum); - LocalThreadContext::GetInstance().ReleaseThread(tid); - return ret; + return UnwindLocalByOtherTid(tid, false, maxFrameNum, skipFrameNum); #endif } @@ -1502,7 +1468,7 @@ bool Unwinder::Impl::UnwindLocalByOtherTid(const pid_t tid, bool fast, size_t ma } instance.SetStackRang(stackTop, stackBottom); } - bool isSuccess = instance.CollectThreadContext(tid); + bool isSuccess = instance.CollectThreadContext(tid, true); if (!isSuccess) { instance.ReleaseCollectThreadContext(); return false;