| 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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 Dart_BreakpointHandler bp_handler) { | 77 Dart_BreakpointHandler bp_handler) { |
| 78 Isolate* isolate = Isolate::Current(); | 78 Isolate* isolate = Isolate::Current(); |
| 79 DARTSCOPE(isolate); | 79 DARTSCOPE(isolate); |
| 80 BreakpointHandler* handler = | 80 BreakpointHandler* handler = |
| 81 reinterpret_cast<BreakpointHandler*>(bp_handler); | 81 reinterpret_cast<BreakpointHandler*>(bp_handler); |
| 82 | 82 |
| 83 isolate->debugger()->SetBreakpointHandler(handler); | 83 isolate->debugger()->SetBreakpointHandler(handler); |
| 84 } | 84 } |
| 85 | 85 |
| 86 | 86 |
| 87 static Dart_BreakpointResolvedHandler* bp_resolved_handler = NULL; |
| 88 |
| 89 static void DebuggerEventHandler(Debugger::DebuggerEvent* event) { |
| 90 printf("Debugger event %d\n", event->type); |
| 91 Isolate* isolate = Isolate::Current(); |
| 92 ASSERT(isolate != NULL); |
| 93 if (event->type == Debugger::kBreakpointResolved) { |
| 94 if (bp_resolved_handler == NULL) { |
| 95 return; |
| 96 } |
| 97 SourceBreakpoint* bpt = event->breakpoint; |
| 98 ASSERT(bpt != NULL); |
| 99 Dart_Handle url = Api::NewHandle(isolate, bpt->SourceUrl()); |
| 100 (*bp_resolved_handler)(bpt->id(), url, bpt->LineNumber()); |
| 101 } else { |
| 102 UNIMPLEMENTED(); |
| 103 } |
| 104 } |
| 105 |
| 106 |
| 107 DART_EXPORT void Dart_SetBreakpointResolvedHandler( |
| 108 Dart_BreakpointResolvedHandler handler) { |
| 109 bp_resolved_handler = handler; |
| 110 Isolate* isolate = Isolate::Current(); |
| 111 DARTSCOPE(isolate); |
| 112 isolate->debugger()->SetEventHandler(DebuggerEventHandler); |
| 113 } |
| 114 |
| 115 |
| 116 DART_EXPORT Dart_Handle Dart_GetStackTrace(Dart_StackTrace* trace) { |
| 117 Isolate* isolate = Isolate::Current(); |
| 118 DARTSCOPE(isolate); |
| 119 CHECK_NOT_NULL(trace); |
| 120 *trace = reinterpret_cast<Dart_StackTrace>(isolate->debugger()->StackTrace()); |
| 121 return Api::True(isolate); |
| 122 } |
| 123 |
| 124 |
| 87 DART_EXPORT Dart_Handle Dart_ActivationFrameInfo( | 125 DART_EXPORT Dart_Handle Dart_ActivationFrameInfo( |
| 88 Dart_ActivationFrame activation_frame, | 126 Dart_ActivationFrame activation_frame, |
| 89 Dart_Handle* function_name, | 127 Dart_Handle* function_name, |
| 90 Dart_Handle* script_url, | 128 Dart_Handle* script_url, |
| 91 intptr_t* line_number) { | 129 intptr_t* line_number) { |
| 92 Isolate* isolate = Isolate::Current(); | 130 Isolate* isolate = Isolate::Current(); |
| 93 DARTSCOPE(isolate); | 131 DARTSCOPE(isolate); |
| 94 CHECK_AND_CAST(ActivationFrame, frame, activation_frame); | 132 CHECK_AND_CAST(ActivationFrame, frame, activation_frame); |
| 95 if (function_name != NULL) { | 133 if (function_name != NULL) { |
| 96 *function_name = Api::NewHandle(isolate, frame->QualifiedFunctionName()); | 134 *function_name = Api::NewHandle(isolate, frame->QualifiedFunctionName()); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 107 | 145 |
| 108 DART_EXPORT Dart_Handle Dart_GetLocalVariables( | 146 DART_EXPORT Dart_Handle Dart_GetLocalVariables( |
| 109 Dart_ActivationFrame activation_frame) { | 147 Dart_ActivationFrame activation_frame) { |
| 110 Isolate* isolate = Isolate::Current(); | 148 Isolate* isolate = Isolate::Current(); |
| 111 DARTSCOPE(isolate); | 149 DARTSCOPE(isolate); |
| 112 CHECK_AND_CAST(ActivationFrame, frame, activation_frame); | 150 CHECK_AND_CAST(ActivationFrame, frame, activation_frame); |
| 113 return Api::NewHandle(isolate, frame->GetLocalVariables()); | 151 return Api::NewHandle(isolate, frame->GetLocalVariables()); |
| 114 } | 152 } |
| 115 | 153 |
| 116 | 154 |
| 155 DART_EXPORT Dart_Handle Dart_SetBreakpoint( |
| 156 Dart_Handle script_url_in, |
| 157 intptr_t line_number) { |
| 158 Isolate* isolate = Isolate::Current(); |
| 159 DARTSCOPE(isolate); |
| 160 |
| 161 String& script_url = String::Handle(); |
| 162 UNWRAP_AND_CHECK_PARAM(String, script_url, script_url_in); |
| 163 |
| 164 Debugger* debugger = isolate->debugger(); |
| 165 ASSERT(debugger != NULL); |
| 166 SourceBreakpoint* bpt = |
| 167 debugger->SetBreakpointAtLine(script_url, line_number); |
| 168 if (bpt == NULL) { |
| 169 return Api::NewError("%s: could not set breakpoint at line %d in '%s'", |
| 170 CURRENT_FUNC, line_number, script_url.ToCString()); |
| 171 } |
| 172 return Dart_NewInteger(bpt->id()); |
| 173 } |
| 174 |
| 175 |
| 176 // TODO(hausner): remove this function. |
| 117 DART_EXPORT Dart_Handle Dart_SetBreakpointAtLine( | 177 DART_EXPORT Dart_Handle Dart_SetBreakpointAtLine( |
| 118 Dart_Handle script_url_in, | 178 Dart_Handle script_url_in, |
| 119 Dart_Handle line_number_in, | 179 Dart_Handle line_number_in, |
| 120 Dart_Breakpoint* breakpoint) { | 180 Dart_Breakpoint* breakpoint) { |
| 121 Isolate* isolate = Isolate::Current(); | 181 Isolate* isolate = Isolate::Current(); |
| 122 DARTSCOPE(isolate); | 182 DARTSCOPE(isolate); |
| 123 | 183 |
| 124 String& script_url = String::Handle(); | 184 String& script_url = String::Handle(); |
| 125 Integer& line_number = Integer::Handle(); | 185 Integer& line_number = Integer::Handle(); |
| 126 UNWRAP_AND_CHECK_PARAM(String, script_url, script_url_in); | 186 UNWRAP_AND_CHECK_PARAM(String, script_url, script_url_in); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 146 if (bpt == NULL) { | 206 if (bpt == NULL) { |
| 147 result = Api::NewError("%s: could not set breakpoint at line %d of '%s'", | 207 result = Api::NewError("%s: could not set breakpoint at line %d of '%s'", |
| 148 CURRENT_FUNC, line, script_url.ToCString()); | 208 CURRENT_FUNC, line, script_url.ToCString()); |
| 149 } else { | 209 } else { |
| 150 *breakpoint = reinterpret_cast<Dart_Breakpoint>(bpt); | 210 *breakpoint = reinterpret_cast<Dart_Breakpoint>(bpt); |
| 151 } | 211 } |
| 152 return result; | 212 return result; |
| 153 } | 213 } |
| 154 | 214 |
| 155 | 215 |
| 216 DART_EXPORT Dart_Handle Dart_GetBreakpointURL(intptr_t bp_id) { |
| 217 Isolate* isolate = Isolate::Current(); |
| 218 DARTSCOPE(isolate); |
| 219 Debugger* debugger = isolate->debugger(); |
| 220 ASSERT(debugger != NULL); |
| 221 |
| 222 SourceBreakpoint* bpt = debugger->GetBreakpointById(bp_id); |
| 223 if (bpt == NULL) { |
| 224 return Api::NewError("%s: breakpoint with id %d does not exist", |
| 225 CURRENT_FUNC, bp_id); |
| 226 } |
| 227 return Api::NewHandle(isolate, bpt->SourceUrl()); |
| 228 } |
| 229 |
| 230 |
| 231 DART_EXPORT Dart_Handle Dart_GetBreakpointLine(intptr_t bp_id) { |
| 232 Isolate* isolate = Isolate::Current(); |
| 233 DARTSCOPE(isolate); |
| 234 Debugger* debugger = isolate->debugger(); |
| 235 ASSERT(debugger != NULL); |
| 236 |
| 237 SourceBreakpoint* bpt = debugger->GetBreakpointById(bp_id); |
| 238 if (bpt == NULL) { |
| 239 return Api::NewError("%s: breakpoint with id %d does not exist", |
| 240 CURRENT_FUNC, bp_id); |
| 241 } |
| 242 return Dart_NewInteger(bpt->LineNumber()); |
| 243 } |
| 244 |
| 245 |
| 156 DART_EXPORT Dart_Handle Dart_SetBreakpointAtEntry( | 246 DART_EXPORT Dart_Handle Dart_SetBreakpointAtEntry( |
| 157 Dart_Handle library_in, | 247 Dart_Handle library_in, |
| 158 Dart_Handle class_name_in, | 248 Dart_Handle class_name_in, |
| 159 Dart_Handle function_name_in, | 249 Dart_Handle function_name_in, |
| 160 Dart_Breakpoint* breakpoint) { | 250 Dart_Breakpoint* breakpoint) { |
| 161 Isolate* isolate = Isolate::Current(); | 251 Isolate* isolate = Isolate::Current(); |
| 162 DARTSCOPE(isolate); | 252 DARTSCOPE(isolate); |
| 163 | 253 |
| 164 Library& library = Library::Handle(); | 254 Library& library = Library::Handle(); |
| 165 String& class_name = String::Handle(); | 255 String& class_name = String::Handle(); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 195 const char* target_name = Debugger::QualifiedFunctionName(bp_target); | 285 const char* target_name = Debugger::QualifiedFunctionName(bp_target); |
| 196 result = Api::NewError("%s: no breakpoint location found in '%s'", | 286 result = Api::NewError("%s: no breakpoint location found in '%s'", |
| 197 CURRENT_FUNC, target_name); | 287 CURRENT_FUNC, target_name); |
| 198 } else { | 288 } else { |
| 199 *breakpoint = reinterpret_cast<Dart_Breakpoint>(bpt); | 289 *breakpoint = reinterpret_cast<Dart_Breakpoint>(bpt); |
| 200 } | 290 } |
| 201 return result; | 291 return result; |
| 202 } | 292 } |
| 203 | 293 |
| 204 | 294 |
| 295 DART_EXPORT Dart_Handle Dart_RemoveBreakpoint(intptr_t bp_id) { |
| 296 Isolate* isolate = Isolate::Current(); |
| 297 DARTSCOPE(isolate); |
| 298 Debugger* debugger = isolate->debugger(); |
| 299 ASSERT(debugger != NULL); |
| 300 |
| 301 isolate->debugger()->RemoveBreakpoint(bp_id); |
| 302 return Api::True(isolate); |
| 303 } |
| 304 |
| 305 |
| 205 DART_EXPORT Dart_Handle Dart_DeleteBreakpoint( | 306 DART_EXPORT Dart_Handle Dart_DeleteBreakpoint( |
| 206 Dart_Breakpoint breakpoint_in) { | 307 Dart_Breakpoint breakpoint_in) { |
| 207 Isolate* isolate = Isolate::Current(); | 308 Isolate* isolate = Isolate::Current(); |
| 208 DARTSCOPE(isolate); | 309 DARTSCOPE(isolate); |
| 209 | 310 |
| 210 CHECK_AND_CAST(SourceBreakpoint, breakpoint, breakpoint_in); | 311 CHECK_AND_CAST(SourceBreakpoint, breakpoint, breakpoint_in); |
| 211 isolate->debugger()->RemoveBreakpoint(breakpoint); | 312 isolate->debugger()->RemoveBreakpoint(breakpoint->id()); |
| 212 return Api::True(isolate); | 313 return Api::True(isolate); |
| 213 } | 314 } |
| 214 | 315 |
| 215 | 316 |
| 216 DART_EXPORT Dart_Handle Dart_SetStepOver() { | 317 DART_EXPORT Dart_Handle Dart_SetStepOver() { |
| 217 Isolate* isolate = Isolate::Current(); | 318 Isolate* isolate = Isolate::Current(); |
| 218 DARTSCOPE(isolate); | 319 DARTSCOPE(isolate); |
| 219 isolate->debugger()->SetStepOver(); | 320 isolate->debugger()->SetStepOver(); |
| 220 return Api::True(isolate); | 321 return Api::True(isolate); |
| 221 } | 322 } |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 for (int i = 0; i < num_libs; i++) { | 448 for (int i = 0; i < num_libs; i++) { |
| 348 ASSERT(!lib.IsNull()); | 449 ASSERT(!lib.IsNull()); |
| 349 lib_url = lib.url(); | 450 lib_url = lib.url(); |
| 350 library_list.SetAt(i, lib_url); | 451 library_list.SetAt(i, lib_url); |
| 351 lib = lib.next_registered(); | 452 lib = lib.next_registered(); |
| 352 } | 453 } |
| 353 return Api::NewHandle(isolate, library_list.raw()); | 454 return Api::NewHandle(isolate, library_list.raw()); |
| 354 } | 455 } |
| 355 | 456 |
| 356 } // namespace dart | 457 } // namespace dart |
| OLD | NEW |