From ecd42427d7f7fa71b4d50388d5f087338a81f2ea Mon Sep 17 00:00:00 2001 From: "dongbosi@huawei.com" Date: Wed, 11 Dec 2024 16:34:16 +0800 Subject: [PATCH] fix the appfreeze not dump Signed-off-by: dongbosi@huawei.com --- .../dump_catcher/dfx_dump_catcher.cpp | 28 +++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/interfaces/innerkits/dump_catcher/dfx_dump_catcher.cpp b/interfaces/innerkits/dump_catcher/dfx_dump_catcher.cpp index 7733b5763..db3cf89d4 100644 --- a/interfaces/innerkits/dump_catcher/dfx_dump_catcher.cpp +++ b/interfaces/innerkits/dump_catcher/dfx_dump_catcher.cpp @@ -77,6 +77,22 @@ enum DfxDumpStatRes : int32_t { }; } +static bool IsLinuxKernel() +{ + static bool isLinux = [] { + std::string content; + LoadStringFromFile("/proc/version", content); + if (content.empty()) { + return true; + } + if (content.find("Linux") != std::string::npos) { + return true; + } + return false; + }(); + return isLinux; +} + bool DfxDumpCatcher::DoDumpCurrTid(const size_t skipFrameNum, std::string& msg, size_t maxFrameNums) { bool ret = false; @@ -242,11 +258,13 @@ bool DfxDumpCatcher::DumpCatch(int pid, int tid, std::string& msg, size_t maxFra DFXLOG_ERROR("%s :: dump_catch :: param error.", DFXDUMPCATCHER_TAG.c_str()); return ret; } - std::string statusPath = StringPrintf("/proc/%d/status", pid); - if (access(statusPath.c_str(), F_OK) != 0 && errno != EACCES) { - DFXLOG_ERROR("DumpCatch:: the pid(%d) process has exited, errno(%d)", pid, errno); - msg.append("Result: pid(" + std::to_string(pid) + ") process has exited.\n"); - return ret; + if (!IsLinuxKernel()) { + std::string statusPath = StringPrintf("/proc/%d/status", pid); + if (access(statusPath.c_str(), F_OK) != 0 && errno != EACCES) { + DFXLOG_ERROR("DumpCatch:: the pid(%d) process has exited, errno(%d)", pid, errno); + msg.append("Result: pid(" + std::to_string(pid) + ") process has exited.\n"); + return ret; + } } DfxEnableTraceDlsym(true); ElapsedTime counter; -- Gitee