diff --git a/src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h b/src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h index 607286d048bab..7ee83ae8c5f84 100644 --- a/src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h +++ b/src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h @@ -1169,7 +1169,22 @@ ep_rt_entrypoint_assembly_name_get_utf8 (void) { STATIC_CONTRACT_NOTHROW; - return reinterpret_cast(GetAppDomain ()->GetRootAssembly ()->GetSimpleName ()); + AppDomain *app_domain_ref = nullptr; + Assembly *assembly_ref = nullptr; + + app_domain_ref = GetAppDomain (); + if (app_domain_ref != nullptr) + { + assembly_ref = app_domain_ref->GetRootAssembly (); + if (assembly_ref != nullptr) + { + return reinterpret_cast(assembly_ref->GetSimpleName ()); + } + } + + // fallback to the empty string if we can't get assembly info, e.g., if the runtime is + // suspended before an assembly is loaded. + return reinterpret_cast(""); } static diff --git a/src/tests/tracing/eventpipe/diagnosticport/diagnosticport.cs b/src/tests/tracing/eventpipe/diagnosticport/diagnosticport.cs index a4e6bd6418100..b1455d01e2113 100644 --- a/src/tests/tracing/eventpipe/diagnosticport/diagnosticport.cs +++ b/src/tests/tracing/eventpipe/diagnosticport/diagnosticport.cs @@ -388,6 +388,42 @@ public static async Task TEST_ConfigValidation() return fSuccess; } + public static async Task TEST_CanGetProcessInfo2WhileSuspended() + { + bool fSuccess = true; + Task subprocessTask = Utils.RunSubprocess( + currentAssembly: Assembly.GetExecutingAssembly(), + environment: new Dictionary + { + { Utils.DiagnosticPortSuspend, "1" } + }, + duringExecution: (int pid) => + { + Stream stream = ConnectionHelper.GetStandardTransport(pid); + + // 0x04 = ProcessCommandSet, 0x04 = ProcessInfo2 + var processInfoMessage = new IpcMessage(0x04, 0x04); + Logger.logger.Log($"Wrote: {processInfoMessage}"); + IpcMessage response = IpcClient.SendMessage(stream, processInfoMessage); + Logger.logger.Log($"Received: [{response.Payload.Select(b => b.ToString("X2") + " ").Aggregate(string.Concat)}]"); + ProcessInfo2 processInfo2 = ProcessInfo2.TryParse(response.Payload); + Utils.Assert(String.IsNullOrEmpty(processInfo2.ManagedEntrypointAssemblyName)); + + // send resume command on this connection + var message = new IpcMessage(0x04,0x01); + Logger.logger.Log($"Sent: {message.ToString()}"); + response = IpcClient.SendMessage(ConnectionHelper.GetStandardTransport(pid), message); + Logger.logger.Log($"Received: {response.ToString()}"); + + return Task.FromResult(true); + } + ); + + fSuccess &= await subprocessTask; + + return fSuccess; + } + public static async Task Main(string[] args) { if (args.Length >= 1)