Bug 819833 (part 3) - Fix fix_macosx_stack.py. r=ted, a=jlebar
authorNicholas Nethercote <nnethercote@mozilla.com>
Mon, 10 Dec 2012 21:24:55 -0800
changeset 117740 08d0867c736c04b1fd5d339471c10c5cc8e6a956
parent 117739 1a054d2478f00187e53acc5d3649ef3c086ac0a1
child 117741 e23b3cb6771b9fc038505ee5469416d1c1dd2ea1
push id62
push userryanvm@gmail.com
push dateWed, 19 Dec 2012 22:28:04 +0000
reviewersted, jlebar
bugs819833
milestone18.0
Bug 819833 (part 3) - Fix fix_macosx_stack.py. r=ted, a=jlebar
tools/rb/fix_macosx_stack.py
--- a/tools/rb/fix_macosx_stack.py
+++ b/tools/rb/fix_macosx_stack.py
@@ -85,29 +85,28 @@ def addressToSymbol(file, address):
         atoses[file] = converter
     else:
         converter = atoses[file]
     return converter.convert("0x%X" % address)
 
 cxxfilt_proc = None
 def cxxfilt(sym):
     if cxxfilt_proc is None:
+        # --no-strip-underscores because atos already stripped the underscore
         globals()["cxxfilt_proc"] = subprocess.Popen(['c++filt',
                                                       '--no-strip-underscores',
                                                       '--format', 'gnu-v3'],
                                                      stdin=subprocess.PIPE,
                                                      stdout=subprocess.PIPE)
-    # strip underscores ourselves (works better than c++filt's
-    # --strip-underscores)
-    cxxfilt_proc.stdin.write(sym[1:] + "\n")
+    cxxfilt_proc.stdin.write(sym + "\n")
     return cxxfilt_proc.stdout.readline().rstrip("\n")
 
 line_re = re.compile("^(.*) ?\[([^ ]*) \+(0x[0-9A-F]{1,8})\](.*)$")
 balance_tree_re = re.compile("^([ \|0-9-]*)")
-atos_sym_re = re.compile("^(\S+) \(in ([^)]+)\) \((.+)\)$")
+atos_name_re = re.compile("^(.+) \(in ([^)]+)\) \((.+)\)$")
 
 def fixSymbols(line):
     result = line_re.match(line)
     if result is not None:
         # before allows preservation of balance trees
         # after allows preservation of counts
         (before, file, address, after) = result.groups()
         address = int(address, 16)
@@ -115,24 +114,27 @@ def fixSymbols(line):
         if os.path.exists(file) and os.path.isfile(file):
             address += address_adjustment(file)
             info = addressToSymbol(file, address)
 
             # atos output seems to have three forms:
             #   address
             #   address (in foo.dylib)
             #   symbol (in foo.dylib) (file:line)
-            symresult = atos_sym_re.match(info)
-            if symresult is not None:
+            name_result = atos_name_re.match(info)
+            if name_result is not None:
                 # Print the first two forms as-is, and transform the third
-                (symbol, library, fileline) = symresult.groups()
-                symbol = cxxfilt(symbol)
-                info = "%s (%s, in %s)" % (symbol, fileline, library)
+                (name, library, fileline) = name_result.groups()
+                # atos demangles, but occasionally it fails.  cxxfilt can mop
+                # up the remaining cases(!), which will begin with '_Z'.
+                if (name.startswith("_Z")):
+                    name = cxxfilt(name)
+                info = "%s (%s, in %s)" % (name, fileline, library)
 
-             # throw away the bad symbol, but keep balance tree structure
+            # throw away the bad symbol, but keep balance tree structure
             before = balance_tree_re.match(before).groups()[0]
 
             return before + info + after + "\n"
         else:
             sys.stderr.write("Warning: File \"" + file + "\" does not exist.\n")
             return line
     else:
         return line