Chromium Code Reviews| 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 import parse_util | 7 from crash import parse_util |
| 8 from crash.type_enums import CallStackFormatType | 8 from crash.type_enums import CallStackFormatType |
| 9 | 9 |
| 10 # Used to parse a line into StackFrame of a Callstack. | 10 # Used to parse a line into StackFrame of a Callstack. |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 29 this - '#0 ...', else use the index in the callstack list. | 29 this - '#0 ...', else use the index in the callstack list. |
| 30 dep_path (str): Path of the dep this frame represents, for example, | 30 dep_path (str): Path of the dep this frame represents, for example, |
| 31 'src/', 'src/v8', 'src/skia'...etc. | 31 'src/', 'src/v8', 'src/skia'...etc. |
| 32 function (str): Function that caused the crash. | 32 function (str): Function that caused the crash. |
| 33 file_path (str): Normalized path of the crashed file, with parts dep_path | 33 file_path (str): Normalized path of the crashed file, with parts dep_path |
| 34 and parts before it stripped, for example, api.cc. | 34 and parts before it stripped, for example, api.cc. |
| 35 raw_file_path (str): Normalized original path of the crashed file, | 35 raw_file_path (str): Normalized original path of the crashed file, |
| 36 for example, /b/build/slave/mac64/build/src/v8/src/heap/ | 36 for example, /b/build/slave/mac64/build/src/v8/src/heap/ |
| 37 incremental-marking-job.cc. | 37 incremental-marking-job.cc. |
| 38 crashed_line_numbers (list): Line numbers of the file that caused the crash. | 38 crashed_line_numbers (list): Line numbers of the file that caused the crash. |
| 39 repo_url (str): Repo url of this frame. | |
| 39 """ | 40 """ |
| 40 def __init__(self, index, dep_path, function, | 41 def __init__(self, index, dep_path, function, |
| 41 file_path, raw_file_path, crashed_line_numbers): | 42 file_path, raw_file_path, crashed_line_numbers, |
| 43 repo_url=None): | |
| 42 self.index = index | 44 self.index = index |
| 43 self.dep_path = dep_path | 45 self.dep_path = dep_path |
| 44 self.function = function | 46 self.function = function |
| 45 self.file_path = file_path | 47 self.file_path = file_path |
| 46 self.raw_file_path = raw_file_path | 48 self.raw_file_path = raw_file_path |
| 47 self.crashed_line_numbers = crashed_line_numbers | 49 self.crashed_line_numbers = crashed_line_numbers |
| 50 self.repo_url = repo_url | |
| 48 | 51 |
| 49 def ToString(self): | 52 def ToString(self): |
| 50 frame_str = '#%d in %s @ %s' % (self.index, self.function, self.file_path) | 53 frame_str = '#%d in %s @ %s' % (self.index, self.function, self.file_path) |
| 51 if self.crashed_line_numbers: | 54 if self.crashed_line_numbers: |
| 52 frame_str += ':%d' % self.crashed_line_numbers[0] | 55 frame_str += ':%d' % self.crashed_line_numbers[0] |
| 53 | 56 |
| 54 # For example, if crashed_line_numbers is [61], returns '... f.cc:61', | 57 # For example, if crashed_line_numbers is [61], returns '... f.cc:61', |
| 55 # if is [61, 62], returns '... f.cc:61:1' | 58 # if is [61, 62], returns '... f.cc:61:1' |
| 56 if len(self.crashed_line_numbers) > 1: | 59 if len(self.crashed_line_numbers) > 1: |
| 57 frame_str += ':%d' % (len(self.crashed_line_numbers) - 1) | 60 frame_str += ':%d' % (len(self.crashed_line_numbers) - 1) |
| 58 | 61 |
| 59 return frame_str | 62 return frame_str |
| 60 | 63 |
| 64 def BlameUrl(self, revision): | |
| 65 if not self.repo_url or not self.dep_path: | |
|
stgao
2016/07/15 23:25:28
why dep_path instead of file_path?
Sharu Jiang
2016/07/18 00:31:58
For some frames, findit cannot find a repo match,
| |
| 66 return None | |
| 67 | |
| 68 blame_url = '%s/+blame/%s/%s' % (self.repo_url, revision, self.file_path) | |
| 69 if self.crashed_line_numbers: | |
| 70 blame_url += '#%d' % self.crashed_line_numbers[0] | |
| 71 | |
| 72 return blame_url | |
| 73 | |
| 61 def __str__(self): | 74 def __str__(self): |
| 62 return self.ToString() | 75 return self.ToString() |
| 63 | 76 |
| 64 | 77 |
| 65 class CallStack(list): | 78 class CallStack(list): |
| 66 """Represents a call stack within a stacktrace. A list of StackFrame objects. | 79 """Represents a call stack within a stacktrace. A list of StackFrame objects. |
| 67 | 80 |
| 68 Attributes: | 81 Attributes: |
| 69 priority (int): The smaller the number, the higher the priority beginning | 82 priority (int): The smaller the number, the higher the priority beginning |
| 70 with 0. | 83 with 0. |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 121 match = line_pattern.match(line_parts[-1]) | 134 match = line_pattern.match(line_parts[-1]) |
| 122 if not match: | 135 if not match: |
| 123 return | 136 return |
| 124 | 137 |
| 125 function = ' '.join(line_parts[3:-1]) | 138 function = ' '.join(line_parts[3:-1]) |
| 126 raw_file_path = match.group(1) | 139 raw_file_path = match.group(1) |
| 127 crashed_line_numbers = parse_util.GetCrashedLineRange( | 140 crashed_line_numbers = parse_util.GetCrashedLineRange( |
| 128 match.group(2) + (match.group(3) if match.group(3) else '')) | 141 match.group(2) + (match.group(3) if match.group(3) else '')) |
| 129 | 142 |
| 130 # Normalize the file path so that it can be compared to repository path. | 143 # Normalize the file path so that it can be compared to repository path. |
| 131 dep_path, file_path = parse_util.GetDepPathAndNormalizedFilePath( | 144 dep_path, file_path, repo_url = parse_util.GetDepPathAndNormalizedFilePath( |
| 132 raw_file_path, deps) | 145 raw_file_path, deps) |
| 133 | 146 |
| 134 # If we have the common stack frame index pattern, then use it | 147 # If we have the common stack frame index pattern, then use it |
| 135 # since it is more reliable. | 148 # since it is more reliable. |
| 136 index_match = FRAME_INDEX_PATTERN.match(line) | 149 index_match = FRAME_INDEX_PATTERN.match(line) |
| 137 if index_match: | 150 if index_match: |
| 138 stack_frame_index = int(index_match.group(1)) | 151 stack_frame_index = int(index_match.group(1)) |
| 139 else: | 152 else: |
| 140 stack_frame_index = len(self) | 153 stack_frame_index = len(self) |
| 141 | 154 |
| 142 self.append(StackFrame(stack_frame_index, dep_path, function, | 155 self.append(StackFrame(stack_frame_index, dep_path, function, file_path, |
| 143 file_path, raw_file_path, crashed_line_numbers)) | 156 raw_file_path, crashed_line_numbers, repo_url)) |
| OLD | NEW |