Update DacCompareNativeTypes (#1335)
authorSteve MacLean <Steve.MacLean@microsoft.com>
Fri, 10 Jul 2020 01:13:43 +0000 (21:13 -0400)
committerGitHub <noreply@github.com>
Fri, 10 Jul 2020 01:13:43 +0000 (21:13 -0400)
Adjust Regex expressions to match dwarfdump in Ubuntu 20.04.
Latest version of dwarfdump dropped quotation marks off type names.
Remove unicode quotes from expression. Use closing group syntax to
match opening '<' to closing '>'.

Extend ignore list for libunwind types. CrossOS DAC is using a different version
of libunwind (1.5+) than the Linux DAC (1.3).  Also add dbi's Target_CLiteWeightStgdbRW

Add stats output to Main()

Add return exit code to Main()

src/tests/DacCompareNativeTypes/DwarfParse.cs
src/tests/DacCompareNativeTypes/Program.cs

index 55a31f4964a3dedd53b2c4eac4237b14ee345eb3..f5ce600d6e160b0d950deadb66eb52ac2cd7e55e 100644 (file)
@@ -16,15 +16,15 @@ using static ParserExtensions;
 #nullable enable
 class DwarfParser
 {
-    static Regex typeNameRegEx = new Regex(@"^<(?<nesting>\d+)><.*GOFF=0x(?<goff>[0-9a-fA-F]+)><DW_TAG_((class_type)|(structure_type)|(union_type)|(typedef))>(.*DW_AT_name<\u0022(?<name>.+?)\u0022>)?");
-    // <1><0x9ad2 GOFF=0x1e17b22><DW_TAG_structure_type> DW_AT_name<"STORAGESIGNATURE"> DW_AT_byte_size<0x00000010> DW_AT_decl_file<0x00000014 /home/stmaclea/git/runtime/src/coreclr/src/md/inc/mdfileformat.h> DW_AT_decl_line<0x0000003f>
-    static Regex typeRegEx = new Regex(@"^<(?<nesting>\d+)><.*GOFF=0x(?<goff>[0-9a-fA-F]+)><DW_TAG_((class)|(structure)|(union))_type>(.*DW_AT_name<\u0022(?<name>.+?)\u0022>)?.*?DW_AT_decl_file");
+    static Regex typeNameRegEx = new Regex(@"^<(?<nesting>\d+)><.*GOFF=0x(?<goff>[0-9a-fA-F]+)><DW_TAG_((class_type)|(structure_type)|(union_type)|(typedef))>(.*DW_AT_name<(?<name>[^<>]*(((?'Open'<)[^<>]*)+((?'Close-Open'>)[^<>]*)+)*(?(Open)(?!)))>)?");
+    // <1><0x9ad2 GOFF=0x1e17b22><DW_TAG_structure_type> DW_AT_name<STORAGESIGNATURE> DW_AT_byte_size<0x00000010> DW_AT_decl_file<0x00000014 /home/stmaclea/git/runtime/src/coreclr/src/md/inc/mdfileformat.h> DW_AT_decl_line<0x0000003f>
+    static Regex typeRegEx = new Regex(@"^<(?<nesting>\d+)><.*GOFF=0x(?<goff>[0-9a-fA-F]+)><DW_TAG_((class)|(structure)|(union))_type>(.*DW_AT_name<(?<name>[^<>]*(((?'Open'<)[^<>]*)+((?'Close-Open'>)[^<>]*)+)*(?(Open)(?!)))>)?.*?DW_AT_decl_file");
 
-    // <2><0x4d GOFF=0x1b5a><DW_TAG_member> DW_AT_name<"Data1"> DW_AT_type<<0x00000082 GOFF=0x00001b8f>> DW_AT_decl_file<0x00000001 /home/stmaclea/git/runtime/src/coreclr/src/pal/inc/pal_mstypes.h> DW_AT_decl_line<0x000002ac> DW_AT_data_member_location<0>
-    static Regex memberRegEx = new Regex(@"^<(?<nesting>\d+)><.*GOFF=0x(?<goff>[0-9a-fA-F]+)><DW_TAG_member>.*.*?DW_AT_data_member_location<(?<offset>\d+)([(][^)]*[)])?>");
+    // <2><0x4d GOFF=0x1b5a><DW_TAG_member> DW_AT_name<Data1> DW_AT_type<<0x00000082 GOFF=0x00001b8f>> DW_AT_decl_file<0x00000001 /home/stmaclea/git/runtime/src/coreclr/src/pal/inc/pal_mstypes.h> DW_AT_decl_line<0x000002ac> DW_AT_data_member_location<0>
+    static Regex memberRegEx = new Regex(@"^<(?<nesting>\d+)><.*GOFF=0x(?<goff>[0-9a-fA-F]+)><DW_TAG_member>.*.*?DW_AT_data_member_location<(?<offset>\d+) *([(][^)]*[)])?>");
 
-    // DW_AT_name<"Data1">
-    static Regex nameRegEx = new Regex(@"DW_AT_name<\u0022(?<name>.+?)\u0022>");
+    // DW_AT_name<Data1>
+    static Regex nameRegEx = new Regex(@"DW_AT_name<(?<name>[^<>]*(((?'Open'<)[^<>]*)+((?'Close-Open'>)[^<>]*)+)*(?(Open)(?!)))>");
 
     // DW_AT_type<<0x00000082 GOFF=0x00001b8f>>
     static Regex typeRefRegEx = new Regex(@"DW_AT_type<<[^>]*GOFF=0x(?<goff>[0-9a-fA-F]+)>>");
index 96253e81ec2951f8755010f337cfdebd0a1f8759..b19727e772d516a2eac49fe0c97f34d5a50e0c5b 100644 (file)
@@ -106,6 +106,7 @@ namespace DacCompareNativeTypes
                 "RSPtrArray<CordbAppDomain,RSSmartPtr<CordbAppDomain>>",
                 "RSPtrArray<CordbInternalFrame,RSSmartPtr<CordbInternalFrame>>",
                 "RSPtrArray<CordbProcess,RSSmartPtr<CordbProcess>>",
+                "Target_CLiteWeightStgdbRW",
 
                 // DBI not used in cross OS
                 "TwoWayPipe",
@@ -113,7 +114,18 @@ namespace DacCompareNativeTypes
                 // Shims
                 // Not expected to matter
                 "ShimProcess",
-                "ShimRemoteDataTarget"
+                "ShimRemoteDataTarget",
+
+                // Libunwind types 3.1 crossdac uses a different libunwind version
+                "cursor",
+                "dwarf_cie_info",
+                "dwarf_cursor",
+                "dwarf_rs_cache",
+                "map_iterator",
+                "mempool",
+                "ucontext",
+                "unw_addr_space",
+                "unw_tdep_save_loc"
             };
 
             return ignoreTypes.Exists(x => String.CompareOrdinal(x, fullName) == 0);
@@ -200,10 +212,29 @@ namespace DacCompareNativeTypes
             return true;
         }
 
-        static void CompareTypes(Type dwarfType, Type pdbType)
+        int ignored;
+        int matched;
+        int mismatched;
+        int dwarfUnique;
+        int pdbUnique;
+
+        Program() {}
+
+        void CompareTypes(Type dwarfType, Type pdbType)
         {
-            if (IsIgnoreType(pdbType) || AllPbdAlternatesMatch(dwarfType, pdbType))
+            if (IsIgnoreType(pdbType))
+            {
+                ignored++;
+                return;
+            }
+
+            if (AllPbdAlternatesMatch(dwarfType, pdbType))
+            {
+                matched++;
                 return;
+            }
+
+            mismatched++;
 
             foreach(var p in pdbType.Alternates.Values)
             {
@@ -214,11 +245,8 @@ namespace DacCompareNativeTypes
             }
         }
 
-        static void Main(string[] args)
+        int Main(string pdbPath, string dwarfPath)
         {
-            string pdbPath = @"pdb";
-            string dwarfPath = @"dwarf";
-
             Dictionary<string, Type> pdbTypes = new Dictionary<string, Type>();
             Dictionary<string, Type> dwarfTypes = new Dictionary<string, Type>();
 
@@ -238,6 +266,8 @@ namespace DacCompareNativeTypes
                 }
             }
 
+            Console.WriteLine($"PDB unique types : {pdbTypes.Keys.Count}");
+
             foreach (Type type in DwarfParser.Parse(File.ReadLines(dwarfPath)))
             {
                 if (dwarfTypes.ContainsKey(type.FullName))
@@ -254,13 +284,47 @@ namespace DacCompareNativeTypes
                 }
             }
 
+            Console.WriteLine($"Dwarf unique types : {dwarfTypes.Keys.Count}");
+
             foreach (Type type in dwarfTypes.Values.OrderBy(x => x.FullName))
             {
                 if (pdbTypes.ContainsKey(type.FullName))
                 {
                     CompareTypes(type, pdbTypes[type.FullName]);
                 }
+                else
+                {
+                    // Console.WriteLine($"dwarf unique type : {type.FullName}");
+                    dwarfUnique++;
+                }
+            }
+
+            foreach (Type type in pdbTypes.Values.OrderBy(x => x.FullName))
+            {
+                if (!dwarfTypes.ContainsKey(type.FullName))
+                {
+                    // Console.WriteLine($"PDB unique type : {type.FullName}");
+                    pdbUnique++;
+                }
             }
+
+            Console.WriteLine($"Matches: {matched}");
+            Console.WriteLine($"Ignored: {ignored}");
+            Console.WriteLine($"Mismatched: {mismatched}");
+            Console.WriteLine($"DwarfUnique: {dwarfUnique}");
+            Console.WriteLine($"PdbUnique: {pdbUnique}");
+
+            return mismatched + (matched == 0 ? 1 : 0);
+        }
+
+        static int Main(string[] args)
+        {
+            string pdbPath = @"pdb";
+            string dwarfPath = @"dwarf";
+
+            Program program = new Program();
+
+            return program.Main(pdbPath, dwarfPath);
         }
     }
 }