From: Mike McLaughlin Date: Mon, 2 Oct 2023 18:52:14 +0000 (-0700) Subject: Remove the symstore dependency from Microsoft.Diagnostics.DebugServices (#4279) X-Git-Tag: accepted/tizen/unified/riscv/20231226.055542~35^2~1^2~65 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=415440718d1a44f95f6f5a38a028d3b8d9615ad9;p=platform%2Fcore%2Fdotnet%2Fdiagnostics.git Remove the symstore dependency from Microsoft.Diagnostics.DebugServices (#4279) This is needed to reduce the conflicts/dependencies on loadable extensions. --- diff --git a/eng/Versions.props b/eng/Versions.props index da0a4d378..7fec60baa 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -43,6 +43,7 @@ true 5.0.0 + 6.0.0 6.0.0 3.0.450101 diff --git a/src/Microsoft.Diagnostics.DebugServices.Implementation/Runtime.cs b/src/Microsoft.Diagnostics.DebugServices.Implementation/Runtime.cs index 11b2308e2..351bd02df 100644 --- a/src/Microsoft.Diagnostics.DebugServices.Implementation/Runtime.cs +++ b/src/Microsoft.Diagnostics.DebugServices.Implementation/Runtime.cs @@ -252,7 +252,7 @@ namespace Microsoft.Diagnostics.DebugServices.Implementation if (key is not null) { // Now download the DAC module from the symbol server - filePath = _symbolService.DownloadFile(key); + filePath = _symbolService.DownloadFile(key.Index, key.FullPathName); } } else diff --git a/src/Microsoft.Diagnostics.DebugServices.Implementation/SymbolService.cs b/src/Microsoft.Diagnostics.DebugServices.Implementation/SymbolService.cs index f764a4b33..4b5ad2b9b 100644 --- a/src/Microsoft.Diagnostics.DebugServices.Implementation/SymbolService.cs +++ b/src/Microsoft.Diagnostics.DebugServices.Implementation/SymbolService.cs @@ -400,44 +400,9 @@ namespace Microsoft.Diagnostics.DebugServices.Implementation /// /// Download a file from the symbol stores/server. /// - /// index of the file to download - /// path to the downloaded file either in the cache or in the temp directory or null if error - public string DownloadFile(SymbolStoreKey key) - { - string downloadFilePath = null; - - if (IsSymbolStoreEnabled) - { - using SymbolStoreFile file = GetSymbolStoreFile(key); - if (file != null) - { - try - { - downloadFilePath = file.FileName; - - // Make sure the stream is at the beginning of the module - file.Stream.Position = 0; - - // If the downloaded doesn't already exists on disk in the cache, then write it to a temporary location. - if (!File.Exists(downloadFilePath)) - { - downloadFilePath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName() + "-" + Path.GetFileName(key.FullPathName)); - using (Stream destinationStream = File.OpenWrite(downloadFilePath)) - { - file.Stream.CopyTo(destinationStream); - } - Trace.WriteLine($"Downloaded symbol file {key.FullPathName}"); - } - } - catch (Exception ex) when (ex is UnauthorizedAccessException or DirectoryNotFoundException) - { - Trace.TraceError("{0}: {1}", file.FileName, ex.Message); - downloadFilePath = null; - } - } - } - return downloadFilePath; - } + /// index to lookup on symbol server + /// the full path name of the file + public string DownloadFile(string index, string file) => DownloadFile(new SymbolStoreKey(index, file)); /// /// Returns the metadata for the assembly @@ -842,6 +807,48 @@ namespace Microsoft.Diagnostics.DebugServices.Implementation return null; } + /// + /// Download a file from the symbol stores/server. + /// + /// index of the file to download + /// path to the downloaded file either in the cache or in the temp directory or null if error + private string DownloadFile(SymbolStoreKey key) + { + string downloadFilePath = null; + + if (IsSymbolStoreEnabled) + { + using SymbolStoreFile file = GetSymbolStoreFile(key); + if (file != null) + { + try + { + downloadFilePath = file.FileName; + + // Make sure the stream is at the beginning of the module + file.Stream.Position = 0; + + // If the downloaded doesn't already exists on disk in the cache, then write it to a temporary location. + if (!File.Exists(downloadFilePath)) + { + downloadFilePath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName() + "-" + Path.GetFileName(key.FullPathName)); + using (Stream destinationStream = File.OpenWrite(downloadFilePath)) + { + file.Stream.CopyTo(destinationStream); + } + Trace.WriteLine($"Downloaded symbol file {key.FullPathName}"); + } + } + catch (Exception ex) when (ex is UnauthorizedAccessException or DirectoryNotFoundException) + { + Trace.TraceError("{0}: {1}", file.FileName, ex.Message); + downloadFilePath = null; + } + } + } + return downloadFilePath; + } + private static void ReadPortableDebugTableEntries(PEReader peReader, out DebugDirectoryEntry codeViewEntry, out DebugDirectoryEntry embeddedPdbEntry) { // See spec: https://github.com/dotnet/runtime/blob/main/docs/design/specs/PE-COFF.md diff --git a/src/Microsoft.Diagnostics.DebugServices/ISymbolService.cs b/src/Microsoft.Diagnostics.DebugServices/ISymbolService.cs index af5dc291c..13e66f4a6 100644 --- a/src/Microsoft.Diagnostics.DebugServices/ISymbolService.cs +++ b/src/Microsoft.Diagnostics.DebugServices/ISymbolService.cs @@ -3,7 +3,6 @@ using System.Collections.Immutable; using System.IO; -using Microsoft.SymbolStore; namespace Microsoft.Diagnostics.DebugServices { @@ -96,9 +95,9 @@ namespace Microsoft.Diagnostics.DebugServices /// /// Download a file from the symbol stores/server. /// - /// index of the file to download - /// path to the downloaded file either in the cache or in the temp directory or null if error - string DownloadFile(SymbolStoreKey key); + /// index to lookup on symbol server + /// the full path name of the file + string DownloadFile(string index, string file); /// /// Returns the metadata for the assembly diff --git a/src/Microsoft.Diagnostics.DebugServices/Microsoft.Diagnostics.DebugServices.csproj b/src/Microsoft.Diagnostics.DebugServices/Microsoft.Diagnostics.DebugServices.csproj index 33f0fe3e9..e550154f2 100644 --- a/src/Microsoft.Diagnostics.DebugServices/Microsoft.Diagnostics.DebugServices.csproj +++ b/src/Microsoft.Diagnostics.DebugServices/Microsoft.Diagnostics.DebugServices.csproj @@ -13,8 +13,8 @@ true false - + - + diff --git a/src/Microsoft.Diagnostics.ExtensionCommands/Microsoft.Diagnostics.ExtensionCommands.csproj b/src/Microsoft.Diagnostics.ExtensionCommands/Microsoft.Diagnostics.ExtensionCommands.csproj index a18bae922..a7c8e842c 100644 --- a/src/Microsoft.Diagnostics.ExtensionCommands/Microsoft.Diagnostics.ExtensionCommands.csproj +++ b/src/Microsoft.Diagnostics.ExtensionCommands/Microsoft.Diagnostics.ExtensionCommands.csproj @@ -1,4 +1,4 @@ - + netstandard2.0 @@ -16,6 +16,7 @@ + diff --git a/src/SOS/SOS.Hosting/SOS.Hosting.csproj b/src/SOS/SOS.Hosting/SOS.Hosting.csproj index 7fee627a7..df9961fb6 100644 --- a/src/SOS/SOS.Hosting/SOS.Hosting.csproj +++ b/src/SOS/SOS.Hosting/SOS.Hosting.csproj @@ -11,6 +11,7 @@ + diff --git a/src/SOS/SOS.Hosting/SymbolServiceExtensions.cs b/src/SOS/SOS.Hosting/SymbolServiceExtensions.cs index aebf7bc0c..6fe61d348 100644 --- a/src/SOS/SOS.Hosting/SymbolServiceExtensions.cs +++ b/src/SOS/SOS.Hosting/SymbolServiceExtensions.cs @@ -120,7 +120,7 @@ namespace SOS.Hosting if (symbolService.IsSymbolStoreEnabled) { SymbolStoreKey key = PEFileKeyGenerator.GetKey(imagePath, imageTimestamp, imageSize); - string localFilePath = symbolService.DownloadFile(key); + string localFilePath = symbolService.DownloadFile(key.Index, key.FullPathName); if (!string.IsNullOrWhiteSpace(localFilePath)) { localFilePath += "\0"; // null terminate the string diff --git a/src/tests/DbgShim.UnitTests/LibraryProviderWrapper.cs b/src/tests/DbgShim.UnitTests/LibraryProviderWrapper.cs index e3c2b99cd..a1c54f93d 100644 --- a/src/tests/DbgShim.UnitTests/LibraryProviderWrapper.cs +++ b/src/tests/DbgShim.UnitTests/LibraryProviderWrapper.cs @@ -331,7 +331,7 @@ namespace SOS.Hosting Assert.True(timeStamp != 0 && sizeOfImage != 0); SymbolStoreKey key = PEFileKeyGenerator.GetKey(moduleName, timeStamp, sizeOfImage); Assert.NotNull(key); - string downloadedPath = SymbolService.DownloadFile(key); + string downloadedPath = SymbolService.DownloadFile(key.Index, key.FullPathName); Assert.NotNull(downloadedPath); return downloadedPath; } @@ -368,7 +368,7 @@ namespace SOS.Hosting key = MachOFileKeyGenerator.GetKeys(KeyTypeFlags.IdentityKey, moduleName, buildId, symbolFile: false, symbolFileName: null).SingleOrDefault(); } Assert.NotNull(key); - string downloadedPath = SymbolService.DownloadFile(key); + string downloadedPath = SymbolService.DownloadFile(key.Index, key.FullPathName); Assert.NotNull(downloadedPath); return downloadedPath; }