diff --git a/tools/process_dump/printer.cpp b/tools/process_dump/printer.cpp index 3c077ff912af186ac146ce26e1e92f8a04596568..648bd1b9e80e9c9fcee2b3919447537c3c3fa79b 100644 --- a/tools/process_dump/printer.cpp +++ b/tools/process_dump/printer.cpp @@ -287,7 +287,7 @@ void Printer::PrintThreadFaultStackByConfig(std::shared_ptr process, } } -void Printer::PrintLongInformation(std::string& info) +void Printer::PrintLongInformation(const std::string& info) { constexpr size_t step = 1024; for (size_t i = 0; i < info.size(); i += step) { diff --git a/tools/process_dump/printer.h b/tools/process_dump/printer.h index f0661c1507f5d873e8fc9dfcc872824c7bc9f590..1f47cf23492f02643d95bc7c5914949c6b54b4b1 100644 --- a/tools/process_dump/printer.h +++ b/tools/process_dump/printer.h @@ -43,7 +43,7 @@ public: static void PrintRegsByConfig(std::shared_ptr regs); static void PrintThreadFaultStackByConfig(std::shared_ptr process, std::shared_ptr thread, std::shared_ptr unwinder); - static void PrintLongInformation(std::string& info); + static void PrintLongInformation(const std::string& info); static bool IsLastValidFrame(const DfxFrame& frame); private: static void PrintReason(std::shared_ptr request, std::shared_ptr process, diff --git a/tools/process_dump/process_dumper.cpp b/tools/process_dump/process_dumper.cpp index d78684a0b6e66c2c8771c3561b31581a56fef4f1..38e5714af0735e223c668a3f1bae69fbfbbafecb 100644 --- a/tools/process_dump/process_dumper.cpp +++ b/tools/process_dump/process_dumper.cpp @@ -458,7 +458,7 @@ void ProcessDumper::UnwindWriteJit(const ProcessDumpRequest &request) (void)close(fd); } -std::string ProcessDumper::ReadCrashObjString(pid_t tid, uintptr_t addr) +std::string ProcessDumper::ReadCrashObjString(pid_t tid, uintptr_t addr) const { std::string stringContent = "ExtraCrashInfo(String):\n"; constexpr int bufLen = 256; @@ -479,14 +479,14 @@ std::string ProcessDumper::ReadCrashObjString(pid_t tid, uintptr_t addr) return stringContent; } -std::string ProcessDumper::ReadCrashObjMemory(pid_t tid, uintptr_t addr, size_t length) +std::string ProcessDumper::ReadCrashObjMemory(pid_t tid, uintptr_t addr, size_t length) const { constexpr size_t step = sizeof(uintptr_t); std::string memoryContent = StringPrintf("ExtraCrashInfo(Memory start address %018" PRIx64 "):", static_cast(addr)); - size_t size = length / step; - uintptr_t memory[size]; - if (DfxMemory::ReadProcMemByPid(tid, addr, memory, length) != length) { + size_t size = (length + step - 1) / step; + std::vector memory(size, 0); + if (DfxMemory::ReadProcMemByPid(tid, addr, memory.data(), length) != length) { DFXLOGE("[%{public}d]: read target mem error %{public}s", __LINE__, strerror(errno)); memoryContent += "\n"; return memoryContent; diff --git a/tools/process_dump/process_dumper.h b/tools/process_dump/process_dumper.h index 6636764b432cda45f7f7b0d68843f1c4bcc6ee81..406d979122b75dc7585cea4f26913f5ad7fe42ee 100644 --- a/tools/process_dump/process_dumper.h +++ b/tools/process_dump/process_dumper.h @@ -61,8 +61,8 @@ private: void UnwindWriteJit(const ProcessDumpRequest &request); void Report(std::shared_ptr request, std::string &jsonInfo); void ReadFdTable(const ProcessDumpRequest &request); - std::string ReadCrashObjString(pid_t tid, uintptr_t addr); - std::string ReadCrashObjMemory(pid_t tid, uintptr_t addr, size_t length); + std::string ReadCrashObjString(pid_t tid, uintptr_t addr) const; + std::string ReadCrashObjMemory(pid_t tid, uintptr_t addr, size_t length) const; void GetCrashObj(std::shared_ptr request); void ReportAddrSanitizer(ProcessDumpRequest &request, std::string &jsonInfo);