OLD | NEW |
1 // Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE.md file. |
4 | 4 |
5 library dartino_compiler.verbs.debug_verb; | 5 library dartino_compiler.verbs.debug_verb; |
6 | 6 |
7 import 'dart:core' hide | 7 import 'dart:core' hide |
8 StackTrace; | 8 StackTrace; |
9 | 9 |
10 import 'infrastructure.dart'; | 10 import 'infrastructure.dart'; |
(...skipping 27 matching lines...) Expand all Loading... |
38 import '../hub/client_commands.dart' show | 38 import '../hub/client_commands.dart' show |
39 ClientCommandCode; | 39 ClientCommandCode; |
40 | 40 |
41 import 'package:dartino_compiler/debug_state.dart' show | 41 import 'package:dartino_compiler/debug_state.dart' show |
42 Breakpoint; | 42 Breakpoint; |
43 | 43 |
44 import '../../debug_state.dart' show | 44 import '../../debug_state.dart' show |
45 RemoteObject, | 45 RemoteObject, |
46 BackTrace; | 46 BackTrace; |
47 | 47 |
| 48 import '../debug_service_protocol.dart' show |
| 49 DebugServer; |
| 50 |
48 import '../../vm_commands.dart' show | 51 import '../../vm_commands.dart' show |
49 VmCommand; | 52 VmCommand; |
50 | 53 |
51 import '../../cli_debugger.dart' show | 54 import '../../cli_debugger.dart' show |
52 CommandLineDebugger; | 55 CommandLineDebugger; |
53 | 56 |
54 const Action debugAction = | 57 const Action debugAction = |
55 const Action( | 58 const Action( |
56 debug, | 59 debug, |
57 debugDocumentation, | 60 debugDocumentation, |
(...skipping 10 matching lines...) Expand all Loading... |
68 TargetKind.FIBERS, | 71 TargetKind.FIBERS, |
69 TargetKind.FILE, | 72 TargetKind.FILE, |
70 TargetKind.FINISH, | 73 TargetKind.FINISH, |
71 TargetKind.FRAME, | 74 TargetKind.FRAME, |
72 TargetKind.LIST, | 75 TargetKind.LIST, |
73 TargetKind.LIST_BREAKPOINTS, | 76 TargetKind.LIST_BREAKPOINTS, |
74 TargetKind.PRINT, | 77 TargetKind.PRINT, |
75 TargetKind.PRINT_ALL, | 78 TargetKind.PRINT_ALL, |
76 TargetKind.RESTART, | 79 TargetKind.RESTART, |
77 TargetKind.RUN_TO_MAIN, | 80 TargetKind.RUN_TO_MAIN, |
| 81 TargetKind.SERVE, |
78 TargetKind.STEP, | 82 TargetKind.STEP, |
79 TargetKind.STEP_BYTECODE, | 83 TargetKind.STEP_BYTECODE, |
80 TargetKind.STEP_OVER, | 84 TargetKind.STEP_OVER, |
81 TargetKind.STEP_OVER_BYTECODE, | 85 TargetKind.STEP_OVER_BYTECODE, |
82 TargetKind.TOGGLE, | 86 TargetKind.TOGGLE, |
83 ]); | 87 ]); |
84 | 88 |
85 const int sigQuit = 3; | 89 const int sigQuit = 3; |
86 | 90 |
87 Future debug(AnalyzedSentence sentence, VerbContext context) async { | 91 Future debug(AnalyzedSentence sentence, VerbContext context) async { |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 debugTask = new DebuggerTask(TargetKind.PRINT.index, base, | 171 debugTask = new DebuggerTask(TargetKind.PRINT.index, base, |
168 argument: sentence.targetName); | 172 argument: sentence.targetName); |
169 break; | 173 break; |
170 case TargetKind.PRINT_ALL: | 174 case TargetKind.PRINT_ALL: |
171 debugTask = new DebuggerTask(TargetKind.PRINT_ALL.index, base); | 175 debugTask = new DebuggerTask(TargetKind.PRINT_ALL.index, base); |
172 break; | 176 break; |
173 case TargetKind.TOGGLE: | 177 case TargetKind.TOGGLE: |
174 debugTask = new DebuggerTask(TargetKind.TOGGLE.index, base, | 178 debugTask = new DebuggerTask(TargetKind.TOGGLE.index, base, |
175 argument: sentence.targetName); | 179 argument: sentence.targetName); |
176 break; | 180 break; |
| 181 case TargetKind.SERVE: |
| 182 debugTask = new DebuggerTask(TargetKind.SERVE.index, base, |
| 183 argument: sentence.targetUri, snapshotLocation: sentence.withUri); |
| 184 break; |
177 case TargetKind.FILE: | 185 case TargetKind.FILE: |
178 debugTask = new DebuggerTask(TargetKind.FILE.index, base, | 186 debugTask = new DebuggerTask(TargetKind.FILE.index, base, |
179 argument: sentence.targetUri, snapshotLocation: sentence.withUri); | 187 argument: sentence.targetUri, snapshotLocation: sentence.withUri); |
180 break; | 188 break; |
| 189 |
181 default: | 190 default: |
182 throwInternalError("Unimplemented ${sentence.target}"); | 191 throwInternalError("Unimplemented ${sentence.target}"); |
183 } | 192 } |
184 | 193 |
185 return context.performTaskInWorker(combineTasks(attachTask, debugTask)); | 194 return context.performTaskInWorker(combineTasks(attachTask, debugTask)); |
186 } | 195 } |
187 | 196 |
188 // Returns a debug client event handler that is bound to the current session. | 197 // Returns a debug client event handler that is bound to the current session. |
189 ClientEventHandler debugClientEventHandler( | 198 ClientEventHandler debugClientEventHandler( |
190 SessionState state, | 199 SessionState state, |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 true, | 278 true, |
270 () => interactiveDebuggerTask( | 279 () => interactiveDebuggerTask( |
271 state, | 280 state, |
272 base, | 281 base, |
273 stdinController, | 282 stdinController, |
274 snapshotLocation: snapshotLocation), | 283 snapshotLocation: snapshotLocation), |
275 eventHandler: | 284 eventHandler: |
276 debugClientEventHandler(state, commandIterator, stdinController)); | 285 debugClientEventHandler(state, commandIterator, stdinController)); |
277 } | 286 } |
278 | 287 |
| 288 Future<int> serveDebuggerTask( |
| 289 CommandSender commandSender, |
| 290 StreamIterator<ClientCommand> commandIterator, |
| 291 SessionState state, |
| 292 Uri script, |
| 293 Uri base, |
| 294 {Uri snapshotLocation}) { |
| 295 |
| 296 return compileAndAttachToVmThen( |
| 297 commandSender, |
| 298 commandIterator, |
| 299 state, |
| 300 script, |
| 301 base, |
| 302 true, |
| 303 () => new DebugServer().serveSingleShot( |
| 304 state, snapshotLocation: snapshotLocation)); |
| 305 } |
| 306 |
279 Future<int> interactiveDebuggerTask( | 307 Future<int> interactiveDebuggerTask( |
280 SessionState state, | 308 SessionState state, |
281 Uri base, | 309 Uri base, |
282 StreamController stdinController, | 310 StreamController stdinController, |
283 {Uri snapshotLocation}) async { | 311 {Uri snapshotLocation}) async { |
284 DartinoVmContext vmContext = state.vmContext; | 312 DartinoVmContext vmContext = state.vmContext; |
285 if (vmContext == null) { | 313 if (vmContext == null) { |
286 throwFatalError(DiagnosticKind.attachToVmBeforeRun); | 314 throwFatalError(DiagnosticKind.attachToVmBeforeRun); |
287 } | 315 } |
288 List<DartinoDelta> compilationResult = state.compilationResults; | 316 List<DartinoDelta> compilationResult = state.compilationResults; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 case TargetKind.STEP_OVER_BYTECODE: | 383 case TargetKind.STEP_OVER_BYTECODE: |
356 return stepOverBytecodeDebuggerTask( | 384 return stepOverBytecodeDebuggerTask( |
357 commandSender, SessionState.current); | 385 commandSender, SessionState.current); |
358 case TargetKind.PRINT: | 386 case TargetKind.PRINT: |
359 return printDebuggerTask(commandSender, SessionState.current, argument); | 387 return printDebuggerTask(commandSender, SessionState.current, argument); |
360 case TargetKind.PRINT_ALL: | 388 case TargetKind.PRINT_ALL: |
361 return printAllDebuggerTask(commandSender, SessionState.current); | 389 return printAllDebuggerTask(commandSender, SessionState.current); |
362 case TargetKind.TOGGLE: | 390 case TargetKind.TOGGLE: |
363 return toggleDebuggerTask( | 391 return toggleDebuggerTask( |
364 commandSender, SessionState.current, argument); | 392 commandSender, SessionState.current, argument); |
| 393 case TargetKind.SERVE: |
| 394 return serveDebuggerTask( |
| 395 commandSender, |
| 396 commandIterator, |
| 397 SessionState.current, |
| 398 argument, |
| 399 base, |
| 400 snapshotLocation: snapshotLocation); |
365 case TargetKind.FILE: | 401 case TargetKind.FILE: |
366 return runInteractiveDebuggerTask( | 402 return runInteractiveDebuggerTask( |
367 commandSender, commandIterator, SessionState.current, argument, | 403 commandSender, commandIterator, SessionState.current, argument, |
368 base, snapshotLocation: snapshotLocation); | 404 base, snapshotLocation: snapshotLocation); |
369 | |
370 default: | 405 default: |
371 throwInternalError("Unimplemented ${TargetKind.values[kind]}"); | 406 throwInternalError("Unimplemented ${TargetKind.values[kind]}"); |
372 } | 407 } |
373 return null; | 408 return null; |
374 } | 409 } |
375 } | 410 } |
376 | 411 |
377 DartinoVmContext attachToSession( | 412 DartinoVmContext attachToSession( |
378 SessionState state, CommandSender commandSender) { | 413 SessionState state, CommandSender commandSender) { |
379 DartinoVmContext vmContext = state.vmContext; | 414 DartinoVmContext vmContext = state.vmContext; |
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
753 | 788 |
754 if (argument != 'internal') { | 789 if (argument != 'internal') { |
755 // TODO(ager, lukechurch): Fix error reporting. | 790 // TODO(ager, lukechurch): Fix error reporting. |
756 throwInternalError("Invalid argument to toggle. " | 791 throwInternalError("Invalid argument to toggle. " |
757 "Valid arguments: 'internal'."); | 792 "Valid arguments: 'internal'."); |
758 } | 793 } |
759 await vmContext.toggleInternal(); | 794 await vmContext.toggleInternal(); |
760 | 795 |
761 return 0; | 796 return 0; |
762 } | 797 } |
OLD | NEW |