Remove the symstore dependency from Microsoft.Diagnostics.DebugServices (#4279)
authorMike McLaughlin <mikem@microsoft.com>
Mon, 2 Oct 2023 18:52:14 +0000 (11:52 -0700)
committerGitHub <noreply@github.com>
Mon, 2 Oct 2023 18:52:14 +0000 (11:52 -0700)
This is needed to reduce the conflicts/dependencies on loadable
extensions.

eng/Versions.props
src/Microsoft.Diagnostics.DebugServices.Implementation/Runtime.cs
src/Microsoft.Diagnostics.DebugServices.Implementation/SymbolService.cs
src/Microsoft.Diagnostics.DebugServices/ISymbolService.cs
src/Microsoft.Diagnostics.DebugServices/Microsoft.Diagnostics.DebugServices.csproj
src/Microsoft.Diagnostics.ExtensionCommands/Microsoft.Diagnostics.ExtensionCommands.csproj
src/SOS/SOS.Hosting/SOS.Hosting.csproj
src/SOS/SOS.Hosting/SymbolServiceExtensions.cs
src/tests/DbgShim.UnitTests/LibraryProviderWrapper.cs

index da0a4d3784c6319065d26c82ca4b8e86a47d12e6..7fec60baa87c0221e76641181071af5fc2df8d8c 100644 (file)
@@ -43,6 +43,7 @@
     <UsingToolNetFrameworkReferenceAssemblies>true</UsingToolNetFrameworkReferenceAssemblies>
     <!-- CoreFX -->
     <SystemReflectionMetadataVersion>5.0.0</SystemReflectionMetadataVersion>
+    <SystemCollectionsImmutableVersion>6.0.0</SystemCollectionsImmutableVersion>
     <!-- Other libs -->
     <MicrosoftBclAsyncInterfacesVersion>6.0.0</MicrosoftBclAsyncInterfacesVersion>
     <MicrosoftDiagnosticsRuntimeVersion>3.0.450101</MicrosoftDiagnosticsRuntimeVersion>
index 11b2308e2f3555abdb9e93e89879eb310e22c801..351bd02df7d38f8f6ef33b7c92323449c291d40c 100644 (file)
@@ -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
index f764a4b336a6ac9c63c69eae45f16332710c4442..4b5ad2b9ba7fdd5aeed469a1a1020d49f0ea6e27 100644 (file)
@@ -400,44 +400,9 @@ namespace Microsoft.Diagnostics.DebugServices.Implementation
         /// <summary>
         /// Download a file from the symbol stores/server.
         /// </summary>
-        /// <param name="key">index of the file to download</param>
-        /// <returns>path to the downloaded file either in the cache or in the temp directory or null if error</returns>
-        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;
-        }
+        /// <param name="index">index to lookup on symbol server</param>
+        /// <param name="file">the full path name of the file</param>
+        public string DownloadFile(string index, string file) => DownloadFile(new SymbolStoreKey(index, file));
 
         /// <summary>
         /// Returns the metadata for the assembly
@@ -842,6 +807,48 @@ namespace Microsoft.Diagnostics.DebugServices.Implementation
             return null;
         }
 
+        /// <summary>
+        /// Download a file from the symbol stores/server.
+        /// </summary>
+        /// <param name="key">index of the file to download</param>
+        /// <returns>path to the downloaded file either in the cache or in the temp directory or null if error</returns>
+        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
index af5dc291c9a6dd8f02d04af0ae297491085703b9..13e66f4a632430c3dff7fc95eb9a10f6cd5bca53 100644 (file)
@@ -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
         /// <summary>
         /// Download a file from the symbol stores/server.
         /// </summary>
-        /// <param name="key">index of the file to download</param>
-        /// <returns>path to the downloaded file either in the cache or in the temp directory or null if error</returns>
-        string DownloadFile(SymbolStoreKey key);
+        /// <param name="index">index to lookup on symbol server</param>
+        /// <param name="file">the full path name of the file</param>
+        string DownloadFile(string index, string file);
 
         /// <summary>
         /// Returns the metadata for the assembly
index 33f0fe3e9028036dec7eb314407f7588d39b1b4d..e550154f292f110d761a7f7c1020b702fa1268a2 100644 (file)
@@ -13,8 +13,8 @@
     <IsShipping>true</IsShipping>
     <IsShippingPackage>false</IsShippingPackage>
   </PropertyGroup>
-  
+
   <ItemGroup>
-    <PackageReference Include="Microsoft.SymbolStore" Version="$(MicrosoftSymbolStoreVersion)" />
+    <PackageReference Include="System.Collections.Immutable" Version="$(SystemCollectionsImmutableVersion)" />
   </ItemGroup>
 </Project>
index a18bae92284f20278db409e53a9032eb372782e6..a7c8e842cc5a9378d91f25d3a9e311d46732e7fa 100644 (file)
@@ -1,4 +1,4 @@
-<!-- Copyright (c)  Microsoft.  All Rights Reserved.  Licensed under the Apache License, Version 2.0.  See License.txt in the project root for license information. -->
+<!-- Copyright (c)  Microsoft.  All Rights Reserved.  Licensed under the Apache License, Version 2.0.  See License.txt in the project root for license information. -->
 <Project Sdk="Microsoft.NET.Sdk">
   <PropertyGroup>
     <TargetFramework>netstandard2.0</TargetFramework>
@@ -16,6 +16,7 @@
 
   <ItemGroup>
     <PackageReference Include="Microsoft.Diagnostics.Runtime" Version="$(MicrosoftDiagnosticsRuntimeVersion)" />
+    <PackageReference Include="Microsoft.SymbolStore" Version="$(MicrosoftSymbolStoreVersion)" />
   </ItemGroup>
 
   <ItemGroup>
index 7fee627a7254d473716a2fde23f783271efaac0f..df9961fb69426c158e3b889141b1a86a2c989797 100644 (file)
@@ -11,6 +11,7 @@
   
   <ItemGroup>
     <PackageReference Include="Microsoft.Diagnostics.Runtime" Version="$(MicrosoftDiagnosticsRuntimeVersion)" />
+    <PackageReference Include="Microsoft.SymbolStore" Version="$(MicrosoftSymbolStoreVersion)" />
   </ItemGroup>
   
   <ItemGroup>
index aebf7bc0c2a2d19d96740da287ce7a2c62f37875..6fe61d348c6b3ff283d85b893bae83fea6e78eb3 100644 (file)
@@ -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
index e3c2b99cdfbf9ecc9d95f2fb78dbd9da3c7b12ed..a1c54f93d4e381c79e81b5427124b9880330c17e 100644 (file)
@@ -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;
         }