| 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 crash.callstack import CallStack | 7 from crash.callstack import CallStack |
| 8 from crash.callstack_filters import FilterFramesBeforeSignature | 8 from crash.callstack_filters import FilterInlineFunctionFrames |
| 9 from crash.stacktrace import Stacktrace | 9 from crash.stacktrace import Stacktrace |
| 10 from crash.stacktrace_parser import StacktraceParser | 10 from crash.stacktrace_parser import StacktraceParser |
| 11 from crash.type_enums import CallStackFormatType | 11 from crash.type_enums import CallStackFormatType |
| 12 | 12 |
| 13 | 13 |
| 14 FRACAS_CALLSTACK_START_PATTERN = re.compile(r'CRASHED \[(.*) @ 0x(.*)\]') | 14 FRACAS_CALLSTACK_START_PATTERN = re.compile(r'CRASHED \[(.*) @ 0x(.*)\]') |
| 15 | 15 |
| 16 | 16 |
| 17 _INFINITY_PRIORITY = 1000 | 17 _INFINITY_PRIORITY = 1000 |
| 18 | 18 |
| 19 | 19 |
| 20 class FracasParser(StacktraceParser): | 20 class FracasParser(StacktraceParser): |
| 21 | 21 |
| 22 def Parse(self, stacktrace_string, deps, signature=None): | 22 def Parse(self, stacktrace_string, deps, signature=None): |
| 23 """Parse fracas stacktrace string into Stacktrace instance.""" | 23 """Parse fracas stacktrace string into Stacktrace instance.""" |
| 24 stacktrace = Stacktrace() | 24 stacktrace = Stacktrace(signature=signature) |
| 25 callstack = CallStack(_INFINITY_PRIORITY) | 25 callstack = CallStack(_INFINITY_PRIORITY) |
| 26 | 26 |
| 27 for line in stacktrace_string.splitlines(): | 27 for line in stacktrace_string.splitlines(): |
| 28 is_new_callstack, stack_priority, format_type = ( | 28 is_new_callstack, stack_priority, format_type = ( |
| 29 self._IsStartOfNewCallStack(line)) | 29 self._IsStartOfNewCallStack(line)) |
| 30 | 30 |
| 31 if is_new_callstack: | 31 if is_new_callstack: |
| 32 # If the callstack is not the initial one or empty, add it | 32 # If the callstack is not the initial one or empty, add it |
| 33 # to stacktrace. | 33 # to stacktrace. |
| 34 if callstack.priority != _INFINITY_PRIORITY and callstack: | 34 if callstack.priority != _INFINITY_PRIORITY and callstack: |
| 35 stacktrace.append(callstack) | 35 stacktrace.append(callstack) |
| 36 | 36 |
| 37 callstack = CallStack(stack_priority, format_type) | 37 callstack = CallStack(stack_priority, format_type) |
| 38 else: | 38 else: |
| 39 callstack.ParseLine(line, deps) | 39 callstack.ParseLine(line, deps) |
| 40 | 40 |
| 41 if callstack.priority != _INFINITY_PRIORITY and callstack: | 41 if callstack.priority != _INFINITY_PRIORITY and callstack: |
| 42 stacktrace.append(callstack) | 42 stacktrace.append(callstack) |
| 43 | 43 |
| 44 # Filter all the frames before signature frame. | 44 # Filter all the frames before signature frame. |
| 45 FilterFramesBeforeSignature(stacktrace.GetCrashStack(), signature) | 45 if stacktrace: |
| 46 stacktrace = Stacktrace(map(FilterInlineFunctionFrames, stacktrace)) |
| 47 |
| 46 return stacktrace | 48 return stacktrace |
| 47 | 49 |
| 48 def _IsStartOfNewCallStack(self, line): | 50 def _IsStartOfNewCallStack(self, line): |
| 49 """Determine whether a line is a start of a callstack or not. | 51 """Determine whether a line is a start of a callstack or not. |
| 50 Returns a tuple - (is_new_callstack, stack_priority, format_type). | 52 Returns a tuple - (is_new_callstack, stack_priority, format_type). |
| 51 """ | 53 """ |
| 52 if FRACAS_CALLSTACK_START_PATTERN.match(line): | 54 if FRACAS_CALLSTACK_START_PATTERN.match(line): |
| 53 #Fracas only provide magic signature stack (crash stack). | 55 #Fracas only provide magic signature stack (crash stack). |
| 54 return True, 0, CallStackFormatType.DEFAULT | 56 return True, 0, CallStackFormatType.DEFAULT |
| 55 | 57 |
| 56 return False, None, None | 58 return False, None, None |
| OLD | NEW |