| OLD | NEW |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import re | 5 import re |
| 6 | 6 |
| 7 from common import constants |
| 7 from crash.callstack import CallStack | 8 from crash.callstack import CallStack |
| 8 from crash.stacktrace import Stacktrace | 9 from crash.stacktrace import Stacktrace |
| 9 from crash.stacktrace_parser import StacktraceParser | 10 from crash.stacktrace_parser import StacktraceParser |
| 10 from crash.type_enums import CallStackFormatType | 11 from crash.type_enums import CallStackFormatType |
| 11 | 12 |
| 12 | 13 |
| 13 FRACAS_CALLSTACK_START_PATTERN = re.compile(r'CRASHED \[(.*) @ 0x(.*)\]') | 14 FRACAS_CALLSTACK_START_PATTERN = re.compile(r'CRASHED \[(.*) @ 0x(.*)\]') |
| 14 | 15 |
| 15 | 16 |
| 16 _INFINITY_PRIORITY = 1000 | |
| 17 | |
| 18 | |
| 19 class FracasParser(StacktraceParser): | 17 class FracasParser(StacktraceParser): |
| 20 | 18 |
| 21 def Parse(self, stacktrace_string, deps): | 19 def Parse(self, stacktrace_string, deps): |
| 22 """Parse fracas stacktrace string into Stacktrace instance.""" | 20 """Parse fracas stacktrace string into Stacktrace instance.""" |
| 23 stacktrace = Stacktrace() | 21 stacktrace = Stacktrace() |
| 24 callstack = CallStack(_INFINITY_PRIORITY) | 22 callstack = CallStack(constants.INFINITY) |
| 25 | 23 |
| 26 for line in stacktrace_string.splitlines(): | 24 for line in stacktrace_string.splitlines(): |
| 27 is_new_callstack, stack_priority, format_type = ( | 25 is_new_callstack, stack_priority, format_type = ( |
| 28 self._IsStartOfNewCallStack(line)) | 26 self._IsStartOfNewCallStack(line)) |
| 29 | 27 |
| 30 if is_new_callstack: | 28 if is_new_callstack: |
| 31 # If the callstack is not the initial one or empty, add it | 29 # If the callstack is not the initial one or empty, add it |
| 32 # to stacktrace. | 30 # to stacktrace. |
| 33 if callstack.priority != _INFINITY_PRIORITY and callstack: | 31 if callstack.priority != constants.INFINITY and callstack: |
| 34 stacktrace.append(callstack) | 32 stacktrace.append(callstack) |
| 35 | 33 |
| 36 callstack = CallStack(stack_priority, format_type) | 34 callstack = CallStack(stack_priority, format_type) |
| 37 else: | 35 else: |
| 38 callstack.ParseLine(line, deps) | 36 callstack.ParseLine(line, deps) |
| 39 | 37 |
| 40 if callstack.priority != _INFINITY_PRIORITY and callstack: | 38 if callstack.priority != constants.INFINITY and callstack: |
| 41 stacktrace.append(callstack) | 39 stacktrace.append(callstack) |
| 42 | 40 |
| 43 return stacktrace | 41 return stacktrace |
| 44 | 42 |
| 45 def _IsStartOfNewCallStack(self, line): | 43 def _IsStartOfNewCallStack(self, line): |
| 46 """Determine whether a line is a start of a callstack or not. | 44 """Determine whether a line is a start of a callstack or not. |
| 47 Returns a tuple - (is_new_callstack, stack_priority, format_type). | 45 Returns a tuple - (is_new_callstack, stack_priority, format_type). |
| 48 """ | 46 """ |
| 49 if FRACAS_CALLSTACK_START_PATTERN.match(line): | 47 if FRACAS_CALLSTACK_START_PATTERN.match(line): |
| 50 #Fracas only provide magic signature stack (crash stack). | 48 #Fracas only provide magic signature stack (crash stack). |
| 51 return True, 0, CallStackFormatType.DEFAULT | 49 return True, 0, CallStackFormatType.DEFAULT |
| 52 | 50 |
| 53 return False, None, None | 51 return False, None, None |
| OLD | NEW |