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

Side by Side Diff: native_client_sdk/src/tools/decode_dump.py

Issue 720233003: [NaCl SDK] Convert python scripts from optparse to argparse. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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 unified diff | Download patch
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # Copyright (c) 2012 The Chromium 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 argparse
binji 2014/11/13 23:57:03 sort
Sam Clegg 2014/11/30 17:55:12 Done.
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,
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 out: file like object to output the trace to. 170 out: file like object to output the trace to.
171 """ 171 """
172 for scope in trace: 172 for scope in trace:
173 out.write('%s at %s:%d\n' % ( 173 out.write('%s at %s:%d\n' % (
174 scope['function'], 174 scope['function'],
175 scope['filename'], 175 scope['filename'],
176 scope['lineno'])) 176 scope['lineno']))
177 177
178 178
179 def Main(args): 179 def Main(args):
180 parser = optparse.OptionParser( 180 parser = argparse.ArgumentParser(
181 usage='USAGE: %prog [options] <core.json>') 181 usage='USAGE: %prog [options] <core.json>')
binji 2014/11/13 23:57:03 remove usage
Sam Clegg 2014/11/30 17:55:12 Done.
182 parser.add_option('-m', '--main-nexe', dest='main_nexe', 182 parser.add_argument('-m', '--main-nexe', dest='main_nexe',
183 help='nexe to resolve NaClMain references from') 183 help='nexe to resolve NaClMain references from')
184 parser.add_option('-n', '--nmf', dest='nmf_filename', default='-', 184 parser.add_argument('-n', '--nmf', dest='nmf_filename', default='-',
185 help='nmf to resolve references from') 185 help='nmf to resolve references from')
186 parser.add_option('-a', '--addr2line', dest='addr2line', 186 parser.add_argument('-a', '--addr2line', dest='addr2line',
187 help='path to appropriate addr2line') 187 help='path to appropriate addr2line')
188 parser.add_option('-L', '--library-path', dest='library_paths', 188 parser.add_argument('-L', '--library-path', dest='library_paths',
189 action='append', default=[], 189 action='append', default=[],
190 help='path to search for shared libraries') 190 help='path to search for shared libraries')
191 parser.add_option('-p', '--platform', dest='platform', 191 parser.add_argument('-p', '--platform', dest='platform',
192 help='platform in a style match nmf files') 192 help='platform in a style match nmf files')
193 options, args = parser.parse_args(args) 193 options, args = parser.parse_args(args)
binji 2014/11/13 23:57:03 options = ...
Sam Clegg 2014/11/30 17:55:12 Done.
194 if len(args) != 1: 194 if len(args) != 1:
binji 2014/11/13 23:57:03 add positional arg
Sam Clegg 2014/11/30 17:55:12 Done.
195 parser.print_help() 195 parser.print_help()
196 sys.exit(1) 196 sys.exit(1)
197 decoder = CoreDecoder( 197 decoder = CoreDecoder(
198 main_nexe=options.main_nexe, 198 main_nexe=options.main_nexe,
199 nmf_filename=options.nmf_filename, 199 nmf_filename=options.nmf_filename,
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:])
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698