OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 part of service; | 5 part of service; |
6 | 6 |
7 // Some value smaller than the object ring, so requesting a large array | 7 // Some value smaller than the object ring, so requesting a large array |
8 // doesn't result in an expired ref because the elements lapped it in the | 8 // doesn't result in an expired ref because the elements lapped it in the |
9 // object ring. | 9 // object ring. |
10 const int kDefaultFieldLimit = 100; | 10 const int kDefaultFieldLimit = 100; |
11 | 11 |
12 /// Helper function for canceling a Future<StreamSubscription>. | 12 /// Helper function for canceling a Future<StreamSubscription>. |
13 Future cancelFutureSubscription( | 13 Future cancelFutureSubscription( |
14 Future<StreamSubscription> subscriptionFuture) async { | 14 Future<StreamSubscription> subscriptionFuture) async { |
15 if (subscriptionFuture != null) { | 15 if (subscriptionFuture != null) { |
16 var subscription = await subscriptionFuture; | 16 var subscription = await subscriptionFuture; |
17 return subscription.cancel(); | 17 return subscription.cancel(); |
18 } else { | 18 } else { |
19 return null; | 19 return null; |
20 } | 20 } |
21 } | 21 } |
22 | 22 |
23 /// An RpcException represents an exceptional event that happened | 23 /// An RpcException represents an exceptional event that happened |
24 /// while invoking an rpc. | 24 /// while invoking an rpc. |
25 abstract class RpcException implements Exception { | 25 abstract class RpcException implements Exception, M.BasicException { |
26 RpcException(this.message); | 26 RpcException(this.message); |
27 | 27 |
28 String message; | 28 String message; |
29 } | 29 } |
30 | 30 |
31 /// A ServerRpcException represents an error returned by the VM. | 31 /// A ServerRpcException represents an error returned by the VM. |
32 class ServerRpcException extends RpcException { | 32 class ServerRpcException extends RpcException implements M.RequestException { |
33 /// A list of well-known server error codes. | 33 /// A list of well-known server error codes. |
34 static const kParseError = -32700; | 34 static const kParseError = -32700; |
35 static const kInvalidRequest = -32600; | 35 static const kInvalidRequest = -32600; |
36 static const kMethodNotFound = -32601; | 36 static const kMethodNotFound = -32601; |
37 static const kInvalidParams = -32602; | 37 static const kInvalidParams = -32602; |
38 static const kInternalError = -32603; | 38 static const kInternalError = -32603; |
39 static const kFeatureDisabled = 100; | 39 static const kFeatureDisabled = 100; |
40 static const kCannotAddBreakpoint = 102; | 40 static const kCannotAddBreakpoint = 102; |
41 static const kStreamAlreadySubscribed = 103; | 41 static const kStreamAlreadySubscribed = 103; |
42 static const kStreamNotSubscribed = 104; | 42 static const kStreamNotSubscribed = 104; |
(...skipping 20 matching lines...) Expand all Loading... |
63 ServerRpcException.fromMap(Map errorMap) : super(_getMessage(errorMap)) { | 63 ServerRpcException.fromMap(Map errorMap) : super(_getMessage(errorMap)) { |
64 code = errorMap['code']; | 64 code = errorMap['code']; |
65 data = errorMap['data']; | 65 data = errorMap['data']; |
66 } | 66 } |
67 | 67 |
68 String toString() => 'ServerRpcException(${message})'; | 68 String toString() => 'ServerRpcException(${message})'; |
69 } | 69 } |
70 | 70 |
71 /// A NetworkRpcException is used to indicate that an rpc has | 71 /// A NetworkRpcException is used to indicate that an rpc has |
72 /// been canceled due to network error. | 72 /// been canceled due to network error. |
73 class NetworkRpcException extends RpcException { | 73 class NetworkRpcException extends RpcException |
| 74 implements M.ConnectionException { |
74 NetworkRpcException(String message) : super(message); | 75 NetworkRpcException(String message) : super(message); |
75 | 76 |
76 String toString() => 'NetworkRpcException(${message})'; | 77 String toString() => 'NetworkRpcException(${message})'; |
77 } | 78 } |
78 | 79 |
79 class MalformedResponseRpcException extends RpcException { | 80 class MalformedResponseRpcException extends RpcException { |
80 MalformedResponseRpcException(String message, this.response) | 81 MalformedResponseRpcException(String message, this.response) |
81 : super(message); | 82 : super(message); |
82 | 83 |
83 Map response; | 84 Map response; |
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 /// be [loaded]. | 418 /// be [loaded]. |
418 ServiceObject getFromMap(ObservableMap map); | 419 ServiceObject getFromMap(ObservableMap map); |
419 } | 420 } |
420 | 421 |
421 abstract class Location { | 422 abstract class Location { |
422 Script get script; | 423 Script get script; |
423 int get tokenPos; | 424 int get tokenPos; |
424 } | 425 } |
425 | 426 |
426 /// A [SourceLocation] represents a location or range in the source code. | 427 /// A [SourceLocation] represents a location or range in the source code. |
427 class SourceLocation extends ServiceObject implements Location { | 428 class SourceLocation extends ServiceObject implements Location, |
| 429 M.SourceLocation { |
428 Script script; | 430 Script script; |
429 int tokenPos; | 431 int tokenPos; |
430 int endTokenPos; | 432 int endTokenPos; |
431 | 433 |
432 Future<int> getLine() async { | 434 Future<int> getLine() async { |
433 await script.load(); | 435 await script.load(); |
434 return script.tokenToLine(tokenPos); | 436 return script.tokenToLine(tokenPos); |
435 } | 437 } |
436 | 438 |
437 Future<int> getColumn() async { | 439 Future<int> getColumn() async { |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
596 } | 598 } |
597 | 599 |
598 void addEvent(ServiceEvent event) { | 600 void addEvent(ServiceEvent event) { |
599 for (var controller in _controllers) { | 601 for (var controller in _controllers) { |
600 controller.add(event); | 602 controller.add(event); |
601 } | 603 } |
602 } | 604 } |
603 } | 605 } |
604 | 606 |
605 /// State for a VM being inspected. | 607 /// State for a VM being inspected. |
606 abstract class VM extends ServiceObjectOwner { | 608 abstract class VM extends ServiceObjectOwner implements M.VM { |
607 @reflectable VM get vm => this; | 609 @reflectable VM get vm => this; |
608 @reflectable Isolate get isolate => null; | 610 @reflectable Isolate get isolate => null; |
609 | 611 |
610 // TODO(turnidge): The connection should not be stored in the VM object. | 612 // TODO(turnidge): The connection should not be stored in the VM object. |
611 bool get isDisconnected; | 613 bool get isDisconnected; |
612 | 614 |
613 // Used for verbose logging. | 615 // Used for verbose logging. |
614 bool verbose = false; | 616 bool verbose = false; |
615 | 617 |
616 // TODO(johnmccutchan): Ensure that isolates do not end up in _cache. | 618 // TODO(johnmccutchan): Ensure that isolates do not end up in _cache. |
617 Map<String,ServiceObject> _cache = new Map<String,ServiceObject>(); | 619 Map<String,ServiceObject> _cache = new Map<String,ServiceObject>(); |
618 final ObservableMap<String,Isolate> _isolateCache = | 620 final ObservableMap<String,Isolate> _isolateCache = |
619 new ObservableMap<String,Isolate>(); | 621 new ObservableMap<String,Isolate>(); |
620 | 622 |
621 // The list of live isolates, ordered by isolate start time. | 623 // The list of live isolates, ordered by isolate start time. |
622 final ObservableList<Isolate> isolates = new ObservableList<Isolate>(); | 624 final ObservableList<Isolate> isolates = new ObservableList<Isolate>(); |
623 | 625 |
624 @observable String version = 'unknown'; | 626 @observable String version = 'unknown'; |
| 627 @observable String hostCPU; |
625 @observable String targetCPU; | 628 @observable String targetCPU; |
626 @observable int architectureBits; | 629 @observable int architectureBits; |
627 @observable bool assertsEnabled = false; | 630 @observable bool assertsEnabled = false; |
628 @observable bool typeChecksEnabled = false; | 631 @observable bool typeChecksEnabled = false; |
629 @observable int pid = 0; | 632 @observable int pid = 0; |
630 @observable bool profileVM = false; | 633 @observable bool profileVM = false; |
631 @observable DateTime startTime; | 634 @observable DateTime startTime; |
632 @observable DateTime refreshTime; | 635 @observable DateTime refreshTime; |
633 @observable Duration get upTime { | 636 @observable Duration get upTime { |
634 if (startTime == null) { | 637 if (startTime == null) { |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
889 vmName = map.containsKey('_vmName') ? map['_vmName'] : name; | 892 vmName = map.containsKey('_vmName') ? map['_vmName'] : name; |
890 if (mapIsRef) { | 893 if (mapIsRef) { |
891 return; | 894 return; |
892 } | 895 } |
893 // Note that upgrading the collection creates any isolates in the | 896 // Note that upgrading the collection creates any isolates in the |
894 // isolate list which are new. | 897 // isolate list which are new. |
895 _upgradeCollection(map, vm); | 898 _upgradeCollection(map, vm); |
896 | 899 |
897 _loaded = true; | 900 _loaded = true; |
898 version = map['version']; | 901 version = map['version']; |
| 902 hostCPU = map['hostCPU']; |
899 targetCPU = map['targetCPU']; | 903 targetCPU = map['targetCPU']; |
900 architectureBits = map['architectureBits']; | 904 architectureBits = map['architectureBits']; |
901 int startTimeMillis = map['startTime']; | 905 int startTimeMillis = map['startTime']; |
902 startTime = new DateTime.fromMillisecondsSinceEpoch(startTimeMillis); | 906 startTime = new DateTime.fromMillisecondsSinceEpoch(startTimeMillis); |
903 refreshTime = new DateTime.now(); | 907 refreshTime = new DateTime.now(); |
904 notifyPropertyChange(#upTime, 0, 1); | 908 notifyPropertyChange(#upTime, 0, 1); |
905 pid = map['pid']; | 909 pid = map['pid']; |
906 profileVM = map['_profilerMode'] == 'VM'; | 910 profileVM = map['_profilerMode'] == 'VM'; |
907 assertsEnabled = map['_assertsEnabled']; | 911 assertsEnabled = map['_assertsEnabled']; |
908 typeChecksEnabled = map['_typeChecksEnabled']; | 912 typeChecksEnabled = map['_typeChecksEnabled']; |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1110 print("${obj.runtimeType} should be a HeapObject"); | 1114 print("${obj.runtimeType} should be a HeapObject"); |
1111 } | 1115 } |
1112 return obj; | 1116 return obj; |
1113 })); | 1117 })); |
1114 } | 1118 } |
1115 return result; | 1119 return result; |
1116 } | 1120 } |
1117 } | 1121 } |
1118 | 1122 |
1119 /// State for a running isolate. | 1123 /// State for a running isolate. |
1120 class Isolate extends ServiceObjectOwner { | 1124 class Isolate extends ServiceObjectOwner implements M.Isolate { |
1121 static const kLoggingStream = '_Logging'; | 1125 static const kLoggingStream = '_Logging'; |
1122 static const kExtensionStream = 'Extension'; | 1126 static const kExtensionStream = 'Extension'; |
1123 | 1127 |
1124 @reflectable VM get vm => owner; | 1128 @reflectable VM get vm => owner; |
1125 @reflectable Isolate get isolate => this; | 1129 @reflectable Isolate get isolate => this; |
1126 @observable int number; | 1130 @observable int number; |
1127 @observable int originNumber; | 1131 @observable int originNumber; |
1128 @observable DateTime startTime; | 1132 @observable DateTime startTime; |
1129 @observable Duration get upTime { | 1133 @observable Duration get upTime { |
1130 if (startTime == null) { | 1134 if (startTime == null) { |
(...skipping 896 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2027 if (data == null) { | 2031 if (data == null) { |
2028 return "ServiceEvent(owner='${ownerName}', kind='${kind}', " | 2032 return "ServiceEvent(owner='${ownerName}', kind='${kind}', " |
2029 "time=${timestamp})"; | 2033 "time=${timestamp})"; |
2030 } else { | 2034 } else { |
2031 return "ServiceEvent(owner='${ownerName}', kind='${kind}', " | 2035 return "ServiceEvent(owner='${ownerName}', kind='${kind}', " |
2032 "data.lengthInBytes=${data.lengthInBytes}, time=${timestamp})"; | 2036 "data.lengthInBytes=${data.lengthInBytes}, time=${timestamp})"; |
2033 } | 2037 } |
2034 } | 2038 } |
2035 } | 2039 } |
2036 | 2040 |
2037 class Breakpoint extends ServiceObject { | 2041 class Breakpoint extends ServiceObject implements M.Breakpoint { |
2038 Breakpoint._empty(ServiceObjectOwner owner) : super._empty(owner); | 2042 Breakpoint._empty(ServiceObjectOwner owner) : super._empty(owner); |
2039 | 2043 |
2040 // TODO(turnidge): Add state to track if a breakpoint has been | 2044 // TODO(turnidge): Add state to track if a breakpoint has been |
2041 // removed from the program. Remove from the cache when deleted. | 2045 // removed from the program. Remove from the cache when deleted. |
2042 bool get canCache => true; | 2046 bool get canCache => true; |
2043 bool get immutable => false; | 2047 bool get immutable => false; |
2044 | 2048 |
2045 // A unique integer identifier for this breakpoint. | 2049 // A unique integer identifier for this breakpoint. |
2046 @observable int number; | 2050 @observable int number; |
2047 | 2051 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2123 | 2127 |
2124 LibraryDependency._(this.isImport, this.isDeferred, this.prefix, this.target); | 2128 LibraryDependency._(this.isImport, this.isDeferred, this.prefix, this.target); |
2125 | 2129 |
2126 static _fromMap(map) => new LibraryDependency._(map["isImport"], | 2130 static _fromMap(map) => new LibraryDependency._(map["isImport"], |
2127 map["isDeferred"], | 2131 map["isDeferred"], |
2128 map["prefix"], | 2132 map["prefix"], |
2129 map["target"]); | 2133 map["target"]); |
2130 } | 2134 } |
2131 | 2135 |
2132 | 2136 |
2133 class Library extends HeapObject { | 2137 class Library extends HeapObject implements M.LibraryRef { |
2134 @observable String uri; | 2138 @observable String uri; |
2135 @reflectable final dependencies = new ObservableList<LibraryDependency>(); | 2139 @reflectable final dependencies = new ObservableList<LibraryDependency>(); |
2136 @reflectable final scripts = new ObservableList<Script>(); | 2140 @reflectable final scripts = new ObservableList<Script>(); |
2137 @reflectable final classes = new ObservableList<Class>(); | 2141 @reflectable final classes = new ObservableList<Class>(); |
2138 @reflectable final variables = new ObservableList<Field>(); | 2142 @reflectable final variables = new ObservableList<Field>(); |
2139 @reflectable final functions = new ObservableList<ServiceFunction>(); | 2143 @reflectable final functions = new ObservableList<ServiceFunction>(); |
2140 | 2144 |
2141 bool get canCache => true; | 2145 bool get canCache => true; |
2142 bool get immutable => false; | 2146 bool get immutable => false; |
2143 | 2147 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2225 void update(List stats) { | 2229 void update(List stats) { |
2226 accumulated.instances = stats[ACCUMULATED]; | 2230 accumulated.instances = stats[ACCUMULATED]; |
2227 accumulated.bytes = stats[ACCUMULATED_SIZE]; | 2231 accumulated.bytes = stats[ACCUMULATED_SIZE]; |
2228 current.instances = stats[LIVE_AFTER_GC] + stats[ALLOCATED_SINCE_GC]; | 2232 current.instances = stats[LIVE_AFTER_GC] + stats[ALLOCATED_SINCE_GC]; |
2229 current.bytes = stats[LIVE_AFTER_GC_SIZE] + stats[ALLOCATED_SINCE_GC_SIZE]; | 2233 current.bytes = stats[LIVE_AFTER_GC_SIZE] + stats[ALLOCATED_SINCE_GC_SIZE]; |
2230 } | 2234 } |
2231 | 2235 |
2232 bool get empty => accumulated.empty && current.empty; | 2236 bool get empty => accumulated.empty && current.empty; |
2233 } | 2237 } |
2234 | 2238 |
2235 class Class extends HeapObject { | 2239 class Class extends HeapObject implements M.ClassRef { |
2236 @observable Library library; | 2240 @observable Library library; |
2237 | 2241 |
2238 @observable bool isAbstract; | 2242 @observable bool isAbstract; |
2239 @observable bool isConst; | 2243 @observable bool isConst; |
2240 @observable bool isFinalized; | 2244 @observable bool isFinalized; |
2241 @observable bool isPatch; | 2245 @observable bool isPatch; |
2242 @observable bool isImplemented; | 2246 @observable bool isImplemented; |
2243 | 2247 |
2244 @observable SourceLocation location; | 2248 @observable SourceLocation location; |
2245 | 2249 |
(...skipping 674 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2920 } | 2924 } |
2921 | 2925 |
2922 /// The location of a local variable reference in a script. | 2926 /// The location of a local variable reference in a script. |
2923 class LocalVarLocation { | 2927 class LocalVarLocation { |
2924 final int line; | 2928 final int line; |
2925 final int column; | 2929 final int column; |
2926 final int endColumn; | 2930 final int endColumn; |
2927 LocalVarLocation(this.line, this.column, this.endColumn); | 2931 LocalVarLocation(this.line, this.column, this.endColumn); |
2928 } | 2932 } |
2929 | 2933 |
2930 class Script extends HeapObject { | 2934 class Script extends HeapObject implements M.Script { |
2931 final lines = new ObservableList<ScriptLine>(); | 2935 final lines = new ObservableList<ScriptLine>(); |
2932 @observable String uri; | 2936 @observable String uri; |
2933 @observable String kind; | 2937 @observable String kind; |
2934 @observable DateTime loadTime; | 2938 @observable DateTime loadTime; |
2935 @observable int firstTokenPos; | 2939 @observable int firstTokenPos; |
2936 @observable int lastTokenPos; | 2940 @observable int lastTokenPos; |
2937 @observable int lineOffset; | 2941 @observable int lineOffset; |
2938 @observable int columnOffset; | 2942 @observable int columnOffset; |
2939 @observable Library library; | 2943 @observable Library library; |
2940 | 2944 |
| 2945 String source; |
| 2946 |
2941 bool get immutable => true; | 2947 bool get immutable => true; |
2942 | 2948 |
2943 String _shortUri; | 2949 String _shortUri; |
2944 | 2950 |
2945 Script._empty(ServiceObjectOwner owner) : super._empty(owner); | 2951 Script._empty(ServiceObjectOwner owner) : super._empty(owner); |
2946 | 2952 |
2947 ScriptLine getLine(int line) { | 2953 ScriptLine getLine(int line) { |
2948 assert(_loaded); | 2954 assert(_loaded); |
2949 assert(line >= 1); | 2955 assert(line >= 1); |
2950 return lines[line - lineOffset - 1]; | 2956 return lines[line - lineOffset - 1]; |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3032 vmName = uri; | 3038 vmName = uri; |
3033 if (mapIsRef) { | 3039 if (mapIsRef) { |
3034 return; | 3040 return; |
3035 } | 3041 } |
3036 _loaded = true; | 3042 _loaded = true; |
3037 int loadTimeMillis = map['_loadTime']; | 3043 int loadTimeMillis = map['_loadTime']; |
3038 loadTime = new DateTime.fromMillisecondsSinceEpoch(loadTimeMillis); | 3044 loadTime = new DateTime.fromMillisecondsSinceEpoch(loadTimeMillis); |
3039 lineOffset = map['lineOffset']; | 3045 lineOffset = map['lineOffset']; |
3040 columnOffset = map['columnOffset']; | 3046 columnOffset = map['columnOffset']; |
3041 _parseTokenPosTable(map['tokenPosTable']); | 3047 _parseTokenPosTable(map['tokenPosTable']); |
| 3048 source = map['source']; |
3042 _processSource(map['source']); | 3049 _processSource(map['source']); |
3043 library = map['library']; | 3050 library = map['library']; |
3044 } | 3051 } |
3045 | 3052 |
3046 void _parseTokenPosTable(List<List<int>> table) { | 3053 void _parseTokenPosTable(List<List<int>> table) { |
3047 if (table == null) { | 3054 if (table == null) { |
3048 return; | 3055 return; |
3049 } | 3056 } |
3050 _tokenToLine.clear(); | 3057 _tokenToLine.clear(); |
3051 _tokenToCol.clear(); | 3058 _tokenToCol.clear(); |
(...skipping 937 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3989 void _onPoll(_) { | 3996 void _onPoll(_) { |
3990 // Reload metrics and add a sample to each. | 3997 // Reload metrics and add a sample to each. |
3991 for (var metric in metrics) { | 3998 for (var metric in metrics) { |
3992 metric.reload().then((m) { | 3999 metric.reload().then((m) { |
3993 m.addSample(new MetricSample(m.value)); | 4000 m.addSample(new MetricSample(m.value)); |
3994 }); | 4001 }); |
3995 } | 4002 } |
3996 } | 4003 } |
3997 } | 4004 } |
3998 | 4005 |
3999 class Frame extends ServiceObject { | 4006 class Frame extends ServiceObject implements M.Frame { |
4000 @observable int index; | 4007 @observable int index; |
4001 @observable ServiceFunction function; | 4008 @observable ServiceFunction function; |
4002 @observable SourceLocation location; | 4009 @observable SourceLocation location; |
4003 @observable Code code; | 4010 @observable Code code; |
4004 @observable List<ServiceMap> variables = new ObservableList<ServiceMap>(); | 4011 @observable List<ServiceMap> variables = new ObservableList<ServiceMap>(); |
4005 | 4012 |
4006 Frame._empty(ServiceObject owner) : super._empty(owner); | 4013 Frame._empty(ServiceObject owner) : super._empty(owner); |
4007 | 4014 |
4008 void _update(ObservableMap map, bool mapIsRef) { | 4015 void _update(ObservableMap map, bool mapIsRef) { |
4009 assert(!mapIsRef); | 4016 assert(!mapIsRef); |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4124 var v = list[i]; | 4131 var v = list[i]; |
4125 if ((v is ObservableMap) && _isServiceMap(v)) { | 4132 if ((v is ObservableMap) && _isServiceMap(v)) { |
4126 list[i] = owner.getFromMap(v); | 4133 list[i] = owner.getFromMap(v); |
4127 } else if (v is ObservableList) { | 4134 } else if (v is ObservableList) { |
4128 _upgradeObservableList(v, owner); | 4135 _upgradeObservableList(v, owner); |
4129 } else if (v is ObservableMap) { | 4136 } else if (v is ObservableMap) { |
4130 _upgradeObservableMap(v, owner); | 4137 _upgradeObservableMap(v, owner); |
4131 } | 4138 } |
4132 } | 4139 } |
4133 } | 4140 } |
OLD | NEW |