OLD | NEW |
| (Empty) |
1 // Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file | |
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.md file. | |
4 | |
5 library fletch.debug_state; | |
6 | |
7 import 'bytecodes.dart'; | |
8 import 'fletch_system.dart'; | |
9 import 'incremental/fletchc_incremental.dart'; | |
10 import 'vm_session.dart'; | |
11 import 'src/debug_info.dart'; | |
12 import 'src/class_debug_info.dart'; | |
13 | |
14 import 'vm_commands.dart' show | |
15 DartValue, | |
16 InstanceStructure; | |
17 | |
18 import 'src/hub/session_manager.dart' show | |
19 SessionState; | |
20 | |
21 part 'back_trace.dart'; | |
22 | |
23 /// A representation of a remote object. | |
24 abstract class RemoteObject { | |
25 String name; | |
26 | |
27 RemoteObject(this.name); | |
28 } | |
29 | |
30 /// A representation of a remote instance. | |
31 class RemoteInstance extends RemoteObject { | |
32 /// An [InstanceStructure] describing the remote instance. | |
33 final InstanceStructure instance; | |
34 | |
35 /// The fields as [DartValue]s of the remote instance. | |
36 final List<DartValue> fields; | |
37 | |
38 RemoteInstance(this.instance, this.fields, {String name}) : super(name); | |
39 } | |
40 | |
41 /// A representation of a remote primitive value (i.e. used for non-instances). | |
42 class RemoteValue extends RemoteObject { | |
43 /// A [DartValue] describing the remote object. | |
44 final DartValue value; | |
45 | |
46 RemoteValue(this.value, {String name}) : super(name); | |
47 } | |
48 | |
49 class Breakpoint { | |
50 final String methodName; | |
51 final int bytecodeIndex; | |
52 final int id; | |
53 Breakpoint(this.methodName, this.bytecodeIndex, this.id); | |
54 String toString() => "id: '$id' method: '$methodName' " | |
55 "bytecode index: '$bytecodeIndex'"; | |
56 } | |
57 | |
58 class DebugState { | |
59 final Session session; | |
60 | |
61 final Map<int, Breakpoint> breakpoints = <int, Breakpoint>{}; | |
62 final Map<FletchFunction, DebugInfo> debugInfos = | |
63 <FletchFunction, DebugInfo>{}; | |
64 final Map<FletchClass, ClassDebugInfo> classDebugInfos = | |
65 <FletchClass, ClassDebugInfo>{}; | |
66 | |
67 bool showInternalFrames = false; | |
68 bool verbose = true; | |
69 BackTraceFrame _topFrame; | |
70 RemoteObject currentUncaughtException; | |
71 BackTrace _currentBackTrace; | |
72 int currentFrame = 0; | |
73 SourceLocation _currentLocation; | |
74 | |
75 DebugState(this.session); | |
76 | |
77 void reset() { | |
78 _topFrame = null; | |
79 currentUncaughtException = null; | |
80 _currentBackTrace = null; | |
81 _currentLocation = null; | |
82 currentFrame = 0; | |
83 } | |
84 | |
85 int get actualCurrentFrameNumber { | |
86 return currentBackTrace.actualFrameNumber(currentFrame); | |
87 } | |
88 | |
89 ScopeInfo get currentScopeInfo { | |
90 return currentBackTrace.scopeInfo(currentFrame); | |
91 } | |
92 | |
93 SourceLocation get currentLocation => _currentLocation; | |
94 | |
95 BackTrace get currentBackTrace => _currentBackTrace; | |
96 | |
97 void set currentBackTrace(BackTrace backTrace) { | |
98 _currentLocation = backTrace.sourceLocation(); | |
99 _topFrame = backTrace.frames[0]; | |
100 _currentBackTrace = backTrace; | |
101 } | |
102 | |
103 BackTraceFrame get topFrame => _topFrame; | |
104 | |
105 void set topFrame(BackTraceFrame frame) { | |
106 _currentLocation = frame.sourceLocation(); | |
107 _topFrame = frame; | |
108 } | |
109 | |
110 DebugInfo getDebugInfo(FletchFunction function) { | |
111 return debugInfos.putIfAbsent(function, () { | |
112 return session.compiler.createDebugInfo(function, session.fletchSystem); | |
113 }); | |
114 } | |
115 | |
116 ClassDebugInfo getClassDebugInfo(FletchClass klass) { | |
117 return classDebugInfos.putIfAbsent(klass, () { | |
118 return session.compiler.createClassDebugInfo(klass); | |
119 }); | |
120 } | |
121 | |
122 String lookupFieldName(FletchClass klass, int field) { | |
123 while (field < klass.superclassFields) { | |
124 klass = session.fletchSystem.lookupClassById(klass.superclassId); | |
125 } | |
126 return getClassDebugInfo(klass).fieldNames[field - klass.superclassFields]; | |
127 } | |
128 | |
129 bool atLocation(SourceLocation previous) { | |
130 return (!topFrame.isVisible || | |
131 currentLocation == null || | |
132 currentLocation.isSameSourceLevelLocationAs(previous) || | |
133 currentLocation.node == null); | |
134 } | |
135 | |
136 SourceLocation sourceLocationForFrame(int frame) { | |
137 return currentBackTrace.frames[frame].sourceLocation(); | |
138 } | |
139 } | |
OLD | NEW |