Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
debugger_api_impl_test.cc
Go to the documentation of this 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
3// BSD-style license that can be found in the LICENSE file.
4
5#include <include/dart_api.h>
7
10#include "vm/dart_api_impl.h"
11#include "vm/dart_api_state.h"
12#include "vm/debugger.h"
14#include "vm/isolate.h"
15#include "vm/object_store.h"
16#include "vm/symbols.h"
17
18namespace dart {
19
20// Facilitate quick access to the current zone once we have the current thread.
21#define Z (T->zone())
22
23#ifndef PRODUCT
24
25#define UNWRAP_AND_CHECK_PARAM(type, var, param) \
26 type& var = type::Handle(); \
27 do { \
28 const Object& tmp = Object::Handle(Api::UnwrapHandle(param)); \
29 if (tmp.IsNull()) { \
30 return Api::NewError("%s expects argument '%s' to be non-null.", \
31 CURRENT_FUNC, #param); \
32 } else if (tmp.IsApiError()) { \
33 return param; \
34 } else if (!tmp.Is##type()) { \
35 return Api::NewError("%s expects argument '%s' to be of type %s.", \
36 CURRENT_FUNC, #param, #type); \
37 } \
38 var ^= tmp.ptr(); \
39 } while (0)
40
41#define CHECK_AND_CAST(type, var, param) \
42 type* var = nullptr; \
43 do { \
44 if (param == nullptr) { \
45 return Api::NewError("%s expects argument '%s' to be non-null.", \
46 CURRENT_FUNC, #param); \
47 } \
48 var = reinterpret_cast<type*>(param); \
49 } while (0)
50
51#define CHECK_NOT_NULL(param) \
52 if (param == nullptr) { \
53 return Api::NewError("%s expects argument '%s' to be non-null.", \
54 CURRENT_FUNC, #param); \
55 }
56
57#define CHECK_DEBUGGER(isolate) \
58 if (isolate->debugger() == nullptr) { \
59 return Api::NewError("%s requires debugger support.", CURRENT_FUNC); \
60 }
61
65 CHECK_AND_CAST(DebuggerStackTrace, stack_trace, trace);
66 *length = stack_trace->Length();
67 return Api::Success();
68}
69
71 int frame_index,
75 CHECK_AND_CAST(DebuggerStackTrace, stack_trace, trace);
76 if ((frame_index < 0) || (frame_index >= stack_trace->Length())) {
77 return Api::NewError("argument 'frame_index' is out of range for %s",
79 }
80 *frame =
81 reinterpret_cast<Dart_ActivationFrame>(stack_trace->FrameAt(frame_index));
82 return Api::Success();
83}
84
87 Isolate* I = T->isolate();
89 CHECK_NOT_NULL(trace);
90 *trace = reinterpret_cast<Dart_StackTrace>(DebuggerStackTrace::Collect());
91 return Api::Success();
92}
93
95 Dart_StackTrace* trace) {
97 CHECK_DEBUGGER(T->isolate());
98 CHECK_NOT_NULL(trace);
99 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(handle));
100 if (obj.IsUnhandledException()) {
101 const UnhandledException& error = UnhandledException::Cast(obj);
102 StackTrace& dart_stacktrace = StackTrace::Handle(Z);
103 dart_stacktrace ^= error.stacktrace();
104 if (dart_stacktrace.IsNull()) {
105 *trace = nullptr;
106 } else {
107 *trace = reinterpret_cast<Dart_StackTrace>(
108 DebuggerStackTrace::From(dart_stacktrace));
109 }
110 return Api::Success();
111 } else {
112 return Api::NewError(
113 "Can only get stacktraces from error handles or "
114 "instances of Error.");
115 }
116}
117
120 Dart_Handle* script_url,
121 intptr_t* line_number,
122 intptr_t* column_number) {
124 CHECK_AND_CAST(ActivationFrame, frame, activation_frame);
125 if (function_name != nullptr) {
126 *function_name = Api::NewHandle(T, frame->QualifiedFunctionName());
127 }
128 if (script_url != nullptr) {
129 *script_url = Api::NewHandle(T, frame->SourceUrl());
130 }
131 if (line_number != nullptr) {
132 *line_number = frame->LineNumber();
133 }
134 if (column_number != nullptr) {
135 *column_number = frame->ColumnNumber();
136 }
137 return Api::Success();
138}
139
141 intptr_t line_number) {
142 Breakpoint* bpt;
143 {
145 Isolate* I = T->isolate();
147 UNWRAP_AND_CHECK_PARAM(String, script_url, script_url_in);
148
149 Debugger* debugger = I->debugger();
150 bpt = debugger->SetBreakpointAtLineCol(script_url, line_number, -1);
151 if (bpt == nullptr) {
152 return Api::NewError("%s: could not set breakpoint at line %" Pd
153 " in '%s'",
154 CURRENT_FUNC, line_number, script_url.ToCString());
155 }
156 }
157 return Dart_NewInteger(bpt->id());
158}
159
162 Isolate* I = T->isolate();
164 UNWRAP_AND_CHECK_PARAM(Integer, breakpoint_id, breakpoint_id_in);
165 I->debugger()->RemoveBreakpoint(breakpoint_id.AsInt64Value());
166 return Api::Success();
167}
168
170 Dart_Handle expr_in) {
172 CHECK_DEBUGGER(T->isolate());
173
174 const Object& target = Object::Handle(Z, Api::UnwrapHandle(lib_handle));
175 if (target.IsError()) return lib_handle;
176 if (target.IsNull()) {
177 return Api::NewError("%s expects argument 'target' to be non-null",
179 }
180 const Library& lib = Library::Cast(target);
181 UNWRAP_AND_CHECK_PARAM(String, expr, expr_in);
182
184 UNREACHABLE();
185 } else {
186 Dart_KernelCompilationResult compilation_result =
188 /* platform_kernel= */ nullptr, /* platform_kernel_size= */ 0,
189 expr.ToCString(),
190 /* definitions= */ Array::empty_array(),
191 /* definition_types= */ Array::empty_array(),
192 /* type_definitions= */ Array::empty_array(),
193 /* type_bounds= */ Array::empty_array(),
194 /* type_defaults= */ Array::empty_array(),
196 /* klass= */ nullptr,
197 /* method= */ nullptr,
198 /* token_pos= */ TokenPosition::kNoSource,
199 /* script_uri= */ String::Handle(lib.url()).ToCString(),
200 /* is_static= */ true);
201 if (compilation_result.status != Dart_KernelCompilationStatus_Ok) {
202 return Api::NewError("Failed to compile expression.");
203 }
204
205 const ExternalTypedData& kernel_buffer =
207 const_cast<uint8_t*>(compilation_result.kernel),
208 compilation_result.kernel_size));
209
211 T,
212 lib.EvaluateCompiledExpression(kernel_buffer,
213 /* type_definitions= */
214 Array::empty_array(),
215 /* param_values= */
216 Array::empty_array(),
217 /* type_param_values= */
218 TypeArguments::null_type_arguments()));
219 return result;
220 }
221}
222
223Dart_Handle Dart_LibraryId(Dart_Handle library, intptr_t* library_id) {
225 const Library& lib = Api::UnwrapLibraryHandle(Z, library);
226 if (lib.IsNull()) {
227 RETURN_TYPE_ERROR(Z, library, Library);
228 }
229 if (library_id == nullptr) {
230 RETURN_NULL_ERROR(library_id);
231 }
232 *library_id = lib.index();
233 return Api::Success();
234}
235
237 bool* is_debuggable) {
239 CHECK_NOT_NULL(is_debuggable);
240 const Library& lib = Library::Handle(Library::GetLibrary(library_id));
241 if (lib.IsNull()) {
242 return Api::NewError("%s: %" Pd " is not a valid library id", CURRENT_FUNC,
243 library_id);
244 }
245 *is_debuggable = lib.IsDebuggable();
246 return Api::Success();
247}
248
249Dart_Handle Dart_SetLibraryDebuggable(intptr_t library_id, bool is_debuggable) {
251 const Library& lib = Library::Handle(Z, Library::GetLibrary(library_id));
252 if (lib.IsNull()) {
253 return Api::NewError("%s: %" Pd " is not a valid library id", CURRENT_FUNC,
254 library_id);
255 }
256 lib.set_debuggable(is_debuggable);
257 return Api::Success();
258}
259
260#endif // !PRODUCT
261
262} // namespace dart
#define UNREACHABLE()
Definition assert.h:248
#define Z
static Dart_Handle Success()
static Dart_Handle NewHandle(Thread *thread, ObjectPtr raw)
static ObjectPtr UnwrapHandle(Dart_Handle object)
static Dart_Handle NewError(const char *format,...) PRINTF_ATTRIBUTE(1
intptr_t id() const
Definition debugger.h:60
static DebuggerStackTrace * Collect()
Definition debugger.cc:1671
static DebuggerStackTrace * From(const class StackTrace &ex_trace)
Definition debugger.cc:1808
Breakpoint * SetBreakpointAtLineCol(const String &script_url, intptr_t line_number, intptr_t column_number)
Definition debugger.cc:2801
static ExternalTypedDataPtr NewFinalizeWithFree(uint8_t *data, intptr_t len)
Definition object.cc:25728
static bool IsRunning()
static Dart_KernelCompilationResult CompileExpressionToKernel(const uint8_t *platform_kernel, intptr_t platform_kernel_size, const char *expression, const Array &definitions, const Array &definition_types, const Array &type_definitions, const Array &type_bounds, const Array &type_defaults, const char *library_url, const char *klass, const char *method, TokenPosition token_pos, char const *script_uri, bool is_static)
ObjectPtr EvaluateCompiledExpression(const ExternalTypedData &kernel_buffer, const Array &type_definitions, const Array &param_values, const TypeArguments &type_param_values) const
Definition object.cc:4866
static LibraryPtr GetLibrary(intptr_t index)
Definition object.cc:14763
intptr_t index() const
Definition object.h:5241
void set_debuggable(bool value) const
Definition object.h:5255
bool IsDebuggable() const
Definition object.h:5252
StringPtr url() const
Definition object.h:5068
virtual const char * ToCString() const
Definition object.h:366
bool IsNull() const
Definition object.h:363
static Object & Handle()
Definition object.h:407
static Thread * Current()
Definition thread.h:361
@ Dart_KernelCompilationStatus_Ok
Definition dart_api.h:3728
struct _Dart_Handle * Dart_Handle
Definition dart_api.h:258
#define DARTSCOPE(thread)
#define RETURN_TYPE_ERROR(zone, dart_handle, type)
#define RETURN_NULL_ERROR(parameter)
#define CURRENT_FUNC
#define CHECK_AND_CAST(type, var, param)
#define CHECK_NOT_NULL(param)
#define UNWRAP_AND_CHECK_PARAM(type, var, param)
#define CHECK_DEBUGGER(isolate)
double frame
Definition examples.cpp:31
const uint8_t uint32_t uint32_t GError ** error
GAsyncResult * result
uint32_t * target
size_t length
Dart_Handle Dart_GetLibraryDebuggable(intptr_t library_id, bool *is_debuggable)
Dart_Handle Dart_StackTraceLength(Dart_StackTrace trace, intptr_t *length)
Dart_Handle Dart_ActivationFrameInfo(Dart_ActivationFrame activation_frame, Dart_Handle *function_name, Dart_Handle *script_url, intptr_t *line_number, intptr_t *column_number)
Dart_Handle Dart_EvaluateStaticExpr(Dart_Handle lib_handle, Dart_Handle expr_in)
Dart_Handle Dart_GetStackTrace(Dart_StackTrace *trace)
Dart_Handle Dart_RemoveBreakpoint(Dart_Handle breakpoint_id_in)
DART_EXPORT Dart_Handle Dart_NewInteger(int64_t value)
Dart_Handle Dart_SetLibraryDebuggable(intptr_t library_id, bool is_debuggable)
struct _Dart_ActivationFrame * Dart_ActivationFrame
Dart_Handle Dart_GetActivationFrame(Dart_StackTrace trace, int frame_index, Dart_ActivationFrame *frame)
Dart_Handle Dart_LibraryId(Dart_Handle library, intptr_t *library_id)
Dart_Handle Dart_GetStackTraceFromError(Dart_Handle handle, Dart_StackTrace *trace)
struct _Dart_StackTrace * Dart_StackTrace
const char *const function_name
Dart_Handle Dart_SetBreakpoint(Dart_Handle script_url_in, intptr_t line_number)
#define Pd
Definition globals.h:408
#define T
Dart_KernelCompilationStatus status
Definition dart_api.h:3735
Definition SkMD5.cpp:134