Bug 1337986 - Modify symbolstore.py to operate on dll/exe files. draft
authorChris Manchester <cmanchester@mozilla.com>
Mon, 03 Apr 2017 10:35:08 -0700
changeset 555117 92717b884006933cdf79446e7b06381d70439a64
parent 555116 244bf79cf4923c64184793334379e9487c5ef7d1
child 555118 227b5af9179ff3849c951c1a624ede13e9e7b3ce
push id52161
push userbmo:cmanchester@mozilla.com
push dateMon, 03 Apr 2017 17:35:35 +0000
bugs1337986
milestone55.0a1
Bug 1337986 - Modify symbolstore.py to operate on dll/exe files. This will be more convenient when we dump symbols from the compile tier. MozReview-Commit-ID: Ltjq8ai5j0m
toolkit/crashreporter/tools/symbolstore.py
toolkit/crashreporter/tools/unit-symbolstore.py
--- a/toolkit/crashreporter/tools/symbolstore.py
+++ b/toolkit/crashreporter/tools/symbolstore.py
@@ -726,23 +726,23 @@ class Dumper:
 
 # Platform-specific subclasses.  For the most part, these just have
 # logic to determine what files to extract symbols from.
 
 class Dumper_Win32(Dumper):
     fixedFilenameCaseCache = {}
 
     def ShouldProcess(self, file):
-        """This function will allow processing of pdb files that have dll
-        or exe files with the same base name next to them."""
+        """This function will allow processing of exe or dll files that have pdb
+        files with the same base name next to them."""
         if not Dumper.ShouldProcess(self, file):
             return False
-        if file.endswith(".pdb"):
-            (path,ext) = os.path.splitext(file)
-            if os.path.isfile(path + ".exe") or os.path.isfile(path + ".dll"):
+        if file.endswith(".exe") or file.endswith(".dll"):
+            path, ext = os.path.splitext(file)
+            if os.path.isfile(path + ".pdb"):
                 return True
         return False
 
     def FixFilenameCase(self, file):
         """Recent versions of Visual C++ put filenames into
         PDB files as all lowercase.  If the file exists
         on the local filesystem, fix it."""
 
@@ -783,16 +783,17 @@ class Dumper_Win32(Dumper):
                 result = buf.value.encode(sys.getfilesystemencoding())[4:]
             ctypes.windll.kernel32.CloseHandle(handle)
 
         # Cache the corrected version to avoid future filesystem hits.
         self.fixedFilenameCaseCache[file] = result
         return result
 
     def CopyDebug(self, file, debug_file, guid, code_file, code_id):
+        file = "%s.pdb" % os.path.splitext(file)[0]
         def compress(path):
             compressed_file = path[:-1] + '_'
             # ignore makecab's output
             makecab = buildconfig.substs['MAKECAB']
             success = subprocess.call([makecab, "-D",
                                        "CompressionType=MSZIP",
                                        path, compressed_file],
                                       stdout=open(os.devnull, 'w'),
@@ -831,17 +832,17 @@ class Dumper_Win32(Dumper):
                 shutil.copyfile(full_code_path, full_path)
                 if compress(full_path):
                     self.output(sys.stdout, rel_path[:-1] + '_')
                 else:
                     self.output(sys.stdout, rel_path)
 
     def SourceServerIndexing(self, debug_file, guid, sourceFileStream, vcs_root):
         # Creates a .pdb.stream file in the mozilla\objdir to be used for source indexing
-        debug_file = os.path.abspath(debug_file)
+        debug_file = os.path.abspath("%s.pdb" % os.path.splitext(debug_file)[0])
         streamFilename = debug_file + ".stream"
         stream_output_path = os.path.abspath(streamFilename)
         # Call SourceIndex to create the .stream file
         result = SourceIndex(sourceFileStream, stream_output_path, vcs_root)
         if self.copy_debug:
             pdbstr_path = os.environ.get("PDBSTR_PATH")
             pdbstr = os.path.normpath(pdbstr_path)
             subprocess.call([pdbstr, "-w", "-p:" + os.path.basename(debug_file),
--- a/toolkit/crashreporter/tools/unit-symbolstore.py
+++ b/toolkit/crashreporter/tools/unit-symbolstore.py
@@ -26,29 +26,29 @@ import symbolstore
 # dump_syms itself will not be run (we mock that call out), but we can't override
 # the ShouldProcessFile method since we actually want to test that.
 def write_elf(filename):
     open(filename, "wb").write(struct.pack("<7B45x", 0x7f, ord("E"), ord("L"), ord("F"), 1, 1, 1))
 
 def write_macho(filename):
     open(filename, "wb").write(struct.pack("<I28x", 0xfeedface))
 
-def write_pdb(filename):
+def write_dll(filename):
     open(filename, "w").write("aaa")
-    # write out a fake DLL too
-    open(os.path.splitext(filename)[0] + ".dll", "w").write("aaa")
+    # write out a fake PDB too
+    open(os.path.splitext(filename)[0] + ".pdb", "w").write("aaa")
 
 def target_platform():
     return buildconfig.substs['OS_TARGET']
 
-writer = {'WINNT': write_pdb,
+writer = {'WINNT': write_dll,
           'Linux': write_elf,
           'Sunos5': write_elf,
           'Darwin': write_macho}[target_platform()]
-extension = {'WINNT': ".pdb",
+extension = {'WINNT': ".dll",
              'Linux': ".so",
              'Sunos5': ".so",
              'Darwin': ".dylib"}[target_platform()]
 
 def add_extension(files):
     return [f + extension for f in files]
 
 class HelperMixin(object):
@@ -214,18 +214,18 @@ class TestCopyDebug(HelperMixin, unittes
         d.Finish(stop_pool=False)
         self.assertEqual(1, len(copied))
 
     @patch.dict('buildconfig.substs', {'MAKECAB': 'makecab'})
     def test_copy_debug_copies_binaries(self):
         """
         Test that CopyDebug copies binaries as well on Windows.
         """
-        test_file = os.path.join(self.test_dir, 'foo.pdb')
-        write_pdb(test_file)
+        test_file = os.path.join(self.test_dir, 'foo.dll')
+        write_dll(test_file)
         code_file = 'foo.dll'
         code_id = 'abc123'
         self.stdouts.append(mock_dump_syms('X' * 33, 'foo.pdb',
                                            ['INFO CODE_ID %s %s' % (code_id, code_file)]))
         def mock_compress(args, **kwargs):
             filename = args[-1]
             open(filename, 'w').write('stuff')
             return 0
@@ -536,17 +536,17 @@ class TestFunctional(HelperMixin, unitte
                                               'toolkit',
                                               'crashreporter',
                                               'tools',
                                               'win32',
                                               'dump_syms_vc{_MSC_VER}.exe'.format(**buildconfig.substs))
             self.target_bin = os.path.join(buildconfig.topobjdir,
                                            'browser',
                                            'app',
-                                           'firefox.pdb')
+                                           'firefox.exe')
         else:
             self.dump_syms = os.path.join(buildconfig.topobjdir,
                                           'dist', 'host', 'bin',
                                           'dump_syms')
             self.target_bin = os.path.join(buildconfig.topobjdir,
                                            'dist', 'bin', 'firefox')