From: Mike McLaughlin Date: Wed, 1 Jun 2022 05:08:31 +0000 (-0700) Subject: Merge main into release/stable (#3100) X-Git-Tag: accepted/tizen/unified/20221103.165810~25 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ab657cc109f93e48d52f6b12cd7f136bb2d0b311;p=platform%2Fcore%2Fdotnet%2Fdiagnostics.git Merge main into release/stable (#3100) * Update dependencies from https://github.com/dotnet/aspnetcore build 20220406.3 (#2990) [main] Update dependencies from dotnet/aspnetcore * Update dependencies from https://github.com/dotnet/runtime build 20220406.5 (#2991) [main] Update dependencies from dotnet/runtime * Set the build ID using arcade's scripts instead of retrieving it from another job (#2993) * Update dependencies from https://github.com/dotnet/source-build-reference-packages build 20220328.1 (#2967) [main] Update dependencies from dotnet/source-build-reference-packages * Update dependencies from https://github.com/dotnet/arcade build 20220406.10 (#3000) [main] Update dependencies from dotnet/arcade * Update dependencies from https://github.com/dotnet/symstore build 20220410.1 (#3002) Microsoft.SymbolStore From Version 1.0.320401 -> To Version 1.0.321001 Co-authored-by: dotnet-maestro[bot] * Update dependencies from https://github.com/dotnet/installer build 20220410.6 (#3001) Microsoft.Dotnet.Sdk.Internal From Version 6.0.104-servicing.22181.15 -> To Version 6.0.104-servicing.22210.6 Co-authored-by: dotnet-maestro[bot] * Update dependencies from https://github.com/dotnet/symstore build 20220411.1 (#3007) [main] Update dependencies from dotnet/symstore * Update dependencies from https://github.com/dotnet/aspnetcore build 20220411.2 (#3006) [main] Update dependencies from dotnet/aspnetcore * Update dependencies from https://github.com/dotnet/runtime build 20220411.4 (#3008) [main] Update dependencies from dotnet/runtime * Update dependencies from https://github.com/dotnet/runtime build 20220412.7 (#3011) [main] Update dependencies from dotnet/runtime * Update dependencies from https://github.com/dotnet/symstore build 20220412.1 (#3010) [main] Update dependencies from dotnet/symstore * Rewrite DumpAsync in C# (#2964) * Rewrite DumpAsync in C# This rewrites the dumpasync command as a C# SOS extension. Doing so makes the code easier to maintain and add features to in the future. Along with the rewrite, a variety of requests for the feature have been satisfied: - Added a "coalesced stacks" view (`--coalesce`) that coalesces stacks together to create a high-level view of the state of the process - Improved filtering so that a specified filter (address, method table, substring) applies to any frame of a stack and not just to the top frame - Improved stack stitching to always consider task objects from the heap and not just if `--tasks` was specified. This helps to better connect state machines separated by constructs like Task.Run. - Added synthesized frames to try to show what's being awaited in the case where the top frame is an async method. - Added DML links for more things to better navigate through results. * Fix tests * Fix tests for DumpAsync on WebApp3 * Skip visiting tasks multiple times * Special case completion sentinnel * Only synthesize faux awaiter frame if the task is not completed. * PR feedback Co-authored-by: Juan Sebastian Hoyos Ayala * Update dependencies from https://github.com/dotnet/runtime build 20220413.11 (#3014) Microsoft.NETCore.App.Runtime.win-x64 , VS.Redist.Common.NetCore.SharedFramework.x64.6.0 From Version 6.0.5 -> To Version 6.0.5 Co-authored-by: dotnet-maestro[bot] * Update dependencies from https://github.com/dotnet/aspnetcore build 20220413.12 (#3013) [main] Update dependencies from dotnet/aspnetcore * Use symstore retry changes in tests (#2968) * Create clear error messages for dotnet-trace (#3012) * Catch UnauthorizedAccessException, Win32Exception and simplify for loop * altered to conventional C# style * Set symstore HTTP retry count in all test cases (#3015) * Set symstore HTTP retry count in all test cases * Update src/Microsoft.Diagnostics.DebugServices/ISymbolService.cs Co-authored-by: Juan Hoyos * Code review feedback Co-authored-by: Juan Hoyos * Update dependencies from https://github.com/dotnet/source-build-reference-packages build 20220415.1 (#3016) [main] Update dependencies from dotnet/source-build-reference-packages * Update dependencies from https://github.com/dotnet/arcade build 20220415.2 (#3017) [main] Update dependencies from dotnet/arcade * Update lldb instuctions (#3020) Mostly just delete distro versions that are not supported for any supported .NET version. * Use minipal in more places (#3019) * Port minipal/getexepath.h from runtime repo * Use ARRAY_SIZE from minipal in more places * Fix C4996 warning on windows * Introspect sys/auxv.h in SOS configuration * Fix include * [main] Update dependencies from dotnet/installer (#3018) * Update dependencies from https://github.com/dotnet/installer build 20220415.3 Microsoft.Dotnet.Sdk.Internal From Version 6.0.104-servicing.22210.6 -> To Version 6.0.105-servicing.22215.3 * Fix single-file runtime version Co-authored-by: dotnet-maestro[bot] Co-authored-by: Mike McLaughlin * Update dependencies from https://github.com/dotnet/symstore build 20220418.1 (#3022) [main] Update dependencies from dotnet/symstore * Update dependencies from https://github.com/dotnet/source-build-reference-packages build 20220419.2 (#3023) [main] Update dependencies from dotnet/source-build-reference-packages * Create EventPipeFormat.md (#3024) * Update dependencies from https://github.com/dotnet/arcade build 20220422.4 (#3027) [main] Update dependencies from dotnet/arcade * Update dependencies from https://github.com/dotnet/installer build 20220419.37 (#3028) [main] Update dependencies from dotnet/installer * dotent-trace report - account for missing symbol (#3021) * Update dependencies from https://github.com/microsoft/clrmd build 20220426.1 (#3035) [main] Update dependencies from microsoft/clrmd * Write temp files to tempdir (#3031) * update to use viewport-relative coordinates (#3034) This fixes some rendering issues of dontet-counters, however, dotnet-counters renders incorrectly when: - terminal changes size while the tool is running - terminal is not wide enough to print the output As noted in #3036 * Update dependencies from https://github.com/dotnet/installer build 20220429.9 (#3038) [main] Update dependencies from dotnet/installer * Update dependencies from https://github.com/dotnet/arcade build 20220425.6 (#3037) [main] Update dependencies from dotnet/arcade * Update dependencies from https://github.com/dotnet/symstore build 20220502.1 (#3040) [main] Update dependencies from dotnet/symstore * Update dependencies from https://github.com/dotnet/source-build-reference-packages build 20220503.1 (#3043) [main] Update dependencies from dotnet/source-build-reference-packages * Update dependencies from https://github.com/dotnet/aspnetcore build 20220503.6 (#3041) [main] Update dependencies from dotnet/aspnetcore * Update dependencies from https://github.com/dotnet/source-build-reference-packages build 20220504.3 (#3045) [main] Update dependencies from dotnet/source-build-reference-packages * Update dependencies from https://github.com/dotnet/aspnetcore build 20220504.26 (#3044) [main] Update dependencies from dotnet/aspnetcore * Update dependencies from https://github.com/dotnet/aspnetcore build 20220505.18 (#3046) [main] Update dependencies from dotnet/aspnetcore * Update dependencies from https://github.com/dotnet/source-build-reference-packages build 20220505.1 (#3048) [main] Update dependencies from dotnet/source-build-reference-packages * Update dependencies from https://github.com/microsoft/clrmd build 20220505.1 (#3047) [main] Update dependencies from microsoft/clrmd * Update EventPipeStress (#3049) * Update dependencies from https://github.com/dotnet/arcade build 20220505.2 (#3052) [main] Update dependencies from dotnet/arcade * Update dependencies from https://github.com/dotnet/installer build 20220504.12 (#3053) [main] Update dependencies from dotnet/installer * Update dependencies from https://github.com/microsoft/clrmd build 20220509.1 (#3056) [main] Update dependencies from microsoft/clrmd * Update dependencies from https://github.com/dotnet/source-build-reference-packages build 20220509.4 (#3058) [main] Update dependencies from dotnet/source-build-reference-packages * Update dependencies from https://github.com/dotnet/symstore build 20220509.1 (#3057) [main] Update dependencies from dotnet/symstore * Update dependencies from https://github.com/dotnet/aspnetcore build 20220509.8 (#3055) [main] Update dependencies from dotnet/aspnetcore * Port setsymbolserver command to C# (#3050) * Port setsymbolserver command to C# Fixes issue: https://github.com/dotnet/diagnostics/issues/3032 Removes quite a bit of native and interop code. Remove some noisy logging in success paths. Rename ISymbolService.DownloadModule to DownloadModuleFile. Add ISymbolService.DownloadSymbolFile. Rename some IModule properties to functions. Add IModule.LoadSymbols(). Fix MacOS test failures Make setsymbolserver a global command * Update dependencies from https://github.com/dotnet/aspnetcore build 20220510.8 (#3063) [main] Update dependencies from dotnet/aspnetcore * Enable SDL required warnings explicitly (#3054) * Enable SDL required warnings explicitly * Fix build issues that don't escape on failure properly * Add devcontainer infra to diagnostics repo (#2986) * Pass by reference (#3066) * Update dependencies from https://github.com/dotnet/aspnetcore build 20220512.8 (#3070) [main] Update dependencies from dotnet/aspnetcore * Fix Typo (#3071) * Misc dbgshim and SOS fixes (#3072) * Fix some issues found with netcoredbg * Fix some sign-extension issues on alpine arm32 * Fix DbgShim.UnitTest's Microsoft.Diagnostics.DbgShimAPI+NativeRuntimeStartupCallbackDelegate being called after collected by the GC * Code review feedback * [main] Update dependencies from dotnet/installer (#3076) [main] Update dependencies from dotnet/installer - Update single-file version * Update dependencies from https://github.com/dotnet/symstore build 20220516.1 (#3079) [main] Update dependencies from dotnet/symstore * Update dependencies from https://github.com/dotnet/arcade build 20220512.8 (#3075) [main] Update dependencies from dotnet/arcade * Update dependencies from https://github.com/dotnet/source-build-reference-packages build 20220511.1 (#3068) [main] Update dependencies from dotnet/source-build-reference-packages * Update dependencies from https://github.com/dotnet/arcade build 20220519.3 (#3086) [main] Update dependencies from dotnet/arcade * Enable shipping dbgshim packages (#3088) * Add error message to WriteDump response (#3084) Add error message to WriteDump response Add the new generate core dump command that can receive error text on failure. Fix issue #2976 * Use Environment.GetFolderPath to obtain home directory (#3087) * Use Environment.GetFolderPath to obtain home directory * Format documents in changeset * Update dependencies from https://github.com/dotnet/symstore build 20220523.1 (#3091) [main] Update dependencies from dotnet/symstore * Update dependencies from https://github.com/dotnet/source-build-reference-packages build 20220520.1 (#3085) [main] Update dependencies from dotnet/source-build-reference-packages * SOS fixes for regions (#3062) Noticed that DacpHeapSegmentData::Request doesn't set the highAllocMark for regions correctly, and that we haven't fixed GCHeapSnapshot::GetGeneration for regions yet. Moved fix for highAllocMark into the DAC, but keep some logic here so things work correctly for older DACs with segments. Fix more places where we need to use highAllocMark. Kudos to @cshung for pointing out the better way to fix this! * Update dependencies from https://github.com/dotnet/arcade build 20220526.1 (#3096) [main] Update dependencies from dotnet/arcade * Update dependencies from https://github.com/dotnet/installer build 20220527.1 (#3097) [main] Update dependencies from dotnet/installer * Update dependencies from https://github.com/dotnet/symstore build 20220530.1 (#3098) [main] Update dependencies from dotnet/symstore * Fix dbgshim's OpenVirtualProcess on windows arm64 (#3099) Co-authored-by: dotnet-maestro[bot] <42748379+dotnet-maestro[bot]@users.noreply.github.com> Co-authored-by: Juan Hoyos Co-authored-by: dotnet-maestro[bot] Co-authored-by: Stephen Toub Co-authored-by: Juan Sebastian Hoyos Ayala Co-authored-by: mikelle-rogers <45022607+mikelle-rogers@users.noreply.github.com> Co-authored-by: Dan Moseley Co-authored-by: Adeel Mujahid <3840695+am11@users.noreply.github.com> Co-authored-by: John Salem Co-authored-by: Andrew Au Co-authored-by: Martin-Molinero Co-authored-by: Peter Sollich --- diff --git a/eng/Version.Details.xml b/eng/Version.Details.xml index 07d6ba866..e29011c03 100644 --- a/eng/Version.Details.xml +++ b/eng/Version.Details.xml @@ -1,8 +1,8 @@ - + https://github.com/dotnet/symstore - 073abc4f492cbc6795989e4a813b0d32017a8623 + 1ff51a5afa61af820a14b3aa84b401d1a79bc783 https://github.com/microsoft/clrmd @@ -12,25 +12,25 @@ https://github.com/microsoft/clrmd a64d9ac11086f28fbd4b2b2337c19be7826fbfa9 - + https://github.com/dotnet/source-build-reference-packages - c71ce108eda9f657c9f58a613a1fe56b6b08235d + 3dbb19f76474f2f22749b2e64d34c15178381ffb - + https://github.com/dotnet/arcade - 0403b0d07aff1b103256cfbe082c97a5c8846d20 + b8b67b243ba93bf9b89390c85b4dee034d3c5609 - + https://github.com/dotnet/arcade - 0403b0d07aff1b103256cfbe082c97a5c8846d20 + b8b67b243ba93bf9b89390c85b4dee034d3c5609 - + https://github.com/dotnet/installer - ee1b7085a6eb99c97851ed67fc3fd52b8bda3ba0 + 0632d08f8d604ed2a9ea697e88991b7f2ec68141 https://github.com/dotnet/aspnetcore diff --git a/eng/Versions.props b/eng/Versions.props index 08c1bc22e..bb8fd3f44 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -18,7 +18,7 @@ 6.0.5 - 1.0.326601 + 1.0.328001 3.1.18 $(MicrosoftNETCoreApp31Version) @@ -31,7 +31,7 @@ 6.0.6-servicing.22262.8 6.0.6 - 6.0.106-servicing.22263.13 + 6.0.106-servicing.22277.1 @@ -58,7 +58,7 @@ 4.7.2 4.7.1 2.0.3 - 7.0.0-beta.22269.3 + 7.0.0-beta.22276.1 10.0.18362 12.0.2 diff --git a/eng/common/tools.ps1 b/eng/common/tools.ps1 index 797f05292..423bd962e 100644 --- a/eng/common/tools.ps1 +++ b/eng/common/tools.ps1 @@ -635,6 +635,10 @@ function InitializeNativeTools() { InstallDirectory = "$ToolsDir" } } + if (Test-Path variable:NativeToolsOnMachine) { + Write-Host "Variable NativeToolsOnMachine detected, enabling native tool path promotion..." + $nativeArgs += @{ PathPromotion = $true } + } & "$PSScriptRoot/init-tools-native.ps1" @nativeArgs } } diff --git a/global.json b/global.json index 37472ac52..4d6c9be5a 100644 --- a/global.json +++ b/global.json @@ -16,6 +16,6 @@ }, "msbuild-sdks": { "Microsoft.Build.NoTargets": "2.0.1", - "Microsoft.DotNet.Arcade.Sdk": "7.0.0-beta.22269.3" + "Microsoft.DotNet.Arcade.Sdk": "7.0.0-beta.22276.1" } } diff --git a/src/Microsoft.Diagnostics.DebugServices.Implementation/SymbolService.cs b/src/Microsoft.Diagnostics.DebugServices.Implementation/SymbolService.cs index 97b82ac45..b7fba2507 100644 --- a/src/Microsoft.Diagnostics.DebugServices.Implementation/SymbolService.cs +++ b/src/Microsoft.Diagnostics.DebugServices.Implementation/SymbolService.cs @@ -79,12 +79,12 @@ namespace Microsoft.Diagnostics.DebugServices.Implementation } else { - _defaultSymbolCache = Path.Combine(Environment.GetEnvironmentVariable("HOME"), ".dotnet", "symbolcache"); + _defaultSymbolCache = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".dotnet", "symbolcache"); } } return _defaultSymbolCache; } - set + set { _defaultSymbolCache = value; } @@ -182,7 +182,7 @@ namespace Microsoft.Diagnostics.DebugServices.Implementation symbolCachePaths.Add(DefaultSymbolCache); } } - else + else { symbolCachePaths.Add(parts[i]); } @@ -461,10 +461,10 @@ namespace Microsoft.Diagnostics.DebugServices.Implementation } } } - catch (Exception ex) when - (ex is UnauthorizedAccessException || - ex is BadImageFormatException || - ex is InvalidVirtualAddressException || + catch (Exception ex) when + (ex is UnauthorizedAccessException || + ex is BadImageFormatException || + ex is InvalidVirtualAddressException || ex is IOException) { Trace.TraceError($"GetMetaData: {ex.Message}"); @@ -493,7 +493,7 @@ namespace Microsoft.Diagnostics.DebugServices.Implementation peStream = Utilities.TryOpenFile(assemblyPath); if (peStream == null) return null; - + options = PEStreamOptions.Default; } @@ -606,7 +606,7 @@ namespace Microsoft.Diagnostics.DebugServices.Implementation Trace.TraceWarning($"DownLoadPE: no key generated for module {fileName} "); return null; } - } + } else if ((flags & KeyTypeFlags.SymbolKey) != 0) { IEnumerable pdbInfos = module.GetPdbFileInfos(); @@ -647,7 +647,7 @@ namespace Microsoft.Diagnostics.DebugServices.Implementation return null; } } - else + else { throw new ArgumentException($"Key flag not supported {flags}"); } @@ -829,7 +829,7 @@ namespace Microsoft.Diagnostics.DebugServices.Implementation string pdbPath = data.Path; Stream pdbStream = null; - if (assemblyPath != null) + if (assemblyPath != null) { try { @@ -916,7 +916,7 @@ namespace Microsoft.Diagnostics.DebugServices.Implementation public override string ToString() { StringBuilder sb = new StringBuilder(); - ForEachSymbolStore((symbolStore) => + ForEachSymbolStore((symbolStore) => { if (symbolStore is HttpSymbolStore httpSymbolStore) { @@ -962,7 +962,7 @@ namespace Microsoft.Diagnostics.DebugServices.Implementation } } - private bool IsDuplicateSymbolStore(Microsoft.SymbolStore.SymbolStores.SymbolStore symbolStore, Func match) + private bool IsDuplicateSymbolStore(Microsoft.SymbolStore.SymbolStores.SymbolStore symbolStore, Func match) where T : Microsoft.SymbolStore.SymbolStores.SymbolStore { while (symbolStore != null) @@ -1006,7 +1006,7 @@ namespace Microsoft.Diagnostics.DebugServices.Implementation /// Last component of path internal static string GetFileName(string pathName) { - int pos = pathName.LastIndexOfAny(new char[] { '/', '\\'}); + int pos = pathName.LastIndexOfAny(new char[] { '/', '\\' }); if (pos < 0) { return pathName; @@ -1019,11 +1019,11 @@ namespace Microsoft.Diagnostics.DebugServices.Implementation /// private static bool IsPathEqual(string path1, string path2) { - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { return StringComparer.OrdinalIgnoreCase.Equals(path1, path2); } - else + else { return string.Equals(path1, path2); } diff --git a/src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsClient/DiagnosticsClient.cs b/src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsClient/DiagnosticsClient.cs index 181ccc4a9..2d58ef862 100644 --- a/src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsClient/DiagnosticsClient.cs +++ b/src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsClient/DiagnosticsClient.cs @@ -121,9 +121,7 @@ namespace Microsoft.Diagnostics.NETCore.Client /// When set to true, display the dump generation debug log to the console. public void WriteDump(DumpType dumpType, string dumpPath, bool logDumpGeneration = false) { - IpcMessage request = CreateWriteDumpMessage(dumpType, dumpPath, logDumpGeneration); - IpcMessage response = IpcClient.SendMessage(_endpoint, request); - ValidateResponseMessage(response, nameof(WriteDump)); + WriteDump(dumpType, dumpPath, logDumpGeneration ? WriteDumpFlags.LoggingEnabled : WriteDumpFlags.None); } /// @@ -134,15 +132,22 @@ namespace Microsoft.Diagnostics.NETCore.Client /// logging and crash report flags. On runtimes less than 6.0, only LoggingEnabled is supported. public void WriteDump(DumpType dumpType, string dumpPath, WriteDumpFlags flags) { - IpcMessage request = CreateWriteDumpMessage2(dumpType, dumpPath, flags); + IpcMessage request = CreateWriteDumpMessage(DumpCommandId.GenerateCoreDump3, dumpType, dumpPath, flags); IpcMessage response = IpcClient.SendMessage(_endpoint, request); - if (!ValidateResponseMessage(response, nameof(WriteDump), ValidateResponseOptions.UnknownCommandReturnsFalse)) + if (!ValidateResponseMessage(response, "Write dump", ValidateResponseOptions.UnknownCommandReturnsFalse | ValidateResponseOptions.ErrorMessageReturned)) { - if ((flags & ~WriteDumpFlags.LoggingEnabled) != 0) + request = CreateWriteDumpMessage(DumpCommandId.GenerateCoreDump2, dumpType, dumpPath, flags); + response = IpcClient.SendMessage(_endpoint, request); + if (!ValidateResponseMessage(response, "Write dump", ValidateResponseOptions.UnknownCommandReturnsFalse)) { - throw new ArgumentException($"Only {nameof(WriteDumpFlags.LoggingEnabled)} flag is supported by this runtime version", nameof(flags)); + if ((flags & ~WriteDumpFlags.LoggingEnabled) != 0) + { + throw new ArgumentException($"Only {nameof(WriteDumpFlags.LoggingEnabled)} flag is supported by this runtime version", nameof(flags)); + } + request = CreateWriteDumpMessage(dumpType, dumpPath, logDumpGeneration: (flags & WriteDumpFlags.LoggingEnabled) != 0); + response = IpcClient.SendMessage(_endpoint, request); + ValidateResponseMessage(response, "Write dump"); } - WriteDump(dumpType, dumpPath, logDumpGeneration: (flags & WriteDumpFlags.LoggingEnabled) != 0); } } @@ -153,11 +158,9 @@ namespace Microsoft.Diagnostics.NETCore.Client /// Full path to the dump to be generated. By default it is /tmp/coredump.{pid} /// When set to true, display the dump generation debug log to the console. /// The token to monitor for cancellation requests. - public async Task WriteDumpAsync(DumpType dumpType, string dumpPath, bool logDumpGeneration, CancellationToken token) + public Task WriteDumpAsync(DumpType dumpType, string dumpPath, bool logDumpGeneration, CancellationToken token) { - IpcMessage request = CreateWriteDumpMessage(dumpType, dumpPath, logDumpGeneration); - IpcMessage response = await IpcClient.SendMessageAsync(_endpoint, request, token).ConfigureAwait(false); - ValidateResponseMessage(response, nameof(WriteDumpAsync)); + return WriteDumpAsync(dumpType, dumpPath, logDumpGeneration ? WriteDumpFlags.LoggingEnabled : WriteDumpFlags.None, token); } /// @@ -169,15 +172,22 @@ namespace Microsoft.Diagnostics.NETCore.Client /// The token to monitor for cancellation requests. public async Task WriteDumpAsync(DumpType dumpType, string dumpPath, WriteDumpFlags flags, CancellationToken token) { - IpcMessage request = CreateWriteDumpMessage2(dumpType, dumpPath, flags); + IpcMessage request = CreateWriteDumpMessage(DumpCommandId.GenerateCoreDump3, dumpType, dumpPath, flags); IpcMessage response = await IpcClient.SendMessageAsync(_endpoint, request, token).ConfigureAwait(false); - if (!ValidateResponseMessage(response, nameof(WriteDumpAsync), ValidateResponseOptions.UnknownCommandReturnsFalse)) + if (!ValidateResponseMessage(response, "Write dump", ValidateResponseOptions.UnknownCommandReturnsFalse | ValidateResponseOptions.ErrorMessageReturned)) { - if ((flags & ~WriteDumpFlags.LoggingEnabled) != 0) + request = CreateWriteDumpMessage(DumpCommandId.GenerateCoreDump2, dumpType, dumpPath, flags); + response = await IpcClient.SendMessageAsync(_endpoint, request, token).ConfigureAwait(false); + if (!ValidateResponseMessage(response, "Write dump", ValidateResponseOptions.UnknownCommandReturnsFalse)) { - throw new ArgumentException($"Only {nameof(WriteDumpFlags.LoggingEnabled)} flag is supported by this runtime version", nameof(flags)); + if ((flags & ~WriteDumpFlags.LoggingEnabled) != 0) + { + throw new ArgumentException($"Only {nameof(WriteDumpFlags.LoggingEnabled)} flag is supported by this runtime version", nameof(flags)); + } + request = CreateWriteDumpMessage(dumpType, dumpPath, logDumpGeneration: (flags & WriteDumpFlags.LoggingEnabled) != 0); + response = await IpcClient.SendMessageAsync(_endpoint, request, token).ConfigureAwait(false); + ValidateResponseMessage(response, "Write dump"); } - await WriteDumpAsync(dumpType, dumpPath, logDumpGeneration: (flags & WriteDumpFlags.LoggingEnabled) != 0, token); } } @@ -522,13 +532,13 @@ namespace Microsoft.Diagnostics.NETCore.Client return new IpcMessage(DiagnosticsServerCommandSet.Dump, (byte)DumpCommandId.GenerateCoreDump, payload); } - private static IpcMessage CreateWriteDumpMessage2(DumpType dumpType, string dumpPath, WriteDumpFlags flags) + private static IpcMessage CreateWriteDumpMessage(DumpCommandId command, DumpType dumpType, string dumpPath, WriteDumpFlags flags) { if (string.IsNullOrEmpty(dumpPath)) throw new ArgumentNullException($"{nameof(dumpPath)} required"); byte[] payload = SerializePayload(dumpPath, (uint)dumpType, (uint)flags); - return new IpcMessage(DiagnosticsServerCommandSet.Dump, (byte)DumpCommandId.GenerateCoreDump2, payload); + return new IpcMessage(DiagnosticsServerCommandSet.Dump, (byte)command, payload); } private static ProcessInfo GetProcessInfoFromResponse(IpcResponse response, string operationName) @@ -552,8 +562,13 @@ namespace Microsoft.Diagnostics.NETCore.Client { switch ((DiagnosticsServerResponseId)responseMessage.Header.CommandId) { + case DiagnosticsServerResponseId.OK: + return true; + case DiagnosticsServerResponseId.Error: uint hr = BitConverter.ToUInt32(responseMessage.Payload, 0); + int index = sizeof(uint); + string message = null; switch (hr) { case (uint)DiagnosticsIpcError.UnknownCommand: @@ -562,18 +577,36 @@ namespace Microsoft.Diagnostics.NETCore.Client return false; } throw new UnsupportedCommandException($"{operationName} failed - Command is not supported."); + case (uint)DiagnosticsIpcError.ProfilerAlreadyActive: throw new ProfilerAlreadyActiveException($"{operationName} failed - A profiler is already loaded."); + case (uint)DiagnosticsIpcError.InvalidArgument: if (options.HasFlag(ValidateResponseOptions.InvalidArgumentIsRequiresSuspension)) { throw new ServerErrorException($"{operationName} failed - The runtime must be suspended for this command."); } throw new UnsupportedCommandException($"{operationName} failed - Invalid command argument."); + + case (uint)DiagnosticsIpcError.NotSupported: + message = $"{operationName} - Not supported by this runtime."; + break; + + default: + break; } - throw new ServerErrorException($"{operationName} failed - HRESULT: 0x{hr:X8}"); - case DiagnosticsServerResponseId.OK: - return true; + // Check if the command can return an error message and if the payload is big enough to contain the + // error code (uint) and the string length (uint). + if (options.HasFlag(ValidateResponseOptions.ErrorMessageReturned) && responseMessage.Payload.Length >= (sizeof(uint) * 2)) + { + message = IpcHelpers.ReadString(responseMessage.Payload, ref index); + } + if (string.IsNullOrWhiteSpace(message)) + { + message = $"{operationName} failed - HRESULT: 0x{hr:X8}."; + } + throw new ServerErrorException(message); + default: throw new ServerErrorException($"{operationName} failed - Server responded with unknown response."); } @@ -585,6 +618,7 @@ namespace Microsoft.Diagnostics.NETCore.Client None = 0x0, UnknownCommandReturnsFalse = 0x1, InvalidArgumentIsRequiresSuspension = 0x2, + ErrorMessageReturned = 0x4, } } } diff --git a/src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsIpc/IpcCommands.cs b/src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsIpc/IpcCommands.cs index 516cf3064..241acaee0 100644 --- a/src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsIpc/IpcCommands.cs +++ b/src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsIpc/IpcCommands.cs @@ -35,6 +35,7 @@ namespace Microsoft.Diagnostics.NETCore.Client { GenerateCoreDump = 0x01, GenerateCoreDump2 = 0x02, + GenerateCoreDump3 = 0x03, } internal enum ProfilerCommandId : byte diff --git a/src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsIpc/IpcMessage.cs b/src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsIpc/IpcMessage.cs index 9aa4d2530..9a771b83b 100644 --- a/src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsIpc/IpcMessage.cs +++ b/src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsIpc/IpcMessage.cs @@ -16,7 +16,9 @@ namespace Microsoft.Diagnostics.NETCore.Client /// internal enum DiagnosticsIpcError : uint { + Fail = 0x80004005, InvalidArgument = 0x80070057, + NotSupported = 0x80131515, ProfilerAlreadyActive = 0x8013136A, BadEncoding = 0x80131384, UnknownCommand = 0x80131385, diff --git a/src/SOS/SOS.InstallHelper/InstallHelper.cs b/src/SOS/SOS.InstallHelper/InstallHelper.cs index b9753f1a4..a89cfe548 100644 --- a/src/SOS/SOS.InstallHelper/InstallHelper.cs +++ b/src/SOS/SOS.InstallHelper/InstallHelper.cs @@ -57,21 +57,10 @@ namespace SOS { m_writeLine = writeLine; string rid = GetRid(architecture); - string home; + string home = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { - home = Environment.GetEnvironmentVariable("USERPROFILE"); - if (string.IsNullOrEmpty(home)) { - throw new SOSInstallerException("USERPROFILE environment variable not found"); - } - } - else - { - home = Environment.GetEnvironmentVariable("HOME"); - if (string.IsNullOrEmpty(home)) { - throw new SOSInstallerException("HOME environment variable not found"); - } LLDBInitFile = Path.Combine(home, ".lldbinit"); } InstallLocation = Path.GetFullPath(Path.Combine(home, ".dotnet", "sos")); @@ -87,16 +76,20 @@ namespace SOS { WriteLine("Installing SOS to {0}", InstallLocation); - if (string.IsNullOrEmpty(SOSNativeSourcePath) || string.IsNullOrEmpty(SOSManagedSourcePath)) { + if (string.IsNullOrEmpty(SOSNativeSourcePath) || string.IsNullOrEmpty(SOSManagedSourcePath)) + { throw new SOSInstallerException("SOS source path not valid"); } - if (!Directory.Exists(SOSNativeSourcePath)) { + if (!Directory.Exists(SOSNativeSourcePath)) + { throw new SOSInstallerException($"Operating system or architecture not supported: installing from {SOSNativeSourcePath}"); } - if (!Directory.Exists(SOSManagedSourcePath)) { + if (!Directory.Exists(SOSManagedSourcePath)) + { throw new SOSInstallerException($"Invalid SOS source directory {SOSManagedSourcePath}"); } - if (string.IsNullOrEmpty(InstallLocation)) { + if (string.IsNullOrEmpty(InstallLocation)) + { throw new SOSInstallerException($"Installation path {InstallLocation} not valid"); } @@ -139,10 +132,12 @@ namespace SOS }); // Configure lldb - if (LLDBInitFile != null) { + if (LLDBInitFile != null) + { Configure(); } - else { + else + { WriteLine($"Execute '.load {InstallLocation}\\sos.dll' to load SOS in your Windows debugger."); } @@ -207,7 +202,8 @@ namespace SOS /// public void Configure(bool remove = false) { - if (string.IsNullOrEmpty(LLDBInitFile)) { + if (string.IsNullOrEmpty(LLDBInitFile)) + { throw new SOSInstallerException("No lldb configuration file path"); } bool changed = false; @@ -243,7 +239,8 @@ namespace SOS } } - if (markerFound) { + if (markerFound) + { throw new SOSInstallerException(".lldbinit file end marker not found"); } } @@ -256,7 +253,8 @@ namespace SOS string extension = RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? ".dylib" : ".so"; lines.Add($"plugin load {plugin}{extension}"); - if (EnableSymbolServer) { + if (EnableSymbolServer) + { lines.Add(string.Format("setsymbolserver -ms")); } lines.Add(InitFileEnd); @@ -266,10 +264,12 @@ namespace SOS // If there is anything to write, write the lldb init file if (changed) { - if (remove) { + if (remove) + { WriteLine("Reverting {0} file - LLDB will no longer load SOS at startup", LLDBInitFile); } - else { + else + { WriteLine("{0} {1} file - LLDB will load SOS automatically at startup", existing ? "Updating existing" : "Creating new", LLDBInitFile); } RetryOperation($"Problem writing lldb init file {LLDBInitFile}", () => File.WriteAllLines(LLDBInitFile, lines.ToArray())); @@ -303,7 +303,8 @@ namespace SOS } catch (Exception ex) when (ex is ArgumentException || ex is UnauthorizedAccessException || ex is SecurityException) { - if (errorMessage == null) { + if (errorMessage == null) + { return; } throw new SOSInstallerException($"{errorMessage}: {ex.Message}", ex); @@ -312,7 +313,8 @@ namespace SOS if (lastfailure != null) { - if (errorMessage == null) { + if (errorMessage == null) + { return; } throw new SOSInstallerException($"{errorMessage}: {lastfailure.Message}", lastfailure); @@ -378,4 +380,4 @@ namespace SOS { } } -} \ No newline at end of file +} diff --git a/src/SOS/Strike/eeheap.cpp b/src/SOS/Strike/eeheap.cpp index 2642d0a75..7bb21cf8b 100644 --- a/src/SOS/Strike/eeheap.cpp +++ b/src/SOS/Strike/eeheap.cpp @@ -503,12 +503,12 @@ void GCPrintSegmentInfo(const GCHeapDetails &heap, DWORD_PTR &total_allocated_si } ExtOut("%p %p %p %p 0x%" POINTERSIZE_TYPE "x(%" POINTERSIZE_TYPE"d) 0x%" POINTERSIZE_TYPE "x(%" POINTERSIZE_TYPE "d)\n", SOS_PTR(dwAddrSeg), - SOS_PTR(segment.mem), SOS_PTR(segment.allocated), SOS_PTR(segment.committed), - (ULONG_PTR)(segment.allocated - segment.mem), - (ULONG_PTR)(segment.allocated - segment.mem), + SOS_PTR(segment.mem), SOS_PTR(segment.highAllocMark), SOS_PTR(segment.committed), + (ULONG_PTR)(segment.highAllocMark - segment.mem), + (ULONG_PTR)(segment.highAllocMark - segment.mem), (ULONG_PTR)(segment.committed - segment.mem), (ULONG_PTR)(segment.committed - segment.mem)); - total_allocated_size += (DWORD_PTR)(segment.allocated - segment.mem); + total_allocated_size += (DWORD_PTR)(segment.highAllocMark - segment.mem); total_committed_size += (DWORD_PTR)(segment.committed - segment.mem); dwAddrSeg = (DWORD_PTR)segment.next; } @@ -700,16 +700,11 @@ BOOL GCObjInSegment(TADDR taddrObj, const GCHeapDetails &heap, ExtOut("Error requesting heap segment %p\n", SOS_PTR(taddrSeg)); return FALSE; } - TADDR allocated = TO_TADDR(dacpSeg.allocated); - if (taddrSeg == TO_TADDR(heap.ephemeral_heap_segment)) - { - allocated = TO_TADDR(heap.alloc_allocated); - } - if (taddrObj >= TO_TADDR(dacpSeg.mem) && taddrObj < allocated) + if (taddrObj >= TO_TADDR(dacpSeg.mem) && taddrObj < dacpSeg.highAllocMark) { rngSeg.segAddr = (TADDR)dacpSeg.segmentAddr; rngSeg.start = (TADDR)dacpSeg.mem; - rngSeg.end = (TADDR)dacpSeg.allocated; + rngSeg.end = (TADDR)dacpSeg.highAllocMark; gen = gen_num; return TRUE; } @@ -983,7 +978,7 @@ BOOL GCHeapUsageStats(const GCHeapDetails& heap, BOOL bIncUnreachable, HeapUsage return FALSE; } #ifndef FEATURE_PAL - GCGenUsageStats((TADDR)dacpSeg.mem, (TADDR)dacpSeg.allocated, (TADDR)dacpSeg.committed, liveObjs, heap, FALSE, FALSE, &allocInfo, &hpUsage->genUsage[n]); + GCGenUsageStats((TADDR)dacpSeg.mem, (TADDR)dacpSeg.highAllocMark, (TADDR)dacpSeg.committed, liveObjs, heap, FALSE, FALSE, &allocInfo, &hpUsage->genUsage[n]); #endif taddrSeg = (TADDR)dacpSeg.next; } @@ -1268,7 +1263,6 @@ BOOL GCHeapTraverse(const GCHeapDetails &heap, AllocInfo* pallocInfo, VISITGCHEA DacpHeapSegmentData segment; if (heap.has_regions) { - DWORD_PTR end_youngest = (DWORD_PTR)heap.alloc_allocated; BOOL bPrevFree = FALSE; for (UINT n = 0; n <= GetMaxGeneration(); n++) { @@ -1286,15 +1280,11 @@ BOOL GCHeapTraverse(const GCHeapDetails &heap, AllocInfo* pallocInfo, VISITGCHEA return FALSE; } dwAddrCurrObj = (DWORD_PTR)segment.mem; - DWORD_PTR end_of_segment = (DWORD_PTR)segment.allocated; - if (dwAddrSeg == (DWORD_PTR)heap.ephemeral_heap_segment) - { - end_of_segment = end_youngest; - } + DWORD_PTR end_of_segment = (DWORD_PTR)segment.highAllocMark; while (true) { - if (dwAddrCurrObj - SIZEOF_OBJHEADER == end_youngest - Align(min_obj_size)) + if (dwAddrCurrObj - SIZEOF_OBJHEADER == end_of_segment - Align(min_obj_size)) break; if (dwAddrCurrObj >= (DWORD_PTR)end_of_segment) @@ -1314,13 +1304,13 @@ BOOL GCHeapTraverse(const GCHeapDetails &heap, AllocInfo* pallocInfo, VISITGCHEA } if (dwAddrSeg == (DWORD_PTR)heap.ephemeral_heap_segment - && dwAddrCurrObj >= end_youngest) + && dwAddrCurrObj >= end_of_segment) { - if (dwAddrCurrObj > end_youngest) + if (dwAddrCurrObj > end_of_segment) { // prev_object length is too long - ExtOut("curr_object: %p > end_youngest: %p\n", - SOS_PTR(dwAddrCurrObj), SOS_PTR(end_youngest)); + ExtOut("curr_object: %p > end_of_segment: %p\n", + SOS_PTR(dwAddrCurrObj), SOS_PTR(end_of_segment)); if (dwAddrPrevObj) { DMLOut("Last good object: %s\n", DMLObject(dwAddrPrevObj)); @@ -2017,18 +2007,45 @@ int GCHeapSnapshot::GetGeneration(CLRDATA_ADDRESS objectPointer) } TADDR taObj = TO_TADDR(objectPointer); - // The DAC doesn't fill the generation table with true CLRDATA_ADDRESS values - // but rather with ULONG64 values (i.e. non-sign-extended 64-bit values) - // We use the TO_TADDR below to ensure we won't break if this will ever - // be fixed in the DAC. - if (taObj >= TO_TADDR(pDetails->generation_table[0].allocation_start) && - taObj <= TO_TADDR(pDetails->alloc_allocated)) - return 0; - - if (taObj >= TO_TADDR(pDetails->generation_table[1].allocation_start) && - taObj <= TO_TADDR(pDetails->generation_table[0].allocation_start)) - return 1; + if (pDetails->has_regions) + { + for (int gen_num = 0; gen_num <= 1; gen_num++) + { + CLRDATA_ADDRESS dwAddrSeg = pDetails->generation_table[gen_num].start_segment; + while (dwAddrSeg != 0) + { + DacpHeapSegmentData segment; + if (segment.Request(g_sos, dwAddrSeg, pDetails->original_heap_details) != S_OK) + { + ExtOut("Error requesting heap segment %p\n", SOS_PTR(dwAddrSeg)); + return 0; + } + // The DAC doesn't fill the generation table with true CLRDATA_ADDRESS values + // but rather with ULONG64 values (i.e. non-sign-extended 64-bit values) + // We use the TO_TADDR below to ensure we won't break if this will ever + // be fixed in the DAC. + if (TO_TADDR(segment.mem) <= taObj && taObj < TO_TADDR(segment.highAllocMark)) + { + return gen_num; + } + dwAddrSeg = segment.next; + } + } + } + else + { + // The DAC doesn't fill the generation table with true CLRDATA_ADDRESS values + // but rather with ULONG64 values (i.e. non-sign-extended 64-bit values) + // We use the TO_TADDR below to ensure we won't break if this will ever + // be fixed in the DAC. + if (taObj >= TO_TADDR(pDetails->generation_table[0].allocation_start) && + taObj <= TO_TADDR(pDetails->alloc_allocated)) + return 0; + if (taObj >= TO_TADDR(pDetails->generation_table[1].allocation_start) && + taObj <= TO_TADDR(pDetails->generation_table[0].allocation_start)) + return 1; + } return 2; } diff --git a/src/SOS/Strike/gcroot.cpp b/src/SOS/Strike/gcroot.cpp index a649bad82..b4cfe5661 100644 --- a/src/SOS/Strike/gcroot.cpp +++ b/src/SOS/Strike/gcroot.cpp @@ -1656,8 +1656,7 @@ BOOL FindSegment(const GCHeapDetails &heap, DacpHeapSegmentData &seg, CLRDATA_AD ExtOut("Error requesting heap segment %p\n", SOS_PTR(dwAddrSeg)); return FALSE; } - if (addr >= TO_TADDR(seg.mem) && - addr < (dwAddrSeg == heap.ephemeral_heap_segment ? heap.alloc_allocated : TO_TADDR(seg.allocated))) + if (addr >= TO_TADDR(seg.mem) && addr < seg.highAllocMark) { return TRUE; } diff --git a/src/SOS/Strike/sos.cpp b/src/SOS/Strike/sos.cpp index a430fac74..f2052cfa2 100644 --- a/src/SOS/Strike/sos.cpp +++ b/src/SOS/Strike/sos.cpp @@ -596,9 +596,7 @@ namespace sos } mCurrObj = mStart < TO_TADDR(mSegment.mem) ? TO_TADDR(mSegment.mem) : mStart; - mSegmentEnd = (segStart == TO_TADDR(mHeaps[0].ephemeral_heap_segment)) ? - TO_TADDR(mHeaps[0].alloc_allocated) : - TO_TADDR(mSegment.allocated); + mSegmentEnd = TO_TADDR(mSegment.highAllocMark); CheckSegmentRange(); } @@ -661,9 +659,7 @@ namespace sos mLastObj = 0; mCurrObj = mStart < TO_TADDR(mSegment.mem) ? TO_TADDR(mSegment.mem) : mStart; - mSegmentEnd = (next == TO_TADDR(mHeaps[mCurrHeap].ephemeral_heap_segment)) ? - TO_TADDR(mHeaps[mCurrHeap].alloc_allocated) : - TO_TADDR(mSegment.allocated); + mSegmentEnd = TO_TADDR(mSegment.highAllocMark); return CheckSegmentRange(); } diff --git a/src/Tools/dotnet-dump/Analyzer.cs b/src/Tools/dotnet-dump/Analyzer.cs index 0e284c974..7532b870d 100644 --- a/src/Tools/dotnet-dump/Analyzer.cs +++ b/src/Tools/dotnet-dump/Analyzer.cs @@ -47,7 +47,8 @@ namespace Microsoft.Diagnostics.Tools.Dump _serviceProvider.AddService(_contextService); _serviceProvider.AddServiceFactory(() => SOSLibrary.Create(this)); - _contextService.ServiceProvider.AddServiceFactory(() => { + _contextService.ServiceProvider.AddServiceFactory(() => + { ClrRuntime clrRuntime = _contextService.Services.GetService(); return clrRuntime != null ? new ClrMDHelper(clrRuntime) : null; }); @@ -64,23 +65,17 @@ namespace Microsoft.Diagnostics.Tools.Dump _consoleProvider.WriteLine($"Loading core dump: {dump_path} ..."); // Attempt to load the persisted command history - string dotnetHome; - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { - dotnetHome = Path.Combine(Environment.GetEnvironmentVariable("USERPROFILE"), ".dotnet"); - } - else { - dotnetHome = Path.Combine(Environment.GetEnvironmentVariable("HOME"), ".dotnet"); - } + string dotnetHome = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".dotnet"); string historyFileName = Path.Combine(dotnetHome, "dotnet-dump.history"); try { string[] history = File.ReadAllLines(historyFileName); _consoleProvider.AddCommandHistory(history); } - catch (Exception ex) when - (ex is IOException || - ex is UnauthorizedAccessException || - ex is NotSupportedException || + catch (Exception ex) when + (ex is IOException || + ex is UnauthorizedAccessException || + ex is NotSupportedException || ex is SecurityException) { } @@ -89,11 +84,12 @@ namespace Microsoft.Diagnostics.Tools.Dump LoadExtensions(); try - { + { using DataTarget dataTarget = DataTarget.LoadDump(dump_path.FullName); OSPlatform targetPlatform = dataTarget.DataReader.TargetPlatform; - if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) || dataTarget.DataReader.EnumerateModules().Any((module) => Path.GetExtension(module.FileName) == ".dylib")) { + if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) || dataTarget.DataReader.EnumerateModules().Any((module) => Path.GetExtension(module.FileName) == ".dylib")) + { targetPlatform = OSPlatform.OSX; } _target = new TargetFromDataReader(dataTarget.DataReader, targetPlatform, this, _targetIdFactory++, dump_path.FullName); @@ -112,7 +108,8 @@ namespace Microsoft.Diagnostics.Tools.Dump foreach (string cmd in command) { _commandService.Execute(cmd, _contextService.Services); - if (_consoleProvider.Shutdown) { + if (_consoleProvider.Shutdown) + { break; } } @@ -123,7 +120,8 @@ namespace Microsoft.Diagnostics.Tools.Dump _consoleProvider.WriteLine("Ready to process analysis commands. Type 'help' to list available commands or 'help [command]' to get detailed help on a command."); _consoleProvider.WriteLine("Type 'quit' or 'exit' to exit the session."); - _consoleProvider.Start((string commandLine, CancellationToken cancellation) => { + _consoleProvider.Start((string commandLine, CancellationToken cancellation) => + { _commandService.Execute(commandLine, _contextService.Services); }); } @@ -152,10 +150,10 @@ namespace Microsoft.Diagnostics.Tools.Dump { File.WriteAllLines(historyFileName, _consoleProvider.GetCommandHistory()); } - catch (Exception ex) when - (ex is IOException || - ex is UnauthorizedAccessException || - ex is NotSupportedException || + catch (Exception ex) when + (ex is IOException || + ex is UnauthorizedAccessException || + ex is NotSupportedException || ex is SecurityException) { } @@ -177,14 +175,16 @@ namespace Microsoft.Diagnostics.Tools.Dump public void DestroyTarget(ITarget target) { - if (target == null) { + if (target == null) + { throw new ArgumentNullException(nameof(target)); } if (target == _target) { _target = null; _contextService.ClearCurrentTarget(); - if (target is IDisposable disposable) { + if (target is IDisposable disposable) + { disposable.Dispose(); } } @@ -221,7 +221,7 @@ namespace Microsoft.Diagnostics.Tools.Dump { assembly = Assembly.LoadFrom(extensionPath); } - catch (Exception ex) when (ex is IOException || ex is ArgumentException || ex is BadImageFormatException || ex is System.Security.SecurityException) + catch (Exception ex) when (ex is IOException || ex is ArgumentException || ex is BadImageFormatException || ex is System.Security.SecurityException) { _consoleProvider.WriteLineError($"Extension load {extensionPath} FAILED {ex.Message}"); } diff --git a/src/Tools/dotnet-dump/Dumper.Windows.cs b/src/Tools/dotnet-dump/Dumper.Windows.cs index 12d4d5cc1..41de4e2ae 100644 --- a/src/Tools/dotnet-dump/Dumper.Windows.cs +++ b/src/Tools/dotnet-dump/Dumper.Windows.cs @@ -4,7 +4,7 @@ using Microsoft.Win32.SafeHandles; using System; -using System.Diagnostics; +using System.ComponentModel; using System.IO; using System.Runtime.InteropServices; @@ -21,7 +21,9 @@ namespace Microsoft.Diagnostics.Tools.Dump using SafeProcessHandle processHandle = NativeMethods.OpenProcess(NativeMethods.PROCESS_QUERY_INFORMATION | NativeMethods.PROCESS_VM_READ, false, processId); if (processHandle.IsInvalid) { - throw new ArgumentException($"Invalid process id {processId} error: {Marshal.GetLastWin32Error()}"); + int error = Marshal.GetLastWin32Error(); + string errorText = new Win32Exception(error).Message; + throw new ArgumentException($"Invalid process id {processId} - {errorText} ({error})"); } // Open the file for writing @@ -77,7 +79,7 @@ namespace Microsoft.Diagnostics.Tools.Dump else { int err = Marshal.GetHRForLastWin32Error(); - if (err != NativeMethods.ERROR_PARTIAL_COPY) + if (err != NativeMethods.HR_ERROR_PARTIAL_COPY) { Marshal.ThrowExceptionForHR(err); } @@ -88,7 +90,7 @@ namespace Microsoft.Diagnostics.Tools.Dump private static class NativeMethods { - public const int ERROR_PARTIAL_COPY = unchecked((int)0x8007012b); + public const int HR_ERROR_PARTIAL_COPY = unchecked((int)0x8007012b); public const int PROCESS_VM_READ = 0x0010; public const int PROCESS_QUERY_INFORMATION = 0x0400; diff --git a/src/dbgshim/debugshim.cpp b/src/dbgshim/debugshim.cpp index 40fa07a85..0f6a0741b 100644 --- a/src/dbgshim/debugshim.cpp +++ b/src/dbgshim/debugshim.cpp @@ -643,13 +643,15 @@ HRESULT CLRDebuggingImpl::GetCLRInfo(ICorDebugDataTarget * pDataTarget, hrGetResource = GetResourceRvaFromResourceSectionRvaByName(pDataTarget, moduleBaseAddress, resourceSectionRVA, 10, resourceName, 0, &debugResourceRVA, &debugResourceSize); useCrossPlatformNaming = SUCCEEDED(hrGetResource); - #if defined(HOST_WINDOWS) && (defined(HOST_X86) || defined(HOST_AMD64) || defined(HOST_ARM)) + #if defined(HOST_WINDOWS) && (defined(HOST_X86) || defined(HOST_AMD64) || defined(HOST_ARM) || defined(HOST_ARM64)) #if defined(HOST_X86) #define _HOST_MACHINE_TYPE IMAGE_FILE_MACHINE_I386 #elif defined(HOST_AMD64) #define _HOST_MACHINE_TYPE IMAGE_FILE_MACHINE_AMD64 #elif defined(HOST_ARM) #define _HOST_MACHINE_TYPE IMAGE_FILE_MACHINE_ARMNT + #elif defined(HOST_ARM64) + #define _HOST_MACHINE_TYPE IMAGE_FILE_MACHINE_ARM64 #endif // if this is windows, and if host_arch matches target arch then we can fallback to searching for CLRDEBUGINFO on failure @@ -661,7 +663,7 @@ HRESULT CLRDebuggingImpl::GetCLRInfo(ICorDebugDataTarget * pDataTarget, #undef _HOST_MACHINE_TYPE #endif // if the search failed, we don't recognize the CLR - if(FAILED(hrGetResource)) + if (FAILED(hrGetResource)) { hr = CORDBG_E_NOT_CLR; } diff --git a/src/dbgshim/pkg/Microsoft.Diagnostics.DbgShim.props b/src/dbgshim/pkg/Microsoft.Diagnostics.DbgShim.props index 045b82e1c..cf15af8c8 100644 --- a/src/dbgshim/pkg/Microsoft.Diagnostics.DbgShim.props +++ b/src/dbgshim/pkg/Microsoft.Diagnostics.DbgShim.props @@ -5,12 +5,10 @@ false true - false - none true - .pdb;.dbg;.dwarf + $(SymbolsSuffix) - + $(TargetsForTfmSpecificDebugSymbolsInPackage);AddRuntimeSpecificNativeSymbolToPackage true $(NoWarn);NU5128 @@ -24,7 +22,13 @@ - + + diff --git a/src/shared/inc/dacprivate.h b/src/shared/inc/dacprivate.h index 1dec58062..abbb31405 100644 --- a/src/shared/inc/dacprivate.h +++ b/src/shared/inc/dacprivate.h @@ -805,13 +805,15 @@ struct MSLAYOUT DacpHeapSegmentData HRESULT Request(ISOSDacInterface *sos, CLRDATA_ADDRESS addr, const DacpGcHeapDetails& heap) { + // clear this here to make sure we don't get stale values + this->highAllocMark = 0; + HRESULT hr = sos->GetHeapSegmentData(addr, this); - // if this is the start segment, set highAllocMark too. - if (SUCCEEDED(hr)) + // if this is the start segment, and the Dac hasn't set highAllocMark, set it here. + if (SUCCEEDED(hr) && this->highAllocMark == 0) { - // TODO: This needs to be put on the Dac side. - if (this->segmentAddr == heap.generation_table[0].start_segment) + if (this->segmentAddr == heap.ephemeral_heap_segment) highAllocMark = heap.alloc_allocated; else highAllocMark = allocated; diff --git a/src/shared/pal/inc/rt/ntimage.h b/src/shared/pal/inc/rt/ntimage.h index 188037518..f722da0e4 100644 --- a/src/shared/pal/inc/rt/ntimage.h +++ b/src/shared/pal/inc/rt/ntimage.h @@ -2,6 +2,9 @@ // The .NET Foundation licenses this file to you under the MIT license. // +// This file is a verbatim copy of the Windows OS header with PE file structure definitions. + + // // =========================================================================== // File: ntimage.h @@ -222,7 +225,7 @@ typedef struct _IMAGE_FILE_HEADER { #define IMAGE_FILE_MACHINE_SH4 0x01a6 // SH4 little-endian #define IMAGE_FILE_MACHINE_SH5 0x01a8 // SH5 #define IMAGE_FILE_MACHINE_ARM 0x01c0 // ARM Little-Endian -#define IMAGE_FILE_MACHINE_THUMB 0x01c2 +#define IMAGE_FILE_MACHINE_THUMB 0x01c2 // ARM Thumb/Thumb-2 Little-Endian #define IMAGE_FILE_MACHINE_ARMNT 0x01c4 // ARM Thumb-2 Little-Endian #define IMAGE_FILE_MACHINE_AM33 0x01d3 #define IMAGE_FILE_MACHINE_POWERPC 0x01F0 // IBM PowerPC Little-Endian @@ -238,7 +241,9 @@ typedef struct _IMAGE_FILE_HEADER { #define IMAGE_FILE_MACHINE_EBC 0x0EBC // EFI Byte Code #define IMAGE_FILE_MACHINE_AMD64 0x8664 // AMD64 (K8) #define IMAGE_FILE_MACHINE_M32R 0x9041 // M32R little-endian +#define IMAGE_FILE_MACHINE_ARM64 0xAA64 // ARM64 Little-Endian #define IMAGE_FILE_MACHINE_CEE 0xC0EE +#define IMAGE_FILE_MACHINE_LOONGARCH64 0x6264 // LOONGARCH64. // // Directory format. @@ -1025,6 +1030,12 @@ typedef IMAGE_RELOCATION UNALIGNED *PIMAGE_RELOCATION; #define IMAGE_REL_IA64_GPREL32 0x001C #define IMAGE_REL_IA64_ADDEND 0x001F +// +// LOONGARCH64 relocation types +// +#define IMAGE_REL_LOONGARCH64_PC 0x0003 +#define IMAGE_REL_LOONGARCH64_JIR 0x0004 + // // CEF relocation types. //