OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2014 Google Inc. All rights reserved. | 2 * Copyright (C) 2014 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 return it->value; | 454 return it->value; |
455 } | 455 } |
456 return ""; | 456 return ""; |
457 } | 457 } |
458 | 458 |
459 DartScriptDebugServer::DartScriptDebugServer() | 459 DartScriptDebugServer::DartScriptDebugServer() |
460 : m_pauseOnExceptionState(DontPauseOnExceptions) | 460 : m_pauseOnExceptionState(DontPauseOnExceptions) |
461 , m_breakpointsActivated(true) | 461 , m_breakpointsActivated(true) |
462 , m_runningNestedMessageLoop(false) | 462 , m_runningNestedMessageLoop(false) |
463 , m_executionState(0) | 463 , m_executionState(0) |
| 464 , m_isPaused(false) |
464 , m_pausedIsolate(0) | 465 , m_pausedIsolate(0) |
465 , m_pausedPage(0) | 466 , m_pausedPage(0) |
466 , m_clientMessageLoop(0) | 467 , m_clientMessageLoop(0) |
467 , m_nextPageId(1) | 468 , m_nextPageId(1) |
468 { | 469 { |
469 } | 470 } |
470 | 471 |
471 DartScriptDebugServer::~DartScriptDebugServer() | 472 DartScriptDebugServer::~DartScriptDebugServer() |
472 { | 473 { |
473 for (DebugDataMap::iterator it = m_pageIdToDebugDataMap.begin(); it != m_pag
eIdToDebugDataMap.end(); ++it) | 474 for (DebugDataMap::iterator it = m_pageIdToDebugDataMap.begin(); it != m_pag
eIdToDebugDataMap.end(); ++it) |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
626 return; | 627 return; |
627 | 628 |
628 // FIXME: determine if this method needs to be implemented for Dart. | 629 // FIXME: determine if this method needs to be implemented for Dart. |
629 } | 630 } |
630 | 631 |
631 void DartScriptDebugServer::continueProgram() | 632 void DartScriptDebugServer::continueProgram() |
632 { | 633 { |
633 if (isPaused()) | 634 if (isPaused()) |
634 quitMessageLoopOnPause(); | 635 quitMessageLoopOnPause(); |
635 m_executionState = 0; | 636 m_executionState = 0; |
| 637 m_isPaused = false; |
636 m_pausedIsolate = 0; | 638 m_pausedIsolate = 0; |
637 } | 639 } |
638 | 640 |
639 void DartScriptDebugServer::stepIntoStatement() | 641 void DartScriptDebugServer::stepIntoStatement() |
640 { | 642 { |
641 ASSERT(isPaused()); | 643 ASSERT(isPaused()); |
642 Dart_SetStepInto(); | 644 Dart_SetStepInto(); |
643 continueProgram(); | 645 continueProgram(); |
644 } | 646 } |
645 | 647 |
646 void DartScriptDebugServer::stepOverStatement() | 648 void DartScriptDebugServer::stepOverStatement() |
647 { | 649 { |
648 ASSERT(isPaused()); | 650 ASSERT(isPaused()); |
649 Dart_SetStepOver(); | 651 Dart_SetStepOver(); |
650 continueProgram(); | 652 continueProgram(); |
651 } | 653 } |
652 | 654 |
653 void DartScriptDebugServer::stepOutOfFunction() | 655 void DartScriptDebugServer::stepOutOfFunction() |
654 { | 656 { |
655 ASSERT(isPaused()); | 657 ASSERT(isPaused()); |
656 Dart_SetStepOut(); | 658 Dart_SetStepOut(); |
657 continueProgram(); | 659 continueProgram(); |
658 } | 660 } |
659 | 661 |
660 bool DartScriptDebugServer::setScriptSource(const String& sourceID, const String
& newContent, bool preview, String* error, RefPtr<TypeBuilder::Debugger::SetScri
ptSourceError>& errorData, StackTrace* newCallFrames, RefPtr<JSONObject>* result
) | 662 bool DartScriptDebugServer::setScriptSource(const String& sourceID, const String
& newContent, bool preview, String* error, RefPtr<TypeBuilder::Debugger::SetScri
ptSourceError>& errorData, StackTraces* newCallFrames, RefPtr<JSONObject>* resul
t) |
661 { | 663 { |
662 *error = "Dart does not support live editing source code yet."; | 664 *error = "Dart does not support live editing source code yet."; |
663 return false; | 665 return false; |
664 } | 666 } |
665 | 667 |
666 bool DartScriptDebugServer::executeSkipPauseRequest(ScriptDebugListener::SkipPau
seRequest request, Dart_StackTrace stackTrace) | 668 bool DartScriptDebugServer::executeSkipPauseRequest(ScriptDebugListener::SkipPau
seRequest request, Dart_StackTrace stackTrace) |
667 { | 669 { |
668 switch (request) { | 670 switch (request) { |
669 case ScriptDebugListener::NoSkip: | 671 case ScriptDebugListener::NoSkip: |
670 return false; | 672 return false; |
671 case ScriptDebugListener::Continue: | 673 case ScriptDebugListener::Continue: |
672 return true; | 674 return true; |
673 case ScriptDebugListener::StepInto: | 675 case ScriptDebugListener::StepInto: |
674 case ScriptDebugListener::StepOut: | 676 case ScriptDebugListener::StepOut: |
675 break; | 677 break; |
676 } | 678 } |
677 ASSERT(0); | 679 ASSERT(0); |
678 // FIXMEDART: actually do something jacobr JACOBR | 680 // FIXMEDART: actually do something jacobr JACOBR |
679 return true; | 681 return true; |
680 } | 682 } |
681 | 683 |
682 int DartScriptDebugServer::frameCount() | 684 int DartScriptDebugServer::frameCount() |
683 { | 685 { |
684 ASSERT(isPaused()); | 686 ASSERT(isPaused()); |
685 intptr_t length = 0; | 687 intptr_t length = 0; |
686 Dart_StackTraceLength(m_executionState, &length); | 688 Dart_StackTraceLength(m_executionState, &length); |
687 return length; | 689 return length; |
688 } | 690 } |
689 | 691 |
690 StackTrace DartScriptDebugServer::currentCallFrames() | 692 StackTraces DartScriptDebugServer::currentCallFrames() |
691 { | 693 { |
692 return StackTrace(m_executionState); | 694 if (!m_executionState) { |
| 695 if (!Dart_CurrentIsolate()) |
| 696 return StackTraces(); |
| 697 ASSERT(!m_isPaused); |
| 698 // We are not paused at a Dart breakpoint but there may be Dart frames |
| 699 // on the call stack. |
| 700 |
| 701 Dart_Handle ALLOW_UNUSED result = Dart_GetStackTrace(&m_executionState); |
| 702 ASSERT(!Dart_IsError(result)); |
| 703 if (!m_executionState) |
| 704 return StackTraces(); |
| 705 intptr_t length = 0; |
| 706 Dart_StackTraceLength(m_executionState, &length); |
| 707 if (!length) { |
| 708 ASSERT_NOT_REACHED(); |
| 709 m_executionState = 0; |
| 710 return StackTraces(); |
| 711 } |
| 712 } |
| 713 return StackTraces(StackTrace(m_executionState), DartUtilities::currentScrip
tState()); |
693 } | 714 } |
694 | 715 |
695 StackTrace DartScriptDebugServer::currentCallFramesForAsyncStack() | 716 StackTraces DartScriptDebugServer::currentCallFramesForAsyncStack() |
696 { | 717 { |
697 // FIXMEDART: implement propertly. These are the regular not Async call fram
es. | 718 // FIXMEDART: implement propertly. These are the regular not Async call fram
es. |
698 return StackTrace(m_executionState); | 719 return currentCallFrames(); |
699 } | 720 } |
700 | 721 |
701 bool DartScriptDebugServer::isPaused() | 722 bool DartScriptDebugServer::isPaused() |
702 { | 723 { |
703 return !!m_executionState; | 724 return m_isPaused; |
704 } | 725 } |
705 | 726 |
706 void DartScriptDebugServer::clearCompiledScripts() | 727 void DartScriptDebugServer::clearCompiledScripts() |
707 { | 728 { |
708 // FIXMEDART: is this meaningful for Dart? | 729 // FIXMEDART: is this meaningful for Dart? |
709 // Currently tracking what scripts have been compiled is handled by a | 730 // Currently tracking what scripts have been compiled is handled by a |
710 // different class. | 731 // different class. |
711 } | 732 } |
712 | 733 |
713 void DartScriptDebugServer::setPreprocessorSource(const String& preprocessorSour
ce) | 734 void DartScriptDebugServer::setPreprocessorSource(const String& preprocessorSour
ce) |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
954 | 975 |
955 DartPageDebug* DartScriptDebugServer::lookupPageDebugForCurrentIsolate() | 976 DartPageDebug* DartScriptDebugServer::lookupPageDebugForCurrentIsolate() |
956 { | 977 { |
957 Page* page = DartUtilities::domWindowForCurrentIsolate()->document()->page()
; | 978 Page* page = DartUtilities::domWindowForCurrentIsolate()->document()->page()
; |
958 return lookupPageDebug(page); | 979 return lookupPageDebug(page); |
959 } | 980 } |
960 | 981 |
961 void DartScriptDebugServer::handleProgramBreak(Dart_Isolate isolate, Dart_StackT
race stackTrace, intptr_t dartBreakpointId, Dart_Handle exception, const Dart_Co
deLocation& location) | 982 void DartScriptDebugServer::handleProgramBreak(Dart_Isolate isolate, Dart_StackT
race stackTrace, intptr_t dartBreakpointId, Dart_Handle exception, const Dart_Co
deLocation& location) |
962 { | 983 { |
963 ASSERT(isolate == Dart_CurrentIsolate()); | 984 ASSERT(isolate == Dart_CurrentIsolate()); |
| 985 |
964 // Don't allow nested breaks. | 986 // Don't allow nested breaks. |
965 if (isAnyScriptPaused()) | 987 if (isAnyScriptPaused()) |
966 return; | 988 return; |
967 | 989 |
968 DartPageDebug* pageDebug = lookupPageDebugForCurrentIsolate(); | 990 DartPageDebug* pageDebug = lookupPageDebugForCurrentIsolate(); |
969 if (!pageDebug) | 991 if (!pageDebug) |
970 return; | 992 return; |
971 ScriptDebugListener* listener = pageDebug->listener(); | 993 ScriptDebugListener* listener = pageDebug->listener(); |
972 | 994 |
973 if (!listener) | 995 if (!listener) |
974 return; | 996 return; |
975 | 997 |
976 // Required as some Dart code executes outside of a valid V8 scope when | 998 // Required as some Dart code executes outside of a valid V8 scope when |
977 // the program is paused due to interrupting a Dart isolate. | 999 // the program is paused due to interrupting a Dart isolate. |
978 V8Scope v8Scope(DartDOMData::current()); | 1000 V8Scope v8Scope(DartDOMData::current()); |
979 | 1001 |
980 Vector<String> breakpointIds; | 1002 Vector<String> breakpointIds; |
981 breakpointIds.append(pageDebug->lookupBreakpointId(dartBreakpointId)); | 1003 breakpointIds.append(pageDebug->lookupBreakpointId(dartBreakpointId)); |
982 m_executionState = stackTrace; | 1004 m_executionState = stackTrace; |
| 1005 m_isPaused = true; |
983 m_pausedIsolate = isolate; | 1006 m_pausedIsolate = isolate; |
984 DartScriptState* scriptState = DartUtilities::currentScriptState(); | 1007 DartScriptState* scriptState = DartUtilities::currentScriptState(); |
985 ScriptDebugListener::SkipPauseRequest result = listener->didPause(scriptStat
e, currentCallFrames(), exception ? DartUtilities::dartToScriptValue(exception)
: ScriptValue(), breakpointIds); | 1008 ScriptDebugListener::SkipPauseRequest result = listener->didPause(scriptStat
e, exception ? DartUtilities::dartToScriptValue(exception) : ScriptValue(), brea
kpointIds); |
986 | 1009 |
987 if (result == ScriptDebugListener::NoSkip) { | 1010 if (result == ScriptDebugListener::NoSkip) { |
988 m_runningNestedMessageLoop = true; | 1011 m_runningNestedMessageLoop = true; |
989 runMessageLoopOnPause(isolate); | 1012 runMessageLoopOnPause(isolate); |
990 m_runningNestedMessageLoop = false; | 1013 m_runningNestedMessageLoop = false; |
991 } | 1014 } |
992 if (result == ScriptDebugListener::StepInto) { | 1015 if (result == ScriptDebugListener::StepInto) { |
993 Dart_SetStepInto(); | 1016 Dart_SetStepInto(); |
994 } else if (result == ScriptDebugListener::StepOut) { | 1017 } else if (result == ScriptDebugListener::StepOut) { |
995 Dart_SetStepOut(); | 1018 Dart_SetStepOut(); |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1154 } | 1177 } |
1155 | 1178 |
1156 void UnifiedScriptDebugServer::setPauseOnExceptionsState(ScriptDebugServer::Paus
eOnExceptionsState pauseOnExceptionsState) | 1179 void UnifiedScriptDebugServer::setPauseOnExceptionsState(ScriptDebugServer::Paus
eOnExceptionsState pauseOnExceptionsState) |
1157 { | 1180 { |
1158 m_dart->setPauseOnExceptionsState(pauseOnExceptionsState); | 1181 m_dart->setPauseOnExceptionsState(pauseOnExceptionsState); |
1159 m_v8->setPauseOnExceptionsState(pauseOnExceptionsState); | 1182 m_v8->setPauseOnExceptionsState(pauseOnExceptionsState); |
1160 } | 1183 } |
1161 | 1184 |
1162 void UnifiedScriptDebugServer::setPauseOnNextStatement(bool pause) | 1185 void UnifiedScriptDebugServer::setPauseOnNextStatement(bool pause) |
1163 { | 1186 { |
1164 if (isPaused()) { | 1187 if (isPaused()) |
1165 return; | 1188 return; |
1166 } | |
1167 m_v8->setPauseOnNextStatement(pause); | 1189 m_v8->setPauseOnNextStatement(pause); |
1168 m_dart->setPauseOnNextStatement(pause); | 1190 m_dart->setPauseOnNextStatement(pause); |
1169 } | 1191 } |
1170 | 1192 |
1171 bool UnifiedScriptDebugServer::canBreakProgram() | 1193 bool UnifiedScriptDebugServer::canBreakProgram() |
1172 { | 1194 { |
1173 return m_v8->canBreakProgram() || m_dart->canBreakProgram(); | 1195 return m_v8->canBreakProgram() || m_dart->canBreakProgram(); |
1174 } | 1196 } |
1175 | 1197 |
1176 void UnifiedScriptDebugServer::breakProgram() | 1198 void UnifiedScriptDebugServer::breakProgram() |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1216 // FIXMEDART: find a cleaner solution. | 1238 // FIXMEDART: find a cleaner solution. |
1217 return sourceID.startsWith(String("{\"dartScript")); | 1239 return sourceID.startsWith(String("{\"dartScript")); |
1218 } | 1240 } |
1219 | 1241 |
1220 bool UnifiedScriptDebugServer::isDartBreakpointId(const String& breakpointId) | 1242 bool UnifiedScriptDebugServer::isDartBreakpointId(const String& breakpointId) |
1221 { | 1243 { |
1222 // FIXMEDART: find a cleaner solution. | 1244 // FIXMEDART: find a cleaner solution. |
1223 return breakpointId.startsWith(String("{\"dartBreakpoint")); | 1245 return breakpointId.startsWith(String("{\"dartBreakpoint")); |
1224 } | 1246 } |
1225 | 1247 |
1226 bool UnifiedScriptDebugServer::setScriptSource(const String& sourceID, const Str
ing& newContent, bool preview, String* error, RefPtr<TypeBuilder::Debugger::SetS
criptSourceError>& errorBuilder, StackTrace* newCallFrames, RefPtr<JSONObject>*
result) | 1248 bool UnifiedScriptDebugServer::setScriptSource(const String& sourceID, const Str
ing& newContent, bool preview, String* error, RefPtr<TypeBuilder::Debugger::SetS
criptSourceError>& errorBuilder, StackTraces* newCallFrames, RefPtr<JSONObject>*
result) |
1227 { | 1249 { |
1228 if (isDartSourceID(sourceID)) | 1250 if (isDartSourceID(sourceID)) |
1229 return m_dart->setScriptSource(sourceID, newContent, preview, error, err
orBuilder, newCallFrames, result); | 1251 return m_dart->setScriptSource(sourceID, newContent, preview, error, err
orBuilder, newCallFrames, result); |
1230 return m_v8->setScriptSource(sourceID, newContent, preview, error, errorBuil
der, newCallFrames, result); | 1252 return m_v8->setScriptSource(sourceID, newContent, preview, error, errorBuil
der, newCallFrames, result); |
1231 } | 1253 } |
1232 | 1254 |
1233 int UnifiedScriptDebugServer::frameCount() | 1255 int UnifiedScriptDebugServer::frameCount() |
1234 { | 1256 { |
1235 // FIXMEDART: Implement cases where both JS and Dart are paused correctly. | 1257 // FIXMEDART: Implement cases where both JS and Dart are paused correctly. |
1236 if (m_v8->isPaused()) { | 1258 if (m_v8->isPaused()) { |
1237 return m_v8->frameCount(); | 1259 return m_v8->frameCount(); |
1238 } | 1260 } |
1239 return m_dart->frameCount(); | 1261 return m_dart->frameCount(); |
1240 } | 1262 } |
1241 | 1263 |
1242 | 1264 StackTraces UnifiedScriptDebugServer::currentCallFrames() |
1243 StackTrace UnifiedScriptDebugServer::currentCallFrames() | |
1244 { | 1265 { |
1245 // FIXMEDART: we need to figure out how to interleave stack traces where pos
sible. | 1266 StackTraces traces = m_v8->currentCallFrames(); |
1246 StackTrace v8StackTrace = m_v8->currentCallFrames(); | 1267 traces.add(m_dart->currentCallFrames()); |
1247 if (!v8StackTrace.isNull()) | 1268 return traces; |
1248 return v8StackTrace; | |
1249 return m_dart->currentCallFrames(); | |
1250 } | 1269 } |
1251 | 1270 |
1252 StackTrace UnifiedScriptDebugServer::currentCallFramesForAsyncStack() | 1271 StackTraces UnifiedScriptDebugServer::currentCallFramesForAsyncStack() |
1253 { | 1272 { |
1254 // FIXMEDART: we need to figure out how to interleave stack traces where pos
sible. | 1273 StackTraces traces = m_v8->currentCallFramesForAsyncStack(); |
1255 StackTrace v8StackTrace = m_v8->currentCallFramesForAsyncStack(); | 1274 traces.add(m_dart->currentCallFramesForAsyncStack()); |
1256 if (!v8StackTrace.isNull()) | 1275 return traces; |
1257 return v8StackTrace; | |
1258 return m_dart->currentCallFramesForAsyncStack(); | |
1259 } | 1276 } |
1260 | 1277 |
1261 | |
1262 bool UnifiedScriptDebugServer::isPaused() | 1278 bool UnifiedScriptDebugServer::isPaused() |
1263 { | 1279 { |
1264 return m_v8->isPaused() || m_dart->isPaused(); | 1280 return m_v8->isPaused() || m_dart->isPaused(); |
1265 } | 1281 } |
1266 | 1282 |
1267 bool UnifiedScriptDebugServer::runningNestedMessageLoop() | 1283 bool UnifiedScriptDebugServer::runningNestedMessageLoop() |
1268 { | 1284 { |
1269 return m_dart->runningNestedMessageLoop() || m_v8->runningNestedMessageLoop(
); | 1285 return m_dart->runningNestedMessageLoop() || m_v8->runningNestedMessageLoop(
); |
1270 } | 1286 } |
1271 | 1287 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1336 MessageQueue<ScriptDebugServer::Task>& tasks = debugTaskQueue(); | 1352 MessageQueue<ScriptDebugServer::Task>& tasks = debugTaskQueue(); |
1337 tasks.append(task); | 1353 tasks.append(task); |
1338 // The first VM interrupt method triggered will drain the task queue. | 1354 // The first VM interrupt method triggered will drain the task queue. |
1339 // FIXMEDART: refactor the V8 code to have an interruptAndRunAllTasks | 1355 // FIXMEDART: refactor the V8 code to have an interruptAndRunAllTasks |
1340 // method. | 1356 // method. |
1341 PageScriptDebugServer::interruptAndRun(adoptPtr(new DrainQueueTask(&tasks)))
; | 1357 PageScriptDebugServer::interruptAndRun(adoptPtr(new DrainQueueTask(&tasks)))
; |
1342 DartScriptDebugServer::interruptAndRunAllTasks(); | 1358 DartScriptDebugServer::interruptAndRunAllTasks(); |
1343 } | 1359 } |
1344 | 1360 |
1345 } | 1361 } |
OLD | NEW |