| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2012 The Native Client Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """Utility to decode a crash dump generated by untrusted_crash_dump.[ch] | 6 """Utility to decode a crash dump generated by untrusted_crash_dump.[ch] |
| 7 | 7 |
| 8 Currently this produces a simple stack trace. | 8 Currently this produces a simple stack trace. |
| 9 """ | 9 """ |
| 10 | 10 |
| 11 import json | 11 import json |
| 12 import optparse | 12 import optparse |
| 13 import os | 13 import os |
| 14 import posixpath | 14 import posixpath |
| 15 import subprocess | 15 import subprocess |
| 16 import sys | 16 import sys |
| 17 | 17 |
| 18 | 18 |
| 19 class CoreDecoder(object): | 19 class CoreDecoder(object): |
| 20 """Class to process core dumps.""" | 20 """Class to process core dumps.""" |
| 21 | 21 |
| 22 def __init__(self, main_nexe, nmf_filename, | 22 def __init__(self, main_nexe, nmf_filename, |
| 23 addr2line, library_paths, platform): | 23 addr2line, library_paths, platform): |
| 24 """Construct and object to process core dumps. | 24 """Construct and object to process core dumps. |
| 25 | 25 |
| 26 Args: | 26 Args: |
| 27 main_nexe: nexe to resolve NaClMain references from. | 27 main_nexe: nexe to resolve NaClMain references from. |
| 28 nmf_filename: nmf to resovle references from. | 28 nmf_filename: nmf to resolve references from. |
| 29 addr2line: path to appropriate addr2line. | 29 addr2line: path to appropriate addr2line. |
| 30 library_paths: list of paths to search for libraries. | 30 library_paths: list of paths to search for libraries. |
| 31 platform: platform string to use in nmf files. | 31 platform: platform string to use in nmf files. |
| 32 """ | 32 """ |
| 33 self.main_nexe = main_nexe | 33 self.main_nexe = main_nexe |
| 34 self.nmf_filename = nmf_filename | 34 self.nmf_filename = nmf_filename |
| 35 if nmf_filename == '-': | 35 if nmf_filename == '-': |
| 36 self.nmf_data = {} | 36 self.nmf_data = {} |
| 37 else: | 37 else: |
| 38 self.nmf_data = json.load(open(nmf_filename)) | 38 self.nmf_data = json.load(open(nmf_filename)) |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 frame['scopes'] = self._Addr2Line(core['segments'], frame['prog_ctr']) | 134 frame['scopes'] = self._Addr2Line(core['segments'], frame['prog_ctr']) |
| 135 return core | 135 return core |
| 136 | 136 |
| 137 | 137 |
| 138 def LoadAndDecode(self, core_path): | 138 def LoadAndDecode(self, core_path): |
| 139 """Given a core.json file, load and embellish with decoded addresses. | 139 """Given a core.json file, load and embellish with decoded addresses. |
| 140 | 140 |
| 141 Args: | 141 Args: |
| 142 core_path: source file containing a dump. | 142 core_path: source file containing a dump. |
| 143 Returns: | 143 Returns: |
| 144 An embelished core dump dict (decoded code addresses). | 144 An embellished core dump dict (decoded code addresses). |
| 145 """ | 145 """ |
| 146 core = json.load(open(core_path)) | 146 core = json.load(open(core_path)) |
| 147 for frame in core['frames']: | 147 for frame in core['frames']: |
| 148 frame['scopes'] = self._Addr2Line(core['segments'], frame['prog_ctr']) | 148 frame['scopes'] = self._Addr2Line(core['segments'], frame['prog_ctr']) |
| 149 return core | 149 return core |
| 150 | 150 |
| 151 def StackTrace(self, info): | 151 def StackTrace(self, info): |
| 152 """Convert a decoded core.json dump to a simple stack trace. | 152 """Convert a decoded core.json dump to a simple stack trace. |
| 153 | 153 |
| 154 Args: | 154 Args: |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 addr2line=options.add2line, | 200 addr2line=options.add2line, |
| 201 library_paths=options.library_paths, | 201 library_paths=options.library_paths, |
| 202 platform=options.platform) | 202 platform=options.platform) |
| 203 info = decoder.LoadAndDecode(args[0]) | 203 info = decoder.LoadAndDecode(args[0]) |
| 204 trace = decoder.StackTrace(info) | 204 trace = decoder.StackTrace(info) |
| 205 decoder.PrintTrace(trace, sys.stdout) | 205 decoder.PrintTrace(trace, sys.stdout) |
| 206 | 206 |
| 207 | 207 |
| 208 if __name__ == '__main__': | 208 if __name__ == '__main__': |
| 209 Main(sys.argv[1:]) | 209 Main(sys.argv[1:]) |
| OLD | NEW |