OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 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. |
| 4 |
| 5 #include "include/dart_debugger_api.h" |
| 6 |
| 7 #include "vm/dart_api_impl.h" |
| 8 #include "vm/dart_api_state.h" |
| 9 #include "vm/debugger.h" |
| 10 #include "vm/isolate.h" |
| 11 #include "vm/longjump.h" |
| 12 |
| 13 namespace dart { |
| 14 |
| 15 #define UNWRAP_AND_CHECK_PARAM(type, var, param) \ |
| 16 do { \ |
| 17 const Object& tmp = Object::Handle(Api::UnwrapHandle(param)); \ |
| 18 if (tmp.IsNull()) { \ |
| 19 return Api::Error("%s expects argument '%s' to be non-null.", \ |
| 20 CURRENT_FUNC, #param); \ |
| 21 } else if (tmp.IsApiError()) { \ |
| 22 return param; \ |
| 23 } else if (!tmp.Is##type()) { \ |
| 24 return Api::Error("%s expects argument '%s' to be of type %s.", \ |
| 25 CURRENT_FUNC, #param, #type); \ |
| 26 } \ |
| 27 var ^= tmp.raw(); \ |
| 28 } while (0); |
| 29 |
| 30 |
| 31 DART_EXPORT Dart_Handle Dart_SetBreakpointAtEntry( |
| 32 Dart_Handle library_in, |
| 33 Dart_Handle class_name_in, |
| 34 Dart_Handle function_name_in, |
| 35 Dart_Breakpoint* breakpoint) { |
| 36 Isolate* isolate = Isolate::Current(); |
| 37 DARTSCOPE(isolate); |
| 38 |
| 39 Library& library = Library::Handle(); |
| 40 String& class_name = String::Handle(); |
| 41 String& function_name = String::Handle(); |
| 42 UNWRAP_AND_CHECK_PARAM(Library, library, library_in); |
| 43 UNWRAP_AND_CHECK_PARAM(String, class_name, class_name_in); |
| 44 UNWRAP_AND_CHECK_PARAM(String, function_name, function_name_in); |
| 45 |
| 46 const char* msg = CheckIsolateState(isolate); |
| 47 if (msg != NULL) { |
| 48 return Api::Error(msg); |
| 49 } |
| 50 |
| 51 if (breakpoint != NULL) { |
| 52 *breakpoint = NULL; |
| 53 } |
| 54 |
| 55 // Resolve the breakpoint target function. |
| 56 Debugger* debugger = isolate->debugger(); |
| 57 const Function& bp_target = Function::Handle( |
| 58 debugger->ResolveFunction(library, class_name, function_name)); |
| 59 if (bp_target.IsNull()) { |
| 60 return Api::Error("Breakpoint target function does not exist"); |
| 61 } |
| 62 |
| 63 LongJump* base = isolate->long_jump_base(); |
| 64 LongJump jump; |
| 65 isolate->set_long_jump_base(&jump); |
| 66 Dart_Handle result = Api::True(); |
| 67 if (setjmp(*jump.Set()) == 0) { |
| 68 Breakpoint* bpt = debugger->SetBreakpointAtEntry(bp_target); |
| 69 if (breakpoint != NULL) { |
| 70 *breakpoint = reinterpret_cast<Dart_Breakpoint>(bpt); |
| 71 } |
| 72 } else { |
| 73 SetupErrorResult(&result); |
| 74 } |
| 75 isolate->set_long_jump_base(base); |
| 76 return result; |
| 77 } |
| 78 |
| 79 |
| 80 } // namespace dart |
OLD | NEW |