Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(304)

Unified Diff: tests/untrusted_crash_dump/decode_dump.py

Issue 9316125: Adding untrusted crash dump / stack trace tests. (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client
Patch Set: fixing 64-bit build issue Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tests/untrusted_crash_dump/decode_dump.py
diff --git a/tests/untrusted_crash_dump/decode_dump.py b/tests/untrusted_crash_dump/decode_dump.py
new file mode 100755
index 0000000000000000000000000000000000000000..4c1b32e85e101f4b52b04dc3dbb81194bfec1320
--- /dev/null
+++ b/tests/untrusted_crash_dump/decode_dump.py
@@ -0,0 +1,108 @@
+#!/usr/bin/python
+# Copyright (c) 2012 The Native Client Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""Utility to decode a crash dump generated by untrusted_crash_dump.[ch]
+
+Current this produces a simple stack trace.
Mark Seaborn 2012/02/06 19:44:06 'Currently'
bradn 2012/02/06 22:27:48 Done.
+"""
+
+import json
+import optparse
+import os
+import posixpath
+import subprocess
+import sys
+
+
+def Addr2Line(options, filename, addr):
+ """Use addr2line to decode a code address.
+
+ Args:
+ options: option object.
+ filename: filename of module that the address is relative to.
+ addr: address.
+ Returns:
+ Dict containing: function, filename, lineno.
+ """
+ filepart = posixpath.split(filename)[1]
Mark Seaborn 2012/02/06 19:44:06 Use posixpath.dirname()?
bradn 2012/02/06 22:27:48 I assume you mean basename. Done.
+ nmf_entry = options.nmf_data.get('files', {}).get(filepart, {})
+ nmf_url = nmf_entry.get('x86-32', {}).get('url')
Mark Seaborn 2012/02/06 19:44:06 Add a TODO for the 'x86-32' part.
bradn 2012/02/06 22:27:48 Done.
+ if nmf_url:
+ for p in [os.path.os.path.dirname(options.nmf), options.toolchain_libs]:
+ if not p: continue
Mark Seaborn 2012/02/06 19:44:06 Split into two lines.
bradn 2012/02/06 22:27:48 Done.
+ pfilename = os.path.join(p, nmf_url)
+ if os.path.exists(pfilename):
+ filename = pfilename
+ break
Mark Seaborn 2012/02/06 19:44:06 Split this loop into a separate lookup function, a
bradn 2012/02/06 22:27:48 Done.
+
+ if filename in ['NaClMain', '(null)']:
+ if options.main_nexe:
+ filename = options.main_nexe
+ else:
+ return {
+ 'function': 'Unknown_function',
+ 'filename': 'unknown_file',
+ 'lineno': '-1',
+ }
+ cmd = [
+ options.addr2line, '-f', '-e', filename, ('0x%08x' % addr),
Mark Seaborn 2012/02/06 19:44:06 Ideally you should also use '--inlines', and check
bradn 2012/02/06 22:27:48 Done.
+ ]
+ p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
+ (p_stdout, p_stderr) = p.communicate()
Mark Seaborn 2012/02/06 19:44:06 BTW, you can use var1, var2 = foo() without the br
bradn 2012/02/06 22:27:48 Done.
+ assert p.returncode == 0
+ (func, fline) = p_stdout.rstrip().split('\n')
+ (afilename, lineno) = fline.split(':')
+ return {
+ 'function': func,
+ 'filename': afilename,
+ 'lineno': lineno,
+ }
+
+
+def Decode(options, core_path, dst_trace):
Mark Seaborn 2012/02/06 19:44:06 'dst' -> 'dest'
bradn 2012/02/06 22:27:48 Done.
+ """Given a core.json file, decode and emit a stack trace.
+
+ Args:
+ options: options object.
+ core_path: source file containing a dump.
+ dst_trace: output file to write the trace to.
+ """
+ core_text = open(core_path, 'r').read()
+ core = json.loads(core_text)
+ out = open(dst_trace, 'w')
+ for f in core['frames']:
Mark Seaborn 2012/02/06 19:44:06 'f' -> 'frame'
bradn 2012/02/06 22:27:48 Done.
+ ip_mapped = f['ip_mapped']
+ info = Addr2Line(options, ip_mapped['file'], ip_mapped['addr'])
+ out.write('%s at %s:%s\n' % (
+ info['function'],
+ posixpath.split(info['filename'])[1],
Mark Seaborn 2012/02/06 19:44:06 posixpath.basename()? But why do you want to drop
bradn 2012/02/06 22:27:48 To allow golden stace traces. I've added a verbose
+ info['lineno']))
+ out.close()
+
+
+def Main(args):
+ parser = optparse.OptionParser(
+ usage='USAGE: %prog [options] <core.json> <trace>')
+ parser.add_option('-m', '--main-nexe', dest='main_nexe',
+ help='nexe to resolve NaClMain references from')
+ parser.add_option('-n', '--nmf', dest='nmf',
+ help='nmf to resolve references from')
+ parser.add_option('-a', '--addr2line', dest='addr2line',
+ help='path to appropriate addr2line')
+ parser.add_option('-l', '--toolchain-libs', dest='toolchain_libs',
+ help='path to the toolchain libraries')
+ options, args = parser.parse_args(args)
+ if len(args) != 2:
+ parser.print_help()
+ sys.exit(1)
+ if options.nmf:
+ options.nmf_data = json.loads(open(options.nmf, 'r').read())
+ else:
+ options.nmf_data = {}
+ Decode(options, args[0], args[1])
+
+
+if __name__ == '__main__':
+ Main(sys.argv[1:])

Powered by Google App Engine
This is Rietveld 408576698