diff --git a/common/cutil/dfx_cutil.c b/common/cutil/dfx_cutil.c index 14b1be1598f94709f52321038b43a90319860583..3a36b13db422d23cdbc544d857a3407c1251b66a 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 c2e5325d8130f2ea0f25566b04f81d55ce3cd8d0..8863644fa2deccb7724ee46dff417aed4dc0675e 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 6eb414ae5bb989bf612400ce36ec1060a4527eff..f24d67f43ee83777064f889f9f0f5ab7ad657f8a 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/dump_catcher/lite_perf.cpp b/interfaces/innerkits/dump_catcher/lite_perf.cpp index c1bfd55c1cde004b2c637efacbcee55c6ef9bec0..0b89c8ff117770d9c8cbf08171a0c8ed9ea267d9 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 477d733883e87d2dc68c4f6dd3ea432507390c57..ac349891bac541a3055b61ea8456da37a51cb195 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; @@ -93,30 +85,19 @@ 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]; if (thread["tid"].isConvertibleTo(Json::stringValue) && thread["thread_name"].isConvertibleTo(Json::stringValue)) { - ss += "Tid:" + JsonAsString(thread["tid"]) + ", Name:" + JsonAsString(thread["thread_name"]) + "\n"; - } - if (!thread.isMember("frames") || !thread["frames"].isArray()) { - continue; + ss += "Tid:" + thread["tid"].asString() + ", Name:" + thread["thread_name"].asString() + "\n"; } 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 (JsonAsString(frames[j]["line"]).empty()) { + if (frames[j]["line"].asString().empty()) { formatStatus = FormatNativeFrame(frames, j, frameStr); } else { formatStatus = FormatJsFrame(frames, j, frameStr); @@ -129,7 +110,6 @@ bool DfxJsonFormatter::FormatJsonStack(const std::string& jsonStack, std::string return false; } } - outStackStr.append(ss); } return true; diff --git a/interfaces/innerkits/signal_handler/BUILD.gn b/interfaces/innerkits/signal_handler/BUILD.gn index 48ca8f28ad61b3d4003dea0424d388285b0cd762..28af9149b8522a9f3c15e045664b2752e6b010d6 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/interfaces/innerkits/signal_handler/dfx_dumprequest.c b/interfaces/innerkits/signal_handler/dfx_dumprequest.c index 88e040a029d44307909ec8b97d4fc877795f5d63..ee0e2aeb5d8a7192483a8174e79d3786166b584b 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/interfaces/innerkits/unwinder/BUILD.gn b/interfaces/innerkits/unwinder/BUILD.gn index 12a6da598603fd2c4f42aa79512796214dc22164..fa4028c2ffb498b6825ee8809fabec4ba59478f3 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/services/snapshot/i_kernel_snapshot_reporter.h b/services/snapshot/i_kernel_snapshot_reporter.h index ab414283a61a1c5ebb8821495aada4f5f269f474..78efcca29238435f3d27e039685230a6cfa6f2e1 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 70828cc0fb4ff131f2b8b83bc9a5c75ffc68c39c..6b09d3ca39aa89129ab7408b5a4ff61e15e9ad5d 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 c11de435050b72b6d50ae05a02d39398d6d91db5..e8b973c7b68038a5674b04e95d2c8324dd4f4bf3 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 b16be5474001e25b18f7b1d33a5ca6177b7e110b..c66195884aae2bd9e46209594e1ecd7215b5d57e 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 70eb92f363a8ebfdb64d9b35ad07e218e39194ff..c2422dea3c39ce52601cfa747cd748200303a637 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/fuzztest/faultloggerddumpcatcher_fuzzer/faultloggerddumpcatcher_fuzzer.cpp b/test/fuzztest/faultloggerddumpcatcher_fuzzer/faultloggerddumpcatcher_fuzzer.cpp index b97f752b2e4cf2f20de322016873b5ea3c699589..c03c9f354bbb33e2a1f43a479fd841962e8a7995 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()); } diff --git a/test/fuzztest/faultloggerdunwinder_fuzzer/faultloggerdunwinder_fuzzer.cpp b/test/fuzztest/faultloggerdunwinder_fuzzer/faultloggerdunwinder_fuzzer.cpp index 51b52b6f5895381c11a6f20d67926eb9a21cd76b..2836e8e4d1df296f2dc315e46979bf47a7df3c7e 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; @@ -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); diff --git a/test/unittest/common/common_cutil_test.cpp b/test/unittest/common/common_cutil_test.cpp index 3c24122bfe1d70a1723645ffce86ec71463c6dfb..ec0f7222844661a078967c0d4b5f53d262e69dd4 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 diff --git a/test/unittest/common/common_test.cpp b/test/unittest/common/common_test.cpp index 7e4a04d52536bfe4be20293de9c9ce54aff977aa..2a8a8cf7dd1ba1d9ffb7997aa2a2ce862bddcd8d 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", @@ -265,4 +265,4 @@ HWTEST_F(CommonTest, ROMBaselineTest001, TestSize.Level2) } } } // namespace HiviewDFX -} // namespace OHOS +} // namespace OHOS \ No newline at end of file diff --git a/test/unittest/kernel_snapshot/kernel_snapshot_test.cpp b/test/unittest/kernel_snapshot/kernel_snapshot_test.cpp index 0b77f0256c19f0cbd2f0e63bc24bd009991973de..b1227faf160535d38106f7f936bb6453de22c1fd 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 diff --git a/test/unittest/process_dump/thread_dump_info_test.cpp b/test/unittest/process_dump/thread_dump_info_test.cpp index 3aba65807ca2bbb3d99110b88a025fd493db5612..a5e09de61efa1dfabf8acdc7aeef161a11f806a3 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 fd7737acc65577317af9a8ddc1f93fe473a8ba58..7698320864dc994136e0334d509f5b6da1fb4fe5 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 28935c9c14cd80e393fe06b349fc6c6d168c66a3..cee0b044f03aad2454c2a5f04832d694934d9bb0 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 a76a339a4a1c89f72fa28e762fc0888ad0779b88..82b5df759a0669146679f204c63bc950b3727bc4 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 f2ef6f9c988eab4ca1f03e19aecee4494596519d..4dd716a1cb2e433d5b4df0a46893f5ef98adf3ec 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/lperf/lperf_events.cpp b/tools/process_dump/lperf/lperf_events.cpp index ea85e4b103f59231e28a6be6295df25132162841..d10cf989b56f9bc59e542f319f7b9d4ec0741e7f 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); diff --git a/tools/process_dump/other_thread_dump_info.cpp b/tools/process_dump/other_thread_dump_info.cpp index 1acd9396a3164a63ba6d87abfca536269839de35..1bb1802290e5d7fa458505f742d2a008829fb655 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 ab6fdaea172eaccc2eeec62b731935bcaa25b506..f22eb02cbd3d60492bd8c54246c5b295a53ec392 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);