Use symbolGenerator to raise diagnostic identity key level (#4924)
authorJuan Hoyos <19413848+hoyosjs@users.noreply.github.com>
Thu, 12 Sep 2024 05:23:36 +0000 (22:23 -0700)
committerGitHub <noreply@github.com>
Thu, 12 Sep 2024 05:23:36 +0000 (22:23 -0700)
src/Microsoft.SymbolManifestGenerator/SymbolManifestGenerator.cs

index d83aa621d0e280fbc0425fee0f99686d550da980..e70b927d39976abfe81b696076f4f3b4a338e8ad 100644 (file)
@@ -16,6 +16,12 @@ public static class SymbolManifestGenerator
 {
     private const int TargetDebugLevel = 0x154 | 0x1 | 0x500; // Private | Binary | SourceIndexed
 
+    private static readonly JsonSerializerOptions s_serializeOptions = new()
+    {
+        PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
+        WriteIndented = true
+    };
+
     public static bool GenerateManifest(ITracer tracer, DirectoryInfo dir, string manifestFileName, bool specialFilesRequireAdjacentRuntime = true)
     {
         ManifestDataV1 manifestData = new();
@@ -58,25 +64,39 @@ public static class SymbolManifestGenerator
                     return false;
                 }
 
-                ManifestDataEntry manifestDataEntry = new()
+                // This is the special module for the runtime in runtimeCorrelatedKey that's under the special index.
+                manifestData.Entries.Add(new()
                 {
                     BasedirRelativePath = basedirRelativePath,
                     SymbolKey = runtimeCorrelatedKey.Index,
                     Sha512 = fileHash,
                     DebugInformationLevel = TargetDebugLevel
-                };
+                });
+
+                using FileStream fs = correlatedFile.OpenRead();
+                SymbolStoreFile specialDiagnosticFile = new(fs, correlatedFile.FullName);
+                FileKeyGenerator correlatedGenerator = new(tracer, specialDiagnosticFile);
+
+                if (!correlatedGenerator.IsValid())
+                {
+                    tracer.Error("Unable to get a key generator for special diagnostic file '{0}' of runtime '{1}'", file.FullName, correlatedFile.FullName);
+                    return false;
+                }
 
-                manifestData.Entries.Add(manifestDataEntry);
+                SymbolStoreKey diagnosticFileIdentityKey = correlatedGenerator.GetKeys(KeyTypeFlags.IdentityKey).Single();
+                // This is the special module for the runtime in runtimeCorrelatedKey that's under its own identity key
+                // with the upgraded debug information level.
+                manifestData.Entries.Add(new()
+                {
+                    BasedirRelativePath = basedirRelativePath,
+                    SymbolKey = diagnosticFileIdentityKey.Index,
+                    Sha512 = fileHash,
+                    DebugInformationLevel = TargetDebugLevel
+                });
             }
         }
 
-        JsonSerializerOptions serializeOptions = new()
-        {
-            PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
-            WriteIndented = true
-        };
-
-        string manifestDataContent = JsonSerializer.Serialize(manifestData, serializeOptions);
+        string manifestDataContent = JsonSerializer.Serialize(manifestData, s_serializeOptions);
         File.WriteAllText(manifestFileName, manifestDataContent);
 
         return true;
@@ -120,20 +140,17 @@ public static class SymbolManifestGenerator
         return BitConverter.ToString(hashValueBytes).Replace("-", "");
     }
 
-    private class ManifestFileVersion
+    private interface IManifestFile
     {
-        public string Version { get; set; }
+        string Version { get; }
     }
 
-    private class ManifestDataV1 : ManifestFileVersion
+    private sealed class ManifestDataV1 : IManifestFile
     {
-        public List<ManifestDataEntry> Entries { get; set; }
+        public List<ManifestDataEntry> Entries { get; } = [];
 
-        public ManifestDataV1()
-        {
-            Version = "1";
-            Entries = new List<ManifestDataEntry>();
-        }
+        [JsonInclude]
+        public string Version => "1";
     }
 
     private class ManifestDataEntry