diff --git a/interfaces/innerkits/dump_catcher/lite_perf.cpp b/interfaces/innerkits/dump_catcher/lite_perf.cpp index 0b89c8ff117770d9c8cbf08171a0c8ed9ea267d9..c1bfd55c1cde004b2c637efacbcee55c6ef9bec0 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 = vfork(); + pid = fork(); if (pid < 0) { - DFXLOGE("Failed to vfork."); + DFXLOGE("Failed to fork."); 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 = vfork(); + pid_t dumpPid = fork(); if (dumpPid < 0) { - DFXLOGE("Failed to vfork."); + DFXLOGE("Failed to fork."); _exit(-1); } if (dumpPid == 0) { diff --git a/interfaces/innerkits/formatter/dfx_json_formatter.cpp b/interfaces/innerkits/formatter/dfx_json_formatter.cpp index ac349891bac541a3055b61ea8456da37a51cb195..0dc02ca37c69c3f0643476d698ae985b46abaf9d 100644 --- a/interfaces/innerkits/formatter/dfx_json_formatter.cpp +++ b/interfaces/innerkits/formatter/dfx_json_formatter.cpp @@ -27,6 +27,14 @@ 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; @@ -36,18 +44,18 @@ static bool FormatJsFrame(const Json::Value& frames, const uint32_t& frameIdx, s return false; } outStr = std::string(buf); - std::string symbol = frames[frameIdx]["symbol"].asString(); + std::string symbol = JsonAsString(frames[frameIdx]["symbol"]); if (!symbol.empty()) { outStr.append(" " + symbol); } - std::string packageName = frames[frameIdx]["packageName"].asString(); + std::string packageName = JsonAsString(frames[frameIdx]["packageName"]); if (!packageName.empty()) { outStr.append(" " + packageName); } - std::string file = frames[frameIdx]["file"].asString(); + std::string file = JsonAsString(frames[frameIdx]["file"]); if (!file.empty()) { - std::string line = frames[frameIdx]["line"].asString(); - std::string column = frames[frameIdx]["column"].asString(); + std::string line = JsonAsString(frames[frameIdx]["line"]); + std::string column = JsonAsString(frames[frameIdx]["column"]); outStr.append(" (" + file + ":" + line + ":" + column + ")"); } return true; @@ -57,11 +65,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 = 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(); + 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"]); if (snprintf_s(buf, sizeof(buf), sizeof(buf) - 1, format, frameIdx, pc.c_str(), file.empty() ? "Unknown" : file.c_str()) <= 0) { return false; @@ -91,13 +99,13 @@ 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:" + thread["tid"].asString() + ", Name:" + thread["thread_name"].asString() + "\n"; + ss += "Tid:" + JsonAsString(thread["tid"]) + ", Name:" + JsonAsString(thread["thread_name"]) + "\n"; } 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()) { + if (JsonAsString(frames[j]["line"]).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 be28a8955b2f5776b49738e025877d27e1967a4e..429fe5047b65ef9af20053f3961b1c20014b31e8 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) { - uint32_t startTime = GetAbsTimeMilliSecondsCInterce(); + uint64_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 d10cf989b56f9bc59e542f319f7b9d4ec0741e7f..ea85e4b103f59231e28a6be6295df25132162841 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) { + if (copySize < size && destSize > copySize) { 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);