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" |
11 #include "vm/object_store.h" | 11 #include "vm/object_store.h" |
12 | 12 |
13 namespace dart { | 13 namespace dart { |
14 | 14 |
15 #define UNWRAP_AND_CHECK_PARAM(type, var, param) \ | 15 #define UNWRAP_AND_CHECK_PARAM(type, var, param) \ |
16 do { \ | 16 type& var = type::Handle(); \ |
17 const Object& tmp = Object::Handle(Api::UnwrapHandle(param)); \ | 17 do { \ |
18 if (tmp.IsNull()) { \ | 18 const Object& tmp = Object::Handle(Api::UnwrapHandle(param)); \ |
19 return Api::NewError("%s expects argument '%s' to be non-null.", \ | 19 if (tmp.IsNull()) { \ |
20 CURRENT_FUNC, #param); \ | 20 return Api::NewError("%s expects argument '%s' to be non-null.", \ |
21 } else if (tmp.IsApiError()) { \ | 21 CURRENT_FUNC, #param); \ |
22 return param; \ | 22 } else if (tmp.IsApiError()) { \ |
23 } else if (!tmp.Is##type()) { \ | 23 return param; \ |
24 return Api::NewError("%s expects argument '%s' to be of type %s.", \ | 24 } else if (!tmp.Is##type()) { \ |
25 CURRENT_FUNC, #param, #type); \ | 25 return Api::NewError("%s expects argument '%s' to be of type %s.", \ |
26 } \ | 26 CURRENT_FUNC, #param, #type); \ |
27 var ^= tmp.raw(); \ | 27 } \ |
28 } while (0); | 28 var ^= tmp.raw(); \ |
| 29 } while (0) |
29 | 30 |
30 | 31 |
31 #define CHECK_AND_CAST(type, var, param) \ | 32 #define CHECK_AND_CAST(type, var, param) \ |
32 if (param == NULL) { \ | 33 type* var = NULL; \ |
33 return Api::NewError("%s expects argument '%s' to be non-null.", \ | 34 do { \ |
34 CURRENT_FUNC, #param); \ | 35 if (param == NULL) { \ |
35 } \ | 36 return Api::NewError("%s expects argument '%s' to be non-null.", \ |
36 type* var = reinterpret_cast<type*>(param); | 37 CURRENT_FUNC, #param); \ |
| 38 } \ |
| 39 var = reinterpret_cast<type*>(param); \ |
| 40 } while (0) |
37 | 41 |
38 | 42 |
39 #define CHECK_NOT_NULL(param) \ | 43 #define CHECK_NOT_NULL(param) \ |
40 if (param == NULL) { \ | 44 if (param == NULL) { \ |
41 return Api::NewError("%s expects argument '%s' to be non-null.", \ | 45 return Api::NewError("%s expects argument '%s' to be non-null.", \ |
42 CURRENT_FUNC, #param); \ | 46 CURRENT_FUNC, #param); \ |
43 } | 47 } |
44 | 48 |
45 | 49 |
46 DART_EXPORT intptr_t Dart_CacheObject(Dart_Handle object_in) { | 50 DART_EXPORT intptr_t Dart_CacheObject(Dart_Handle object_in) { |
47 Isolate* isolate = Isolate::Current(); | 51 Isolate* isolate = Isolate::Current(); |
48 DARTSCOPE(isolate); | 52 DARTSCOPE(isolate); |
49 const Object& obj = Object::Handle(Api::UnwrapHandle(object_in)); | 53 const Object& obj = Object::Handle(Api::UnwrapHandle(object_in)); |
50 if (obj.IsApiError()) { | 54 if (obj.IsApiError()) { |
51 return -1; | 55 return -1; |
52 } | 56 } |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 CHECK_AND_CAST(ActivationFrame, frame, activation_frame); | 206 CHECK_AND_CAST(ActivationFrame, frame, activation_frame); |
203 return Api::NewHandle(isolate, frame->GetLocalVariables()); | 207 return Api::NewHandle(isolate, frame->GetLocalVariables()); |
204 } | 208 } |
205 | 209 |
206 | 210 |
207 DART_EXPORT Dart_Handle Dart_SetBreakpoint( | 211 DART_EXPORT Dart_Handle Dart_SetBreakpoint( |
208 Dart_Handle script_url_in, | 212 Dart_Handle script_url_in, |
209 intptr_t line_number) { | 213 intptr_t line_number) { |
210 Isolate* isolate = Isolate::Current(); | 214 Isolate* isolate = Isolate::Current(); |
211 DARTSCOPE(isolate); | 215 DARTSCOPE(isolate); |
212 | |
213 String& script_url = String::Handle(); | |
214 UNWRAP_AND_CHECK_PARAM(String, script_url, script_url_in); | 216 UNWRAP_AND_CHECK_PARAM(String, script_url, script_url_in); |
215 | |
216 Debugger* debugger = isolate->debugger(); | 217 Debugger* debugger = isolate->debugger(); |
217 ASSERT(debugger != NULL); | 218 ASSERT(debugger != NULL); |
218 SourceBreakpoint* bpt = | 219 SourceBreakpoint* bpt = |
219 debugger->SetBreakpointAtLine(script_url, line_number); | 220 debugger->SetBreakpointAtLine(script_url, line_number); |
220 if (bpt == NULL) { | 221 if (bpt == NULL) { |
221 return Api::NewError("%s: could not set breakpoint at line %d in '%s'", | 222 return Api::NewError("%s: could not set breakpoint at line %d in '%s'", |
222 CURRENT_FUNC, line_number, script_url.ToCString()); | 223 CURRENT_FUNC, line_number, script_url.ToCString()); |
223 } | 224 } |
224 return Dart_NewInteger(bpt->id()); | 225 return Dart_NewInteger(bpt->id()); |
225 } | 226 } |
226 | 227 |
227 | 228 |
228 // TODO(hausner): remove this function. | 229 // TODO(hausner): remove this function. |
229 DART_EXPORT Dart_Handle Dart_SetBreakpointAtLine( | 230 DART_EXPORT Dart_Handle Dart_SetBreakpointAtLine( |
230 Dart_Handle script_url_in, | 231 Dart_Handle script_url_in, |
231 Dart_Handle line_number_in, | 232 Dart_Handle line_number_in, |
232 Dart_Breakpoint* breakpoint) { | 233 Dart_Breakpoint* breakpoint) { |
233 Isolate* isolate = Isolate::Current(); | 234 Isolate* isolate = Isolate::Current(); |
234 DARTSCOPE(isolate); | 235 DARTSCOPE(isolate); |
235 | |
236 String& script_url = String::Handle(); | |
237 Integer& line_number = Integer::Handle(); | |
238 UNWRAP_AND_CHECK_PARAM(String, script_url, script_url_in); | 236 UNWRAP_AND_CHECK_PARAM(String, script_url, script_url_in); |
239 UNWRAP_AND_CHECK_PARAM(Integer, line_number, line_number_in); | 237 UNWRAP_AND_CHECK_PARAM(Integer, line_number, line_number_in); |
240 CHECK_NOT_NULL(breakpoint); | 238 CHECK_NOT_NULL(breakpoint); |
241 | 239 |
242 if (!line_number.IsSmi()) { | 240 if (!line_number.IsSmi()) { |
243 return Api::NewError("%s: line number out of range", CURRENT_FUNC); | 241 return Api::NewError("%s: line number out of range", CURRENT_FUNC); |
244 } | 242 } |
245 intptr_t line = line_number.AsInt64Value(); | 243 intptr_t line = line_number.AsInt64Value(); |
246 | 244 |
247 const char* msg = CheckIsolateState(isolate); | 245 const char* msg = CheckIsolateState(isolate); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 } | 293 } |
296 | 294 |
297 | 295 |
298 DART_EXPORT Dart_Handle Dart_SetBreakpointAtEntry( | 296 DART_EXPORT Dart_Handle Dart_SetBreakpointAtEntry( |
299 Dart_Handle library_in, | 297 Dart_Handle library_in, |
300 Dart_Handle class_name_in, | 298 Dart_Handle class_name_in, |
301 Dart_Handle function_name_in, | 299 Dart_Handle function_name_in, |
302 Dart_Breakpoint* breakpoint) { | 300 Dart_Breakpoint* breakpoint) { |
303 Isolate* isolate = Isolate::Current(); | 301 Isolate* isolate = Isolate::Current(); |
304 DARTSCOPE(isolate); | 302 DARTSCOPE(isolate); |
305 | |
306 Library& library = Library::Handle(); | |
307 String& class_name = String::Handle(); | |
308 String& function_name = String::Handle(); | |
309 UNWRAP_AND_CHECK_PARAM(Library, library, library_in); | 303 UNWRAP_AND_CHECK_PARAM(Library, library, library_in); |
310 UNWRAP_AND_CHECK_PARAM(String, class_name, class_name_in); | 304 UNWRAP_AND_CHECK_PARAM(String, class_name, class_name_in); |
311 UNWRAP_AND_CHECK_PARAM(String, function_name, function_name_in); | 305 UNWRAP_AND_CHECK_PARAM(String, function_name, function_name_in); |
312 CHECK_NOT_NULL(breakpoint); | 306 CHECK_NOT_NULL(breakpoint); |
313 | 307 |
314 const char* msg = CheckIsolateState(isolate); | 308 const char* msg = CheckIsolateState(isolate); |
315 if (msg != NULL) { | 309 if (msg != NULL) { |
316 return Api::NewError(msg); | 310 return Api::NewError(msg); |
317 } | 311 } |
318 | 312 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 Isolate* isolate = Isolate::Current(); | 380 Isolate* isolate = Isolate::Current(); |
387 DARTSCOPE(isolate); | 381 DARTSCOPE(isolate); |
388 isolate->debugger()->SetStepOut(); | 382 isolate->debugger()->SetStepOut(); |
389 return Api::True(isolate); | 383 return Api::True(isolate); |
390 } | 384 } |
391 | 385 |
392 | 386 |
393 DART_EXPORT Dart_Handle Dart_GetInstanceFields(Dart_Handle object_in) { | 387 DART_EXPORT Dart_Handle Dart_GetInstanceFields(Dart_Handle object_in) { |
394 Isolate* isolate = Isolate::Current(); | 388 Isolate* isolate = Isolate::Current(); |
395 DARTSCOPE(isolate); | 389 DARTSCOPE(isolate); |
396 Instance& obj = Instance::Handle(); | |
397 UNWRAP_AND_CHECK_PARAM(Instance, obj, object_in); | 390 UNWRAP_AND_CHECK_PARAM(Instance, obj, object_in); |
398 return Api::NewHandle(isolate, isolate->debugger()->GetInstanceFields(obj)); | 391 return Api::NewHandle(isolate, isolate->debugger()->GetInstanceFields(obj)); |
399 } | 392 } |
400 | 393 |
401 | 394 |
402 DART_EXPORT Dart_Handle Dart_GetStaticFields(Dart_Handle cls_in) { | 395 DART_EXPORT Dart_Handle Dart_GetStaticFields(Dart_Handle cls_in) { |
403 Isolate* isolate = Isolate::Current(); | 396 Isolate* isolate = Isolate::Current(); |
404 DARTSCOPE(isolate); | 397 DARTSCOPE(isolate); |
405 Class& cls = Class::Handle(); | |
406 UNWRAP_AND_CHECK_PARAM(Class, cls, cls_in); | 398 UNWRAP_AND_CHECK_PARAM(Class, cls, cls_in); |
407 return Api::NewHandle(isolate, isolate->debugger()->GetStaticFields(cls)); | 399 return Api::NewHandle(isolate, isolate->debugger()->GetStaticFields(cls)); |
408 } | 400 } |
409 | 401 |
410 | 402 |
411 DART_EXPORT Dart_Handle Dart_GetLibraryFields(intptr_t library_id) { | 403 DART_EXPORT Dart_Handle Dart_GetLibraryFields(intptr_t library_id) { |
412 Isolate* isolate = Isolate::Current(); | 404 Isolate* isolate = Isolate::Current(); |
413 DARTSCOPE(isolate); | 405 DARTSCOPE(isolate); |
414 const Library& lib = | 406 const Library& lib = |
415 Library::Handle(isolate, Library::GetLibrary(library_id)); | 407 Library::Handle(isolate, Library::GetLibrary(library_id)); |
(...skipping 14 matching lines...) Expand all Loading... |
430 return Api::NewError("%s: %d is not a valid library id", | 422 return Api::NewError("%s: %d is not a valid library id", |
431 CURRENT_FUNC, library_id); | 423 CURRENT_FUNC, library_id); |
432 } | 424 } |
433 return Api::NewHandle(isolate, isolate->debugger()->GetGlobalFields(lib)); | 425 return Api::NewHandle(isolate, isolate->debugger()->GetGlobalFields(lib)); |
434 } | 426 } |
435 | 427 |
436 | 428 |
437 DART_EXPORT Dart_Handle Dart_GetObjClass(Dart_Handle object_in) { | 429 DART_EXPORT Dart_Handle Dart_GetObjClass(Dart_Handle object_in) { |
438 Isolate* isolate = Isolate::Current(); | 430 Isolate* isolate = Isolate::Current(); |
439 DARTSCOPE(isolate); | 431 DARTSCOPE(isolate); |
440 Instance& obj = Instance::Handle(); | |
441 UNWRAP_AND_CHECK_PARAM(Instance, obj, object_in); | 432 UNWRAP_AND_CHECK_PARAM(Instance, obj, object_in); |
442 return Api::NewHandle(isolate, obj.clazz()); | 433 return Api::NewHandle(isolate, obj.clazz()); |
443 } | 434 } |
444 | 435 |
445 | 436 |
446 DART_EXPORT Dart_Handle Dart_GetObjClassId(Dart_Handle object_in, | 437 DART_EXPORT Dart_Handle Dart_GetObjClassId(Dart_Handle object_in, |
447 intptr_t* class_id) { | 438 intptr_t* class_id) { |
448 Isolate* isolate = Isolate::Current(); | 439 Isolate* isolate = Isolate::Current(); |
449 DARTSCOPE(isolate); | 440 DARTSCOPE(isolate); |
450 Instance& obj = Instance::Handle(); | |
451 UNWRAP_AND_CHECK_PARAM(Instance, obj, object_in); | 441 UNWRAP_AND_CHECK_PARAM(Instance, obj, object_in); |
452 CHECK_NOT_NULL(class_id); | 442 CHECK_NOT_NULL(class_id); |
453 *class_id = Class::Handle(obj.clazz()).id(); | 443 *class_id = Class::Handle(obj.clazz()).id(); |
454 return Api::True(isolate); | 444 return Api::True(isolate); |
455 } | 445 } |
456 | 446 |
457 | 447 |
458 DART_EXPORT Dart_Handle Dart_GetSuperclass(Dart_Handle cls_in) { | 448 DART_EXPORT Dart_Handle Dart_GetSuperclass(Dart_Handle cls_in) { |
459 Isolate* isolate = Isolate::Current(); | 449 Isolate* isolate = Isolate::Current(); |
460 DARTSCOPE(isolate); | 450 DARTSCOPE(isolate); |
461 Class& cls = Class::Handle(); | |
462 UNWRAP_AND_CHECK_PARAM(Class, cls, cls_in); | 451 UNWRAP_AND_CHECK_PARAM(Class, cls, cls_in); |
463 return Api::NewHandle(isolate, cls.SuperClass()); | 452 return Api::NewHandle(isolate, cls.SuperClass()); |
464 } | 453 } |
465 | 454 |
466 | 455 |
467 DART_EXPORT Dart_Handle Dart_GetClassInfo( | 456 DART_EXPORT Dart_Handle Dart_GetClassInfo( |
468 intptr_t cls_id, | 457 intptr_t cls_id, |
469 Dart_Handle* class_name, | 458 Dart_Handle* class_name, |
470 intptr_t* library_id, | 459 intptr_t* library_id, |
471 intptr_t* super_class_id, | 460 intptr_t* super_class_id, |
(...skipping 30 matching lines...) Expand all Loading... |
502 DART_EXPORT Dart_Handle Dart_ScriptGetSource( | 491 DART_EXPORT Dart_Handle Dart_ScriptGetSource( |
503 intptr_t library_id, | 492 intptr_t library_id, |
504 Dart_Handle script_url_in) { | 493 Dart_Handle script_url_in) { |
505 Isolate* isolate = Isolate::Current(); | 494 Isolate* isolate = Isolate::Current(); |
506 DARTSCOPE(isolate); | 495 DARTSCOPE(isolate); |
507 const Library& lib = Library::Handle(Library::GetLibrary(library_id)); | 496 const Library& lib = Library::Handle(Library::GetLibrary(library_id)); |
508 if (lib.IsNull()) { | 497 if (lib.IsNull()) { |
509 return Api::NewError("%s: %d is not a valid library id", | 498 return Api::NewError("%s: %d is not a valid library id", |
510 CURRENT_FUNC, library_id); | 499 CURRENT_FUNC, library_id); |
511 } | 500 } |
512 String& script_url = String::Handle(); | |
513 UNWRAP_AND_CHECK_PARAM(String, script_url, script_url_in); | 501 UNWRAP_AND_CHECK_PARAM(String, script_url, script_url_in); |
514 const Script& script = Script::Handle(lib.LookupScript(script_url)); | 502 const Script& script = Script::Handle(lib.LookupScript(script_url)); |
515 if (script.IsNull()) { | 503 if (script.IsNull()) { |
516 return Api::NewError("%s: script '%s' not found in library '%s'", | 504 return Api::NewError("%s: script '%s' not found in library '%s'", |
517 CURRENT_FUNC, script_url.ToCString(), | 505 CURRENT_FUNC, script_url.ToCString(), |
518 String::Handle(lib.url()).ToCString()); | 506 String::Handle(lib.url()).ToCString()); |
519 } | 507 } |
520 return Api::NewHandle(isolate, script.source()); | 508 return Api::NewHandle(isolate, script.source()); |
521 } | 509 } |
522 | 510 |
523 | 511 |
524 DART_EXPORT Dart_Handle Dart_GetScriptSource( | 512 DART_EXPORT Dart_Handle Dart_GetScriptSource( |
525 Dart_Handle library_url_in, | 513 Dart_Handle library_url_in, |
526 Dart_Handle script_url_in) { | 514 Dart_Handle script_url_in) { |
527 Isolate* isolate = Isolate::Current(); | 515 Isolate* isolate = Isolate::Current(); |
528 DARTSCOPE(isolate); | 516 DARTSCOPE(isolate); |
529 String& library_url = String::Handle(); | |
530 UNWRAP_AND_CHECK_PARAM(String, library_url, library_url_in); | 517 UNWRAP_AND_CHECK_PARAM(String, library_url, library_url_in); |
531 String& script_url = String::Handle(); | |
532 UNWRAP_AND_CHECK_PARAM(String, script_url, script_url_in); | 518 UNWRAP_AND_CHECK_PARAM(String, script_url, script_url_in); |
533 | 519 |
534 const Library& library = Library::Handle(Library::LookupLibrary(library_url)); | 520 const Library& library = Library::Handle(Library::LookupLibrary(library_url)); |
535 if (library.IsNull()) { | 521 if (library.IsNull()) { |
536 return Api::NewError("%s: library '%s' not found", | 522 return Api::NewError("%s: library '%s' not found", |
537 CURRENT_FUNC, library_url.ToCString()); | 523 CURRENT_FUNC, library_url.ToCString()); |
538 } | 524 } |
539 | 525 |
540 const Script& script = Script::Handle(library.LookupScript(script_url)); | 526 const Script& script = Script::Handle(library.LookupScript(script_url)); |
541 if (script.IsNull()) { | 527 if (script.IsNull()) { |
542 return Api::NewError("%s: script '%s' not found in library '%s'", | 528 return Api::NewError("%s: script '%s' not found in library '%s'", |
543 CURRENT_FUNC, script_url.ToCString(), | 529 CURRENT_FUNC, script_url.ToCString(), |
544 library_url.ToCString()); | 530 library_url.ToCString()); |
545 } | 531 } |
546 | 532 |
547 return Api::NewHandle(isolate, script.source()); | 533 return Api::NewHandle(isolate, script.source()); |
548 } | 534 } |
549 | 535 |
550 | 536 |
551 DART_EXPORT Dart_Handle Dart_GetScriptURLs(Dart_Handle library_url_in) { | 537 DART_EXPORT Dart_Handle Dart_GetScriptURLs(Dart_Handle library_url_in) { |
552 Isolate* isolate = Isolate::Current(); | 538 Isolate* isolate = Isolate::Current(); |
553 DARTSCOPE(isolate); | 539 DARTSCOPE(isolate); |
554 String& library_url = String::Handle(); | |
555 UNWRAP_AND_CHECK_PARAM(String, library_url, library_url_in); | 540 UNWRAP_AND_CHECK_PARAM(String, library_url, library_url_in); |
556 | 541 |
557 const Library& library = Library::Handle(Library::LookupLibrary(library_url)); | 542 const Library& library = Library::Handle(Library::LookupLibrary(library_url)); |
558 if (library.IsNull()) { | 543 if (library.IsNull()) { |
559 return Api::NewError("%s: library '%s' not found", | 544 return Api::NewError("%s: library '%s' not found", |
560 CURRENT_FUNC, library_url.ToCString()); | 545 CURRENT_FUNC, library_url.ToCString()); |
561 } | 546 } |
562 const Array& loaded_scripts = Array::Handle(library.LoadedScripts()); | 547 const Array& loaded_scripts = Array::Handle(library.LoadedScripts()); |
563 ASSERT(!loaded_scripts.IsNull()); | 548 ASSERT(!loaded_scripts.IsNull()); |
564 intptr_t num_scripts = loaded_scripts.Length(); | 549 intptr_t num_scripts = loaded_scripts.Length(); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
665 for (int i = 0; i < num_libs; i++) { | 650 for (int i = 0; i < num_libs; i++) { |
666 lib ^= libs.At(i); | 651 lib ^= libs.At(i); |
667 ASSERT(!lib.IsNull()); | 652 ASSERT(!lib.IsNull()); |
668 lib_url = lib.url(); | 653 lib_url = lib.url(); |
669 library_url_list.SetAt(i, lib_url); | 654 library_url_list.SetAt(i, lib_url); |
670 } | 655 } |
671 return Api::NewHandle(isolate, library_url_list.raw()); | 656 return Api::NewHandle(isolate, library_url_list.raw()); |
672 } | 657 } |
673 | 658 |
674 } // namespace dart | 659 } // namespace dart |
OLD | NEW |