Bug 1074008 - Add a --fix-stacks option to dmd.py. r=glandium.

--HG--
extra : rebase_source : 6ecfdf21ed09671bf9e1e65072dafc1402052a65
This commit is contained in:
Nicholas Nethercote 2014-09-28 18:36:49 -07:00
parent 24912152f6
commit cce4aa7ac7
3 changed files with 54 additions and 3 deletions

View File

@ -98,7 +98,7 @@ libs:: $(_VALGRIND_FILES)
$(INSTALL) $^ $(_VALGRIND_DIR)
endif
ifdef ENABLE_TESTS
ifneq (,$(ENABLE_TESTS)$(MOZ_DMD))
libs:: $(topsrcdir)/tools/rb/fix_stack_using_bpsyms.py
$(INSTALL) $< $(DIST)/bin
@ -111,7 +111,14 @@ ifeq ($(OS_ARCH),Linux)
libs:: $(topsrcdir)/tools/rb/fix_linux_stack.py
$(INSTALL) $< $(DIST)/bin
endif
endif # ENABLE_TESTS or MOZ_DMD
ifdef ENABLE_TESTS
GARBAGE += $(srcdir)/automationutils.pyc
endif # ENABLE_TESTS
ifdef MOZ_DMD
libs:: $(topsrcdir)/memory/replace/dmd/dmd.py
$(INSTALL) $< $(DIST)/bin
endif

View File

@ -55,7 +55,7 @@ def test(src_dir, kind, options, i):
# Convert from JSON
convert = [os.path.join(src_dir, "memory", "replace", "dmd", "dmd.py")] + \
options + [fixed_name]
options + ['--no-fix-stacks', fixed_name]
subprocess.call(convert, stdout=open(converted_name, "w"))
# Filter output

View File

@ -11,8 +11,12 @@ from __future__ import print_function, division
import argparse
import collections
import json
import os
import platform
import re
import shutil
import sys
import tempfile
# The DMD output version this script handles.
outputVersion = 1
@ -96,6 +100,9 @@ def parseCommandLine():
Analyze heap data produced by DMD.
If no files are specified, read from stdin.
Write to stdout unless -o/--output is specified.
Stack traces are fixed to show function names, filenames and line numbers
unless --no-fix-stacks is specified; stack fixing modifies the original file
and may take some time.
'''
p = argparse.ArgumentParser(description=description)
@ -119,14 +126,51 @@ Write to stdout unless -o/--output is specified.
p.add_argument('-b', '--show-all-block-sizes', action='store_true',
help='show individual block sizes for each record')
p.add_argument('--no-fix-stacks', action='store_true',
help='do not fix stacks')
p.add_argument('input_file', type=argparse.FileType('r'))
return p.parse_args(sys.argv[1:])
# Fix stacks if necessary: first write the output to a tempfile, then replace
# the original file with it.
def fixStackTraces(args):
# This append() call is needed to make the import statements work when this
# script is installed as a symlink.
sys.path.append(os.path.dirname(__file__))
# XXX: should incorporate fix_stack_using_bpsyms.py here as well, like in
# testing/mochitests/runtests.py
sysname = platform.system()
if sysname == 'Linux':
import fix_linux_stack as fixModule
fix = lambda line: fixModule.fixSymbols(line)
elif sysname == 'Darwin':
import fix_macosx_stack as fixModule
fix = lambda line: fixModule.fixSymbols(line)
else:
fix = None # there is no fix script for Windows
if fix:
# Fix stacks, writing output to a temporary file, and then
# overwrite the original file.
with tempfile.NamedTemporaryFile(delete=False) as tmp:
for line in args.input_file:
tmp.write(fix(line))
shutil.move(tmp.name, args.input_file.name)
args.input_file = open(args.input_file.name)
def main():
args = parseCommandLine()
# Fix stack traces unless otherwise instructed.
if not args.no_fix_stacks:
fixStackTraces(args)
j = json.load(args.input_file)
if j['version'] != outputVersion: