Skip to content

Commit c4d5f6d

Browse files
authored
Fix various dump generation issues for VS4Mac (#60995)
Fix dump generation issues for VS4Mac Fixes issue: #60932 Fix how the load bias is calculate for shared modules Add new generate core dump IPC command that allows the generate crash report flag to be passed through to createdump for VS4Mac. Issue: #60775 VS4Mac needs to distinguish between WriteDump/no signal and unknown signal ExceptionType Change unknown signal exception type to 0
1 parent 1711db7 commit c4d5f6d

File tree

13 files changed

+84
-41
lines changed

13 files changed

+84
-41
lines changed

src/coreclr/debug/createdump/crashreportwriter.cpp

+13-8
Original file line numberDiff line numberDiff line change
@@ -84,18 +84,20 @@ CrashReportWriter::WriteCrashReport()
8484
{
8585
OpenObject();
8686
bool crashed = false;
87-
if (thread->ManagedExceptionObject() != 0)
87+
if (thread->Tid() == m_crashInfo.CrashThread())
8888
{
8989
crashed = true;
90-
exceptionType = "0x05000000"; // ManagedException
91-
}
92-
else
93-
{
94-
if (thread->Tid() == m_crashInfo.CrashThread())
90+
if (thread->ManagedExceptionObject() != 0)
91+
{
92+
exceptionType = "0x05000000"; // ManagedException
93+
}
94+
else
9595
{
96-
crashed = true;
9796
switch (m_crashInfo.Signal())
9897
{
98+
case 0:
99+
break;
100+
99101
case SIGILL:
100102
exceptionType = "0x50000000";
101103
break;
@@ -121,9 +123,12 @@ CrashReportWriter::WriteCrashReport()
121123
break;
122124

123125
case SIGABRT:
124-
default:
125126
exceptionType = "0x30000000";
126127
break;
128+
129+
default:
130+
exceptionType = "0x00000000";
131+
break;
127132
}
128133
}
129134
}

src/coreclr/debug/dbgutil/machoreader.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -207,11 +207,11 @@ MachOModule::ReadLoadCommands()
207207
m_segments.push_back(segment);
208208

209209
// Calculate the load bias for the module. This is the value to add to the vmaddr of a
210-
// segment to get the actual address.
211-
if (strcmp(segment->segname, SEG_TEXT) == 0)
210+
// segment to get the actual address. For shared modules, this is 0 since those segments
211+
// are absolute address.
212+
if (segment->fileoff == 0 && segment->filesize > 0)
212213
{
213214
m_loadBias = m_baseAddress - segment->vmaddr;
214-
m_reader.TraceVerbose("CMD: load bias %016llx\n", m_loadBias);
215215
}
216216

217217
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",
@@ -245,6 +245,7 @@ MachOModule::ReadLoadCommands()
245245
// Get next load command
246246
command = (load_command*)((char*)command + command->cmdsize);
247247
}
248+
m_reader.TraceVerbose("CMD: load bias %016llx\n", m_loadBias);
248249
}
249250

250251
return true;

src/coreclr/pal/inc/pal.h

+10-1
Original file line numberDiff line numberDiff line change
@@ -432,13 +432,22 @@ PALAPI
432432
PAL_SetShutdownCallback(
433433
IN PSHUTDOWN_CALLBACK callback);
434434

435+
// Must be the same as the copy in excep.h and the WriteDumpFlags enum in the diagnostics repo
436+
enum
437+
{
438+
GenerateDumpFlagsNone = 0x00,
439+
GenerateDumpFlagsLoggingEnabled = 0x01,
440+
GenerateDumpFlagsVerboseLoggingEnabled = 0x02,
441+
GenerateDumpFlagsCrashReportEnabled = 0x04
442+
};
443+
435444
PALIMPORT
436445
BOOL
437446
PALAPI
438447
PAL_GenerateCoreDump(
439448
IN LPCSTR dumpName,
440449
IN INT dumpType,
441-
IN BOOL diag);
450+
IN ULONG32 flags);
442451

443452
typedef VOID (*PPAL_STARTUP_CALLBACK)(
444453
char *modulePath,

src/coreclr/pal/src/thread/process.cpp

+22-13
Original file line numberDiff line numberDiff line change
@@ -3139,8 +3139,7 @@ PROCBuildCreateDumpCommandLine(
31393139
char** ppidarg,
31403140
const char* dumpName,
31413141
INT dumpType,
3142-
BOOL diag,
3143-
BOOL crashReport)
3142+
ULONG32 flags)
31443143
{
31453144
if (g_szCoreCLRPath == nullptr)
31463145
{
@@ -3198,12 +3197,17 @@ PROCBuildCreateDumpCommandLine(
31983197
break;
31993198
}
32003199

3201-
if (diag)
3200+
if (flags & GenerateDumpFlagsLoggingEnabled)
32023201
{
32033202
argv.push_back("--diag");
32043203
}
32053204

3206-
if (crashReport)
3205+
if (flags & GenerateDumpFlagsVerboseLoggingEnabled)
3206+
{
3207+
argv.push_back("--verbose");
3208+
}
3209+
3210+
if (flags & GenerateDumpFlagsCrashReportEnabled)
32073211
{
32083212
argv.push_back("--crashreport");
32093213
}
@@ -3305,17 +3309,22 @@ PROCAbortInitialize()
33053309
}
33063310
}
33073311

3312+
ULONG32 flags = GenerateDumpFlagsNone;
33083313
CLRConfigNoCache createDumpCfg = CLRConfigNoCache::Get("CreateDumpDiagnostics", /*noprefix*/ false, &getenv);
33093314
DWORD val = 0;
3310-
BOOL diag = createDumpCfg.IsSet() && createDumpCfg.TryAsInteger(10, val) && val == 1;
3311-
3315+
if (createDumpCfg.IsSet() && createDumpCfg.TryAsInteger(10, val) && val == 1)
3316+
{
3317+
flags |= GenerateDumpFlagsLoggingEnabled;
3318+
}
33123319
CLRConfigNoCache enabldReportCfg = CLRConfigNoCache::Get("EnableCrashReport", /*noprefix*/ false, &getenv);
33133320
val = 0;
3314-
BOOL crashReport = enabldReportCfg.IsSet() && enabldReportCfg.TryAsInteger(10, val) && val == 1;
3315-
3321+
if (enabldReportCfg.IsSet() && enabldReportCfg.TryAsInteger(10, val) && val == 1)
3322+
{
3323+
flags |= GenerateDumpFlagsCrashReportEnabled;
3324+
}
33163325
char* program = nullptr;
33173326
char* pidarg = nullptr;
3318-
if (!PROCBuildCreateDumpCommandLine(g_argvCreateDump, &program, &pidarg, dmpNameCfg.AsString(), dumpType, diag, crashReport))
3327+
if (!PROCBuildCreateDumpCommandLine(g_argvCreateDump, &program, &pidarg, dmpNameCfg.AsString(), dumpType, flags))
33193328
{
33203329
return FALSE;
33213330
}
@@ -3337,8 +3346,8 @@ PROCAbortInitialize()
33373346
WithHeap = 2,
33383347
Triage = 3,
33393348
Full = 4
3340-
diag
3341-
true - log createdump diagnostics to console
3349+
flags
3350+
See enum
33423351
33433352
Return:
33443353
TRUE success
@@ -3348,7 +3357,7 @@ BOOL
33483357
PAL_GenerateCoreDump(
33493358
LPCSTR dumpName,
33503359
INT dumpType,
3351-
BOOL diag)
3360+
ULONG32 flags)
33523361
{
33533362
std::vector<const char*> argvCreateDump;
33543363

@@ -3362,7 +3371,7 @@ PAL_GenerateCoreDump(
33623371
}
33633372
char* program = nullptr;
33643373
char* pidarg = nullptr;
3365-
BOOL result = PROCBuildCreateDumpCommandLine(argvCreateDump, &program, &pidarg, dumpName, dumpType, diag, false);
3374+
BOOL result = PROCBuildCreateDumpCommandLine(argvCreateDump, &program, &pidarg, dumpName, dumpType, flags);
33663375
if (result)
33673376
{
33683377
result = PROCCreateCrashDump(argvCreateDump);

src/coreclr/vm/eventing/eventpipe/ds-rt-coreclr.h

+8-2
Original file line numberDiff line numberDiff line change
@@ -188,16 +188,22 @@ ds_rt_config_value_get_default_port_suspend (void)
188188

189189
static
190190
ds_ipc_result_t
191-
ds_rt_generate_core_dump (DiagnosticsGenerateCoreDumpCommandPayload *payload)
191+
ds_rt_generate_core_dump (DiagnosticsDumpCommandId commandId, DiagnosticsGenerateCoreDumpCommandPayload *payload)
192192
{
193193
STATIC_CONTRACT_NOTHROW;
194194

195195
ds_ipc_result_t result = DS_IPC_E_FAIL;
196196
EX_TRY
197197
{
198+
uint32_t flags = ds_generate_core_dump_command_payload_get_flags(payload);
199+
if (commandId == DS_DUMP_COMMANDID_GENERATE_CORE_DUMP)
200+
{
201+
// For the old commmand, this payload field is a bool of whether to enable logging
202+
flags = flags != 0 ? GenerateDumpFlagsLoggingEnabled : 0;
203+
}
198204
if (GenerateDump (reinterpret_cast<LPCWSTR>(ds_generate_core_dump_command_payload_get_dump_name (payload)),
199205
static_cast<int32_t>(ds_generate_core_dump_command_payload_get_dump_type (payload)),
200-
(ds_generate_core_dump_command_payload_get_diagnostics (payload) != 0) ? true : false))
206+
flags))
201207
result = DS_IPC_S_OK;
202208
}
203209
EX_CATCH {}

src/coreclr/vm/excep.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -4175,8 +4175,8 @@ InitializeCrashDump()
41754175

41764176
bool GenerateDump(
41774177
LPCWSTR dumpName,
4178-
int dumpType,
4179-
bool diag)
4178+
INT dumpType,
4179+
ULONG32 flags)
41804180
{
41814181
#ifdef TARGET_UNIX
41824182
MAKE_UTF8PTR_FROMWIDE_NOTHROW (dumpNameUtf8, dumpName);
@@ -4186,10 +4186,10 @@ bool GenerateDump(
41864186
}
41874187
else
41884188
{
4189-
return PAL_GenerateCoreDump(dumpNameUtf8, dumpType, diag);
4189+
return PAL_GenerateCoreDump(dumpNameUtf8, dumpType, flags);
41904190
}
41914191
#else // TARGET_UNIX
4192-
return GenerateCrashDump(dumpName, dumpType, diag);
4192+
return GenerateCrashDump(dumpName, dumpType, flags & GenerateDumpFlagsLoggingEnabled);
41934193
#endif // TARGET_UNIX
41944194
}
41954195

src/coreclr/vm/excep.h

+11-1
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,20 @@ enum UnhandledExceptionLocation
195195
};
196196

197197
#ifdef HOST_WINDOWS
198+
199+
// Must be the same as the copy in pal.h and the WriteDumpFlags enum in the diagnostics repo
200+
enum
201+
{
202+
GenerateDumpFlagsNone = 0x00,
203+
GenerateDumpFlagsLoggingEnabled = 0x01,
204+
GenerateDumpFlagsVerboseLoggingEnabled = 0x02,
205+
GenerateDumpFlagsCrashReportEnabled = 0x04
206+
};
207+
198208
void InitializeCrashDump();
199209
void CreateCrashDumpIfEnabled(bool stackoverflow = false);
200210
#endif
201-
bool GenerateDump(LPCWSTR dumpName, int dumpType, bool diag);
211+
bool GenerateDump(LPCWSTR dumpName, INT dumpType, ULONG32 flags);
202212

203213
// Generates crash dumps if enabled for both Windows and Linux
204214
void CrashDumpAndTerminateProcess(UINT exitCode);

src/coreclr/vm/gcenv.ee.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1695,7 +1695,7 @@ void GCToEEInterface::AnalyzeSurvivorsFinished(size_t gcIndex, int condemnedGene
16951695
{
16961696
EX_TRY
16971697
{
1698-
GenerateDump (GENAWARE_DUMP_FILE_NAME, 2, false);
1698+
GenerateDump (GENAWARE_DUMP_FILE_NAME, 2, GenerateDumpFlagsNone);
16991699
}
17001700
EX_CATCH {}
17011701
EX_END_CATCH(SwallowAllExceptions);
@@ -1775,4 +1775,4 @@ uint32_t GCToEEInterface::GetCurrentProcessCpuCount()
17751775
void GCToEEInterface::DiagAddNewRegion(int generation, uint8_t* rangeStart, uint8_t* rangeEnd, uint8_t* rangeEndReserved)
17761776
{
17771777
ProfilerAddNewRegion(generation, rangeStart, rangeEnd, rangeEndReserved);
1778-
}
1778+
}

src/mono/mono/eventpipe/ds-rt-mono.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ ds_rt_config_value_get_default_port_suspend (void)
172172
static
173173
inline
174174
ds_ipc_result_t
175-
ds_rt_generate_core_dump (DiagnosticsGenerateCoreDumpCommandPayload *payload)
175+
ds_rt_generate_core_dump (DiagnosticsDumpCommandId commandId, DiagnosticsGenerateCoreDumpCommandPayload *payload)
176176
{
177177
// TODO: Implement.
178178
return DS_IPC_E_NOTSUPPORTED;

src/native/eventpipe/ds-dump-protocol.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ generate_core_dump_command_try_parse_payload (
5151

5252
if (!ds_ipc_message_try_parse_string_utf16_t (&buffer_cursor, &buffer_cursor_len, &instance->dump_name ) ||
5353
!ds_ipc_message_try_parse_uint32_t (&buffer_cursor, &buffer_cursor_len, &instance->dump_type) ||
54-
!ds_ipc_message_try_parse_uint32_t (&buffer_cursor, &buffer_cursor_len, &instance->diagnostics))
54+
!ds_ipc_message_try_parse_uint32_t (&buffer_cursor, &buffer_cursor_len, &instance->flags))
5555
ep_raise_error ();
5656

5757
ep_on_exit:
@@ -106,6 +106,7 @@ dump_protocol_helper_generate_core_dump (
106106
return false;
107107

108108
ds_ipc_result_t ipc_result = DS_IPC_E_FAIL;
109+
DiagnosticsDumpCommandId commandId = (DiagnosticsDumpCommandId)ds_ipc_header_get_commandid (ds_ipc_message_get_header_ref (message));
109110
DiagnosticsGenerateCoreDumpCommandPayload *payload;
110111
payload = (DiagnosticsGenerateCoreDumpCommandPayload *)ds_ipc_message_try_parse_payload (message, generate_core_dump_command_try_parse_payload);
111112

@@ -114,7 +115,7 @@ dump_protocol_helper_generate_core_dump (
114115
ep_raise_error ();
115116
}
116117

117-
ipc_result = ds_rt_generate_core_dump (payload);
118+
ipc_result = ds_rt_generate_core_dump (commandId, payload);
118119
if (ipc_result != DS_IPC_S_OK) {
119120
ds_ipc_message_send_error (stream, ipc_result);
120121
ep_raise_error ();
@@ -144,6 +145,7 @@ ds_dump_protocol_helper_handle_ipc_message (
144145

145146
switch ((DiagnosticsDumpCommandId)ds_ipc_header_get_commandid (ds_ipc_message_get_header_ref (message))) {
146147
case DS_DUMP_COMMANDID_GENERATE_CORE_DUMP:
148+
case DS_DUMP_COMMANDID_GENERATE_CORE_DUMP2:
147149
result = dump_protocol_helper_generate_core_dump (message, stream);
148150
break;
149151
default:

src/native/eventpipe/ds-dump-protocol.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ struct _DiagnosticsGenerateCoreDumpCommandPayload_Internal {
2727
// The protocol buffer is defined as:
2828
// string - dumpName (UTF16)
2929
// int - dumpType
30-
// int - diagnostics
30+
// uint32 - flags
3131
// returns
3232
// ulong - status
3333

3434
const ep_char16_t *dump_name;
3535
uint32_t dump_type;
36-
uint32_t diagnostics;
36+
uint32_t flags;
3737
};
3838

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

4545
DS_DEFINE_GETTER(DiagnosticsGenerateCoreDumpCommandPayload *, generate_core_dump_command_payload, const ep_char16_t *, dump_name)
4646
DS_DEFINE_GETTER(DiagnosticsGenerateCoreDumpCommandPayload *, generate_core_dump_command_payload, uint32_t, dump_type)
47-
DS_DEFINE_GETTER(DiagnosticsGenerateCoreDumpCommandPayload *, generate_core_dump_command_payload, uint32_t, diagnostics)
47+
DS_DEFINE_GETTER(DiagnosticsGenerateCoreDumpCommandPayload *, generate_core_dump_command_payload, uint32_t, flags)
4848

4949
DiagnosticsGenerateCoreDumpCommandPayload *
5050
ds_generate_core_dump_command_payload_alloc (void);

src/native/eventpipe/ds-rt.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ ds_rt_config_value_get_default_port_suspend (void);
8787

8888
static
8989
ds_ipc_result_t
90-
ds_rt_generate_core_dump (DiagnosticsGenerateCoreDumpCommandPayload *payload);
90+
ds_rt_generate_core_dump (DiagnosticsDumpCommandId commandId, DiagnosticsGenerateCoreDumpCommandPayload *payload);
9191

9292
/*
9393
* DiagnosticsIpc.

src/native/eventpipe/ds-types.h

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ typedef struct _EventPipeStopTracingCommandPayload EventPipeStopTracingCommandPa
4444
typedef enum {
4545
DS_DUMP_COMMANDID_RESERVED = 0x00,
4646
DS_DUMP_COMMANDID_GENERATE_CORE_DUMP = 0x01,
47+
DS_DUMP_COMMANDID_GENERATE_CORE_DUMP2 = 0x02,
4748
// future
4849
} DiagnosticsDumpCommandId;
4950

0 commit comments

Comments
 (0)