1 # Copyright 2013 The Chromium Authors. All rights reserved. 2 # Use of this source code is governed by a BSD-style license that can be 3 # found in the LICENSE file. 4 5 import sys 6 7 from lib.bucket import BUCKET_ID 8 from lib.subcommand import SubCommand 9 10 11 class StacktraceCommand(SubCommand): 12 def __init__(self): 13 super(StacktraceCommand, self).__init__( 14 'Usage: %prog stacktrace <dump>') 15 16 def do(self, sys_argv): 17 _, args = self._parse_args(sys_argv, 1) 18 dump_path = args[1] 19 (bucket_set, dump) = SubCommand.load_basic_files(dump_path, False) 20 21 StacktraceCommand._output(dump, bucket_set, sys.stdout) 22 return 0 23 24 @staticmethod 25 def _output(dump, bucket_set, out): 26 """Outputs a given stacktrace. 27 28 Args: 29 bucket_set: A BucketSet object. 30 out: A file object to output. 31 """ 32 for line in dump.iter_stacktrace: 33 words = line.split() 34 bucket = bucket_set.get(int(words[BUCKET_ID])) 35 if not bucket: 36 continue 37 for i in range(0, BUCKET_ID - 1): 38 out.write(words[i] + ' ') 39 for frame in bucket.symbolized_stackfunction: 40 out.write(frame + ' ') 41 out.write('\n') 42