#!/usr/bin/env python """Script and library for symbolizing MongoDB stack traces. To use as a script, paste the JSON object on the line after ----- BEGIN BACKTRACE ----- into the standard input of this script. There are numerous caveats. In the default mode, you need to pass in the path to the executable being symbolized, and if you want shared library stack traces, you must be on the same system. There is largely untested support for extracting debug information from S3 buckets. This work is experimental. Sample usage: mongosymb.py --symbolizer-path=/path/to/llvm-symbolizer /path/to/executable 0: for sframe in symbinfo: outfile.write(" %(file)s:%(line)s %(fn)s\n" % sframe) else: outfile.write(" %(path)s!!!\n" % symbinfo) def main(argv): parser = optparse.OptionParser() parser.add_option("--dsym-hint", action="append", dest="dsym_hint") parser.add_option("--symbolizer-path", dest="symbolizer_path", default=None) parser.add_option("--debug-file-resolver", dest="debug_file_resolver", default="path") parser.add_option("--output-format", dest="output_format", default="classic") (options, args) = parser.parse_args(argv) resolver_constructor = dict(path=path_dbg_file_resolver, s3=s3_buildid_dbg_file_resolver).get( options.debug_file_resolver, None) if resolver_constructor is None: sys.stderr.write("Invalid debug-file-resolver argument: %s\n" % options.debug_file_resolver) sys.exit(1) output_fn = dict(json=json.dump, classic=classic_output).get(options.output_format, None) if output_fn is None: sys.stderr.write("Invalid output-format argument: %s\n" % options.output_format) sys.exit(1) resolver = resolver_constructor(*args[1:]) trace_doc = json.load(sys.stdin) frames = symbolize_frames(trace_doc, resolver, symbolizer_path=options.symbolizer_path, dsym_hint=options.dsym_hint) output_fn(frames, sys.stdout, indent=2) if __name__ == '__main__': main(sys.argv) sys.exit(0)