From 283ac72f742035235b62c0437c8c52ffe034826e Mon Sep 17 00:00:00 2001 From: John Salem Date: Tue, 4 May 2021 10:39:58 -0700 Subject: [PATCH 01/16] Stash the entrypoint assembly path --- src/coreclr/vm/ceeload.cpp | 10 ++++++++++ src/coreclr/vm/ceeload.h | 1 + 2 files changed, 11 insertions(+) diff --git a/src/coreclr/vm/ceeload.cpp b/src/coreclr/vm/ceeload.cpp index e1003c8cff634..3f5e1ab348edd 100644 --- a/src/coreclr/vm/ceeload.cpp +++ b/src/coreclr/vm/ceeload.cpp @@ -11304,6 +11304,7 @@ static bool GetBasename(LPCWSTR _src, __out_ecount(dstlen) __out_z LPWSTR _dst, } static LPCWSTR s_pCommandLine = NULL; +static LPCWSTR s_pEntrypointAssemblyPath = NULL; // Retrieve the full command line for the current process. LPCWSTR GetManagedCommandLine() @@ -11312,6 +11313,12 @@ LPCWSTR GetManagedCommandLine() return s_pCommandLine; } +LPCWSTR GetManagedEntrypointAssemblyPath() +{ + LIMITED_METHOD_CONTRACT; + return s_pEntrypointAssemblyPath; +} + LPCWSTR GetCommandLineForDiagnostics() { // Get the managed command line. @@ -11368,6 +11375,9 @@ void SaveManagedCommandLine(LPCWSTR pwzAssemblyPath, int argc, LPCWSTR *argv) // Get the command line. LPCWSTR osCommandLine = GetCommandLineW(); + // store the entrypoint path + s_pEntrypointAssemblyPath = pwzAssemblyPath; + #ifndef TARGET_UNIX // On Windows, osCommandLine contains the executable and all arguments. s_pCommandLine = osCommandLine; diff --git a/src/coreclr/vm/ceeload.h b/src/coreclr/vm/ceeload.h index 13a78ec96f4ef..96286856807e5 100644 --- a/src/coreclr/vm/ceeload.h +++ b/src/coreclr/vm/ceeload.h @@ -3390,5 +3390,6 @@ struct VASigCookieEx : public VASigCookie void SaveManagedCommandLine(LPCWSTR pwzAssemblyPath, int argc, LPCWSTR *argv); LPCWSTR GetCommandLineForDiagnostics(); +LPCWSTR GetManagedEntrypointAssemblyPath(); #endif // !CEELOAD_H_ From 66fd5f2b1d021e06d010fbe621c04d5016137190 Mon Sep 17 00:00:00 2001 From: John Salem Date: Tue, 4 May 2021 10:41:20 -0700 Subject: [PATCH 02/16] Add ep funcs for accessing entrypoint and version * TODO: get Mono's entrypoint asm --- .../vm/eventing/eventpipe/ep-rt-coreclr.h | 16 +++++++++++ src/mono/mono/eventpipe/ep-rt-mono.h | 27 +++++++++++++++++++ src/native/eventpipe/ep-rt.h | 8 ++++++ 3 files changed, 51 insertions(+) diff --git a/src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h b/src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h index da3ff470670ed..161efec64fbab 100644 --- a/src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h +++ b/src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h @@ -12,6 +12,7 @@ #include "fstream.h" #include "typestring.h" #include "win32threadpool.h" +#include "clrversion.h" #undef EP_ARRAY_SIZE #define EP_ARRAY_SIZE(expr) (sizeof(expr) / sizeof ((expr) [0])) @@ -1161,6 +1162,21 @@ ep_rt_coreclr_config_lock_get (void) return &_ep_rt_coreclr_config_lock_handle; } +static +inline +const ep_char16_t * +ep_rt_entrypoint_assembly_path_get_ref_utf16 () +{ + return reinterpret_cast(GetManagedEntrypointAssemblyPath()); +} + +static +const ep_char16_t * +ep_rt_runtime_version_get_ref_utf16 () +{ + return reinterpret_cast(CLR_PRODUCT_VERSION_L); +} + /* * Atomics. */ diff --git a/src/mono/mono/eventpipe/ep-rt-mono.h b/src/mono/mono/eventpipe/ep-rt-mono.h index 985e7d847a3c2..1afac506eaa83 100644 --- a/src/mono/mono/eventpipe/ep-rt-mono.h +++ b/src/mono/mono/eventpipe/ep-rt-mono.h @@ -1820,6 +1820,33 @@ ep_rt_diagnostics_command_line_get (void) return cmd_line; } +static +const ep_char16_t * +ep_rt_entrypoint_assembly_path_get_ref_utf16 () +{ + // TODO: find mono entrypoint assembly path + const ep_char8_t *foo = "TODO"; + return g_utf8_to_utf16 ((const gchar *)foo g_utf8_len (foo), NULL, NULL, NULL); +} + +static +const ep_char16_t * +runtime_version_string_lazy_get_ref_utf16 () +{ + // stash a utf16 copy of the version string from _version.h + extern ep_char16_t *runtime_version_string_utf16 = NULL; + if (runtime_version_string_utf16 == NULL) + runtime_version_string_utf16 = (ep_char16_t *)g_utf8_to_utf16 ((const gchar *)runtime_version_string, g_utf8_len (runtime_version_string), NULL, NULL, NULL); + return runtime_version_string_utf16; +} + +static +const ep_char16_t * +ep_rt_runtime_version_get_ref_utf16 () +{ + return runtime_version_string_lazy_get_ref_utf16 (); +} + /* * Thread. */ diff --git a/src/native/eventpipe/ep-rt.h b/src/native/eventpipe/ep-rt.h index dab786dbf34a4..491d5557a4517 100644 --- a/src/native/eventpipe/ep-rt.h +++ b/src/native/eventpipe/ep-rt.h @@ -597,6 +597,14 @@ static void ep_rt_os_environment_get_utf16 (ep_rt_env_array_utf16_t *env_array); +static +const ep_char16_t * +ep_rt_entrypoint_assembly_path_get_ref_utf16 (); + +static +const ep_char16_t * +ep_rt_runtime_version_get_ref_utf16 (); + /* * Lock */ From 915c16d4e83ab5ef87e65fa8e3595995c87b3fe8 Mon Sep 17 00:00:00 2001 From: John Salem Date: Tue, 4 May 2021 10:42:14 -0700 Subject: [PATCH 03/16] Add ProcessInfo2 command * command includes everything the first one did + product ver and entrypoint asm path * Add a test too --- src/native/eventpipe/ds-process-protocol.c | 211 ++++++++++++++++ src/native/eventpipe/ds-process-protocol.h | 50 ++++ src/native/eventpipe/ds-types.h | 2 + .../tracing/eventpipe/common/IpcUtils.cs | 47 ++++ .../eventpipe/processinfo2/processinfo2.cs | 235 ++++++++++++++++++ .../processinfo2/processinfo2.csproj | 19 ++ 6 files changed, 564 insertions(+) create mode 100644 src/tests/tracing/eventpipe/processinfo2/processinfo2.cs create mode 100644 src/tests/tracing/eventpipe/processinfo2/processinfo2.csproj diff --git a/src/native/eventpipe/ds-process-protocol.c b/src/native/eventpipe/ds-process-protocol.c index 2ce9ddc4fc44a..e9998e4238d1a 100644 --- a/src/native/eventpipe/ds-process-protocol.c +++ b/src/native/eventpipe/ds-process-protocol.c @@ -53,6 +53,12 @@ process_protocol_helper_get_process_info ( DiagnosticsIpcMessage *message, DiagnosticsIpcStream *stream); +static +bool +process_protocol_helper_get_process_info_2 ( + DiagnosticsIpcMessage *message, + DiagnosticsIpcStream *stream); + static bool process_protocol_helper_get_process_env ( @@ -191,6 +197,141 @@ ds_process_info_payload_fini (DiagnosticsProcessInfoPayload *payload) ; } +/* + * DiagnosticsProcessInfo2Payload. + */ + +static +uint16_t +process_info_2_payload_get_size (DiagnosticsProcessInfo2Payload *payload) +{ + // see IPC spec @ https://github.com/dotnet/diagnostics/blob/master/documentation/design-docs/ipc-protocol.md + // for definition of serialization format + + // uint64_t ProcessId; -> 8 bytes + // GUID RuntimeCookie; -> 16 bytes + // LPCWSTR CommandLine; -> 4 bytes + strlen * sizeof(WCHAR) + // LPCWSTR OS; -> 4 bytes + strlen * sizeof(WCHAR) + // LPCWSTR Arch; -> 4 bytes + strlen * sizeof(WCHAR) + + EP_ASSERT (payload != NULL); + + size_t size = 0; + size += sizeof(payload->process_id); + size += sizeof(payload->runtime_cookie); + + size += sizeof(uint32_t); + size += (payload->command_line != NULL) ? + (ep_rt_utf16_string_len (payload->command_line) + 1) * sizeof(ep_char16_t) : 0; + + size += sizeof(uint32_t); + size += (payload->os != NULL) ? + (ep_rt_utf16_string_len (payload->os) + 1) * sizeof(ep_char16_t) : 0; + + size += sizeof(uint32_t); + size += (payload->arch != NULL) ? + (ep_rt_utf16_string_len (payload->arch) + 1) * sizeof(ep_char16_t) : 0; + + size += sizeof(uint32_t); + size += (payload->managed_entrypoint_assembly_path != NULL) ? + (ep_rt_utf16_string_len (payload->managed_entrypoint_assembly_path) + 1) * sizeof(ep_char16_t) : 0; + + size += sizeof(uint32_t); + size += (payload->clr_product_version != NULL) ? + (ep_rt_utf16_string_len (payload->clr_product_version) + 1) * sizeof(ep_char16_t) : 0; + + EP_ASSERT (size <= UINT16_MAX); + return (uint16_t)size; +} + +static +bool +process_info_2_payload_flatten ( + void *payload, + uint8_t **buffer, + uint16_t *size) +{ + DiagnosticsProcessInfo2Payload *process_info = (DiagnosticsProcessInfo2Payload*)payload; + + EP_ASSERT (payload != NULL); + EP_ASSERT (buffer != NULL); + EP_ASSERT (*buffer != NULL); + EP_ASSERT (size != NULL); + EP_ASSERT (process_info_2_payload_get_size (process_info) == *size); + + // see IPC spec @ https://github.com/dotnet/diagnostics/blob/master/documentation/design-docs/ipc-protocol.md + // for definition of serialization format + + bool success = true; + + // uint64_t ProcessId; + memcpy (*buffer, &process_info->process_id, sizeof (process_info->process_id)); + *buffer += sizeof (process_info->process_id); + *size -= sizeof (process_info->process_id); + + // GUID RuntimeCookie; + memcpy(*buffer, &process_info->runtime_cookie, sizeof (process_info->runtime_cookie)); + *buffer += sizeof (process_info->runtime_cookie); + *size -= sizeof (process_info->runtime_cookie); + + // LPCWSTR CommandLine; + success &= ds_ipc_message_try_write_string_utf16_t (buffer, size, process_info->command_line); + + // LPCWSTR OS; + if (success) + success &= ds_ipc_message_try_write_string_utf16_t (buffer, size, process_info->os); + + // LPCWSTR Arch; + if (success) + success &= ds_ipc_message_try_write_string_utf16_t (buffer, size, process_info->arch); + + // LPCWSTR managed_entrypoint_assembly_path; + if (success) + success &= ds_ipc_message_try_write_string_utf16_t (buffer, size, process_info->managed_entrypoint_assembly_path); + + // LPCWSTR clr_product_version; + if (success) + success &= ds_ipc_message_try_write_string_utf16_t (buffer, size, process_info->clr_product_version); + + // Assert we've used the whole buffer we were given + EP_ASSERT(*size == 0); + + return success; +} + +DiagnosticsProcessInfo2Payload * +ds_process_info_2_payload_init ( + DiagnosticsProcessInfo2Payload *payload, + const ep_char16_t *command_line, + const ep_char16_t *os, + const ep_char16_t *arch, + uint32_t process_id, + const uint8_t *runtime_cookie, + const ep_char16_t *managed_entrypoint_assembly_path, + const ep_char16_t *clr_product_version) +{ + ep_return_null_if_nok (payload != NULL); + + payload->command_line = command_line; + payload->os = os; + payload->arch = arch; + payload->process_id = process_id; + payload->managed_entrypoint_assembly_path = managed_entrypoint_assembly_path; + payload->clr_product_version = clr_product_version; + + if (runtime_cookie) + memcpy (&payload->runtime_cookie, runtime_cookie, EP_GUID_SIZE); + + return payload; +} + +void +ds_process_info_2_payload_fini (DiagnosticsProcessInfo2Payload *payload) +{ + ; +} + + /* * DiagnosticsEnvironmentInfoPayload. */ @@ -386,6 +527,74 @@ process_protocol_helper_get_process_info ( ep_exit_error_handler (); } +static +bool +process_protocol_helper_get_process_info_2 ( + DiagnosticsIpcMessage *message, + DiagnosticsIpcStream *stream) +{ + EP_ASSERT (message != NULL); + EP_ASSERT (stream != NULL); + + bool result = false; + ep_char16_t *command_line = NULL; + ep_char16_t *os_info = NULL; + ep_char16_t *arch_info = NULL; + const ep_char16_t *managed_entrypoint_assembly_path_ref = ep_rt_entrypoint_assembly_path_get_ref_utf16 (); + const ep_char16_t *clr_product_version_ref = ep_rt_runtime_version_get_ref_utf16 (); + DiagnosticsProcessInfo2Payload payload; + DiagnosticsProcessInfo2Payload *process_info_2_payload = NULL; + + command_line = ep_rt_utf8_to_utf16_string (ep_rt_diagnostics_command_line_get (), -1); + ep_raise_error_if_nok (command_line != NULL); + + os_info = ep_rt_utf8_to_utf16_string (ep_event_source_get_os_info (), -1); + ep_raise_error_if_nok (os_info != NULL); + + arch_info = ep_rt_utf8_to_utf16_string (ep_event_source_get_arch_info (), -1); + ep_raise_error_if_nok (arch_info != NULL); + + ep_raise_error_if_nok (managed_entrypoint_assembly_path_ref != NULL); + + ep_raise_error_if_nok (clr_product_version_ref != NULL); + + process_info_2_payload = ds_process_info_2_payload_init ( + &payload, + command_line, + os_info, + arch_info, + ep_rt_current_process_get_id (), + ds_ipc_advertise_cookie_v1_get (), + managed_entrypoint_assembly_path_ref, + clr_product_version_ref); + ep_raise_error_if_nok (process_info_2_payload != NULL); + + ep_raise_error_if_nok (ds_ipc_message_initialize_buffer ( + message, + ds_ipc_header_get_generic_success (), + (void *)process_info_2_payload, + process_info_2_payload_get_size (process_info_2_payload), + process_info_2_payload_flatten)); + + ep_raise_error_if_nok (ds_ipc_message_send (message, stream)); + + result = true; + +ep_on_exit: + ds_process_info_2_payload_fini (process_info_2_payload); + ep_rt_utf16_string_free (arch_info); + ep_rt_utf16_string_free (os_info); + ep_rt_utf16_string_free (command_line); + ds_ipc_stream_free (stream); + return result; + +ep_on_error: + EP_ASSERT (!result); + ds_ipc_message_send_error (stream, DS_IPC_E_FAIL); + DS_LOG_WARNING_0 ("Failed to send DiagnosticsIPC response"); + ep_exit_error_handler (); +} + static bool process_protocol_helper_get_process_env ( @@ -566,6 +775,8 @@ ds_process_protocol_helper_handle_ipc_message ( break; case DS_PROCESS_COMMANDID_SET_ENV_VAR: result = process_protocol_helper_set_environment_variable (message, stream); + case DS_PROCESS_COMMANDID_GET_PROCESS_INFO_2: + result = process_protocol_helper_get_process_info_2 (message, stream); break; default: result = process_protocol_helper_unknown_command (message, stream); diff --git a/src/native/eventpipe/ds-process-protocol.h b/src/native/eventpipe/ds-process-protocol.h index 1b2c279aeee14..c7cee8b9c1d88 100644 --- a/src/native/eventpipe/ds-process-protocol.h +++ b/src/native/eventpipe/ds-process-protocol.h @@ -58,6 +58,56 @@ ds_process_info_payload_init ( void ds_process_info_payload_fini (DiagnosticsProcessInfoPayload *payload); +/* +* DiagnosticsProcessInfo2Payload +*/ + +// command = 0x0400 +#if defined(DS_INLINE_GETTER_SETTER) || defined(DS_IMPL_PROCESS_PROTOCOL_GETTER_SETTER) +struct _DiagnosticsProcessInfo2Payload { +#else +struct _DiagnosticsProcessInfo2Payload_Internal { +#endif + // The protocol buffer is defined as: + // X, Y, Z means encode bytes for X followed by bytes for Y followed by bytes for Z + // uint = 4 little endian bytes + // long = 8 little endian bytes + // GUID = 16 little endian bytes + // wchar = 2 little endian bytes, UTF16 encoding + // array = uint length, length # of Ts + // string = (array where the last char must = 0) or (length = 0) + + // ProcessInfo = long pid, string cmdline, string OS, string arch, GUID runtimeCookie, string managed entrypoint assembly path, string clr product version + uint64_t process_id; + const ep_char16_t *command_line; + const ep_char16_t *os; + const ep_char16_t *arch; + uint8_t runtime_cookie [EP_GUID_SIZE]; + const ep_char16_t *managed_entrypoint_assembly_path; + const ep_char16_t *clr_product_version; + +}; + +#if !defined(DS_INLINE_GETTER_SETTER) && !defined(DS_IMPL_PROCESS_PROTOCOL_GETTER_SETTER) +struct _DiagnosticsProcessInfo2Payload { + uint8_t _internal [sizeof (struct _DiagnosticsProcessInfo2Payload_Internal)]; +}; +#endif + +DiagnosticsProcessInfo2Payload * +ds_process_info_2_payload_init ( + DiagnosticsProcessInfo2Payload *payload, + const ep_char16_t *command_line, + const ep_char16_t *os, + const ep_char16_t *arch, + uint32_t process_id, + const uint8_t *runtime_cookie, + const ep_char16_t *managed_entrypoint_assembly_path, + const ep_char16_t *clr_product_version); + +void +ds_process_info_2_payload_fini (DiagnosticsProcessInfo2Payload *payload); + /* * DiagnosticsEnvironmentInfoPayload */ diff --git a/src/native/eventpipe/ds-types.h b/src/native/eventpipe/ds-types.h index 243951d243dce..fc5d3e1a2eccc 100644 --- a/src/native/eventpipe/ds-types.h +++ b/src/native/eventpipe/ds-types.h @@ -29,6 +29,7 @@ typedef struct _DiagnosticsPort DiagnosticsPort; typedef struct _DiagnosticsPortBuilder DiagnosticsPortBuilder; typedef struct _DiagnosticsPortVtable DiagnosticsPortVtable; typedef struct _DiagnosticsProcessInfoPayload DiagnosticsProcessInfoPayload; +typedef struct _DiagnosticsProcessInfo2Payload DiagnosticsProcessInfo2Payload; typedef struct _EventPipeCollectTracingCommandPayload EventPipeCollectTracingCommandPayload; typedef struct _EventPipeCollectTracing2CommandPayload EventPipeCollectTracing2CommandPayload; typedef struct _EventPipeStopTracingCommandPayload EventPipeStopTracingCommandPayload; @@ -67,6 +68,7 @@ typedef enum { DS_PROCESS_COMMANDID_RESUME_RUNTIME = 0x01, DS_PROCESS_COMMANDID_GET_PROCESS_ENV = 0x02, DS_PROCESS_COMMANDID_SET_ENV_VAR = 0x03, + DS_PROCESS_COMMANDID_GET_PROCESS_INFO_2 = 0x04 // future } DiagnosticsProcessCommandId; diff --git a/src/tests/tracing/eventpipe/common/IpcUtils.cs b/src/tests/tracing/eventpipe/common/IpcUtils.cs index 6f60368894d7e..47eb0db2dc669 100644 --- a/src/tests/tracing/eventpipe/common/IpcUtils.cs +++ b/src/tests/tracing/eventpipe/common/IpcUtils.cs @@ -339,6 +339,53 @@ string ParseString(ref int start, ref int end) } } + public class ProcessInfo2 + { + // uint64_t ProcessId; + // GUID RuntimeCookie; + // LPCWSTR CommandLine; + // LPCWSTR OS; + // LPCWSTR Arch; + public UInt64 ProcessId; + public Guid RuntimeCookie; + public string Commandline; + public string OS; + public string Arch; + public string ManagedEntrypointAssemblyPath; + public string ClrProductVersion; + + public static ProcessInfo2 TryParse(byte[] buf) + { + var info = new ProcessInfo2(); + int start = 0; + int end = 8; /* sizeof(uint64_t) */ + info.ProcessId = BitConverter.ToUInt64(buf[start..end]); + + start = end; + end = start + 16; /* sizeof(guid) */ + info.RuntimeCookie = new Guid(buf[start..end]); + + string ParseString(ref int start, ref int end) + { + start = end; + end = start + 4; /* sizeof(uint32_t) */ + uint nChars = BitConverter.ToUInt32(buf[start..end]); + + start = end; + end = start + ((int)nChars * sizeof(char)); + return System.Text.Encoding.Unicode.GetString(buf[start..end]).TrimEnd('\0'); + } + + info.Commandline = ParseString(ref start, ref end); + info.OS = ParseString(ref start, ref end); + info.Arch = ParseString(ref start, ref end); + info.ManagedEntrypointAssemblyPath = ParseString(ref start, ref end); + info.ClrProductVersion = ParseString(ref start, ref end); + + return info; + } + } + public class IpcClient { public static IpcMessage SendMessage(Stream stream, IpcMessage message) diff --git a/src/tests/tracing/eventpipe/processinfo2/processinfo2.cs b/src/tests/tracing/eventpipe/processinfo2/processinfo2.cs new file mode 100644 index 0000000000000..2bd00ddaece84 --- /dev/null +++ b/src/tests/tracing/eventpipe/processinfo2/processinfo2.cs @@ -0,0 +1,235 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; +using System.Collections.Generic; +using System.Diagnostics.Tracing; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Runtime.InteropServices; +using System.Reflection; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Diagnostics.Tools.RuntimeClient; +using Microsoft.Diagnostics.Tracing; +using Tracing.Tests.Common; + +namespace Tracing.Tests.ProcessInfoValidation +{ + public class ProcessInfoValidation + { + public static string NormalizeCommandLine(string cmdline) + { + // ASSUMPTION: double quotes (") and single quotes (') are used for paths with spaces + // ASSUMPTION: This test will only have two parts to the commandline + + // check for quotes in first part + var parts = new List(); + bool isQuoted = false; + int start = 0; + + for (int i = 0; i < cmdline.Length; i++) + { + if (isQuoted) + { + if (cmdline[i] == '"' || cmdline[i] == '\'') + { + parts.Add(cmdline.Substring(start, i - start)); + isQuoted = false; + start = i + 1; + } + } + else if (cmdline[i] == '"' || cmdline[i] == '\'') + { + isQuoted = true; + start = i + 1; + } + else if (cmdline[i] == ' ') + { + parts.Add(cmdline.Substring(start, i - start)); + start = i + 1; + } + else if (i == cmdline.Length - 1) + { + parts.Add(cmdline.Substring(start)); + } + } + + string normalizedCommandLine = parts + .Where(part => !string.IsNullOrWhiteSpace(part)) + .Select(part => (new FileInfo(part)).FullName) + .Aggregate((s1, s2) => string.Join(' ', s1, s2)); + + // Tests are run out of /tmp on Mac and linux, but on Mac /tmp is actually a symlink that points to /private/tmp. + // This isn't represented in the output from FileInfo.FullName unfortunately, so we'll fake that completion in that case. + if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) && normalizedCommandLine.StartsWith("/tmp/")) + normalizedCommandLine = "/private" + normalizedCommandLine; + + return normalizedCommandLine; + } + + public static int Main(string[] args) + { + + Process currentProcess = Process.GetCurrentProcess(); + int pid = currentProcess.Id; + Logger.logger.Log($"Test PID: {pid}"); + + Stream stream = ConnectionHelper.GetStandardTransport(pid); + + // 0x04 = ProcessCommandSet, 0x03 = ProcessInfo2 + var processInfoMessage = new IpcMessage(0x04, 0x03); + Logger.logger.Log($"Wrote: {processInfoMessage}"); + IpcMessage response = IpcClient.SendMessage(stream, processInfoMessage); + Logger.logger.Log($"Received: "); + + Utils.Assert(response.Header.CommandSet == 0xFF, $"Response must have Server command set. Expected: 0xFF, Received: 0x{response.Header.CommandSet:X2}"); // server + Utils.Assert(response.Header.CommandId == 0x00, $"Response must have OK command id. Expected: 0x00, Received: 0x{response.Header.CommandId:X2}"); // OK + + // Parse payload + // uint64_t ProcessId; + // GUID RuntimeCookie; + // LPCWSTR CommandLine; + // LPCWSTR OS; + // LPCWSTR Arch; + + int totalSize = response.Payload.Length; + Logger.logger.Log($"Total size of Payload = {totalSize} bytes"); + + // VALIDATE PID + int start = 0; + int end = start + 8 /* sizeof(uint63_t) */; + UInt64 processId = BitConverter.ToUInt64(response.Payload[start..end]); + Utils.Assert((int)processId == pid, $"PID in process info must match. Expected: {pid}, Received: {processId}"); + Logger.logger.Log($"pid: {processId}"); + + // VALIDATE RUNTIME COOKIE + start = end; + end = start + 16 /* sizeof(GUID) */; + Guid runtimeCookie = new Guid(response.Payload[start..end]); + Logger.logger.Log($"runtimeCookie: {runtimeCookie}"); + + // VALIDATE COMMAND LINE + start = end; + end = start + 4 /* sizeof(uint32_t) */; + UInt32 commandLineLength = BitConverter.ToUInt32(response.Payload[start..end]); + Logger.logger.Log($"commandLineLength: {commandLineLength}"); + + start = end; + end = start + ((int)commandLineLength * sizeof(char)); + Utils.Assert(end <= totalSize, $"String end can't exceed payload size. Expected: <{totalSize}, Received: {end} (decoded length: {commandLineLength})"); + Logger.logger.Log($"commandLine bytes: [ {response.Payload[start..end].Select(b => b.ToString("X2") + " ").Aggregate(string.Concat)}]"); + string commandLine = System.Text.Encoding.Unicode.GetString(response.Payload[start..end]).TrimEnd('\0'); + Logger.logger.Log($"commandLine: \"{commandLine}\""); + + // The following logic is tailored to this specific test where the cmdline _should_ look like the following: + // /path/to/corerun /path/to/processinfo.dll + // or + // "C:\path\to\CoreRun.exe" C:\path\to\processinfo.dll + string currentProcessCommandLine = $"{currentProcess.MainModule.FileName} {System.Reflection.Assembly.GetExecutingAssembly().Location}"; + string receivedCommandLine = NormalizeCommandLine(commandLine); + + Utils.Assert(currentProcessCommandLine.Equals(receivedCommandLine, StringComparison.OrdinalIgnoreCase), $"CommandLine must match current process. Expected: {currentProcessCommandLine}, Received: {receivedCommandLine} (original: {commandLine})"); + + // VALIDATE OS + start = end; + end = start + 4 /* sizeof(uint32_t) */; + UInt32 OSLength = BitConverter.ToUInt32(response.Payload[start..end]); + Logger.logger.Log($"OSLength: {OSLength}"); + + start = end; + end = start + ((int)OSLength * sizeof(char)); + Utils.Assert(end <= totalSize, $"String end can't exceed payload size. Expected: <{totalSize}, Received: {end} (decoded length: {OSLength})"); + Logger.logger.Log($"OS bytes: [ {response.Payload[start..end].Select(b => b.ToString("X2") + " ").Aggregate(string.Concat)}]"); + string OS = System.Text.Encoding.Unicode.GetString(response.Payload[start..end]).TrimEnd('\0'); + Logger.logger.Log($"OS: \"{OS}\""); + + // see eventpipeeventsource.cpp for these values + string expectedOSValue = null; + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + expectedOSValue = "Windows"; + } + else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + { + expectedOSValue = "macOS"; + } + else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + expectedOSValue = "Linux"; + } + else + { + expectedOSValue = "Unknown"; + } + + Utils.Assert(expectedOSValue.Equals(OS), $"OS must match current Operating System. Expected: \"{expectedOSValue}\", Received: \"{OS}\""); + + // VALIDATE ARCH + start = end; + end = start + 4 /* sizeof(uint32_t) */; + UInt32 archLength = BitConverter.ToUInt32(response.Payload[start..end]); + Logger.logger.Log($"archLength: {archLength}"); + + start = end; + end = start + ((int)archLength * sizeof(char)); + Utils.Assert(end <= totalSize, $"String end can't exceed payload size. Expected: <{totalSize}, Received: {end} (decoded length: {archLength})"); + Logger.logger.Log($"arch bytes: [ {response.Payload[start..end].Select(b => b.ToString("X2") + " ").Aggregate(string.Concat)}]"); + string arch = System.Text.Encoding.Unicode.GetString(response.Payload[start..end]).TrimEnd('\0'); + Logger.logger.Log($"arch: \"{arch}\""); + + // see eventpipeeventsource.cpp for these values + string expectedArchValue = RuntimeInformation.ProcessArchitecture switch + { + Architecture.X86 => "x86", + Architecture.X64 => "x64", + Architecture.Arm => "arm32", + Architecture.Arm64 => "arm64", + _ => "Unknown" + }; + + Utils.Assert(expectedArchValue.Equals(arch), $"OS must match current Operating System. Expected: \"{expectedArchValue}\", Received: \"{arch}\""); + + // VALIDATE ManagedEntrypointAssemblyPath + start = end; + end = start + 4 /* sizeof(uint32_t) */; + UInt32 managedEntrypointAssemblyPathSize = BitConverter.ToUInt32(response.Payload[start..end]); + Logger.logger.Log($"managedEntrypointAssemblyPathSize: {managedEntrypointAssemblyPathSize}"); + + start = end; + end = start + ((int)managedEntrypointAssemblyPathSize * sizeof(char)); + Utils.Assert(end <= totalSize, $"String end can't exceed payload size. Expected: <{totalSize}, Received: {end} (decoded length: {managedEntrypointAssemblyPathSize})"); + Logger.logger.Log($"ManagedEntrypointAssemblyPath bytes: [ {response.Payload[start..end].Select(b => b.ToString("X2") + " ").Aggregate(string.Concat)}]"); + string managedEntrypointAssemblyPath = System.Text.Encoding.Unicode.GetString(response.Payload[start..end]).TrimEnd('\0'); + Logger.logger.Log($"ManagedEntrypointAssemblyPath: \"{managedEntrypointAssemblyPath}\""); + + string expectedManagedEntrypointAssemblyPath = System.Reflection.Assembly.GetExecutingAssembly().Location; + + Utils.Assert(expectedManagedEntrypointAssemblyPath.Equals(managedEntrypointAssemblyPath), $"ManagedEntrypointAssemblyPath must match. Expected: \"{expectedManagedEntrypointAssemblyPath}\", received: \"{managedEntrypointAssemblyPath}\""); + + // VALIDATE ClrProductVersion + start = end; + end = start + 4 /* sizeof(uint32_t) */; + UInt32 clrProductVersionSize = BitConverter.ToUInt32(response.Payload[start..end]); + Logger.logger.Log($"clrProductVersionSize: {clrProductVersionSize}"); + + start = end; + end = start + ((int)clrProductVersionSize * sizeof(char)); + Utils.Assert(end <= totalSize, $"String end can't exceed payload size. Expected: <{totalSize}, Received: {end} (decoded length: {clrProductVersionSize})"); + Logger.logger.Log($"ClrProductVersion bytes: [ {response.Payload[start..end].Select(b => b.ToString("X2") + " ").Aggregate(string.Concat)}]"); + string clrProductVersion = System.Text.Encoding.Unicode.GetString(response.Payload[start..end]).TrimEnd('\0'); + Logger.logger.Log($"ClrProductVersion: \"{clrProductVersion}\""); + + string expectedClrProductVersion = typeof(object).Assembly.GetCustomAttribute()?.InformationalVersion; + + Utils.Assert(expectedClrProductVersion.Equals(clrProductVersion), $"ClrProductVersion must match. Expected: \"{expectedClrProductVersion}\", received: \"{clrProductVersion}\""); + + Utils.Assert(end == totalSize, $"Full payload should have been read. Expected: {totalSize}, Received: {end}"); + + Logger.logger.Log($"\n{{\n\tprocessId: {processId},\n\truntimeCookie: {runtimeCookie},\n\tcommandLine: {commandLine},\n\tOS: {OS},\n\tArch: {arch},\n\tManagedEntrypointAssemblyPath: {managedEntrypointAssemblyPath},\n\tClrProductVersion: {clrProductVersion}\n}}"); + + return 100; + } + } +} \ No newline at end of file diff --git a/src/tests/tracing/eventpipe/processinfo2/processinfo2.csproj b/src/tests/tracing/eventpipe/processinfo2/processinfo2.csproj new file mode 100644 index 0000000000000..69e7a9fba00c2 --- /dev/null +++ b/src/tests/tracing/eventpipe/processinfo2/processinfo2.csproj @@ -0,0 +1,19 @@ + + + .NETCoreApp + exe + BuildAndRun + true + 0 + true + true + + true + + + + + + From b0372ce12cc0e6409a40df33708bf8b5ca8fe8be Mon Sep 17 00:00:00 2001 From: John Salem Date: Tue, 4 May 2021 15:12:48 -0700 Subject: [PATCH 04/16] Mono build fixes --- src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h | 4 ++-- src/mono/mono/eventpipe/ep-rt-mono.h | 10 +++++----- src/native/eventpipe/ep-rt.h | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h b/src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h index 161efec64fbab..64e714bc500b0 100644 --- a/src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h +++ b/src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h @@ -1165,14 +1165,14 @@ ep_rt_coreclr_config_lock_get (void) static inline const ep_char16_t * -ep_rt_entrypoint_assembly_path_get_ref_utf16 () +ep_rt_entrypoint_assembly_path_get_ref_utf16 (void) { return reinterpret_cast(GetManagedEntrypointAssemblyPath()); } static const ep_char16_t * -ep_rt_runtime_version_get_ref_utf16 () +ep_rt_runtime_version_get_ref_utf16 (void) { return reinterpret_cast(CLR_PRODUCT_VERSION_L); } diff --git a/src/mono/mono/eventpipe/ep-rt-mono.h b/src/mono/mono/eventpipe/ep-rt-mono.h index 1afac506eaa83..57eacc3685af8 100644 --- a/src/mono/mono/eventpipe/ep-rt-mono.h +++ b/src/mono/mono/eventpipe/ep-rt-mono.h @@ -1822,27 +1822,27 @@ ep_rt_diagnostics_command_line_get (void) static const ep_char16_t * -ep_rt_entrypoint_assembly_path_get_ref_utf16 () +ep_rt_entrypoint_assembly_path_get_ref_utf16 (void) { // TODO: find mono entrypoint assembly path const ep_char8_t *foo = "TODO"; - return g_utf8_to_utf16 ((const gchar *)foo g_utf8_len (foo), NULL, NULL, NULL); + return g_utf8_to_utf16 ((const gchar *)foo, g_utf8_len (foo), NULL, NULL, NULL); } static const ep_char16_t * -runtime_version_string_lazy_get_ref_utf16 () +runtime_version_string_lazy_get_ref_utf16 (void) { // stash a utf16 copy of the version string from _version.h extern ep_char16_t *runtime_version_string_utf16 = NULL; if (runtime_version_string_utf16 == NULL) - runtime_version_string_utf16 = (ep_char16_t *)g_utf8_to_utf16 ((const gchar *)runtime_version_string, g_utf8_len (runtime_version_string), NULL, NULL, NULL); + runtime_version_string_utf16 = (ep_char16_t *)g_utf8_to_utf16 ((const gchar *)product_version_string, g_utf8_len (product_version_string), NULL, NULL, NULL); return runtime_version_string_utf16; } static const ep_char16_t * -ep_rt_runtime_version_get_ref_utf16 () +ep_rt_runtime_version_get_ref_utf16 (void) { return runtime_version_string_lazy_get_ref_utf16 (); } diff --git a/src/native/eventpipe/ep-rt.h b/src/native/eventpipe/ep-rt.h index 491d5557a4517..42708e1a26f28 100644 --- a/src/native/eventpipe/ep-rt.h +++ b/src/native/eventpipe/ep-rt.h @@ -599,11 +599,11 @@ ep_rt_os_environment_get_utf16 (ep_rt_env_array_utf16_t *env_array); static const ep_char16_t * -ep_rt_entrypoint_assembly_path_get_ref_utf16 (); +ep_rt_entrypoint_assembly_path_get_ref_utf16 (void); static const ep_char16_t * -ep_rt_runtime_version_get_ref_utf16 (); +ep_rt_runtime_version_get_ref_utf16 (void); /* * Lock From aed54edfa061d9586c3cdd1a614330d174e90011 Mon Sep 17 00:00:00 2001 From: John Salem Date: Tue, 4 May 2021 16:35:28 -0700 Subject: [PATCH 05/16] fix Mono build --- src/mono/mono/eventpipe/ep-rt-mono.h | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/mono/mono/eventpipe/ep-rt-mono.h b/src/mono/mono/eventpipe/ep-rt-mono.h index 57eacc3685af8..1993075d65042 100644 --- a/src/mono/mono/eventpipe/ep-rt-mono.h +++ b/src/mono/mono/eventpipe/ep-rt-mono.h @@ -23,6 +23,16 @@ #include #include #include +#include + +#ifndef QUOTE_MACRO_L +#define QUOTE_MACRO_L_HELPER(x) L###x +#define QUOTE_MACRO_L(x) QUOTE_MACRO_L_HELPER(x) +#endif // QUOTE_MACRO_L + +#ifndef PRODUCT_VERSION_L +#define PRODUCT_VERSION_L QUOTE_MACRO_L(RuntimeProductVersion) +#endif // PRODUCT_VERSION_L #undef EP_ARRAY_SIZE #define EP_ARRAY_SIZE(expr) G_N_ELEMENTS(expr) @@ -1825,19 +1835,14 @@ const ep_char16_t * ep_rt_entrypoint_assembly_path_get_ref_utf16 (void) { // TODO: find mono entrypoint assembly path - const ep_char8_t *foo = "TODO"; - return g_utf8_to_utf16 ((const gchar *)foo, g_utf8_len (foo), NULL, NULL, NULL); + return (const ep_char16_t *)L"TODO"; } static const ep_char16_t * runtime_version_string_lazy_get_ref_utf16 (void) { - // stash a utf16 copy of the version string from _version.h - extern ep_char16_t *runtime_version_string_utf16 = NULL; - if (runtime_version_string_utf16 == NULL) - runtime_version_string_utf16 = (ep_char16_t *)g_utf8_to_utf16 ((const gchar *)product_version_string, g_utf8_len (product_version_string), NULL, NULL, NULL); - return runtime_version_string_utf16; + return (const ep_char16_t *)PRODUCT_VERSION_L; } static From 9535171b652f09d948948b6b35896ea4e29aec42 Mon Sep 17 00:00:00 2001 From: John Salem Date: Wed, 5 May 2021 11:52:03 -0700 Subject: [PATCH 06/16] PR feedback * fetch mono info from main assembly * remove ref naming * remove lazy method --- .../vm/eventing/eventpipe/ep-rt-coreclr.h | 4 +- src/mono/mono/eventpipe/ep-rt-mono.c | 4 + src/mono/mono/eventpipe/ep-rt-mono.h | 73 ++++++++++++++++--- src/native/eventpipe/ds-process-protocol.c | 4 +- src/native/eventpipe/ep-rt.h | 4 +- 5 files changed, 72 insertions(+), 17 deletions(-) diff --git a/src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h b/src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h index 64e714bc500b0..1025c95447b13 100644 --- a/src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h +++ b/src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h @@ -1165,14 +1165,14 @@ ep_rt_coreclr_config_lock_get (void) static inline const ep_char16_t * -ep_rt_entrypoint_assembly_path_get_ref_utf16 (void) +ep_rt_entrypoint_assembly_path_get_utf16 (void) { return reinterpret_cast(GetManagedEntrypointAssemblyPath()); } static const ep_char16_t * -ep_rt_runtime_version_get_ref_utf16 (void) +ep_rt_runtime_version_get_utf16 (void) { return reinterpret_cast(CLR_PRODUCT_VERSION_L); } diff --git a/src/mono/mono/eventpipe/ep-rt-mono.c b/src/mono/mono/eventpipe/ep-rt-mono.c index 77940f612202b..c07ac8411fe3d 100644 --- a/src/mono/mono/eventpipe/ep-rt-mono.c +++ b/src/mono/mono/eventpipe/ep-rt-mono.c @@ -43,6 +43,10 @@ char *_ep_rt_mono_os_cmd_line = NULL; mono_lazy_init_t _ep_rt_mono_managed_cmd_line_init = MONO_LAZY_INIT_STATUS_NOT_INITIALIZED; char *_ep_rt_mono_managed_cmd_line = NULL; +// Managed Entrypoint Assembly Path +mono_lazy_init_t _ep_rt_mono_managed_entrypoint_assembly_path_init = MONO_LAZY_INIT_STATUS_NOT_INITIALIZED; +ep_char16_t *_ep_rt_mono_managed_entrypoint_assembly_path = NULL; + // Sample profiler. static GArray * _ep_rt_mono_sampled_thread_callstacks = NULL; static uint32_t _ep_rt_mono_max_sampled_thread_count = 32; diff --git a/src/mono/mono/eventpipe/ep-rt-mono.h b/src/mono/mono/eventpipe/ep-rt-mono.h index 1993075d65042..b105a45d6cc3d 100644 --- a/src/mono/mono/eventpipe/ep-rt-mono.h +++ b/src/mono/mono/eventpipe/ep-rt-mono.h @@ -20,9 +20,11 @@ #include #include #include +#include #include #include #include +#include #include #ifndef QUOTE_MACRO_L @@ -446,6 +448,54 @@ managed_command_line_lazy_clean (void) *managed_command_line_get_ref () = NULL; } +static +inline +ep_char16_t * +managed_entrypoint_assembly_path_get (void) +{ + const MonoAssembly *main_assembly = mono_assembly_get_main (); + if (main_assembly == NULL) + return NULL; // TODO: default value? + const ep_char8_t *assembly_path = (const ep_char8_t *)m_image_get_filename (main_assembly->image); + return ep_rt_utf8_to_utf16_string (assembly_path, strlen((const char *)assembly_path)); +} + +static +inline +ep_char16_t ** +managed_entrypoint_assembly_path_get_ref (void) +{ + extern ep_char16_t *_ep_rt_mono_managed_entrypoint_assembly_path; + return &_ep_rt_mono_managed_entrypoint_assembly_path; +} + +static +inline +mono_lazy_init_t * +managed_entrypoint_assembly_path_get_init (void) +{ + extern mono_lazy_init_t _ep_rt_mono_managed_entrypoint_assembly_path_init; + return &_ep_rt_mono_managed_entrypoint_assembly_path_init; +} + +static +inline +void +managed_entrypoint_assembly_path_lazy_init (void) +{ + if (!*managed_entrypoint_assembly_path_get_ref ()) + *managed_entrypoint_assembly_path_get_ref () = managed_entrypoint_assembly_path_get (); +} + +static +inline +void +managed_entrypoint_assembly_path_lazy_clean (void) +{ + g_free (*managed_entrypoint_assembly_path_get_ref ()); + *managed_entrypoint_assembly_path_get_ref () = NULL; +} + static inline ep_rt_spin_lock_handle_t * @@ -1832,24 +1882,25 @@ ep_rt_diagnostics_command_line_get (void) static const ep_char16_t * -ep_rt_entrypoint_assembly_path_get_ref_utf16 (void) +ep_rt_entrypoint_assembly_path_get_utf16 (void) { - // TODO: find mono entrypoint assembly path - return (const ep_char16_t *)L"TODO"; -} + if (!mono_lazy_is_initialized (managed_entrypoint_assembly_path_get_init ())) { + ep_char16_t *entrypoint_assembly_path = managed_entrypoint_assembly_path_get (); + if (!entrypoint_assembly_path) + return NULL; + g_free (entrypoint_assembly_path); + } -static -const ep_char16_t * -runtime_version_string_lazy_get_ref_utf16 (void) -{ - return (const ep_char16_t *)PRODUCT_VERSION_L; + mono_lazy_initialize (managed_entrypoint_assembly_path_get_init (), managed_entrypoint_assembly_path_lazy_init); + EP_ASSERT (*managed_entrypoint_assembly_path_get_ref () != NULL); + return *managed_entrypoint_assembly_path_get_ref (); } static const ep_char16_t * -ep_rt_runtime_version_get_ref_utf16 (void) +ep_rt_runtime_version_get_utf16 (void) { - return runtime_version_string_lazy_get_ref_utf16 (); + return (const ep_char16_t *)PRODUCT_VERSION_L; } /* diff --git a/src/native/eventpipe/ds-process-protocol.c b/src/native/eventpipe/ds-process-protocol.c index e9998e4238d1a..d24e672fe9a34 100644 --- a/src/native/eventpipe/ds-process-protocol.c +++ b/src/native/eventpipe/ds-process-protocol.c @@ -540,8 +540,8 @@ process_protocol_helper_get_process_info_2 ( ep_char16_t *command_line = NULL; ep_char16_t *os_info = NULL; ep_char16_t *arch_info = NULL; - const ep_char16_t *managed_entrypoint_assembly_path_ref = ep_rt_entrypoint_assembly_path_get_ref_utf16 (); - const ep_char16_t *clr_product_version_ref = ep_rt_runtime_version_get_ref_utf16 (); + const ep_char16_t *managed_entrypoint_assembly_path_ref = ep_rt_entrypoint_assembly_path_get_utf16 (); + const ep_char16_t *clr_product_version_ref = ep_rt_runtime_version_get_utf16 (); DiagnosticsProcessInfo2Payload payload; DiagnosticsProcessInfo2Payload *process_info_2_payload = NULL; diff --git a/src/native/eventpipe/ep-rt.h b/src/native/eventpipe/ep-rt.h index 42708e1a26f28..5f8acdc869659 100644 --- a/src/native/eventpipe/ep-rt.h +++ b/src/native/eventpipe/ep-rt.h @@ -599,11 +599,11 @@ ep_rt_os_environment_get_utf16 (ep_rt_env_array_utf16_t *env_array); static const ep_char16_t * -ep_rt_entrypoint_assembly_path_get_ref_utf16 (void); +ep_rt_entrypoint_assembly_path_get_utf16 (void); static const ep_char16_t * -ep_rt_runtime_version_get_ref_utf16 (void); +ep_rt_runtime_version_get_utf16 (void); /* * Lock From 9db4313bf0789bf3fc9e221ffd6d3e28e3f1ac42 Mon Sep 17 00:00:00 2001 From: John Salem Date: Wed, 5 May 2021 17:14:43 -0700 Subject: [PATCH 07/16] handle bundled host * need to test still --- src/coreclr/vm/ceeload.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/vm/ceeload.cpp b/src/coreclr/vm/ceeload.cpp index 3f5e1ab348edd..973690160be71 100644 --- a/src/coreclr/vm/ceeload.cpp +++ b/src/coreclr/vm/ceeload.cpp @@ -11376,7 +11376,7 @@ void SaveManagedCommandLine(LPCWSTR pwzAssemblyPath, int argc, LPCWSTR *argv) LPCWSTR osCommandLine = GetCommandLineW(); // store the entrypoint path - s_pEntrypointAssemblyPath = pwzAssemblyPath; + s_pEntrypointAssemblyPath = Bundle::AppIsBundle() ? static_cast(Bundle::AppBundle->Path()) : pwzAssemblyPath; #ifndef TARGET_UNIX // On Windows, osCommandLine contains the executable and all arguments. From 9132d97b95294be2d6a72e176e3d525f0dcd1d58 Mon Sep 17 00:00:00 2001 From: John Salem Date: Fri, 7 May 2021 16:07:03 -0700 Subject: [PATCH 08/16] Use assembly name * simplify access patterns * change API to utf8 * updated test --- .../vm/eventing/eventpipe/ep-rt-coreclr.h | 16 ++-- src/mono/mono/eventpipe/ep-rt-mono.h | 78 ++----------------- src/native/eventpipe/ds-process-protocol.c | 26 ++++--- src/native/eventpipe/ds-process-protocol.h | 4 +- src/native/eventpipe/ep-rt.h | 8 +- .../eventpipe/processinfo2/processinfo2.cs | 22 +++--- 6 files changed, 47 insertions(+), 107 deletions(-) diff --git a/src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h b/src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h index 1025c95447b13..0493e3686a650 100644 --- a/src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h +++ b/src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h @@ -1164,17 +1164,21 @@ ep_rt_coreclr_config_lock_get (void) static inline -const ep_char16_t * -ep_rt_entrypoint_assembly_path_get_utf16 (void) +const ep_char8_t * +ep_rt_entrypoint_assembly_name_get_utf8 (void) { - return reinterpret_cast(GetManagedEntrypointAssemblyPath()); + STATIC_CONTRACT_NOTHROW; + + return reinterpret_cast(GetAppDomain ()->GetRootAssembly ()->GetSimpleName ()); } static -const ep_char16_t * -ep_rt_runtime_version_get_utf16 (void) +const ep_char8_t * +ep_rt_runtime_version_get_utf8 (void) { - return reinterpret_cast(CLR_PRODUCT_VERSION_L); + STATIC_CONTRACT_NOTHROW; + + return reinterpret_cast(CLR_PRODUCT_VERSION); } /* diff --git a/src/mono/mono/eventpipe/ep-rt-mono.h b/src/mono/mono/eventpipe/ep-rt-mono.h index b105a45d6cc3d..49cb26b6fdb31 100644 --- a/src/mono/mono/eventpipe/ep-rt-mono.h +++ b/src/mono/mono/eventpipe/ep-rt-mono.h @@ -27,15 +27,6 @@ #include #include -#ifndef QUOTE_MACRO_L -#define QUOTE_MACRO_L_HELPER(x) L###x -#define QUOTE_MACRO_L(x) QUOTE_MACRO_L_HELPER(x) -#endif // QUOTE_MACRO_L - -#ifndef PRODUCT_VERSION_L -#define PRODUCT_VERSION_L QUOTE_MACRO_L(RuntimeProductVersion) -#endif // PRODUCT_VERSION_L - #undef EP_ARRAY_SIZE #define EP_ARRAY_SIZE(expr) G_N_ELEMENTS(expr) @@ -448,54 +439,6 @@ managed_command_line_lazy_clean (void) *managed_command_line_get_ref () = NULL; } -static -inline -ep_char16_t * -managed_entrypoint_assembly_path_get (void) -{ - const MonoAssembly *main_assembly = mono_assembly_get_main (); - if (main_assembly == NULL) - return NULL; // TODO: default value? - const ep_char8_t *assembly_path = (const ep_char8_t *)m_image_get_filename (main_assembly->image); - return ep_rt_utf8_to_utf16_string (assembly_path, strlen((const char *)assembly_path)); -} - -static -inline -ep_char16_t ** -managed_entrypoint_assembly_path_get_ref (void) -{ - extern ep_char16_t *_ep_rt_mono_managed_entrypoint_assembly_path; - return &_ep_rt_mono_managed_entrypoint_assembly_path; -} - -static -inline -mono_lazy_init_t * -managed_entrypoint_assembly_path_get_init (void) -{ - extern mono_lazy_init_t _ep_rt_mono_managed_entrypoint_assembly_path_init; - return &_ep_rt_mono_managed_entrypoint_assembly_path_init; -} - -static -inline -void -managed_entrypoint_assembly_path_lazy_init (void) -{ - if (!*managed_entrypoint_assembly_path_get_ref ()) - *managed_entrypoint_assembly_path_get_ref () = managed_entrypoint_assembly_path_get (); -} - -static -inline -void -managed_entrypoint_assembly_path_lazy_clean (void) -{ - g_free (*managed_entrypoint_assembly_path_get_ref ()); - *managed_entrypoint_assembly_path_get_ref () = NULL; -} - static inline ep_rt_spin_lock_handle_t * @@ -1881,26 +1824,17 @@ ep_rt_diagnostics_command_line_get (void) } static -const ep_char16_t * -ep_rt_entrypoint_assembly_path_get_utf16 (void) +const ep_char8_t * +ep_rt_entrypoint_assembly_name_get_utf8 (void) { - if (!mono_lazy_is_initialized (managed_entrypoint_assembly_path_get_init ())) { - ep_char16_t *entrypoint_assembly_path = managed_entrypoint_assembly_path_get (); - if (!entrypoint_assembly_path) - return NULL; - g_free (entrypoint_assembly_path); - } - - mono_lazy_initialize (managed_entrypoint_assembly_path_get_init (), managed_entrypoint_assembly_path_lazy_init); - EP_ASSERT (*managed_entrypoint_assembly_path_get_ref () != NULL); - return *managed_entrypoint_assembly_path_get_ref (); + return (const ep_char8_t *)m_image_get_assembly_name (mono_assembly_get_main ()->image); } static -const ep_char16_t * -ep_rt_runtime_version_get_utf16 (void) +const ep_char8_t * +ep_rt_runtime_version_get_utf8 (void) { - return (const ep_char16_t *)PRODUCT_VERSION_L; + return (const ep_char8_t *)EGLIB_TOSTRING (RuntimeProductVersion); } /* diff --git a/src/native/eventpipe/ds-process-protocol.c b/src/native/eventpipe/ds-process-protocol.c index d24e672fe9a34..4511a26cdc7f2 100644 --- a/src/native/eventpipe/ds-process-protocol.c +++ b/src/native/eventpipe/ds-process-protocol.c @@ -233,8 +233,8 @@ process_info_2_payload_get_size (DiagnosticsProcessInfo2Payload *payload) (ep_rt_utf16_string_len (payload->arch) + 1) * sizeof(ep_char16_t) : 0; size += sizeof(uint32_t); - size += (payload->managed_entrypoint_assembly_path != NULL) ? - (ep_rt_utf16_string_len (payload->managed_entrypoint_assembly_path) + 1) * sizeof(ep_char16_t) : 0; + size += (payload->managed_entrypoint_assembly_name != NULL) ? + (ep_rt_utf16_string_len (payload->managed_entrypoint_assembly_name) + 1) * sizeof(ep_char16_t) : 0; size += sizeof(uint32_t); size += (payload->clr_product_version != NULL) ? @@ -285,9 +285,9 @@ process_info_2_payload_flatten ( if (success) success &= ds_ipc_message_try_write_string_utf16_t (buffer, size, process_info->arch); - // LPCWSTR managed_entrypoint_assembly_path; + // LPCWSTR managed_entrypoint_assembly_name; if (success) - success &= ds_ipc_message_try_write_string_utf16_t (buffer, size, process_info->managed_entrypoint_assembly_path); + success &= ds_ipc_message_try_write_string_utf16_t (buffer, size, process_info->managed_entrypoint_assembly_name); // LPCWSTR clr_product_version; if (success) @@ -307,7 +307,7 @@ ds_process_info_2_payload_init ( const ep_char16_t *arch, uint32_t process_id, const uint8_t *runtime_cookie, - const ep_char16_t *managed_entrypoint_assembly_path, + const ep_char16_t *managed_entrypoint_assembly_name, const ep_char16_t *clr_product_version) { ep_return_null_if_nok (payload != NULL); @@ -316,7 +316,7 @@ ds_process_info_2_payload_init ( payload->os = os; payload->arch = arch; payload->process_id = process_id; - payload->managed_entrypoint_assembly_path = managed_entrypoint_assembly_path; + payload->managed_entrypoint_assembly_name = managed_entrypoint_assembly_name; payload->clr_product_version = clr_product_version; if (runtime_cookie) @@ -540,8 +540,8 @@ process_protocol_helper_get_process_info_2 ( ep_char16_t *command_line = NULL; ep_char16_t *os_info = NULL; ep_char16_t *arch_info = NULL; - const ep_char16_t *managed_entrypoint_assembly_path_ref = ep_rt_entrypoint_assembly_path_get_utf16 (); - const ep_char16_t *clr_product_version_ref = ep_rt_runtime_version_get_utf16 (); + ep_char16_t *managed_entrypoint_assembly_name = NULL; + ep_char16_t *clr_product_version = NULL; DiagnosticsProcessInfo2Payload payload; DiagnosticsProcessInfo2Payload *process_info_2_payload = NULL; @@ -554,9 +554,11 @@ process_protocol_helper_get_process_info_2 ( arch_info = ep_rt_utf8_to_utf16_string (ep_event_source_get_arch_info (), -1); ep_raise_error_if_nok (arch_info != NULL); - ep_raise_error_if_nok (managed_entrypoint_assembly_path_ref != NULL); + managed_entrypoint_assembly_name = ep_rt_utf8_to_utf16_string (ep_rt_entrypoint_assembly_name_get_utf8 (), -1); + ep_raise_error_if_nok (managed_entrypoint_assembly_name != NULL); - ep_raise_error_if_nok (clr_product_version_ref != NULL); + clr_product_version = ep_rt_utf8_to_utf16_string (ep_rt_runtime_version_get_utf8 (), -1); + ep_raise_error_if_nok (clr_product_version != NULL); process_info_2_payload = ds_process_info_2_payload_init ( &payload, @@ -565,8 +567,8 @@ process_protocol_helper_get_process_info_2 ( arch_info, ep_rt_current_process_get_id (), ds_ipc_advertise_cookie_v1_get (), - managed_entrypoint_assembly_path_ref, - clr_product_version_ref); + managed_entrypoint_assembly_name, + clr_product_version); ep_raise_error_if_nok (process_info_2_payload != NULL); ep_raise_error_if_nok (ds_ipc_message_initialize_buffer ( diff --git a/src/native/eventpipe/ds-process-protocol.h b/src/native/eventpipe/ds-process-protocol.h index c7cee8b9c1d88..8e750170e2fac 100644 --- a/src/native/eventpipe/ds-process-protocol.h +++ b/src/native/eventpipe/ds-process-protocol.h @@ -83,7 +83,7 @@ struct _DiagnosticsProcessInfo2Payload_Internal { const ep_char16_t *os; const ep_char16_t *arch; uint8_t runtime_cookie [EP_GUID_SIZE]; - const ep_char16_t *managed_entrypoint_assembly_path; + const ep_char16_t *managed_entrypoint_assembly_name; const ep_char16_t *clr_product_version; }; @@ -102,7 +102,7 @@ ds_process_info_2_payload_init ( const ep_char16_t *arch, uint32_t process_id, const uint8_t *runtime_cookie, - const ep_char16_t *managed_entrypoint_assembly_path, + const ep_char16_t *managed_entrypoint_assembly_name, const ep_char16_t *clr_product_version); void diff --git a/src/native/eventpipe/ep-rt.h b/src/native/eventpipe/ep-rt.h index 5f8acdc869659..839ec2fbd49bc 100644 --- a/src/native/eventpipe/ep-rt.h +++ b/src/native/eventpipe/ep-rt.h @@ -598,12 +598,12 @@ void ep_rt_os_environment_get_utf16 (ep_rt_env_array_utf16_t *env_array); static -const ep_char16_t * -ep_rt_entrypoint_assembly_path_get_utf16 (void); +const ep_char8_t * +ep_rt_entrypoint_assembly_name_get_utf8 (void); static -const ep_char16_t * -ep_rt_runtime_version_get_utf16 (void); +const ep_char8_t * +ep_rt_runtime_version_get_utf8 (void); /* * Lock diff --git a/src/tests/tracing/eventpipe/processinfo2/processinfo2.cs b/src/tests/tracing/eventpipe/processinfo2/processinfo2.cs index 2bd00ddaece84..443fc6b8f466b 100644 --- a/src/tests/tracing/eventpipe/processinfo2/processinfo2.cs +++ b/src/tests/tracing/eventpipe/processinfo2/processinfo2.cs @@ -191,22 +191,22 @@ public static int Main(string[] args) Utils.Assert(expectedArchValue.Equals(arch), $"OS must match current Operating System. Expected: \"{expectedArchValue}\", Received: \"{arch}\""); - // VALIDATE ManagedEntrypointAssemblyPath + // VALIDATE ManagedEntrypointAssemblyName start = end; end = start + 4 /* sizeof(uint32_t) */; - UInt32 managedEntrypointAssemblyPathSize = BitConverter.ToUInt32(response.Payload[start..end]); - Logger.logger.Log($"managedEntrypointAssemblyPathSize: {managedEntrypointAssemblyPathSize}"); + UInt32 managedEntrypointAssemblyNameLength = BitConverter.ToUInt32(response.Payload[start..end]); + Logger.logger.Log($"managedEntrypointAssemblyNameLength: {managedEntrypointAssemblyNameLength}"); start = end; - end = start + ((int)managedEntrypointAssemblyPathSize * sizeof(char)); - Utils.Assert(end <= totalSize, $"String end can't exceed payload size. Expected: <{totalSize}, Received: {end} (decoded length: {managedEntrypointAssemblyPathSize})"); - Logger.logger.Log($"ManagedEntrypointAssemblyPath bytes: [ {response.Payload[start..end].Select(b => b.ToString("X2") + " ").Aggregate(string.Concat)}]"); - string managedEntrypointAssemblyPath = System.Text.Encoding.Unicode.GetString(response.Payload[start..end]).TrimEnd('\0'); - Logger.logger.Log($"ManagedEntrypointAssemblyPath: \"{managedEntrypointAssemblyPath}\""); + end = start + ((int)managedEntrypointAssemblyNameLength * sizeof(char)); + Utils.Assert(end <= totalSize, $"String end can't exceed payload size. Expected: <{totalSize}, Received: {end} (decoded length: {managedEntrypointAssemblyNameLength})"); + Logger.logger.Log($"ManagedEntrypointAssemblyName bytes: [ {response.Payload[start..end].Select(b => b.ToString("X2") + " ").Aggregate(string.Concat)}]"); + string managedEntrypointAssemblyName = System.Text.Encoding.Unicode.GetString(response.Payload[start..end]).TrimEnd('\0'); + Logger.logger.Log($"ManagedEntrypointAssemblyName: \"{managedEntrypointAssemblyName}\""); - string expectedManagedEntrypointAssemblyPath = System.Reflection.Assembly.GetExecutingAssembly().Location; + string expectedManagedEntrypointAssemblyName = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name; - Utils.Assert(expectedManagedEntrypointAssemblyPath.Equals(managedEntrypointAssemblyPath), $"ManagedEntrypointAssemblyPath must match. Expected: \"{expectedManagedEntrypointAssemblyPath}\", received: \"{managedEntrypointAssemblyPath}\""); + Utils.Assert(expectedManagedEntrypointAssemblyName.Equals(managedEntrypointAssemblyName), $"ManagedEntrypointAssemblyName must match. Expected: \"{expectedManagedEntrypointAssemblyName}\", received: \"{managedEntrypointAssemblyName}\""); // VALIDATE ClrProductVersion start = end; @@ -227,7 +227,7 @@ public static int Main(string[] args) Utils.Assert(end == totalSize, $"Full payload should have been read. Expected: {totalSize}, Received: {end}"); - Logger.logger.Log($"\n{{\n\tprocessId: {processId},\n\truntimeCookie: {runtimeCookie},\n\tcommandLine: {commandLine},\n\tOS: {OS},\n\tArch: {arch},\n\tManagedEntrypointAssemblyPath: {managedEntrypointAssemblyPath},\n\tClrProductVersion: {clrProductVersion}\n}}"); + Logger.logger.Log($"\n{{\n\tprocessId: {processId},\n\truntimeCookie: {runtimeCookie},\n\tcommandLine: {commandLine},\n\tOS: {OS},\n\tArch: {arch},\n\tManagedEntrypointAssemblyName: {managedEntrypointAssemblyName},\n\tClrProductVersion: {clrProductVersion}\n}}"); return 100; } From 1babfe0e13b6220bb44ec207e9bad8c85aab3933 Mon Sep 17 00:00:00 2001 From: John Salem Date: Fri, 7 May 2021 16:08:41 -0700 Subject: [PATCH 09/16] update comment --- src/native/eventpipe/ds-process-protocol.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/native/eventpipe/ds-process-protocol.c b/src/native/eventpipe/ds-process-protocol.c index 4511a26cdc7f2..ae01fad34a2da 100644 --- a/src/native/eventpipe/ds-process-protocol.c +++ b/src/native/eventpipe/ds-process-protocol.c @@ -213,6 +213,8 @@ process_info_2_payload_get_size (DiagnosticsProcessInfo2Payload *payload) // LPCWSTR CommandLine; -> 4 bytes + strlen * sizeof(WCHAR) // LPCWSTR OS; -> 4 bytes + strlen * sizeof(WCHAR) // LPCWSTR Arch; -> 4 bytes + strlen * sizeof(WCHAR) + // LPCWSTR managed_entrypoint_assembly_name; -> 4 bytes + strlen * sizeof(WCHAR) + // LPCWSTR clr_product_version; -> 4 bytes + strlen * sizeof(WCHAR) EP_ASSERT (payload != NULL); From cae637ab809aca05a8e2ab58fb856340e42e50cc Mon Sep 17 00:00:00 2001 From: John Salem Date: Tue, 11 May 2021 13:43:22 -0700 Subject: [PATCH 10/16] PR feedback --- src/coreclr/vm/ceeload.cpp | 7 ------- src/tests/tracing/eventpipe/common/IpcUtils.cs | 4 ++-- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/src/coreclr/vm/ceeload.cpp b/src/coreclr/vm/ceeload.cpp index 973690160be71..1816f2c9c2f91 100644 --- a/src/coreclr/vm/ceeload.cpp +++ b/src/coreclr/vm/ceeload.cpp @@ -11304,7 +11304,6 @@ static bool GetBasename(LPCWSTR _src, __out_ecount(dstlen) __out_z LPWSTR _dst, } static LPCWSTR s_pCommandLine = NULL; -static LPCWSTR s_pEntrypointAssemblyPath = NULL; // Retrieve the full command line for the current process. LPCWSTR GetManagedCommandLine() @@ -11313,12 +11312,6 @@ LPCWSTR GetManagedCommandLine() return s_pCommandLine; } -LPCWSTR GetManagedEntrypointAssemblyPath() -{ - LIMITED_METHOD_CONTRACT; - return s_pEntrypointAssemblyPath; -} - LPCWSTR GetCommandLineForDiagnostics() { // Get the managed command line. diff --git a/src/tests/tracing/eventpipe/common/IpcUtils.cs b/src/tests/tracing/eventpipe/common/IpcUtils.cs index 47eb0db2dc669..b3448f704f238 100644 --- a/src/tests/tracing/eventpipe/common/IpcUtils.cs +++ b/src/tests/tracing/eventpipe/common/IpcUtils.cs @@ -351,7 +351,7 @@ public class ProcessInfo2 public string Commandline; public string OS; public string Arch; - public string ManagedEntrypointAssemblyPath; + public string ManagedEntrypointAssemblyName; public string ClrProductVersion; public static ProcessInfo2 TryParse(byte[] buf) @@ -379,7 +379,7 @@ string ParseString(ref int start, ref int end) info.Commandline = ParseString(ref start, ref end); info.OS = ParseString(ref start, ref end); info.Arch = ParseString(ref start, ref end); - info.ManagedEntrypointAssemblyPath = ParseString(ref start, ref end); + info.ManagedEntrypointAssemblyName = ParseString(ref start, ref end); info.ClrProductVersion = ParseString(ref start, ref end); return info; From dd39bf100e2915fd34a7774d248a1979d3fd4460 Mon Sep 17 00:00:00 2001 From: John Salem Date: Tue, 11 May 2021 14:46:07 -0700 Subject: [PATCH 11/16] save before I commit this time... --- src/coreclr/vm/ceeload.cpp | 3 --- src/coreclr/vm/ceeload.h | 1 - 2 files changed, 4 deletions(-) diff --git a/src/coreclr/vm/ceeload.cpp b/src/coreclr/vm/ceeload.cpp index 1816f2c9c2f91..e1003c8cff634 100644 --- a/src/coreclr/vm/ceeload.cpp +++ b/src/coreclr/vm/ceeload.cpp @@ -11368,9 +11368,6 @@ void SaveManagedCommandLine(LPCWSTR pwzAssemblyPath, int argc, LPCWSTR *argv) // Get the command line. LPCWSTR osCommandLine = GetCommandLineW(); - // store the entrypoint path - s_pEntrypointAssemblyPath = Bundle::AppIsBundle() ? static_cast(Bundle::AppBundle->Path()) : pwzAssemblyPath; - #ifndef TARGET_UNIX // On Windows, osCommandLine contains the executable and all arguments. s_pCommandLine = osCommandLine; diff --git a/src/coreclr/vm/ceeload.h b/src/coreclr/vm/ceeload.h index 96286856807e5..13a78ec96f4ef 100644 --- a/src/coreclr/vm/ceeload.h +++ b/src/coreclr/vm/ceeload.h @@ -3390,6 +3390,5 @@ struct VASigCookieEx : public VASigCookie void SaveManagedCommandLine(LPCWSTR pwzAssemblyPath, int argc, LPCWSTR *argv); LPCWSTR GetCommandLineForDiagnostics(); -LPCWSTR GetManagedEntrypointAssemblyPath(); #endif // !CEELOAD_H_ From 2db4be10449488a712c17dcfff76c9408256d26e Mon Sep 17 00:00:00 2001 From: John Salem Date: Wed, 26 May 2021 14:54:21 -0700 Subject: [PATCH 12/16] fix merge conflict --- src/tests/tracing/eventpipe/processinfo2/processinfo2.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tests/tracing/eventpipe/processinfo2/processinfo2.cs b/src/tests/tracing/eventpipe/processinfo2/processinfo2.cs index 443fc6b8f466b..08a1082104118 100644 --- a/src/tests/tracing/eventpipe/processinfo2/processinfo2.cs +++ b/src/tests/tracing/eventpipe/processinfo2/processinfo2.cs @@ -78,8 +78,8 @@ public static int Main(string[] args) Stream stream = ConnectionHelper.GetStandardTransport(pid); - // 0x04 = ProcessCommandSet, 0x03 = ProcessInfo2 - var processInfoMessage = new IpcMessage(0x04, 0x03); + // 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: "); From 65ce9da1bf2504ec939bec3da4bdec893b7cf98b Mon Sep 17 00:00:00 2001 From: John Salem Date: Wed, 26 May 2021 16:28:30 -0700 Subject: [PATCH 13/16] Update ds-process-protocol.c add missing break statement from merge conflict fix --- src/native/eventpipe/ds-process-protocol.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/native/eventpipe/ds-process-protocol.c b/src/native/eventpipe/ds-process-protocol.c index ae01fad34a2da..1250d2cad1ce2 100644 --- a/src/native/eventpipe/ds-process-protocol.c +++ b/src/native/eventpipe/ds-process-protocol.c @@ -779,6 +779,7 @@ ds_process_protocol_helper_handle_ipc_message ( break; case DS_PROCESS_COMMANDID_SET_ENV_VAR: result = process_protocol_helper_set_environment_variable (message, stream); + break; case DS_PROCESS_COMMANDID_GET_PROCESS_INFO_2: result = process_protocol_helper_get_process_info_2 (message, stream); break; From f8c5fa8a030b687dd4411959d79f87a107f59e79 Mon Sep 17 00:00:00 2001 From: John Salem Date: Thu, 27 May 2021 14:00:39 -0700 Subject: [PATCH 14/16] Update src/native/eventpipe/ds-process-protocol.h --- src/native/eventpipe/ds-process-protocol.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/native/eventpipe/ds-process-protocol.h b/src/native/eventpipe/ds-process-protocol.h index 8e750170e2fac..ac145c0bd1dbe 100644 --- a/src/native/eventpipe/ds-process-protocol.h +++ b/src/native/eventpipe/ds-process-protocol.h @@ -77,7 +77,7 @@ struct _DiagnosticsProcessInfo2Payload_Internal { // array = uint length, length # of Ts // string = (array where the last char must = 0) or (length = 0) - // ProcessInfo = long pid, string cmdline, string OS, string arch, GUID runtimeCookie, string managed entrypoint assembly path, string clr product version + // ProcessInfo = long pid, GUID runtimeCookie, string cmdline, string OS, string arch, string managed entrypoint assembly path, string clr product version uint64_t process_id; const ep_char16_t *command_line; const ep_char16_t *os; @@ -175,4 +175,3 @@ ds_process_protocol_helper_handle_ipc_message ( #endif /* ENABLE_PERFTRACING */ #endif /* __DIAGNOSTICS_PROCESS_PROTOCOL_H__ */ - From d625df95d158046f8159edb0828b6c379b86890e Mon Sep 17 00:00:00 2001 From: John Salem Date: Thu, 27 May 2021 15:34:03 -0700 Subject: [PATCH 15/16] Update ds-process-protocol.c add missing frees --- src/native/eventpipe/ds-process-protocol.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/native/eventpipe/ds-process-protocol.c b/src/native/eventpipe/ds-process-protocol.c index 1250d2cad1ce2..75886a79ff3c2 100644 --- a/src/native/eventpipe/ds-process-protocol.c +++ b/src/native/eventpipe/ds-process-protocol.c @@ -589,6 +589,8 @@ process_protocol_helper_get_process_info_2 ( ep_rt_utf16_string_free (arch_info); ep_rt_utf16_string_free (os_info); ep_rt_utf16_string_free (command_line); + ep_rt_utf16_string_free (managed_entrypoint_assembly_name); + ep_rt_utf16_string_free (clr_product_version); ds_ipc_stream_free (stream); return result; From fe5b218469baa260aa2dbd16f7b10aa97fa39d67 Mon Sep 17 00:00:00 2001 From: John Salem Date: Tue, 8 Jun 2021 23:10:31 +0000 Subject: [PATCH 16/16] PR feedback --- src/mono/mono/eventpipe/ep-rt-mono.c | 3 --- src/mono/mono/eventpipe/ep-rt-mono.h | 2 ++ 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/mono/mono/eventpipe/ep-rt-mono.c b/src/mono/mono/eventpipe/ep-rt-mono.c index c07ac8411fe3d..02c6a390eda72 100644 --- a/src/mono/mono/eventpipe/ep-rt-mono.c +++ b/src/mono/mono/eventpipe/ep-rt-mono.c @@ -43,9 +43,6 @@ char *_ep_rt_mono_os_cmd_line = NULL; mono_lazy_init_t _ep_rt_mono_managed_cmd_line_init = MONO_LAZY_INIT_STATUS_NOT_INITIALIZED; char *_ep_rt_mono_managed_cmd_line = NULL; -// Managed Entrypoint Assembly Path -mono_lazy_init_t _ep_rt_mono_managed_entrypoint_assembly_path_init = MONO_LAZY_INIT_STATUS_NOT_INITIALIZED; -ep_char16_t *_ep_rt_mono_managed_entrypoint_assembly_path = NULL; // Sample profiler. static GArray * _ep_rt_mono_sampled_thread_callstacks = NULL; diff --git a/src/mono/mono/eventpipe/ep-rt-mono.h b/src/mono/mono/eventpipe/ep-rt-mono.h index 49cb26b6fdb31..8276bc718deb3 100644 --- a/src/mono/mono/eventpipe/ep-rt-mono.h +++ b/src/mono/mono/eventpipe/ep-rt-mono.h @@ -1824,6 +1824,7 @@ ep_rt_diagnostics_command_line_get (void) } static +inline const ep_char8_t * ep_rt_entrypoint_assembly_name_get_utf8 (void) { @@ -1831,6 +1832,7 @@ ep_rt_entrypoint_assembly_name_get_utf8 (void) } static +inline const ep_char8_t * ep_rt_runtime_version_get_utf8 (void) {