From 5ea11f6d5ca470f930fbe291e9040bf6ace0bc33 Mon Sep 17 00:00:00 2001 From: Jan Vorlicek Date: Mon, 24 Jan 2022 20:14:59 +0100 Subject: [PATCH] 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. --- src/SOS/lldbplugin/services.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) 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) { -- 2.34.1