diff --git a/buildscripts/mongosymb.py b/buildscripts/mongosymb.py index a8544cdf92..7ad3eef782 100755 --- a/buildscripts/mongosymb.py +++ b/buildscripts/mongosymb.py @@ -20,6 +20,7 @@ but emits json instead of plain text. import json import argparse import os +import signal import subprocess import sys @@ -210,6 +211,7 @@ def make_argument_parser(parser=None, **kwargs): parser.add_argument('--src-dir-to-move', action="store", type=str, default=None, help="Specify a src dir to move to /data/mci/{original_buildid}/src") + parser.add_argument('--live', action='store_true') s3_group = parser.add_argument_group( "s3 options", description='Options used with \'--debug-file-resolver s3\'') s3_group.add_argument('--s3-cache-dir') @@ -219,10 +221,38 @@ def make_argument_parser(parser=None, **kwargs): parser.add_argument('path_to_executable', nargs="?") return parser +def substitute_stdin(options): + # Ignore Ctrl-C. When the process feeding the pipe exits, `stdin` will be closed. + signal.signal(signal.SIGINT, signal.SIG_IGN) + + while True: + line = os.sys.stdin.readline() + if not line: + return + + line = line.rstrip() + + if 'Frame: 0x' in line: + continue + + if '{"backtrace":' in line: + prefix = line[:line.index('{"backtrace":')] + backtrace = line[line.index('{"backtrace":'):] + traceDoc = json.JSONDecoder().raw_decode(backtrace)[0] + frames = symbolize_frames(traceDoc, PathDbgFileResolver(options.path_to_executable), options.symbolizer_path, [], 'classic') + print(prefix) + classic_output(frames, os.sys.stdout, indent=2) + else: + print(line) def main(options): """Execute Main program.""" + if options.live: + print(options) + substitute_stdin(options) + sys.exit(0) + # Skip over everything before the first '{' since it is likely to be log line prefixes. # Additionally, using raw_decode() to ignore extra data after the closing '}' to allow maximal # sloppiness in copy-pasting input.