Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library trace; | 5 library trace; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 import 'dart:math' as math; | 8 import 'dart:math' as math; |
| 9 | 9 |
| 10 import 'chain.dart'; | 10 import 'chain.dart'; |
| 11 import 'frame.dart'; | 11 import 'frame.dart'; |
| 12 import 'lazy_trace.dart'; | 12 import 'lazy_trace.dart'; |
| 13 import 'utils.dart'; | 13 import 'utils.dart'; |
| 14 import 'vm_trace.dart'; | 14 import 'vm_trace.dart'; |
| 15 | 15 |
| 16 import 'dart:convert'; | |
| 17 | |
| 16 final _terseRegExp = new RegExp(r"(-patch)?(/.*)?$"); | 18 final _terseRegExp = new RegExp(r"(-patch)?(/.*)?$"); |
| 17 | 19 |
| 18 /// A RegExp to match V8's stack traces. | 20 /// A RegExp to match V8's stack traces. |
| 19 /// | 21 /// |
| 20 /// V8's traces start with a line that's either just "Error" or else is a | 22 /// V8's traces start with a line that's either just "Error" or else is a |
| 21 /// description of the exception that occurred. That description can be multiple | 23 /// description of the exception that occurred. That description can be multiple |
| 22 /// lines, so we just look for any line other than the first that begins with | 24 /// lines, so we just look for any line other than the first that begins with |
| 23 /// three or four spaces and "at". | 25 /// three or four spaces and "at". |
| 24 final _v8Trace = new RegExp(r"\n ?at "); | 26 final _v8Trace = new RegExp(r"\n ?at "); |
| 25 | 27 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 108 } | 110 } |
| 109 | 111 |
| 110 /// Parses a string representation of a stack trace. | 112 /// Parses a string representation of a stack trace. |
| 111 /// | 113 /// |
| 112 /// [trace] should be formatted in the same way as a Dart VM or browser stack | 114 /// [trace] should be formatted in the same way as a Dart VM or browser stack |
| 113 /// trace. | 115 /// trace. |
| 114 factory Trace.parse(String trace) { | 116 factory Trace.parse(String trace) { |
| 115 try { | 117 try { |
| 116 if (trace.isEmpty) return new Trace(<Frame>[]); | 118 if (trace.isEmpty) return new Trace(<Frame>[]); |
| 117 if (trace.contains(_v8Trace)) return new Trace.parseV8(trace); | 119 if (trace.contains(_v8Trace)) return new Trace.parseV8(trace); |
| 120 if (trace.startsWith("\tat ")) return new Trace.parseJSCore(trace); | |
| 118 if (trace.contains(_firefoxSafariTrace)) { | 121 if (trace.contains(_firefoxSafariTrace)) { |
| 119 return new Trace.parseFirefox(trace); | 122 return new Trace.parseFirefox(trace); |
| 120 } | 123 } |
| 121 if (trace.contains(_friendlyTrace)) { | 124 if (trace.contains(_friendlyTrace)) { |
| 122 return new Trace.parseFriendly(trace); | 125 return new Trace.parseFriendly(trace); |
| 123 } | 126 } |
| 124 | 127 |
| 125 // Default to parsing the stack trace as a VM trace. This is also hit on | 128 // Default to parsing the stack trace as a VM trace. This is also hit on |
| 126 // IE and Safari, where the stack trace is just an empty string (issue | 129 // IE and Safari, where the stack trace is just an empty string (issue |
| 127 // 11257). | 130 // 11257). |
| 128 return new Trace.parseVM(trace); | 131 return new Trace.parseVM(trace); |
| 129 } on FormatException catch (error) { | 132 } on FormatException catch (error) { |
| 133 print(JSON.encode(trace)); | |
|
kevmoo
2015/04/13 23:25:47
Oops?
nweiz
2015/04/13 23:27:19
Done.
| |
| 130 throw new FormatException('${error.message}\nStack trace:\n$trace'); | 134 throw new FormatException('${error.message}\nStack trace:\n$trace'); |
| 131 } | 135 } |
| 132 } | 136 } |
| 133 | 137 |
| 134 /// Parses a string representation of a Dart VM stack trace. | 138 /// Parses a string representation of a Dart VM stack trace. |
| 135 Trace.parseVM(String trace) | 139 Trace.parseVM(String trace) |
| 136 : this(trace.trim().split("\n"). | 140 : this(trace.trim().split("\n"). |
| 137 // TODO(nweiz): remove this when issue 15920 is fixed. | 141 // TODO(nweiz): remove this when issue 15920 is fixed. |
| 138 where((line) => line.isNotEmpty). | 142 where((line) => line.isNotEmpty). |
| 139 map((line) => new Frame.parseVM(line))); | 143 map((line) => new Frame.parseVM(line))); |
| 140 | 144 |
| 141 /// Parses a string representation of a Chrome/V8 stack trace. | 145 /// Parses a string representation of a Chrome/V8 stack trace. |
| 142 Trace.parseV8(String trace) | 146 Trace.parseV8(String trace) |
| 143 : this(trace.split("\n").skip(1) | 147 : this(trace.split("\n").skip(1) |
| 144 // It's possible that an Exception's description contains a line that | 148 // It's possible that an Exception's description contains a line that |
| 145 // looks like a V8 trace line, which will screw this up. | 149 // looks like a V8 trace line, which will screw this up. |
| 146 // Unfortunately, that's impossible to detect. | 150 // Unfortunately, that's impossible to detect. |
| 147 .skipWhile((line) => !line.startsWith(_v8TraceLine)) | 151 .skipWhile((line) => !line.startsWith(_v8TraceLine)) |
| 148 .map((line) => new Frame.parseV8(line))); | 152 .map((line) => new Frame.parseV8(line))); |
| 149 | 153 |
| 154 /// Parses a string representation of a JavaScriptCore stack trace. | |
| 155 Trace.parseJSCore(String trace) | |
| 156 : this(trace.split("\n").map((line) => new Frame.parseV8(line))); | |
| 157 | |
| 150 /// Parses a string representation of an Internet Explorer stack trace. | 158 /// Parses a string representation of an Internet Explorer stack trace. |
| 151 /// | 159 /// |
| 152 /// IE10+ traces look just like V8 traces. Prior to IE10, stack traces can't | 160 /// IE10+ traces look just like V8 traces. Prior to IE10, stack traces can't |
| 153 /// be retrieved. | 161 /// be retrieved. |
| 154 Trace.parseIE(String trace) | 162 Trace.parseIE(String trace) |
| 155 : this.parseV8(trace); | 163 : this.parseV8(trace); |
| 156 | 164 |
| 157 /// Parses a string representation of a Firefox stack trace. | 165 /// Parses a string representation of a Firefox stack trace. |
| 158 Trace.parseFirefox(String trace) | 166 Trace.parseFirefox(String trace) |
| 159 : this(trace.trim().split("\n") | 167 : this(trace.trim().split("\n") |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 267 // Figure out the longest path so we know how much to pad. | 275 // Figure out the longest path so we know how much to pad. |
| 268 var longest = frames.map((frame) => frame.location.length) | 276 var longest = frames.map((frame) => frame.location.length) |
| 269 .fold(0, math.max); | 277 .fold(0, math.max); |
| 270 | 278 |
| 271 // Print out the stack trace nicely formatted. | 279 // Print out the stack trace nicely formatted. |
| 272 return frames.map((frame) { | 280 return frames.map((frame) { |
| 273 return '${padRight(frame.location, longest)} ${frame.member}\n'; | 281 return '${padRight(frame.location, longest)} ${frame.member}\n'; |
| 274 }).join(); | 282 }).join(); |
| 275 } | 283 } |
| 276 } | 284 } |
| OLD | NEW |