From fbb32a2cad31efdaaefc8df57748c03f799fb950 Mon Sep 17 00:00:00 2001 From: yuhaoqiang Date: Sat, 6 Sep 2025 12:54:09 +0800 Subject: [PATCH 01/10] =?UTF-8?q?Revert=20"fuzz=5Ftest=E8=B6=8A=E7=95=8C?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E4=BF=AE=E5=A4=8D"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit d0cfaeabd3e44f173bfb9b516ef164bc2c51d8db. --- .../faultloggerdunwinder_fuzzer.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/test/fuzztest/faultloggerdunwinder_fuzzer/faultloggerdunwinder_fuzzer.cpp b/test/fuzztest/faultloggerdunwinder_fuzzer/faultloggerdunwinder_fuzzer.cpp index 51b52b6f5..ef847768c 100644 --- a/test/fuzztest/faultloggerdunwinder_fuzzer/faultloggerdunwinder_fuzzer.cpp +++ b/test/fuzztest/faultloggerdunwinder_fuzzer/faultloggerdunwinder_fuzzer.cpp @@ -195,21 +195,20 @@ void TestThreadContext(const uint8_t* data, size_t size) void TestDfxInstrStatistic(const uint8_t* data, size_t size) { - constexpr int maxStringLength = 50; struct TestData { uint32_t type; uint64_t val; uint64_t errInfo; - char soName[maxStringLength]; }; if (data == nullptr || size < sizeof(TestData)) { return; } auto testData = reinterpret_cast(data); + std::string soName(reinterpret_cast(data), FAULTLOGGER_FUZZTEST_MAX_STRING_LENGTH); + data += FAULTLOGGER_FUZZTEST_MAX_STRING_LENGTH; InstrStatisticType statisticType = (testData->type % 10) ? InstructionEntriesArmExidx : UnsupportedArmExidx; DfxInstrStatistic& statistic = DfxInstrStatistic::GetInstance(); - std::string testSoName(testData->soName, maxStringLength); - statistic.SetCurrentStatLib(testSoName); + statistic.SetCurrentStatLib(soName); statistic.AddInstrStatistic(statisticType, testData->val, testData->errInfo); std::vector> result; statistic.DumpInstrStatResult(result); -- Gitee From e5f2db48be84dbfdc59a28f4d2a0266304adca63 Mon Sep 17 00:00:00 2001 From: yuhaoqiang Date: Sat, 6 Sep 2025 12:54:09 +0800 Subject: [PATCH 02/10] Revert "others" This reverts commit f81fcaac5dd6e419d392e777353e9f5af125930e. --- .../faultloggerdunwinder_fuzzer/faultloggerdunwinder_fuzzer.cpp | 2 +- test/unittest/common/common_test.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/fuzztest/faultloggerdunwinder_fuzzer/faultloggerdunwinder_fuzzer.cpp b/test/fuzztest/faultloggerdunwinder_fuzzer/faultloggerdunwinder_fuzzer.cpp index ef847768c..2836e8e4d 100644 --- a/test/fuzztest/faultloggerdunwinder_fuzzer/faultloggerdunwinder_fuzzer.cpp +++ b/test/fuzztest/faultloggerdunwinder_fuzzer/faultloggerdunwinder_fuzzer.cpp @@ -28,7 +28,7 @@ namespace OHOS { namespace HiviewDFX { - +const int FAULTLOGGER_FUZZTEST_MAX_STRING_LENGTH = 50; struct TestArkFrameData { uintptr_t pc; uintptr_t fp; diff --git a/test/unittest/common/common_test.cpp b/test/unittest/common/common_test.cpp index 7e4a04d52..d473028d8 100644 --- a/test/unittest/common/common_test.cpp +++ b/test/unittest/common/common_test.cpp @@ -265,4 +265,4 @@ HWTEST_F(CommonTest, ROMBaselineTest001, TestSize.Level2) } } } // namespace HiviewDFX -} // namespace OHOS +} // namespace OHOS \ No newline at end of file -- Gitee From b6cbcf9badfce0c0de14571e8ded26ea79ff0950 Mon Sep 17 00:00:00 2001 From: yuhaoqiang Date: Sat, 6 Sep 2025 12:54:10 +0800 Subject: [PATCH 03/10] =?UTF-8?q?Revert=20"fuzz=5Ftest=E8=B6=8A=E7=95=8C?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E4=BF=AE=E5=A4=8D"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 922c503f6d1064e6acff768a8347a704c37ff8d6. --- .../faultloggerddumpcatcher_fuzzer.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/fuzztest/faultloggerddumpcatcher_fuzzer/faultloggerddumpcatcher_fuzzer.cpp b/test/fuzztest/faultloggerddumpcatcher_fuzzer/faultloggerddumpcatcher_fuzzer.cpp index b97f752b2..c03c9f354 100644 --- a/test/fuzztest/faultloggerddumpcatcher_fuzzer/faultloggerddumpcatcher_fuzzer.cpp +++ b/test/fuzztest/faultloggerddumpcatcher_fuzzer/faultloggerddumpcatcher_fuzzer.cpp @@ -38,8 +38,7 @@ void DumpStackTraceTest(const uint8_t* data, size_t size) std::string processdumpCmd = "dumpcatcher -p " + std::to_string(testData->pid) + " -t " + std::to_string(testData->tid); system(processdumpCmd.c_str()); - std::string processdumpInvalidCmd = std::string("dumpcatcher -") + - std::string(testData->option, FAULTLOGGER_FUZZTEST_MAX_STRING_LENGTH) + " -p " + + std::string processdumpInvalidCmd = std::string("dumpcatcher -") + std::string(testData->option) + " -p " + std::to_string(testData->pid) + " -t " + std::to_string(testData->tid); system(processdumpInvalidCmd.c_str()); } -- Gitee From fc0b1bda3787a07d1310d18a9aace7fe6b588c1d Mon Sep 17 00:00:00 2001 From: yuhaoqiang Date: Sat, 6 Sep 2025 12:54:10 +0800 Subject: [PATCH 04/10] Revert "Fix the issue of unwinder.host compilation failure" This reverts commit 1458cc05097747e01cdebf325a69f0eab8b5d47d. --- common/cutil/dfx_cutil.c | 16 +++++++++++++ common/cutil/dfx_cutil.h | 2 ++ common/dfxutil/smart_fd.h | 4 ---- interfaces/innerkits/unwinder/BUILD.gn | 3 --- test/unittest/common/common_cutil_test.cpp | 28 ++++++++++++++++++++++ 5 files changed, 46 insertions(+), 7 deletions(-) diff --git a/common/cutil/dfx_cutil.c b/common/cutil/dfx_cutil.c index 14b1be159..3a36b13db 100644 --- a/common/cutil/dfx_cutil.c +++ b/common/cutil/dfx_cutil.c @@ -86,6 +86,22 @@ uint64_t GetTimeMilliseconds(void) (((uint64_t)ts.tv_nsec) / NUMBER_ONE_MILLION); // 1000000 : nanosecond to millisecond convert ratio } +bool TrimAndDupStr(const char* src, char* dst) +{ + if (src == NULL || dst == NULL) { + return false; + } + + for (char ch = *src; ch != '\0' && ch != '\n';) { + if (ch != ' ') { + *dst++ = ch; + } + ch = *++src; + } + *dst = '\0'; + return true; +} + uint64_t GetAbsTimeMilliSecondsCInterce(void) { struct timespec ts; diff --git a/common/cutil/dfx_cutil.h b/common/cutil/dfx_cutil.h index c2e5325d8..8863644fa 100644 --- a/common/cutil/dfx_cutil.h +++ b/common/cutil/dfx_cutil.h @@ -34,6 +34,8 @@ AT_SYMBOL_HIDDEN bool GetProcessName(char* buffer, size_t bufferSz); AT_SYMBOL_HIDDEN uint64_t GetTimeMilliseconds(void); +AT_SYMBOL_HIDDEN bool TrimAndDupStr(const char* src, char* dst); + AT_SYMBOL_HIDDEN uint64_t GetAbsTimeMilliSecondsCInterce(void); AT_SYMBOL_HIDDEN void ParseSiValue(const siginfo_t* si, uint64_t* endTime, int* tid); diff --git a/common/dfxutil/smart_fd.h b/common/dfxutil/smart_fd.h index 6eb414ae5..f24d67f43 100644 --- a/common/dfxutil/smart_fd.h +++ b/common/dfxutil/smart_fd.h @@ -27,11 +27,9 @@ public: SmartFd() = default; explicit SmartFd(int fd, bool fdsan = true) : fd_(fd), fdsan_(fdsan) { -#ifndef is_host if (fd_ >= 0 && fdsan_) { fdsan_exchange_owner_tag(fd_, 0, fdsan_create_owner_tag(FDSAN_OWNER_TYPE_FILE, DFX_FDSAN_DOMAIN)); } -#endif // is_host } ~SmartFd() @@ -86,12 +84,10 @@ private: if (fd_ < 0) { return; } -#ifndef is_host if (fdsan_) { fdsan_close_with_tag(fd_, fdsan_create_owner_tag(FDSAN_OWNER_TYPE_FILE, DFX_FDSAN_DOMAIN)); return; } -#endif // is_host close(fd_); } diff --git a/interfaces/innerkits/unwinder/BUILD.gn b/interfaces/innerkits/unwinder/BUILD.gn index 12a6da598..fa4028c2f 100644 --- a/interfaces/innerkits/unwinder/BUILD.gn +++ b/interfaces/innerkits/unwinder/BUILD.gn @@ -333,9 +333,6 @@ if (defined(ohos_lite)) { "is_emulator=${is_emulator}", "DFX_NO_PRINT_LOG", ] - if (is_linux || is_mingw) { - defines += [ "is_host" ] - } } ohos_static_library("unwinder_host") { diff --git a/test/unittest/common/common_cutil_test.cpp b/test/unittest/common/common_cutil_test.cpp index 3c24122bf..ec0f72228 100644 --- a/test/unittest/common/common_cutil_test.cpp +++ b/test/unittest/common/common_cutil_test.cpp @@ -78,6 +78,34 @@ HWTEST_F(CommonCutilTest, DfxCutilTest003, TestSize.Level2) GTEST_LOG_(INFO) << "DfxCutilTest003: end."; } +/** + * @tc.name: DfxCutilTest004 + * @tc.desc: test cutil functions TrimAndDupStr + * @tc.type: FUNC + */ +HWTEST_F(CommonCutilTest, DfxCutilTest004, TestSize.Level2) +{ + GTEST_LOG_(INFO) << "DfxCutilTest004: start."; + ASSERT_FALSE(TrimAndDupStr(nullptr, nullptr)); + GTEST_LOG_(INFO) << "DfxCutilTest004: end."; +} + +/** + * @tc.name: DfxCutilTest005 + * @tc.desc: test cutil functions TrimAndDupStr + * @tc.type: FUNC + */ +HWTEST_F(CommonCutilTest, DfxCutilTest005, TestSize.Level2) +{ + GTEST_LOG_(INFO) << "DfxCutilTest005: start."; + const char src[] = "ab cd \n ef"; + char dst[11] = {0}; // 11: The length is consistent with the src[] array + ASSERT_TRUE(TrimAndDupStr(src, dst)); + GTEST_LOG_(INFO) << "dst:" << dst; + ASSERT_EQ(strncmp(dst, "abcd", 5), 0); // 5:length of "abcd" + GTEST_LOG_(INFO) << "DfxCutilTest005: end."; +} + /** * @tc.name: TraceTest001 * @tc.desc: test Trace functions DfxStartTraceDlsym -- Gitee From 70b90cd723fbd19bf6a80f13435de16a14ef1e53 Mon Sep 17 00:00:00 2001 From: yuhaoqiang Date: Sat, 6 Sep 2025 12:54:10 +0800 Subject: [PATCH 05/10] Revert "fix code" This reverts commit 19e54f5ed958b95aa31ee3c05a20367afd4161e3. --- .../innerkits/dump_catcher/lite_perf.cpp | 8 ++--- .../formatter/dfx_json_formatter.cpp | 32 +++++++------------ .../signal_handler/dfx_dumprequest.c | 2 +- tools/process_dump/lperf/lperf_events.cpp | 2 +- 4 files changed, 18 insertions(+), 26 deletions(-) diff --git a/interfaces/innerkits/dump_catcher/lite_perf.cpp b/interfaces/innerkits/dump_catcher/lite_perf.cpp index c1bfd55c1..0b89c8ff1 100644 --- a/interfaces/innerkits/dump_catcher/lite_perf.cpp +++ b/interfaces/innerkits/dump_catcher/lite_perf.cpp @@ -300,9 +300,9 @@ int LitePerf::Impl::ExecDump(const std::vector& tids, int freq, int duratio } pid_t pid = 0; - pid = fork(); + pid = vfork(); if (pid < 0) { - DFXLOGE("Failed to fork."); + DFXLOGE("Failed to vfork."); return -1; } if (pid == 0) { @@ -312,9 +312,9 @@ int LitePerf::Impl::ExecDump(const std::vector& tids, int freq, int duratio _exit(-1); } - pid_t dumpPid = fork(); + pid_t dumpPid = vfork(); if (dumpPid < 0) { - DFXLOGE("Failed to fork."); + DFXLOGE("Failed to vfork."); _exit(-1); } if (dumpPid == 0) { diff --git a/interfaces/innerkits/formatter/dfx_json_formatter.cpp b/interfaces/innerkits/formatter/dfx_json_formatter.cpp index 477d73388..677c5ce8c 100644 --- a/interfaces/innerkits/formatter/dfx_json_formatter.cpp +++ b/interfaces/innerkits/formatter/dfx_json_formatter.cpp @@ -27,14 +27,6 @@ namespace HiviewDFX { #ifndef is_ohos_lite namespace { const int FRAME_BUF_LEN = 1024; -static std::string JsonAsString(const Json::Value& val) -{ - if (val.isConvertibleTo(Json::stringValue)) { - return val.asString(); - } - return ""; -} - static bool FormatJsFrame(const Json::Value& frames, const uint32_t& frameIdx, std::string& outStr) { const int jsIdxLen = 10; @@ -44,18 +36,18 @@ static bool FormatJsFrame(const Json::Value& frames, const uint32_t& frameIdx, s return false; } outStr = std::string(buf); - std::string symbol = JsonAsString(frames[frameIdx]["symbol"]); + std::string symbol = frames[frameIdx]["symbol"].asString(); if (!symbol.empty()) { outStr.append(" " + symbol); } - std::string packageName = JsonAsString(frames[frameIdx]["packageName"]); + std::string packageName = frames[frameIdx]["packageName"].asString(); if (!packageName.empty()) { outStr.append(" " + packageName); } - std::string file = JsonAsString(frames[frameIdx]["file"]); + std::string file = frames[frameIdx]["file"].asString(); if (!file.empty()) { - std::string line = JsonAsString(frames[frameIdx]["line"]); - std::string column = JsonAsString(frames[frameIdx]["column"]); + std::string line = frames[frameIdx]["line"].asString(); + std::string column = frames[frameIdx]["column"].asString(); outStr.append(" (" + file + ":" + line + ":" + column + ")"); } return true; @@ -65,11 +57,11 @@ static bool FormatNativeFrame(const Json::Value& frames, const uint32_t& frameId { char buf[FRAME_BUF_LEN] = {0}; char format[] = "#%02u pc %s %s"; - std::string buildId = JsonAsString(frames[frameIdx]["buildId"]); - std::string file = JsonAsString(frames[frameIdx]["file"]); - std::string offset = JsonAsString(frames[frameIdx]["offset"]); - std::string pc = JsonAsString(frames[frameIdx]["pc"]); - std::string symbol = JsonAsString(frames[frameIdx]["symbol"]); + std::string buildId = frames[frameIdx]["buildId"].asString(); + std::string file = frames[frameIdx]["file"].asString(); + std::string offset = frames[frameIdx]["offset"].asString(); + std::string pc = frames[frameIdx]["pc"].asString(); + std::string symbol = frames[frameIdx]["symbol"].asString(); if (snprintf_s(buf, sizeof(buf), sizeof(buf) - 1, format, frameIdx, pc.c_str(), file.empty() ? "Unknown" : file.c_str()) <= 0) { return false; @@ -103,7 +95,7 @@ bool DfxJsonFormatter::FormatJsonStack(const std::string& jsonStack, std::string Json::Value thread = threads[i]; if (thread["tid"].isConvertibleTo(Json::stringValue) && thread["thread_name"].isConvertibleTo(Json::stringValue)) { - ss += "Tid:" + JsonAsString(thread["tid"]) + ", Name:" + JsonAsString(thread["thread_name"]) + "\n"; + ss += "Tid:" + thread["tid"].asString() + ", Name:" + thread["thread_name"].asString() + "\n"; } if (!thread.isMember("frames") || !thread["frames"].isArray()) { continue; @@ -116,7 +108,7 @@ bool DfxJsonFormatter::FormatJsonStack(const std::string& jsonStack, std::string for (uint32_t j = 0; j < frames.size(); ++j) { std::string frameStr = ""; bool formatStatus = false; - if (JsonAsString(frames[j]["line"]).empty()) { + if (frames[j]["line"].asString().empty()) { formatStatus = FormatNativeFrame(frames, j, frameStr); } else { formatStatus = FormatJsFrame(frames, j, frameStr); diff --git a/interfaces/innerkits/signal_handler/dfx_dumprequest.c b/interfaces/innerkits/signal_handler/dfx_dumprequest.c index 88e040a02..ee0e2aeb5 100644 --- a/interfaces/innerkits/signal_handler/dfx_dumprequest.c +++ b/interfaces/innerkits/signal_handler/dfx_dumprequest.c @@ -430,7 +430,7 @@ static bool StartProcessdump(void) static bool StartVMProcessUnwind(void) { - uint64_t startTime = GetAbsTimeMilliSecondsCInterce(); + uint32_t startTime = GetAbsTimeMilliSecondsCInterce(); pid_t pid = ForkBySyscall(); if (pid < 0) { DFXLOGE("Failed to fork vm process(%{public}d)", errno); diff --git a/tools/process_dump/lperf/lperf_events.cpp b/tools/process_dump/lperf/lperf_events.cpp index ea85e4b10..d10cf989b 100644 --- a/tools/process_dump/lperf/lperf_events.cpp +++ b/tools/process_dump/lperf/lperf_events.cpp @@ -178,7 +178,7 @@ void LperfEvents::GetRecordFieldFromMmap(MmapFd& mmap, void* dest, size_t destSi if (memcpy_s(dest, destSize, mmap.buf + pos, copySize) != 0) { DFXLOGE("memcpy_s failed. size %{public}zd", copySize); } - if (copySize < size && destSize > copySize) { + if (copySize < size) { size -= copySize; if (memcpy_s(static_cast(dest) + copySize, destSize - copySize, mmap.buf, size) != 0) { DFXLOGE("memcpy_s mmap.buf to dest failed. size %{public}zd", size); -- Gitee From 3a419a4ea76e332f37f13ba9fa8bb1ff5af434a3 Mon Sep 17 00:00:00 2001 From: yuhaoqiang Date: Sat, 6 Sep 2025 12:54:10 +0800 Subject: [PATCH 06/10] Revert "update interfaces/innerkits/formatter/dfx_json_formatter.cpp." This reverts commit 995e807cbf8298a351a03560a4b669eefe923e65. --- .../formatter/dfx_json_formatter.cpp | 41 +++++++++---------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/interfaces/innerkits/formatter/dfx_json_formatter.cpp b/interfaces/innerkits/formatter/dfx_json_formatter.cpp index 677c5ce8c..f438cf718 100644 --- a/interfaces/innerkits/formatter/dfx_json_formatter.cpp +++ b/interfaces/innerkits/formatter/dfx_json_formatter.cpp @@ -97,28 +97,27 @@ bool DfxJsonFormatter::FormatJsonStack(const std::string& jsonStack, std::string thread["thread_name"].isConvertibleTo(Json::stringValue)) { ss += "Tid:" + thread["tid"].asString() + ", Name:" + thread["thread_name"].asString() + "\n"; } - if (!thread.isMember("frames") || !thread["frames"].isArray()) { - continue; - } - const Json::Value frames = thread["frames"]; - constexpr int maxFrameNum = 1000; - if (frames.size() > maxFrameNum) { - continue; - } - for (uint32_t j = 0; j < frames.size(); ++j) { - std::string frameStr = ""; - bool formatStatus = false; - if (frames[j]["line"].asString().empty()) { - formatStatus = FormatNativeFrame(frames, j, frameStr); - } else { - formatStatus = FormatJsFrame(frames, j, frameStr); + if (thread.isMember("frames") && thread["frames"].isArray()) { + const Json::Value frames = thread["frames"]; + constexpr int maxFrameNum = 1000; + if (frames.size() > maxFrameNum) { + continue; } - if (formatStatus) { - ss += frameStr + "\n"; - } else { - // Shall we try to print more information? - outStackStr.append("Frame info is illegal."); - return false; + for (uint32_t j = 0; j < frames.size(); ++j) { + std::string frameStr = ""; + bool formatStatus = false; + if (frames[j]["line"].asString().empty()) { + formatStatus = FormatNativeFrame(frames, j, frameStr); + } else { + formatStatus = FormatJsFrame(frames, j, frameStr); + } + if (formatStatus) { + ss += frameStr + "\n"; + } else { + // Shall we try to print more information? + outStackStr.append("Frame info is illegal."); + return false; + } } } -- Gitee From 28f367cb684c8d983d0ed4e8e770f2bd0573e4a5 Mon Sep 17 00:00:00 2001 From: yuhaoqiang Date: Sat, 6 Sep 2025 12:54:10 +0800 Subject: [PATCH 07/10] Revert "fix:FormatJsonStack" This reverts commit c7f6cd5b7b8e1cc816bce089aedee7984e60644e. --- .../formatter/dfx_json_formatter.cpp | 41 +++++++------------ 1 file changed, 15 insertions(+), 26 deletions(-) diff --git a/interfaces/innerkits/formatter/dfx_json_formatter.cpp b/interfaces/innerkits/formatter/dfx_json_formatter.cpp index f438cf718..ac349891b 100644 --- a/interfaces/innerkits/formatter/dfx_json_formatter.cpp +++ b/interfaces/innerkits/formatter/dfx_json_formatter.cpp @@ -85,11 +85,7 @@ bool DfxJsonFormatter::FormatJsonStack(const std::string& jsonStack, std::string outStackStr.append("Failed to parse json stack info."); return false; } - constexpr int maxThreadCount = 10000; - if (threads.size() > maxThreadCount) { - outStackStr.append("Thread count exceeds limit(10000)."); - return false; - } + for (uint32_t i = 0; i < threads.size(); ++i) { std::string ss; Json::Value thread = threads[i]; @@ -97,30 +93,23 @@ bool DfxJsonFormatter::FormatJsonStack(const std::string& jsonStack, std::string thread["thread_name"].isConvertibleTo(Json::stringValue)) { ss += "Tid:" + thread["tid"].asString() + ", Name:" + thread["thread_name"].asString() + "\n"; } - if (thread.isMember("frames") && thread["frames"].isArray()) { - const Json::Value frames = thread["frames"]; - constexpr int maxFrameNum = 1000; - if (frames.size() > maxFrameNum) { - continue; + const Json::Value frames = thread["frames"]; + for (uint32_t j = 0; j < frames.size(); ++j) { + std::string frameStr = ""; + bool formatStatus = false; + if (frames[j]["line"].asString().empty()) { + formatStatus = FormatNativeFrame(frames, j, frameStr); + } else { + formatStatus = FormatJsFrame(frames, j, frameStr); } - for (uint32_t j = 0; j < frames.size(); ++j) { - std::string frameStr = ""; - bool formatStatus = false; - if (frames[j]["line"].asString().empty()) { - formatStatus = FormatNativeFrame(frames, j, frameStr); - } else { - formatStatus = FormatJsFrame(frames, j, frameStr); - } - if (formatStatus) { - ss += frameStr + "\n"; - } else { - // Shall we try to print more information? - outStackStr.append("Frame info is illegal."); - return false; - } + if (formatStatus) { + ss += frameStr + "\n"; + } else { + // Shall we try to print more information? + outStackStr.append("Frame info is illegal."); + return false; } } - outStackStr.append(ss); } return true; -- Gitee From 9a00a9095622b9654de5d54d76cc1da724e3e7f0 Mon Sep 17 00:00:00 2001 From: yuhaoqiang Date: Sat, 6 Sep 2025 12:54:10 +0800 Subject: [PATCH 08/10] Revert "fix:SetIsJitCrashFlag" This reverts commit a913d242bcfa8c0d59eac220851f57a3146d696e. --- test/unittest/process_dump/thread_dump_info_test.cpp | 12 ++++++------ tools/process_dump/decorative_dump_info.h | 6 +++--- tools/process_dump/dump_info.h | 2 +- tools/process_dump/key_thread_dump_info.cpp | 4 ++-- tools/process_dump/key_thread_dump_info.h | 2 +- tools/process_dump/other_thread_dump_info.cpp | 4 ++-- tools/process_dump/process_dumper.cpp | 2 +- 7 files changed, 16 insertions(+), 16 deletions(-) diff --git a/test/unittest/process_dump/thread_dump_info_test.cpp b/test/unittest/process_dump/thread_dump_info_test.cpp index 3aba65807..a5e09de61 100644 --- a/test/unittest/process_dump/thread_dump_info_test.cpp +++ b/test/unittest/process_dump/thread_dump_info_test.cpp @@ -110,7 +110,7 @@ HWTEST_F(ThreadDumpInfoTest, ThreadDumpInfoTest001, TestSize.Level2) Unwinder unwinder(pid, nsPid, request.type == ProcessDumpType::DUMP_TYPE_CPP_CRASH); unwinder.EnableFillFrames(false); KeyThreadDumpInfo dumpInfo; - EXPECT_GT(dumpInfo.UnwindStack(process, request, unwinder), 0); + EXPECT_GT(dumpInfo.UnwindStack(process, unwinder), 0); dumpInfo.Symbolize(process, unwinder); dumpInfo.Print(process, request, unwinder); std::vector keyWords = { @@ -167,7 +167,7 @@ HWTEST_F(ThreadDumpInfoTest, ThreadDumpInfoTest002, TestSize.Level2) Unwinder unwinder(pid, nsPid, request.type == ProcessDumpType::DUMP_TYPE_CPP_CRASH); unwinder.EnableFillFrames(false); KeyThreadDumpInfo dumpInfo; - EXPECT_GT(dumpInfo.UnwindStack(process, request, unwinder), 0); + EXPECT_GT(dumpInfo.UnwindStack(process, unwinder), 0); dumpInfo.Symbolize(process, unwinder); dumpInfo.Print(process, request, unwinder); std::vector keyWords = { @@ -215,7 +215,7 @@ HWTEST_F(ThreadDumpInfoTest, ThreadDumpInfoTest003, TestSize.Level2) Unwinder unwinder(pid, nsPid, request.type == ProcessDumpType::DUMP_TYPE_CPP_CRASH); unwinder.EnableFillFrames(false); KeyThreadDumpInfo dumpInfo; - EXPECT_GT(dumpInfo.UnwindStack(process, request, unwinder), 0); + EXPECT_GT(dumpInfo.UnwindStack(process, unwinder), 0); dumpInfo.Symbolize(process, unwinder); dumpInfo.Print(process, request, unwinder); std::vector keyWords = { @@ -257,7 +257,7 @@ HWTEST_F(ThreadDumpInfoTest, ThreadDumpInfoTest004, TestSize.Level2) Unwinder unwinder(pid, nsPid, request.type == ProcessDumpType::DUMP_TYPE_CPP_CRASH); unwinder.EnableFillFrames(false); OtherThreadDumpInfo dumpInfo; - EXPECT_GT(dumpInfo.UnwindStack(process, request, unwinder), 0); + EXPECT_GT(dumpInfo.UnwindStack(process, unwinder), 0); dumpInfo.Symbolize(process, unwinder); dumpInfo.Print(process, request, unwinder); std::vector keyWords = { @@ -300,7 +300,7 @@ HWTEST_F(ThreadDumpInfoTest, ThreadDumpInfoTest005, TestSize.Level2) Unwinder unwinder(pid, nsPid, request.type == ProcessDumpType::DUMP_TYPE_CPP_CRASH); unwinder.EnableFillFrames(false); OtherThreadDumpInfo dumpInfo; - EXPECT_GT(dumpInfo.UnwindStack(process, request, unwinder), 0); + EXPECT_GT(dumpInfo.UnwindStack(process, unwinder), 0); dumpInfo.Symbolize(process, unwinder); dumpInfo.Print(process, request, unwinder); std::vector keyWords = { @@ -345,7 +345,7 @@ HWTEST_F(ThreadDumpInfoTest, ThreadDumpInfoTest006, TestSize.Level2) std::shared_ptr keyThreadDumpInfo = std::make_shared(); OtherThreadDumpInfo dumpInfo; dumpInfo.SetDumpInfo(keyThreadDumpInfo); - EXPECT_GT(dumpInfo.UnwindStack(process, request, unwinder), threadCount); + EXPECT_GT(dumpInfo.UnwindStack(process, unwinder), threadCount); dumpInfo.Symbolize(process, unwinder); dumpInfo.Print(process, request, unwinder); std::vector keyWords = { diff --git a/tools/process_dump/decorative_dump_info.h b/tools/process_dump/decorative_dump_info.h index fd7737acc..769832086 100644 --- a/tools/process_dump/decorative_dump_info.h +++ b/tools/process_dump/decorative_dump_info.h @@ -50,10 +50,10 @@ public: } } - int UnwindStack(DfxProcess& process, const ProcessDumpRequest& request, Unwinder& unwinder) override + int UnwindStack(DfxProcess& process, Unwinder& unwinder) override { if (dumpInfo_ != nullptr) { - return dumpInfo_->UnwindStack(process, request, unwinder); + return dumpInfo_->UnwindStack(process, unwinder); } return 0; } @@ -113,7 +113,7 @@ private: class OtherThreadDumpInfo : public DecorativeDumpInfo { public: - int UnwindStack(DfxProcess& process, const ProcessDumpRequest& request, Unwinder& unwinder) override; + int UnwindStack(DfxProcess& process, Unwinder& unwinder) override; void Print(DfxProcess& process, const ProcessDumpRequest& request, Unwinder& unwinder) override; void Symbolize(DfxProcess& process, Unwinder& unwinder) override; static std::shared_ptr CreateInstance() { return std::make_shared(); } diff --git a/tools/process_dump/dump_info.h b/tools/process_dump/dump_info.h index 28935c9c1..cee0b044f 100644 --- a/tools/process_dump/dump_info.h +++ b/tools/process_dump/dump_info.h @@ -31,7 +31,7 @@ public: virtual ~DumpInfo() {} virtual void SetDumpInfo(const std::shared_ptr& dumpInfo) {} virtual void Print(DfxProcess& process, const ProcessDumpRequest& request, Unwinder& unwinder) = 0; - virtual int UnwindStack(DfxProcess& process, const ProcessDumpRequest& request, Unwinder& unwinder) = 0; + virtual int UnwindStack(DfxProcess& process, Unwinder& unwinder) = 0; virtual void Symbolize(DfxProcess& process, Unwinder& unwinder) = 0; virtual void GetMemoryValues(std::set& memoryValues) {}; }; diff --git a/tools/process_dump/key_thread_dump_info.cpp b/tools/process_dump/key_thread_dump_info.cpp index a76a339a4..82b5df759 100644 --- a/tools/process_dump/key_thread_dump_info.cpp +++ b/tools/process_dump/key_thread_dump_info.cpp @@ -107,7 +107,7 @@ void KeyThreadDumpInfo::Print(DfxProcess& process, const ProcessDumpRequest& req DfxBufferWriter::GetInstance().AppendBriefDumpInfo(dumpInfo); } -int KeyThreadDumpInfo::UnwindStack(DfxProcess& process, const ProcessDumpRequest& request, Unwinder& unwinder) +int KeyThreadDumpInfo::UnwindStack(DfxProcess& process, Unwinder& unwinder) { DFXLOGI("unwind key thread dump start"); int result = 0; @@ -119,7 +119,7 @@ int KeyThreadDumpInfo::UnwindStack(DfxProcess& process, const ProcessDumpRequest DFXLOGW("vm pid is null, can not unwind key thread!"); return result; } - unwinder.SetIsJitCrashFlag(request.type == ProcessDumpType::DUMP_TYPE_CPP_CRASH); + if (process.GetKeyThread()->GetThreadRegs() != nullptr) { result = GetKeyThreadStack(process, unwinder) ? 1 : 0; } else { diff --git a/tools/process_dump/key_thread_dump_info.h b/tools/process_dump/key_thread_dump_info.h index f2ef6f9c9..4dd716a1c 100644 --- a/tools/process_dump/key_thread_dump_info.h +++ b/tools/process_dump/key_thread_dump_info.h @@ -28,7 +28,7 @@ namespace HiviewDFX { class KeyThreadDumpInfo : public DumpInfo { public: void Print(DfxProcess& process, const ProcessDumpRequest& request, Unwinder& unwinder) override; - int UnwindStack(DfxProcess& process, const ProcessDumpRequest& request, Unwinder& unwinder) override; + int UnwindStack(DfxProcess& process, Unwinder& unwinder) override; void Symbolize(DfxProcess& process, Unwinder& unwinder) override; static std::shared_ptr CreateInstance() { return std::make_shared(); } private: diff --git a/tools/process_dump/other_thread_dump_info.cpp b/tools/process_dump/other_thread_dump_info.cpp index 1acd9396a..1bb180229 100644 --- a/tools/process_dump/other_thread_dump_info.cpp +++ b/tools/process_dump/other_thread_dump_info.cpp @@ -23,9 +23,9 @@ namespace OHOS { namespace HiviewDFX { REGISTER_DUMP_INFO_CLASS(OtherThreadDumpInfo); -int OtherThreadDumpInfo::UnwindStack(DfxProcess& process, const ProcessDumpRequest& request, Unwinder& unwinder) +int OtherThreadDumpInfo::UnwindStack(DfxProcess& process, Unwinder& unwinder) { - int unwindSuccessCnt = DecorativeDumpInfo::UnwindStack(process, request, unwinder); + int unwindSuccessCnt = DecorativeDumpInfo::UnwindStack(process, unwinder); DFXLOGI("unwind other thread dump start"); auto pid = process.GetVmPid(); if (pid == 0) { diff --git a/tools/process_dump/process_dumper.cpp b/tools/process_dump/process_dumper.cpp index ab6fdaea1..f22eb02cb 100644 --- a/tools/process_dump/process_dumper.cpp +++ b/tools/process_dump/process_dumper.cpp @@ -437,7 +437,7 @@ void ProcessDumper::PrintDumpInfo(int& dumpRes) prevDumpInfo = dumpInfo; } if (threadDumpInfo != nullptr) { - int unwindSuccessCnt = threadDumpInfo->UnwindStack(*process_, request_, *unwinder_); + int unwindSuccessCnt = threadDumpInfo->UnwindStack(*process_, *unwinder_); DFXLOGI("unwind success thread count(%{public}d)", unwindSuccessCnt); if (unwindSuccessCnt > 0) { dumpRes = ParseSymbols(threadDumpInfo); -- Gitee From 7a270154a7f45df52eca3b8cc19658804673e3c7 Mon Sep 17 00:00:00 2001 From: yuhaoqiang Date: Sat, 6 Sep 2025 12:54:10 +0800 Subject: [PATCH 09/10] =?UTF-8?q?Revert=20"=E5=86=85=E6=A0=B8=E8=BD=AC?= =?UTF-8?q?=E5=82=A8=E8=A7=A3=E6=9E=90=E5=A4=B1=E8=B4=A5=E5=9C=BA=E6=99=AF?= =?UTF-8?q?=EF=BC=8C=E4=B8=8A=E6=8A=A5=E4=BA=8B=E4=BB=B6"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 689eba75636bdbaea6a990efe0e366cad96ee697. --- .../snapshot/i_kernel_snapshot_reporter.h | 2 +- services/snapshot/kernel_snapshot_manager.cpp | 3 - .../kernel_snapshot_processor_impl.cpp | 2 +- .../snapshot/kernel_snapshot_reporter.cpp | 58 ++----------------- services/snapshot/kernel_snapshot_reporter.h | 4 +- .../kernel_snapshot/kernel_snapshot_test.cpp | 49 ++-------------- 6 files changed, 13 insertions(+), 105 deletions(-) diff --git a/services/snapshot/i_kernel_snapshot_reporter.h b/services/snapshot/i_kernel_snapshot_reporter.h index ab414283a..78efcca29 100644 --- a/services/snapshot/i_kernel_snapshot_reporter.h +++ b/services/snapshot/i_kernel_snapshot_reporter.h @@ -22,7 +22,7 @@ namespace OHOS { namespace HiviewDFX { class IKernelSnapshotReporter { public: - virtual void ReportEvents(std::vector& outputs, const std::string& snapshot) = 0; + virtual void ReportEvents(std::vector& outputs) = 0; virtual ~IKernelSnapshotReporter() = default; }; } // namespace HiviewDFX diff --git a/services/snapshot/kernel_snapshot_manager.cpp b/services/snapshot/kernel_snapshot_manager.cpp index 70828cc0f..6b09d3ca3 100644 --- a/services/snapshot/kernel_snapshot_manager.cpp +++ b/services/snapshot/kernel_snapshot_manager.cpp @@ -89,9 +89,6 @@ void KernelSnapshotManager::MonitorCrashKernelSnapshot() break; } std::string snapshotCont = ReadKernelSnapshot(); - if (snapshotCont.empty()) { - continue; - } processor->Process(snapshotCont); } } diff --git a/services/snapshot/kernel_snapshot_processor_impl.cpp b/services/snapshot/kernel_snapshot_processor_impl.cpp index c11de4350..e8b973c7b 100644 --- a/services/snapshot/kernel_snapshot_processor_impl.cpp +++ b/services/snapshot/kernel_snapshot_processor_impl.cpp @@ -37,7 +37,7 @@ void KernelSnapshotProcessorImpl::Process(const std::string& snapshot) DFXLOGE("reporter is null"); return; } - reporter_->ReportEvents(crashMaps, snapshot); + reporter_->ReportEvents(crashMaps); } } // namespace HiviewDFX } // namespace OHOS diff --git a/services/snapshot/kernel_snapshot_reporter.cpp b/services/snapshot/kernel_snapshot_reporter.cpp index b16be5474..c66195884 100644 --- a/services/snapshot/kernel_snapshot_reporter.cpp +++ b/services/snapshot/kernel_snapshot_reporter.cpp @@ -20,28 +20,25 @@ #include "dfx_log.h" #ifndef HISYSEVENT_DISABLE #include "hisysevent.h" -#include "hisysevent_c.h" #endif #include "kernel_snapshot_content_builder.h" -#include "dfx_util.h" namespace OHOS { namespace HiviewDFX { -void KernelSnapshotReporter::ReportEvents(std::vector& outputs, const std::string& snapshot) +void KernelSnapshotReporter::ReportEvents(std::vector& outputs) { for (auto& output : outputs) { - if (output[CrashSection::UID].empty()) { - DFXLOGE("msg format fail, report raw msg"); - ReportRawMsg(snapshot); - return; - } ReportCrashNoLogEvent(output); } } bool KernelSnapshotReporter::ReportCrashNoLogEvent(CrashMap& output) { + if (output[CrashSection::UID].empty()) { + DFXLOGE("uid is empty, not report"); + return false; + } #ifndef HISYSEVENT_DISABLE int32_t uid = static_cast(strtol(output[CrashSection::UID].c_str(), nullptr, DECIMAL_BASE)); int32_t pid = static_cast(strtol(output[CrashSection::PID].c_str(), nullptr, DECIMAL_BASE)); @@ -58,50 +55,7 @@ bool KernelSnapshotReporter::ReportCrashNoLogEvent(CrashMap& output) "PROCESS_NAME", output[CrashSection::PROCESS_NAME], "HAPPEN_TIME", timeStamp, "SUMMARY", KernelSnapshotContentBuilder(output).GenerateSummary()); - DFXLOGI("Report pid %{public}d kernel snapshot complate event ret %{public}d", pid, ret); - return ret == 0; -#else - DFXLOGI("Not supported for kernel snapshot report."); - return true; -#endif -} - -int32_t KernelSnapshotReporter::GetSnapshotPid(const std::string& content) -{ - std::string pidKey = "pid="; - auto pos = content.find(pidKey); - if (pos == std::string::npos) { - return 0; - } - auto end = content.find_first_of(')', pos); - if (end == std::string::npos) { - return 0; - } - pos += pidKey.size(); - std::string pidStr = content.substr(pos, end - pos); - auto pid = static_cast(strtol(pidStr.c_str(), nullptr, 10)); - if (errno == ERANGE) { - return 0; - } - return pid; -} - -bool KernelSnapshotReporter::ReportRawMsg(const std::string& content) -{ - if (content.empty()) { - return false; - } -#ifndef HISYSEVENT_DISABLE - int32_t pid = GetSnapshotPid(content); - char procName[] = "encrypt_snapshot_proc"; - HiSysEventParam params[] = { - {.name = "PID", .t = HISYSEVENT_UINT32, .v = { .ui32 = pid}, .arraySize = 0}, - {.name = "PROCESS_NAME", .t = HISYSEVENT_STRING, .v = {.s = procName}, .arraySize = 0}, - {.name = "HAPPEN_TIME", .t = HISYSEVENT_UINT64, .v = {.ui64 = GetTimeMilliSeconds()}, .arraySize = 0}, - }; - int ret = OH_HiSysEvent_Write("RELIABILITY", "CPP_CRASH_NO_LOG", - HISYSEVENT_FAULT, params, sizeof(params) / sizeof(params[0])); - DFXLOGI("Report pid %{public}d kernel snapshot raw event ret %{public}d", pid, ret); + DFXLOGI("Report kernel snapshot event done, ret %{public}d", ret); return ret == 0; #else DFXLOGI("Not supported for kernel snapshot report."); diff --git a/services/snapshot/kernel_snapshot_reporter.h b/services/snapshot/kernel_snapshot_reporter.h index 70eb92f36..c2422dea3 100644 --- a/services/snapshot/kernel_snapshot_reporter.h +++ b/services/snapshot/kernel_snapshot_reporter.h @@ -22,11 +22,9 @@ namespace OHOS { namespace HiviewDFX { class KernelSnapshotReporter : public IKernelSnapshotReporter { public: - void ReportEvents(std::vector& outputs, const std::string& snapshot) override; + void ReportEvents(std::vector& outputs) override; private: - bool ReportRawMsg(const std::string& content); bool ReportCrashNoLogEvent(CrashMap& output); - int32_t GetSnapshotPid(const std::string& content); }; } // namespace HiviewDFX } // namespace OHOS diff --git a/test/unittest/kernel_snapshot/kernel_snapshot_test.cpp b/test/unittest/kernel_snapshot/kernel_snapshot_test.cpp index 0b77f0256..b1227faf1 100644 --- a/test/unittest/kernel_snapshot/kernel_snapshot_test.cpp +++ b/test/unittest/kernel_snapshot/kernel_snapshot_test.cpp @@ -576,59 +576,18 @@ HWTEST_F(KernelSnapshotTest, KernelSnapshotTest051, TestSize.Level2) KernelSnapshotReporter reporter; CrashMap output; + auto ret = reporter.ReportCrashNoLogEvent(output); + ASSERT_FALSE(ret); + output[CrashSection::UID] = "123"; output[CrashSection::PID] = "156"; output[CrashSection::TIME_STAMP] = "152451571481"; output[CrashSection::PROCESS_NAME] = "testProcess"; - auto ret = reporter.ReportCrashNoLogEvent(output); + ret = reporter.ReportCrashNoLogEvent(output); ASSERT_TRUE(ret); GTEST_LOG_(INFO) << "KernelSnapshotTest051: end."; } -/** - * @tc.name: KernelSnapshotReporter002 - * @tc.desc: test ReportRawMsg - * @tc.type: FUNC - */ -HWTEST_F(KernelSnapshotTest, KernelSnapshotReporter002, TestSize.Level2) -{ - GTEST_LOG_(INFO) << "KernelSnapshotReporter002: start."; - KernelSnapshotReporter reporter; - - std::string snapshot; - std::vector outputs; - CrashMap output; - output[CrashSection::UID] = ""; - output[CrashSection::PID] = "156"; - output[CrashSection::TIME_STAMP] = "152451571481"; - output[CrashSection::PROCESS_NAME] = "testProcess"; - outputs.push_back(output); - reporter.ReportEvents(outputs, snapshot); - - auto ret = reporter.ReportRawMsg(snapshot); - EXPECT_FALSE(ret); - snapshot = "kernel_snapshot"; - ret = reporter.ReportRawMsg(snapshot); - EXPECT_TRUE(ret); - GTEST_LOG_(INFO) << "KernelSnapshotReporter002: end."; -} - -/** - * @tc.name: KernelSnapshotReporter003 - * @tc.desc: test GetSnapshotPid - * @tc.type: FUNC - */ -HWTEST_F(KernelSnapshotTest, KernelSnapshotReporter003, TestSize.Level2) -{ - GTEST_LOG_(INFO) << "KernelSnapshotReporter003: start."; - KernelSnapshotReporter reporter; - EXPECT_EQ(reporter.GetSnapshotPid("12)"), 0); - EXPECT_EQ(reporter.GetSnapshotPid("abcpid=123"), 0); - EXPECT_EQ(reporter.GetSnapshotPid("abcpid=abc)"), 0); - EXPECT_EQ(reporter.GetSnapshotPid("abcpid=123)"), 123); - GTEST_LOG_(INFO) << "KernelSnapshotReporter003: end."; -} - /** * @tc.name: KernelSnapshotTest052 * @tc.desc: test kernel snapshot trie insert -- Gitee From f880c3825addf636b29b249a2339a68cae61f080 Mon Sep 17 00:00:00 2001 From: yuhaoqiang Date: Sat, 6 Sep 2025 12:54:10 +0800 Subject: [PATCH 10/10] Revert "fit the innertags of dfx_signalhandler" This reverts commit 856f8cc63c2e6c1aac7f8355be831ea07b372b74. --- interfaces/innerkits/signal_handler/BUILD.gn | 2 +- test/unittest/common/common_test.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/interfaces/innerkits/signal_handler/BUILD.gn b/interfaces/innerkits/signal_handler/BUILD.gn index 48ca8f28a..28af9149b 100644 --- a/interfaces/innerkits/signal_handler/BUILD.gn +++ b/interfaces/innerkits/signal_handler/BUILD.gn @@ -83,7 +83,7 @@ if (defined(ohos_lite)) { ] innerapi_tags = [ - "chipsetsdk_sp_indirect", + "chipsetsdk_indirect", "platformsdk_indirect", ] install_enable = true diff --git a/test/unittest/common/common_test.cpp b/test/unittest/common/common_test.cpp index d473028d8..2a8a8cf7d 100644 --- a/test/unittest/common/common_test.cpp +++ b/test/unittest/common/common_test.cpp @@ -46,8 +46,8 @@ static void getLibPathsBySystemBits(vector &filePaths) "/system/lib64/libstacktrace_rust.dylib.so", "/system/lib64/libpanic_handler.dylib.so", "/system/lib64/platformsdk/libjson_stack_formatter.z.so", + "/system/lib64/chipset-sdk/libdfx_signalhandler.z.so", "/system/lib64/chipset-sdk/libcrash_exception.z.so", - "/system/lib64/chipset-sdk-sp/libdfx_signalhandler.z.so", "/system/lib64/chipset-sdk-sp/librustc_demangle.z.so", "/system/lib64/chipset-sdk-sp/libasync_stack.z.so", "/system/lib64/chipset-sdk-sp/libdfx_dumpcatcher.z.so", @@ -61,8 +61,8 @@ static void getLibPathsBySystemBits(vector &filePaths) "/system/lib/libstacktrace_rust.dylib.so", "/system/lib/libpanic_handler.dylib.so", "/system/lib/platformsdk/libjson_stack_formatter.z.so", + "/system/lib/chipset-sdk/libdfx_signalhandler.z.so", "/system/lib/chipset-sdk/libcrash_exception.z.so", - "/system/lib/chipset-sdk-sp/libdfx_signalhandler.z.so", "/system/lib/chipset-sdk-sp/librustc_demangle.z.so", "/system/lib/chipset-sdk-sp/libasync_stack.z.so", "/system/lib/chipset-sdk-sp/libdfx_dumpcatcher.z.so", -- Gitee