Skip to content

Commit d7dd98f

Browse files
author
Mike McLaughlin
authored
createdump improvements for better VS4Mac Watson bucketing (#71863)
* Createdump changes for VS4Mac Add target process terminated/alive message. Smaller MacOS dumps. Don't add share_mode == SM_EMPTY regions. Add crashreport success status message for VS4Mac. Launch createdump from SIGTERM handler directly to reduce the time it takes to get the crash report/dump for VS4Mac. * Add more instrumentation to diagnose SIGTERM problem * Remove useless thread state logging
1 parent 3b022db commit d7dd98f

File tree

6 files changed

+31
-5
lines changed

6 files changed

+31
-5
lines changed

src/coreclr/debug/createdump/crashinfomac.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
#include "createdump.h"
55

6+
int g_readProcessMemoryResult = KERN_SUCCESS;
7+
68
bool
79
CrashInfo::Initialize()
810
{
@@ -127,7 +129,7 @@ CrashInfo::EnumerateMemoryRegions()
127129
}
128130
else
129131
{
130-
if ((info.protection & (VM_PROT_READ | VM_PROT_WRITE | VM_PROT_EXECUTE)) != 0)
132+
if (info.share_mode != SM_EMPTY && (info.protection & (VM_PROT_READ | VM_PROT_WRITE | VM_PROT_EXECUTE)) != 0)
131133
{
132134
MemoryRegion memoryRegion(ConvertProtectionFlags(info.protection), address, address + size, info.offset);
133135
m_allMemoryRegions.insert(memoryRegion);
@@ -362,6 +364,7 @@ CrashInfo::ReadProcessMemory(void* address, void* buffer, size_t size, size_t* r
362364
kern_return_t result = ::vm_read_overwrite(Task(), addressAligned, PAGE_SIZE, (vm_address_t)data, &bytesRead);
363365
if (result != KERN_SUCCESS || bytesRead != PAGE_SIZE)
364366
{
367+
g_readProcessMemoryResult = result;
365368
TRACE_VERBOSE("ReadProcessMemory(%p %d): vm_read_overwrite failed bytesLeft %d bytesRead %d from %p: %x %s\n",
366369
address, size, bytesLeft, bytesRead, (void*)addressAligned, result, mach_error_string(result));
367370
break;

src/coreclr/debug/createdump/crashreportwriter.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ CrashReportWriter::WriteCrashReport(const std::string& dumpFileName)
4141
}
4242
WriteCrashReport();
4343
CloseWriter();
44+
printf_status("Crash report successfully written\n");
4445
}
4546
catch (const std::exception& e)
4647
{

src/coreclr/debug/createdump/createdumpunix.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,22 @@ CreateDump(const char* dumpPathTemplate, int pid, const char* dumpType, MINIDUMP
6969
}
7070
result = true;
7171
exit:
72+
if (kill(pid, 0) == 0)
73+
{
74+
printf_status("Target process is alive\n");
75+
}
76+
else
77+
{
78+
int err = errno;
79+
if (err == ESRCH)
80+
{
81+
printf_error("Target process terminated\n");
82+
}
83+
else
84+
{
85+
printf_error("kill(%d, 0) FAILED %s (%d)\n", pid, strerror(err), err);
86+
}
87+
}
7288
crashInfo->CleanupAndResumeProcess();
7389
return result;
7490
}

src/coreclr/debug/createdump/dumpwritermacho.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include "createdump.h"
55
#include "specialthreadinfo.h"
66

7+
extern int g_readProcessMemoryResult;
8+
79
//
810
// Write the core dump file
911
//
@@ -264,13 +266,13 @@ DumpWriter::WriteSegments()
264266
size_t read = 0;
265267

266268
if (!m_crashInfo.ReadProcessMemory((void*)address, m_tempBuffer, bytesToRead, &read)) {
267-
printf_error("ReadProcessMemory(%" PRIA PRIx64 ", %08zx) FAILED\n", address, bytesToRead);
269+
printf_error("ReadProcessMemory(%" PRIA PRIx64 ", %08zx) read %d FAILED %s (%x)\n", address, bytesToRead, read, mach_error_string(g_readProcessMemoryResult), g_readProcessMemoryResult);
268270
return false;
269271
}
270272

271273
// This can happen if the target process dies before createdump is finished
272274
if (read == 0) {
273-
printf_error("ReadProcessMemory(%" PRIA PRIx64 ", %08zx) returned 0 bytes read\n", address, bytesToRead);
275+
printf_error("ReadProcessMemory(%" PRIA PRIx64 ", %08zx) returned 0 bytes read: %s (%x)\n", address, bytesToRead, mach_error_string(g_readProcessMemoryResult), g_readProcessMemoryResult);
274276
return false;
275277
}
276278

src/coreclr/pal/src/exception/signal.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,11 @@ static void sigterm_handler(int code, siginfo_t *siginfo, void *context)
746746
{
747747
if (PALIsInitialized())
748748
{
749+
char* enable = getenv("COMPlus_EnableDumpOnSigTerm");
750+
if (enable != nullptr && strcmp(enable, "1") == 0)
751+
{
752+
PROCCreateCrashDumpIfEnabled(code);
753+
}
749754
// g_pSynchronizationManager shouldn't be null if PAL is initialized.
750755
_ASSERTE(g_pSynchronizationManager != nullptr);
751756

src/coreclr/vm/exceptionhandling.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,7 @@ void HandleTerminationRequest(int terminationExitCode)
213213
{
214214
SetLatchedExitCode(terminationExitCode);
215215

216-
DWORD enabled = CLRConfig::GetConfigValue(CLRConfig::INTERNAL_EnableDumpOnSigTerm);
217-
ForceEEShutdown(enabled == 1 ? SCA_TerminateProcessWhenShutdownComplete : SCA_ExitProcessWhenShutdownComplete);
216+
ForceEEShutdown(SCA_ExitProcessWhenShutdownComplete);
218217
}
219218
}
220219
#endif

0 commit comments

Comments
 (0)