Bug 1337986 - Modify symbolstore.py to operate on dll/exe files. draft
authorChris Manchester <cmanchester@mozilla.com>
Mon, 10 Apr 2017 10:27:49 -0700
changeset 559819 396a5167bd4bfbf595d6ca6427a64fe94cfe6ad9
parent 559818 21967057ce6bb3f3489f6ab16a8e0978cb55ae03
child 559820 bfe2016c28070c09a0bf8390eb0d2812f04e1cb2
push id53227
push userbmo:cmanchester@mozilla.com
push dateMon, 10 Apr 2017 17:27:51 +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
@@ -700,17 +700,17 @@ class Dumper:
                             result['status'] = True
                     f.close()
                     proc.wait()
                     # we output relative paths so callers can get a list of what
                     # was generated
                     self.output(sys.stdout, rel_path)
                     if self.srcsrv and vcs_root:
                         # add source server indexing to the pdb file
-                        self.SourceServerIndexing(file, guid, sourceFileStream, vcs_root)
+                        self.SourceServerIndexing(debug_file, guid, sourceFileStream, vcs_root)
                     # only copy debug the first time if we have multiple architectures
                     if self.copy_debug and arch_num == 0:
                         self.CopyDebug(file, debug_file, guid,
                                        code_file, code_id)
             except StopIteration:
                 pass
             except Exception as e:
                 self.output(sys.stderr, "Unexpected error: %s" % (str(e),))
@@ -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,16 @@ 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)
         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')