From: Jan Vorlicek Date: Mon, 24 Jan 2022 19:14:59 +0000 (+0100) Subject: Enhance core dump debugging (#2827) X-Git-Tag: accepted/tizen/unified/20221103.165810~28^2^2~108 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5ea11f6d5ca470f930fbe291e9040bf6ace0bc33;p=platform%2Fcore%2Fdotnet%2Fdiagnostics.git Enhance core dump debugging (#2827) I've found that when a core dump is taken by the OS without the extra settings that makes it copy shared libraries binaries into the dump, SOS doesn't work as it relies on the libcoreclr.so ELF header to be present. I have discovered a way to make lldb read that data from the image of the libcoreclr.so that it has loaded together with the dump. This change makes it possible to use SOS even for the above mentioned dump cases. In fact, it allows SOS to read any data that were mapped as read only from any shared library loaded in the process. --- diff --git a/src/SOS/lldbplugin/services.cpp b/src/SOS/lldbplugin/services.cpp index fbbf40958..37ae00c4e 100644 --- a/src/SOS/lldbplugin/services.cpp +++ b/src/SOS/lldbplugin/services.cpp @@ -778,6 +778,36 @@ LLDBServices::ReadVirtual( read = process.ReadMemory(offset, buffer, bufferSize, error); + if (!error.Success()) + { + lldb::SBTarget target = process.GetTarget(); + if (!target.IsValid()) + { + goto exit; + } + + int numModules = target.GetNumModules(); + bool found = false; + for (int i = 0; !found && i < numModules; i++) + { + lldb::SBModule module = target.GetModuleAtIndex(i); + int numSections = module.GetNumSections(); + for (int j = 0; j < numSections; j++) + { + lldb::SBSection section = module.GetSectionAtIndex(j); + lldb::addr_t loadAddr = section.GetLoadAddress(target); + lldb::addr_t byteSize = section.GetByteSize(); + if ((loadAddr != LLDB_INVALID_ADDRESS) && (offset >= loadAddr) && (offset < loadAddr + byteSize)) + { + lldb::SBData sectionData = section.GetSectionData(offset - loadAddr, bufferSize); + read = sectionData.ReadRawData(error, 0, buffer, bufferSize); + found = true; + break; + } + } + } + } + exit: if (bytesRead) {