Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dump generation issues for VS4Mac #61063

Merged
merged 1 commit into from
Nov 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions src/coreclr/debug/createdump/crashreportwriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,20 @@ CrashReportWriter::WriteCrashReport()
{
OpenObject();
bool crashed = false;
if (thread->ManagedExceptionObject() != 0)
if (thread->Tid() == m_crashInfo.CrashThread())
{
crashed = true;
exceptionType = "0x05000000"; // ManagedException
}
else
{
if (thread->Tid() == m_crashInfo.CrashThread())
if (thread->ManagedExceptionObject() != 0)
{
exceptionType = "0x05000000"; // ManagedException
}
else
{
crashed = true;
switch (m_crashInfo.Signal())
{
case 0:
break;

case SIGILL:
exceptionType = "0x50000000";
break;
Expand All @@ -121,9 +123,12 @@ CrashReportWriter::WriteCrashReport()
break;

case SIGABRT:
default:
exceptionType = "0x30000000";
break;

default:
exceptionType = "0x00000000";
break;
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/coreclr/debug/dbgutil/machoreader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,11 @@ MachOModule::ReadLoadCommands()
m_segments.push_back(segment);

// Calculate the load bias for the module. This is the value to add to the vmaddr of a
// segment to get the actual address.
if (strcmp(segment->segname, SEG_TEXT) == 0)
// segment to get the actual address. For shared modules, this is 0 since those segments
// are absolute address.
if (segment->fileoff == 0 && segment->filesize > 0)
mikem8361 marked this conversation as resolved.
Show resolved Hide resolved
{
m_loadBias = m_baseAddress - segment->vmaddr;
m_reader.TraceVerbose("CMD: load bias %016llx\n", m_loadBias);
}

m_reader.TraceVerbose("CMD: vmaddr %016llx vmsize %016llx fileoff %016llx filesize %016llx nsects %d max %c%c%c init %c%c%c %02x %s\n",
Expand Down Expand Up @@ -245,6 +245,7 @@ MachOModule::ReadLoadCommands()
// Get next load command
command = (load_command*)((char*)command + command->cmdsize);
}
m_reader.TraceVerbose("CMD: load bias %016llx\n", m_loadBias);
}

return true;
Expand Down
11 changes: 10 additions & 1 deletion src/coreclr/pal/inc/pal.h
Original file line number Diff line number Diff line change
Expand Up @@ -432,13 +432,22 @@ PALAPI
PAL_SetShutdownCallback(
IN PSHUTDOWN_CALLBACK callback);

// Must be the same as the copy in excep.h and the WriteDumpFlags enum in the diagnostics repo
enum
{
GenerateDumpFlagsNone = 0x00,
GenerateDumpFlagsLoggingEnabled = 0x01,
GenerateDumpFlagsVerboseLoggingEnabled = 0x02,
GenerateDumpFlagsCrashReportEnabled = 0x04
};

PALIMPORT
BOOL
PALAPI
PAL_GenerateCoreDump(
IN LPCSTR dumpName,
IN INT dumpType,
IN BOOL diag);
IN ULONG32 flags);

typedef VOID (*PPAL_STARTUP_CALLBACK)(
char *modulePath,
Expand Down
36 changes: 24 additions & 12 deletions src/coreclr/pal/src/thread/process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3124,10 +3124,9 @@ PROCBuildCreateDumpCommandLine(
std::vector<const char*>& argv,
char** pprogram,
char** ppidarg,
char* dumpName,
char* dumpType,
BOOL diag,
BOOL crashReport)
const char* dumpName,
const char* dumpType,
ULONG32 flags)
{
if (g_szCoreCLRPath == nullptr)
{
Expand Down Expand Up @@ -3190,12 +3189,17 @@ PROCBuildCreateDumpCommandLine(
}
}

if (diag)
if (flags & GenerateDumpFlagsLoggingEnabled)
{
argv.push_back("--diag");
}

if (crashReport)
if (flags & GenerateDumpFlagsVerboseLoggingEnabled)
{
argv.push_back("--verbose");
}

if (flags & GenerateDumpFlagsCrashReportEnabled)
{
argv.push_back("--crashreport");
}
Expand Down Expand Up @@ -3286,10 +3290,18 @@ PROCAbortInitialize()
BOOL diag = diagStr != nullptr && strcmp(diagStr, "1") == 0;
char* crashReportStr = getenv("COMPlus_EnableCrashReport");
BOOL crashReport = crashReportStr != nullptr && strcmp(crashReportStr, "1") == 0;

ULONG32 flags = GenerateDumpFlagsNone;
if (diag)
{
flags |= GenerateDumpFlagsLoggingEnabled;
}
if (crashReport)
{
flags |= GenerateDumpFlagsCrashReportEnabled;
}
char* program = nullptr;
char* pidarg = nullptr;
if (!PROCBuildCreateDumpCommandLine(g_argvCreateDump, &program, &pidarg, dumpName, dumpType, diag, crashReport))
if (!PROCBuildCreateDumpCommandLine(g_argvCreateDump, &program, &pidarg, dumpName, dumpType, flags))
{
return FALSE;
}
Expand All @@ -3311,8 +3323,8 @@ PROCAbortInitialize()
WithHeap = 2,
Triage = 3,
Full = 4
diag
true - log createdump diagnostics to console
flags
See enum

Return:
TRUE success
Expand All @@ -3322,7 +3334,7 @@ BOOL
PAL_GenerateCoreDump(
LPCSTR dumpName,
INT dumpType,
BOOL diag)
ULONG32 flags)
{
std::vector<const char*> argvCreateDump;
char dumpTypeStr[16];
Expand All @@ -3341,7 +3353,7 @@ PAL_GenerateCoreDump(
}
char* program = nullptr;
char* pidarg = nullptr;
BOOL result = PROCBuildCreateDumpCommandLine(argvCreateDump, &program, &pidarg, (char*)dumpName, dumpTypeStr, diag, false);
BOOL result = PROCBuildCreateDumpCommandLine(argvCreateDump, &program, &pidarg, dumpName, dumpTypeStr, flags);
if (result)
{
result = PROCCreateCrashDump(argvCreateDump);
Expand Down
10 changes: 8 additions & 2 deletions src/coreclr/vm/eventing/eventpipe/ds-rt-coreclr.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,16 +188,22 @@ ds_rt_config_value_get_default_port_suspend (void)

static
ds_ipc_result_t
ds_rt_generate_core_dump (DiagnosticsGenerateCoreDumpCommandPayload *payload)
ds_rt_generate_core_dump (DiagnosticsDumpCommandId commandId, DiagnosticsGenerateCoreDumpCommandPayload *payload)
{
STATIC_CONTRACT_NOTHROW;

ds_ipc_result_t result = DS_IPC_E_FAIL;
EX_TRY
{
uint32_t flags = ds_generate_core_dump_command_payload_get_flags(payload);
if (commandId == DS_DUMP_COMMANDID_GENERATE_CORE_DUMP)
{
// For the old commmand, this payload field is a bool of whether to enable logging
flags = flags != 0 ? GenerateDumpFlagsLoggingEnabled : 0;
}
if (GenerateDump (reinterpret_cast<LPCWSTR>(ds_generate_core_dump_command_payload_get_dump_name (payload)),
static_cast<int32_t>(ds_generate_core_dump_command_payload_get_dump_type (payload)),
(ds_generate_core_dump_command_payload_get_diagnostics (payload) != 0) ? true : false))
flags))
result = DS_IPC_S_OK;
}
EX_CATCH {}
Expand Down
8 changes: 4 additions & 4 deletions src/coreclr/vm/excep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4178,8 +4178,8 @@ InitializeCrashDump()

bool GenerateDump(
LPCWSTR dumpName,
int dumpType,
bool diag)
INT dumpType,
ULONG32 flags)
{
#ifdef TARGET_UNIX
MAKE_UTF8PTR_FROMWIDE_NOTHROW (dumpNameUtf8, dumpName);
Expand All @@ -4189,10 +4189,10 @@ bool GenerateDump(
}
else
{
return PAL_GenerateCoreDump(dumpNameUtf8, dumpType, diag);
return PAL_GenerateCoreDump(dumpNameUtf8, dumpType, flags);
}
#else // TARGET_UNIX
return GenerateCrashDump(dumpName, dumpType, diag);
return GenerateCrashDump(dumpName, dumpType, flags & GenerateDumpFlagsLoggingEnabled);
#endif // TARGET_UNIX
}

Expand Down
12 changes: 11 additions & 1 deletion src/coreclr/vm/excep.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,20 @@ enum UnhandledExceptionLocation
};

#ifdef HOST_WINDOWS

// Must be the same as the copy in pal.h and the WriteDumpFlags enum in the diagnostics repo
enum
{
GenerateDumpFlagsNone = 0x00,
GenerateDumpFlagsLoggingEnabled = 0x01,
GenerateDumpFlagsVerboseLoggingEnabled = 0x02,
GenerateDumpFlagsCrashReportEnabled = 0x04
};

void InitializeCrashDump();
void CreateCrashDumpIfEnabled(bool stackoverflow = false);
#endif
bool GenerateDump(LPCWSTR dumpName, int dumpType, bool diag);
bool GenerateDump(LPCWSTR dumpName, INT dumpType, ULONG32 flags);

// Generates crash dumps if enabled for both Windows and Linux
void CrashDumpAndTerminateProcess(UINT exitCode);
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/vm/gcenv.ee.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1656,7 +1656,7 @@ void GCToEEInterface::AnalyzeSurvivorsFinished(size_t gcIndex, int condemnedGene
{
EX_TRY
{
GenerateDump (GENAWARE_DUMP_FILE_NAME, 2, false);
GenerateDump (GENAWARE_DUMP_FILE_NAME, 2, GenerateDumpFlagsNone);
}
EX_CATCH {}
EX_END_CATCH(SwallowAllExceptions);
Expand Down Expand Up @@ -1736,4 +1736,4 @@ uint32_t GCToEEInterface::GetCurrentProcessCpuCount()
void GCToEEInterface::DiagAddNewRegion(int generation, uint8_t* rangeStart, uint8_t* rangeEnd, uint8_t* rangeEndReserved)
{
ProfilerAddNewRegion(generation, rangeStart, rangeEnd, rangeEndReserved);
}
}
2 changes: 1 addition & 1 deletion src/mono/mono/eventpipe/ds-rt-mono.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ ds_rt_config_value_get_default_port_suspend (void)
static
inline
ds_ipc_result_t
ds_rt_generate_core_dump (DiagnosticsGenerateCoreDumpCommandPayload *payload)
ds_rt_generate_core_dump (DiagnosticsDumpCommandId commandId, DiagnosticsGenerateCoreDumpCommandPayload *payload)
{
// TODO: Implement.
return DS_IPC_E_NOTSUPPORTED;
Expand Down
8 changes: 5 additions & 3 deletions src/native/eventpipe/ds-dump-protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ generate_core_dump_command_try_parse_payload (

if (!ds_ipc_message_try_parse_string_utf16_t (&buffer_cursor, &buffer_cursor_len, &instance->dump_name ) ||
!ds_ipc_message_try_parse_uint32_t (&buffer_cursor, &buffer_cursor_len, &instance->dump_type) ||
!ds_ipc_message_try_parse_uint32_t (&buffer_cursor, &buffer_cursor_len, &instance->diagnostics))
!ds_ipc_message_try_parse_uint32_t (&buffer_cursor, &buffer_cursor_len, &instance->flags))
ep_raise_error ();

ep_on_exit:
Expand Down Expand Up @@ -106,6 +106,7 @@ dump_protocol_helper_generate_core_dump (
return false;

bool result = false;
DiagnosticsDumpCommandId commandId = (DiagnosticsDumpCommandId)ds_ipc_header_get_commandid (ds_ipc_message_get_header_ref (message));
DiagnosticsGenerateCoreDumpCommandPayload *payload;
payload = (DiagnosticsGenerateCoreDumpCommandPayload *)ds_ipc_message_try_parse_payload (message, generate_core_dump_command_try_parse_payload);

Expand All @@ -115,8 +116,8 @@ dump_protocol_helper_generate_core_dump (
}

ds_ipc_result_t ipc_result;
ipc_result = ds_rt_generate_core_dump (payload);
if (result != DS_IPC_S_OK) {
ipc_result = ds_rt_generate_core_dump (commandId, payload);
if (ipc_result != DS_IPC_S_OK) {
ds_ipc_message_send_error (stream, result);
ep_raise_error ();
} else {
Expand Down Expand Up @@ -147,6 +148,7 @@ ds_dump_protocol_helper_handle_ipc_message (

switch ((DiagnosticsDumpCommandId)ds_ipc_header_get_commandid (ds_ipc_message_get_header_ref (message))) {
case DS_DUMP_COMMANDID_GENERATE_CORE_DUMP:
case DS_DUMP_COMMANDID_GENERATE_CORE_DUMP2:
result = dump_protocol_helper_generate_core_dump (message, stream);
break;
default:
Expand Down
6 changes: 3 additions & 3 deletions src/native/eventpipe/ds-dump-protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ struct _DiagnosticsGenerateCoreDumpCommandPayload_Internal {
// The protocol buffer is defined as:
// string - dumpName (UTF16)
// int - dumpType
// int - diagnostics
// uint32 - flags
// returns
// ulong - status

const ep_char16_t *dump_name;
uint32_t dump_type;
uint32_t diagnostics;
uint32_t flags;
};

#if !defined(DS_INLINE_GETTER_SETTER) && !defined(DS_IMPL_DUMP_PROTOCOL_GETTER_SETTER)
Expand All @@ -44,7 +44,7 @@ struct _DiagnosticsGenerateCoreDumpCommandPayload {

DS_DEFINE_GETTER(DiagnosticsGenerateCoreDumpCommandPayload *, generate_core_dump_command_payload, const ep_char16_t *, dump_name)
DS_DEFINE_GETTER(DiagnosticsGenerateCoreDumpCommandPayload *, generate_core_dump_command_payload, uint32_t, dump_type)
DS_DEFINE_GETTER(DiagnosticsGenerateCoreDumpCommandPayload *, generate_core_dump_command_payload, uint32_t, diagnostics)
DS_DEFINE_GETTER(DiagnosticsGenerateCoreDumpCommandPayload *, generate_core_dump_command_payload, uint32_t, flags)

DiagnosticsGenerateCoreDumpCommandPayload *
ds_generate_core_dump_command_payload_alloc (void);
Expand Down
2 changes: 1 addition & 1 deletion src/native/eventpipe/ds-rt.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ ds_rt_config_value_get_default_port_suspend (void);

static
ds_ipc_result_t
ds_rt_generate_core_dump (DiagnosticsGenerateCoreDumpCommandPayload *payload);
ds_rt_generate_core_dump (DiagnosticsDumpCommandId commandId, DiagnosticsGenerateCoreDumpCommandPayload *payload);

/*
* DiagnosticsIpc.
Expand Down
1 change: 1 addition & 0 deletions src/native/eventpipe/ds-types.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ typedef struct _EventPipeStopTracingCommandPayload EventPipeStopTracingCommandPa
typedef enum {
DS_DUMP_COMMANDID_RESERVED = 0x00,
DS_DUMP_COMMANDID_GENERATE_CORE_DUMP = 0x01,
DS_DUMP_COMMANDID_GENERATE_CORE_DUMP2 = 0x02,
// future
} DiagnosticsDumpCommandId;

Expand Down