From 934918e491eabcb3a3150644f936b90bd9dc7cc9 Mon Sep 17 00:00:00 2001 From: Mike McLaughlin Date: Thu, 11 Mar 2021 13:40:26 -0800 Subject: [PATCH] Backport "Fix incomplete dumps generated by createdump (#49468)" The core dump generated for a app that has large GC heaps (>4GB) are don't contain all the memory needed in process. This is because of a 32bit size value overflow; changed to size_t. Multiple customers have reported this problem in 3.1 and 5.0. Issue: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1277488?src=WorkItemMention&src-action=artifact_link and https://github.com/dotnet/diagnostics/issues/1780 --- src/coreclr/src/debug/createdump/createdumpunix.cpp | 1 + src/coreclr/src/debug/createdump/dumpwriter.cpp | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/coreclr/src/debug/createdump/createdumpunix.cpp b/src/coreclr/src/debug/createdump/createdumpunix.cpp index 6ddc21a75c2a05..da74ddaee5c994 100644 --- a/src/coreclr/src/debug/createdump/createdumpunix.cpp +++ b/src/coreclr/src/debug/createdump/createdumpunix.cpp @@ -45,6 +45,7 @@ CreateDump(const char* dumpPathTemplate, int pid, const char* dumpType, MINIDUMP } if (!dumpWriter.WriteDump()) { + fprintf(stderr, "Writing dump FAILED\n"); goto exit; } result = true; diff --git a/src/coreclr/src/debug/createdump/dumpwriter.cpp b/src/coreclr/src/debug/createdump/dumpwriter.cpp index 677a8b07118a29..3c61aeb9e56cd0 100644 --- a/src/coreclr/src/debug/createdump/dumpwriter.cpp +++ b/src/coreclr/src/debug/createdump/dumpwriter.cpp @@ -203,24 +203,24 @@ DumpWriter::WriteDump() // Only write the regions that are backed by memory if (memoryRegion.IsBackedByMemory()) { - uint32_t size = memoryRegion.Size(); uint64_t address = memoryRegion.StartAddress(); + size_t size = memoryRegion.Size(); total += size; while (size > 0) { - uint32_t bytesToRead = std::min(size, (uint32_t)sizeof(m_tempBuffer)); + size_t bytesToRead = std::min(size, sizeof(m_tempBuffer)); size_t read = 0; if (!m_crashInfo.ReadProcessMemory((void*)address, m_tempBuffer, bytesToRead, &read)) { - fprintf(stderr, "ReadProcessMemory(%" PRIA PRIx64 ", %08x) FAILED\n", address, bytesToRead); + fprintf(stderr, "ReadProcessMemory(%" PRIA PRIx64 ", %08zx) FAILED\n", address, bytesToRead); return false; } // This can happen if the target process dies before createdump is finished if (read == 0) { - TRACE("ReadProcessMemory(%" PRIA PRIx64 ", %08x) return 0 bytes read\n", address, bytesToRead); - break; + fprintf(stderr, "ReadProcessMemory(%" PRIA PRIx64 ", %08zx) returned 0 bytes read\n", address, bytesToRead); + return false; } if (!WriteData(m_tempBuffer, read)) {