Bug 1619837 - Make `fix_stacks.py` more like `fix_linux_stacks.py`. r=erahm
authorNicholas Nethercote <nnethercote@mozilla.com>
Tue, 10 Mar 2020 06:19:21 +0000
changeset 517982 a6baed370a03bfd798a25e3601d01ba300f9823a
parent 517981 d80207f0940763b6fcce2ffea0ebd858d3313ffa
child 517983 c2f10d341da80e1bb1aef0aa77311e4569bec2ad
push id109724
push usernnethercote@mozilla.com
push dateTue, 10 Mar 2020 22:21:32 +0000
treeherderautoland@a6baed370a03 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1619837 - Make `fix_stacks.py` more like `fix_linux_stacks.py`. r=erahm Specifically: - handle input that doesn't end in a newline; - only pass lines that match the regexp to `fix-stacks`. These changes are needed for `utils.py` to use `fix_stacks.py` without problems. Differential Revision: https://phabricator.services.mozilla.com/D65944
--- a/tools/rb/fix_stacks.py
+++ b/tools/rb/fix_stacks.py
@@ -6,25 +6,33 @@
 # This script uses `fix-stacks` to post-process the entries produced by
 # MozFormatCodeAddress().
 from __future__ import absolute_import
 from subprocess import Popen, PIPE
 import os
 import platform
+import re
 import sys
+# Matches lines produced by MozFormatCodeAddress(), e.g.
+# `#01: ???[tests/example +0x43a0]`.
+line_re = re.compile("#\d+: .+\[.+ \+0x[0-9A-Fa-f]+\]")
 fix_stacks = None
 def fixSymbols(line, jsonMode=False):
     global fix_stacks
+    result = line_re.search(line)
+    if result is None:
+        return line
     if not fix_stacks:
         # Look in MOZ_FETCHES_DIR (for automation), then in MOZBUILD_STATE_PATH
         # (for a local build where the user has that set), then in ~/.mozbuild
         # (for a local build with default settings).
         base = os.environ.get(
@@ -39,16 +47,26 @@ def fixSymbols(line, jsonMode=False):
             raise Exception('cannot find `fix-stacks`; please run `./mach bootstrap`')
         args = [fix_stacks_exe]
         if jsonMode:
         fix_stacks = Popen(args, stdin=PIPE, stdout=PIPE, stderr=None)
+    # Sometimes `line` is lacking a trailing newline. If we pass such a `line`
+    # to `fix-stacks` it will wait until it receives a newline, causing this
+    # script to hang. So we add a newline if one is missing and then remove it
+    # from the output.
+    is_missing_newline = not line.endswith('\n')
+    if is_missing_newline:
+        line = line + "\n"
-    return fix_stacks.stdout.readline()
+    out = fix_stacks.stdout.readline()
+    if is_missing_newline:
+        out = out[:-1]
+    return out
 if __name__ == "__main__":
     for line in sys.stdin: