From 66a3b803910b389de38703ce349695a247146f5b Mon Sep 17 00:00:00 2001 From: "Mateusz Moscicki/System (PLT) /SRPOL/Engineer/Samsung Electronics" Date: Mon, 5 Oct 2020 03:33:40 +0200 Subject: [Tizen] Add method to write coredump of .NET process (#317) This method allows to create minimal coredump (as createdump does) of a process that is in dumping state after crash. --- src/debug/createdump/CMakeLists.txt | 1 + src/debug/createdump/dnetmemoryenumlib.cpp | 84 +++++++++++++++++++++--------- src/debug/createdump/dnetmemoryenumlib.h | 6 ++- 3 files changed, 65 insertions(+), 26 deletions(-) (limited to 'src') diff --git a/src/debug/createdump/CMakeLists.txt b/src/debug/createdump/CMakeLists.txt index 7063b57c93..9d99dc0ef0 100644 --- a/src/debug/createdump/CMakeLists.txt +++ b/src/debug/createdump/CMakeLists.txt @@ -33,6 +33,7 @@ set(DNETMEMORYENUM_SOURCES crashinfo.cpp threadinfo.cpp datatarget.cpp + dumpwriter.cpp ) _add_library(createdump_lib diff --git a/src/debug/createdump/dnetmemoryenumlib.cpp b/src/debug/createdump/dnetmemoryenumlib.cpp index 3e0dc5bb58..1c07881804 100644 --- a/src/debug/createdump/dnetmemoryenumlib.cpp +++ b/src/debug/createdump/dnetmemoryenumlib.cpp @@ -46,23 +46,9 @@ get_regions(CrashInfo *crashInfo) return reg_vec; } - -extern "C" DLLEXPORT int -DotNetMemoryEnumInit() -{ - int exitCode = PAL_InitializeDLL(); - return exitCode; -} - -extern "C" DLLEXPORT void -DotNetMemoryEnumFinish() -{ - PAL_TerminateEx(0); -} - -extern "C" DLLEXPORT int -DotNetMemoryEnumRegions(pid_t pid, elf_prstatus **statuses, int statuses_count, - DUMP_TYPE minidump_type, SimpleMemoryRegion **regions) +int +prepare_crash_info(pid_t pid, elf_prstatus **statuses, int statuses_count, + DUMP_TYPE minidump_type, ReleaseHolder &crash_info) { g_diagnostics = true; @@ -91,19 +77,16 @@ DotNetMemoryEnumRegions(pid_t pid, elf_prstatus **statuses, int statuses_count, if (pid != 0) { ReleaseHolder dataTarget = new DumpDataTarget(pid); - ReleaseHolder crashInfo = new CrashInfo(pid, dataTarget, true); + crash_info = new CrashInfo(pid, dataTarget, true); - if (dataTarget->Initialize(crashInfo)) + if (dataTarget->Initialize(crash_info)) { - if (!crashInfo->EnumerateAndSuspendThreads(false)) + if (!crash_info->EnumerateAndSuspendThreads(false)) { return REGERR_ENUMERATION_ERROR; } - crashInfo->SetThreadsRegisters(stats); - crashInfo->GatherCrashInfo(minidumpType, false); - sm_regions = get_regions(crashInfo); - *regions = sm_regions.data(); - exitCode = sm_regions.size(); + crash_info->SetThreadsRegisters(stats); + crash_info->GatherCrashInfo(minidumpType, false); } else { @@ -116,3 +99,54 @@ DotNetMemoryEnumRegions(pid_t pid, elf_prstatus **statuses, int statuses_count, } return exitCode; } + +extern "C" DLLEXPORT int +DotNetMemoryEnumInit() +{ + int exitCode = PAL_InitializeDLL(); + return exitCode; +} + +extern "C" DLLEXPORT void +DotNetMemoryEnumFinish() +{ + PAL_TerminateEx(0); +} + +extern "C" DLLEXPORT int +DotNetMemoryEnumRegions(pid_t pid, elf_prstatus **statuses, int statuses_count, + DUMP_TYPE minidump_type, SimpleMemoryRegion **regions) +{ + ReleaseHolder crashInfo; + int exitCode = prepare_crash_info(pid, statuses, statuses_count, minidump_type, crashInfo); + + if (exitCode != REGERR_OK) + return exitCode; + + sm_regions = get_regions(crashInfo); + *regions = sm_regions.data(); + exitCode = sm_regions.size(); + + return exitCode; +} + +extern "C" DLLEXPORT int +DotNetMemoryWriteDump(pid_t pid, elf_prstatus **statuses, int statuses_count, + DUMP_TYPE minidump_type, const char *dump_path) +{ + ReleaseHolder crashInfo; + int exitCode = prepare_crash_info(pid, statuses, statuses_count, minidump_type, crashInfo); + + if (exitCode != REGERR_OK) + return exitCode; + + ReleaseHolder dumpWriter = new DumpWriter(*crashInfo); + + if (!dumpWriter->OpenDump(dump_path)) + exitCode = REGERR_OPENDUMP_ERROR; + + if (!dumpWriter->WriteDump()) + exitCode = REGERR_WRITEDUMP_ERROR; + + return exitCode; +} diff --git a/src/debug/createdump/dnetmemoryenumlib.h b/src/debug/createdump/dnetmemoryenumlib.h index 930d4f33c5..feb5c28178 100644 --- a/src/debug/createdump/dnetmemoryenumlib.h +++ b/src/debug/createdump/dnetmemoryenumlib.h @@ -45,11 +45,15 @@ enum REG_ERR { REGERR_OK = 0, REGERR_WRONG_PID = -1, REGERR_INITIALIZATION_ERROR = -2, - REGERR_ENUMERATION_ERROR = -3 + REGERR_ENUMERATION_ERROR = -3, + REGERR_OPENDUMP_ERROR = -4, + REGERR_WRITEDUMP_ERROR = -5, }; extern "C" DLLEXPORT int DotNetMemoryEnumRegions(pid_t pid, elf_prstatus **statuses, int statuses_count, DUMP_TYPE minidump_type, SimpleMemoryRegion **regions); +extern "C" DLLEXPORT int DotNetMemoryWriteDump(pid_t pid, elf_prstatus **statuses, int statuses_count, + DUMP_TYPE minidump_type, const char *dump_path); extern "C" DLLEXPORT int DotNetMemoryEnumInit(); extern "C" DLLEXPORT void DotNetMemoryEnumFinish(); -- cgit v1.2.3