| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 #include "include/dart_debugger_api.h" | 5 #include "include/dart_debugger_api.h" |
| 6 | 6 |
| 7 #include "vm/dart_api_impl.h" | 7 #include "vm/dart_api_impl.h" |
| 8 #include "vm/dart_api_state.h" | 8 #include "vm/dart_api_state.h" |
| 9 #include "vm/debugger.h" | 9 #include "vm/debugger.h" |
| 10 #include "vm/isolate.h" | 10 #include "vm/isolate.h" |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 static Dart_ExceptionThrownHandler* exc_thrown_handler = NULL; | 104 static Dart_ExceptionThrownHandler* exc_thrown_handler = NULL; |
| 105 static Dart_IsolateEventHandler* isolate_event_handler = NULL; | 105 static Dart_IsolateEventHandler* isolate_event_handler = NULL; |
| 106 | 106 |
| 107 static Dart_BreakpointHandler* legacy_bp_handler = NULL; | 107 static Dart_BreakpointHandler* legacy_bp_handler = NULL; |
| 108 | 108 |
| 109 | 109 |
| 110 static void DebuggerEventHandler(Debugger::DebuggerEvent* event) { | 110 static void DebuggerEventHandler(Debugger::DebuggerEvent* event) { |
| 111 Isolate* isolate = Isolate::Current(); | 111 Isolate* isolate = Isolate::Current(); |
| 112 ASSERT(isolate != NULL); | 112 ASSERT(isolate != NULL); |
| 113 ASSERT(isolate->debugger() != NULL); | 113 ASSERT(isolate->debugger() != NULL); |
| 114 Dart_EnterScope(); |
| 114 Dart_IsolateId isolate_id = isolate->debugger()->GetIsolateId(); | 115 Dart_IsolateId isolate_id = isolate->debugger()->GetIsolateId(); |
| 115 if (event->type == Debugger::kBreakpointReached) { | 116 if (event->type == Debugger::kBreakpointReached) { |
| 116 if (legacy_bp_handler != NULL) { | 117 if (legacy_bp_handler != NULL) { |
| 117 Dart_StackTrace stack_trace = | 118 Dart_StackTrace stack_trace = |
| 118 reinterpret_cast<Dart_StackTrace>(isolate->debugger()->StackTrace()); | 119 reinterpret_cast<Dart_StackTrace>(isolate->debugger()->StackTrace()); |
| 119 (*legacy_bp_handler)(isolate_id, NULL, stack_trace); | 120 (*legacy_bp_handler)(isolate_id, NULL, stack_trace); |
| 120 return; | 121 } else if (paused_event_handler != NULL) { |
| 122 Dart_CodeLocation location; |
| 123 ActivationFrame* top_frame = event->top_frame; |
| 124 location.script_url = Api::NewHandle(isolate, top_frame->SourceUrl()); |
| 125 const Library& lib = Library::Handle(top_frame->Library()); |
| 126 location.library_id = lib.index(); |
| 127 location.token_pos = top_frame->TokenPos(); |
| 128 (*paused_event_handler)(isolate_id, location); |
| 121 } | 129 } |
| 122 if (paused_event_handler == NULL) { | 130 } else if (event->type == Debugger::kBreakpointResolved) { |
| 123 return; | 131 if (bp_resolved_handler != NULL) { |
| 132 SourceBreakpoint* bpt = event->breakpoint; |
| 133 ASSERT(bpt != NULL); |
| 134 Dart_CodeLocation location; |
| 135 Library& library = Library::Handle(isolate); |
| 136 Script& script = Script::Handle(isolate); |
| 137 intptr_t token_pos; |
| 138 bpt->GetCodeLocation(&library, &script, &token_pos); |
| 139 location.script_url = Api::NewHandle(isolate, script.url()); |
| 140 location.library_id = library.index(); |
| 141 location.token_pos = token_pos; |
| 142 (*bp_resolved_handler)(isolate_id, bpt->id(), location); |
| 124 } | 143 } |
| 125 Dart_CodeLocation location; | 144 } else if (event->type == Debugger::kExceptionThrown) { |
| 126 ActivationFrame* top_frame = event->top_frame; | 145 if (exc_thrown_handler != NULL) { |
| 127 location.script_url = Api::NewHandle(isolate, top_frame->SourceUrl()); | 146 Dart_Handle exception = Api::NewHandle(isolate, event->exception->raw()); |
| 128 const Library& lib = Library::Handle(top_frame->Library()); | 147 Dart_StackTrace trace = |
| 129 location.library_id = lib.index(); | 148 reinterpret_cast<Dart_StackTrace>(isolate->debugger()->StackTrace()); |
| 130 location.token_pos = top_frame->TokenPos(); | 149 (*exc_thrown_handler)(isolate_id, exception, trace); |
| 131 (*paused_event_handler)(isolate_id, location); | |
| 132 } else if (event->type == Debugger::kBreakpointResolved) { | |
| 133 if (bp_resolved_handler == NULL) { | |
| 134 return; | |
| 135 } | 150 } |
| 136 SourceBreakpoint* bpt = event->breakpoint; | |
| 137 ASSERT(bpt != NULL); | |
| 138 Dart_CodeLocation location; | |
| 139 Library& library = Library::Handle(isolate); | |
| 140 Script& script = Script::Handle(isolate); | |
| 141 intptr_t token_pos; | |
| 142 bpt->GetCodeLocation(&library, &script, &token_pos); | |
| 143 location.script_url = Api::NewHandle(isolate, script.url()); | |
| 144 location.library_id = library.index(); | |
| 145 location.token_pos = token_pos; | |
| 146 (*bp_resolved_handler)(isolate_id, bpt->id(), location); | |
| 147 } else if (event->type == Debugger::kExceptionThrown) { | |
| 148 if (exc_thrown_handler == NULL) { | |
| 149 return; | |
| 150 } | |
| 151 Dart_Handle exception = Api::NewHandle(isolate, event->exception->raw()); | |
| 152 Dart_StackTrace trace = | |
| 153 reinterpret_cast<Dart_StackTrace>(isolate->debugger()->StackTrace()); | |
| 154 (*exc_thrown_handler)(isolate_id, exception, trace); | |
| 155 } else if (event->type == Debugger::kIsolateCreated) { | 151 } else if (event->type == Debugger::kIsolateCreated) { |
| 156 if (isolate_event_handler != NULL) { | 152 if (isolate_event_handler != NULL) { |
| 157 (*isolate_event_handler)(event->isolate_id, kCreated); | 153 (*isolate_event_handler)(event->isolate_id, kCreated); |
| 158 } | 154 } |
| 159 } else if (event->type == Debugger::kIsolateInterrupted) { | 155 } else if (event->type == Debugger::kIsolateInterrupted) { |
| 160 if (isolate_event_handler != NULL) { | 156 if (isolate_event_handler != NULL) { |
| 161 (*isolate_event_handler)(event->isolate_id, kInterrupted); | 157 (*isolate_event_handler)(event->isolate_id, kInterrupted); |
| 162 } | 158 } |
| 163 } else if (event->type == Debugger::kIsolateShutdown) { | 159 } else if (event->type == Debugger::kIsolateShutdown) { |
| 164 if (isolate_event_handler != NULL) { | 160 if (isolate_event_handler != NULL) { |
| 165 (*isolate_event_handler)(event->isolate_id, kShutdown); | 161 (*isolate_event_handler)(event->isolate_id, kShutdown); |
| 166 } | 162 } |
| 167 } else { | 163 } else { |
| 168 UNIMPLEMENTED(); | 164 UNIMPLEMENTED(); |
| 169 } | 165 } |
| 166 Dart_ExitScope(); |
| 170 } | 167 } |
| 171 | 168 |
| 172 | 169 |
| 173 DART_EXPORT void Dart_SetBreakpointHandler(Dart_BreakpointHandler bp_handler) { | 170 DART_EXPORT void Dart_SetBreakpointHandler(Dart_BreakpointHandler bp_handler) { |
| 174 legacy_bp_handler = bp_handler; | 171 legacy_bp_handler = bp_handler; |
| 175 Debugger::SetEventHandler(DebuggerEventHandler); | 172 Debugger::SetEventHandler(DebuggerEventHandler); |
| 176 } | 173 } |
| 177 | 174 |
| 178 | 175 |
| 179 DART_EXPORT void Dart_SetPausedEventHandler(Dart_PausedEventHandler handler) { | 176 DART_EXPORT void Dart_SetPausedEventHandler(Dart_PausedEventHandler handler) { |
| (...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 776 | 773 |
| 777 | 774 |
| 778 DART_EXPORT char* Dart_GetVmStatus(const char* request) { | 775 DART_EXPORT char* Dart_GetVmStatus(const char* request) { |
| 779 if (strncmp(request, "/isolate/", 9) == 0) { | 776 if (strncmp(request, "/isolate/", 9) == 0) { |
| 780 return Isolate::GetStatus(request); | 777 return Isolate::GetStatus(request); |
| 781 } | 778 } |
| 782 return NULL; | 779 return NULL; |
| 783 } | 780 } |
| 784 | 781 |
| 785 } // namespace dart | 782 } // namespace dart |
| OLD | NEW |