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 'frame.dart'; | 10 import 'frame.dart'; |
| 11 import 'lazy_trace.dart'; | 11 import 'lazy_trace.dart'; |
| 12 import 'utils.dart'; | 12 import 'utils.dart'; |
| 13 import 'vm_trace.dart'; | 13 import 'vm_trace.dart'; |
| 14 | 14 |
| 15 final _terseRegExp = new RegExp(r"(-patch)?(/.*)?$"); | 15 final _terseRegExp = new RegExp(r"(-patch)?(/.*)?$"); |
| 16 | 16 |
| 17 /// A RegExp to match V8's stack traces. | 17 /// A RegExp to match V8's stack traces. |
| 18 /// | 18 /// |
| 19 /// V8's traces start with a line that's either just "Error" or else is a | 19 /// V8's traces start with a line that's either just "Error" or else is a |
| 20 /// description of the exception that occurred. That description can be multiple | 20 /// description of the exception that occurred. That description can be multiple |
| 21 /// lines, so we just look for any line other than the first that begins with | 21 /// lines, so we just look for any line other than the first that begins with |
| 22 /// four spaces and "at". | 22 /// three or four spaces and "at". |
| 23 final _v8Trace = new RegExp(r"\n at "); | 23 final _v8Trace = new RegExp(r"\n\s{3,4}at "); |
|
nweiz
2013/08/27 18:16:06
\s isn't ideal here, since it can also match tabs.
blois
2013/08/27 18:20:30
Done.
| |
| 24 | |
| 25 /// A RegExp to match indidual lines of V8's stack traces. | |
| 26 /// | |
| 27 /// This is intended to filter out the leading exception details of the trace | |
| 28 /// though it is possible for the message to match this as well. | |
| 29 final _v8TraceLine = new RegExp(r"\s{3,4}at "); | |
| 24 | 30 |
| 25 /// A RegExp to match Firefox's stack traces. | 31 /// A RegExp to match Firefox's stack traces. |
| 26 /// | 32 /// |
| 27 /// Firefox's trace frames start with the name of the function in which the | 33 /// Firefox's trace frames start with the name of the function in which the |
| 28 /// error occurred, possibly including its parameters inside `()`. For example, | 34 /// error occurred, possibly including its parameters inside `()`. For example, |
| 29 /// `.VW.call$0("arg")@http://pub.dartlang.org/stuff.dart.js:560`. | 35 /// `.VW.call$0("arg")@http://pub.dartlang.org/stuff.dart.js:560`. |
| 30 final _firefoxTrace = new RegExp(r"^([.0-9A-Za-z_$/<]|\(.*\))*@"); | 36 final _firefoxTrace = new RegExp(r"^([.0-9A-Za-z_$/<]|\(.*\))*@"); |
| 31 | 37 |
| 32 /// A RegExp to match this package's stack traces. | 38 /// A RegExp to match this package's stack traces. |
| 33 final _friendlyTrace = new RegExp(r"^[^\s]+( \d+:\d+)?\s+[^\s]+($|\n)"); | 39 final _friendlyTrace = new RegExp(r"^[^\s]+( \d+:\d+)?\s+[^\s]+($|\n)"); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 99 /// Parses a string representation of a Dart VM stack trace. | 105 /// Parses a string representation of a Dart VM stack trace. |
| 100 Trace.parseVM(String trace) | 106 Trace.parseVM(String trace) |
| 101 : this(trace.trim().split("\n").map((line) => new Frame.parseVM(line))); | 107 : this(trace.trim().split("\n").map((line) => new Frame.parseVM(line))); |
| 102 | 108 |
| 103 /// Parses a string representation of a Chrome/V8 stack trace. | 109 /// Parses a string representation of a Chrome/V8 stack trace. |
| 104 Trace.parseV8(String trace) | 110 Trace.parseV8(String trace) |
| 105 : this(trace.split("\n").skip(1) | 111 : this(trace.split("\n").skip(1) |
| 106 // It's possible that an Exception's description contains a line that | 112 // It's possible that an Exception's description contains a line that |
| 107 // looks like a V8 trace line, which will screw this up. | 113 // looks like a V8 trace line, which will screw this up. |
| 108 // Unfortunately, that's impossible to detect. | 114 // Unfortunately, that's impossible to detect. |
| 109 .skipWhile((line) => !line.startsWith(" at ")) | 115 .skipWhile((line) => !line.startsWith(_v8TraceLine)) |
| 110 .map((line) => new Frame.parseV8(line))); | 116 .map((line) => new Frame.parseV8(line))); |
| 111 | 117 |
| 112 /// Parses a string representation of an Internet Explorer stack trace. | |
| 113 /// | |
| 114 /// IE10+ traces look just like V8 traces. Prior to IE10, stack traces can't | |
| 115 /// be retrieved. | |
| 116 Trace.parseIE(String trace) | |
| 117 : this.parseV8(trace); | |
|
nweiz
2013/08/27 18:16:06
This should be retained.
blois
2013/08/27 18:20:30
Done.
| |
| 118 | |
| 119 /// Parses a string representation of a Firefox stack trace. | 118 /// Parses a string representation of a Firefox stack trace. |
| 120 Trace.parseFirefox(String trace) | 119 Trace.parseFirefox(String trace) |
| 121 : this(trace.trim().split("\n") | 120 : this(trace.trim().split("\n") |
| 122 .map((line) => new Frame.parseFirefox(line))); | 121 .map((line) => new Frame.parseFirefox(line))); |
| 123 | 122 |
| 124 /// Parses a string representation of a Safari stack trace. | 123 /// Parses a string representation of a Safari stack trace. |
| 125 /// | 124 /// |
| 126 /// Safari 6+ stack traces look just like Firefox traces, except that they | 125 /// Safari 6+ stack traces look just like Firefox traces, except that they |
| 127 /// sometimes (e.g. in isolates) have a "[native code]" frame. We just ignore | 126 /// sometimes (e.g. in isolates) have a "[native code]" frame. We just ignore |
| 128 /// this frame to make the stack format more consistent between browsers. | 127 /// this frame to make the stack format more consistent between browsers. |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 187 // Figure out the longest path so we know how much to pad. | 186 // Figure out the longest path so we know how much to pad. |
| 188 var longest = frames.map((frame) => frame.location.length) | 187 var longest = frames.map((frame) => frame.location.length) |
| 189 .fold(0, math.max); | 188 .fold(0, math.max); |
| 190 | 189 |
| 191 // Print out the stack trace nicely formatted. | 190 // Print out the stack trace nicely formatted. |
| 192 return frames.map((frame) { | 191 return frames.map((frame) { |
| 193 return '${padRight(frame.location, longest)} ${frame.member}\n'; | 192 return '${padRight(frame.location, longest)} ${frame.member}\n'; |
| 194 }).join(); | 193 }).join(); |
| 195 } | 194 } |
| 196 } | 195 } |
| OLD | NEW |