Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/editor/debugger/debug_adapter/debug_adapter_parser.cpp
9906 views
1
/**************************************************************************/
2
/* debug_adapter_parser.cpp */
3
/**************************************************************************/
4
/* This file is part of: */
5
/* GODOT ENGINE */
6
/* https://godotengine.org */
7
/**************************************************************************/
8
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10
/* */
11
/* Permission is hereby granted, free of charge, to any person obtaining */
12
/* a copy of this software and associated documentation files (the */
13
/* "Software"), to deal in the Software without restriction, including */
14
/* without limitation the rights to use, copy, modify, merge, publish, */
15
/* distribute, sublicense, and/or sell copies of the Software, and to */
16
/* permit persons to whom the Software is furnished to do so, subject to */
17
/* the following conditions: */
18
/* */
19
/* The above copyright notice and this permission notice shall be */
20
/* included in all copies or substantial portions of the Software. */
21
/* */
22
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29
/**************************************************************************/
30
31
#include "debug_adapter_parser.h"
32
33
#include "editor/debugger/debug_adapter/debug_adapter_types.h"
34
#include "editor/debugger/editor_debugger_node.h"
35
#include "editor/debugger/script_editor_debugger.h"
36
#include "editor/export/editor_export_platform.h"
37
#include "editor/run/editor_run_bar.h"
38
#include "editor/script/script_editor_plugin.h"
39
40
void DebugAdapterParser::_bind_methods() {
41
// Requests
42
ClassDB::bind_method(D_METHOD("req_initialize", "params"), &DebugAdapterParser::req_initialize);
43
ClassDB::bind_method(D_METHOD("req_disconnect", "params"), &DebugAdapterParser::req_disconnect);
44
ClassDB::bind_method(D_METHOD("req_launch", "params"), &DebugAdapterParser::req_launch);
45
ClassDB::bind_method(D_METHOD("req_attach", "params"), &DebugAdapterParser::req_attach);
46
ClassDB::bind_method(D_METHOD("req_restart", "params"), &DebugAdapterParser::req_restart);
47
ClassDB::bind_method(D_METHOD("req_terminate", "params"), &DebugAdapterParser::req_terminate);
48
ClassDB::bind_method(D_METHOD("req_configurationDone", "params"), &DebugAdapterParser::req_configurationDone);
49
ClassDB::bind_method(D_METHOD("req_pause", "params"), &DebugAdapterParser::req_pause);
50
ClassDB::bind_method(D_METHOD("req_continue", "params"), &DebugAdapterParser::req_continue);
51
ClassDB::bind_method(D_METHOD("req_threads", "params"), &DebugAdapterParser::req_threads);
52
ClassDB::bind_method(D_METHOD("req_stackTrace", "params"), &DebugAdapterParser::req_stackTrace);
53
ClassDB::bind_method(D_METHOD("req_setBreakpoints", "params"), &DebugAdapterParser::req_setBreakpoints);
54
ClassDB::bind_method(D_METHOD("req_breakpointLocations", "params"), &DebugAdapterParser::req_breakpointLocations);
55
ClassDB::bind_method(D_METHOD("req_scopes", "params"), &DebugAdapterParser::req_scopes);
56
ClassDB::bind_method(D_METHOD("req_variables", "params"), &DebugAdapterParser::req_variables);
57
ClassDB::bind_method(D_METHOD("req_next", "params"), &DebugAdapterParser::req_next);
58
ClassDB::bind_method(D_METHOD("req_stepIn", "params"), &DebugAdapterParser::req_stepIn);
59
ClassDB::bind_method(D_METHOD("req_evaluate", "params"), &DebugAdapterParser::req_evaluate);
60
ClassDB::bind_method(D_METHOD("req_godot/put_msg", "params"), &DebugAdapterParser::req_godot_put_msg);
61
}
62
63
Dictionary DebugAdapterParser::prepare_base_event() const {
64
Dictionary event;
65
event["type"] = "event";
66
67
return event;
68
}
69
70
Dictionary DebugAdapterParser::prepare_success_response(const Dictionary &p_params) const {
71
Dictionary response;
72
response["type"] = "response";
73
response["request_seq"] = p_params["seq"];
74
response["command"] = p_params["command"];
75
response["success"] = true;
76
77
return response;
78
}
79
80
Dictionary DebugAdapterParser::prepare_error_response(const Dictionary &p_params, DAP::ErrorType err_type, const Dictionary &variables) const {
81
Dictionary response, body;
82
response["type"] = "response";
83
response["request_seq"] = p_params["seq"];
84
response["command"] = p_params["command"];
85
response["success"] = false;
86
response["body"] = body;
87
88
DAP::Message message;
89
String error, error_desc;
90
switch (err_type) {
91
case DAP::ErrorType::WRONG_PATH:
92
error = "wrong_path";
93
error_desc = "The editor and client are working on different paths; the client is on \"{clientPath}\", but the editor is on \"{editorPath}\"";
94
break;
95
case DAP::ErrorType::NOT_RUNNING:
96
error = "not_running";
97
error_desc = "Can't attach to a running session since there isn't one.";
98
break;
99
case DAP::ErrorType::TIMEOUT:
100
error = "timeout";
101
error_desc = "Timeout reached while processing a request.";
102
break;
103
case DAP::ErrorType::UNKNOWN_PLATFORM:
104
error = "unknown_platform";
105
error_desc = "The specified platform is unknown.";
106
break;
107
case DAP::ErrorType::MISSING_DEVICE:
108
error = "missing_device";
109
error_desc = "There's no connected device with specified id.";
110
break;
111
case DAP::ErrorType::UNKNOWN:
112
default:
113
error = "unknown";
114
error_desc = "An unknown error has occurred when processing the request.";
115
break;
116
}
117
118
message.id = err_type;
119
message.format = error_desc;
120
message.variables = variables;
121
response["message"] = error;
122
body["error"] = message.to_json();
123
124
return response;
125
}
126
127
Dictionary DebugAdapterParser::req_initialize(const Dictionary &p_params) const {
128
Dictionary response = prepare_success_response(p_params);
129
Dictionary args = p_params["arguments"];
130
131
Ref<DAPeer> peer = DebugAdapterProtocol::get_singleton()->get_current_peer();
132
133
peer->linesStartAt1 = args.get("linesStartAt1", false);
134
peer->columnsStartAt1 = args.get("columnsStartAt1", false);
135
peer->supportsVariableType = args.get("supportsVariableType", false);
136
peer->supportsInvalidatedEvent = args.get("supportsInvalidatedEvent", false);
137
138
DAP::Capabilities caps;
139
response["body"] = caps.to_json();
140
141
DebugAdapterProtocol::get_singleton()->notify_initialized();
142
143
if (DebugAdapterProtocol::get_singleton()->_sync_breakpoints) {
144
// Send all current breakpoints
145
List<String> breakpoints;
146
ScriptEditor::get_singleton()->get_breakpoints(&breakpoints);
147
for (const String &breakpoint : breakpoints) {
148
String path = breakpoint.left(breakpoint.find_char(':', 6)); // Skip initial part of path, aka "res://"
149
int line = breakpoint.substr(path.size()).to_int();
150
151
DebugAdapterProtocol::get_singleton()->on_debug_breakpoint_toggled(path, line, true);
152
}
153
} else {
154
// Remove all current breakpoints
155
EditorDebuggerNode::get_singleton()->get_default_debugger()->_clear_breakpoints();
156
}
157
158
return response;
159
}
160
161
Dictionary DebugAdapterParser::req_disconnect(const Dictionary &p_params) const {
162
if (!DebugAdapterProtocol::get_singleton()->get_current_peer()->attached) {
163
EditorRunBar::get_singleton()->stop_playing();
164
}
165
166
return prepare_success_response(p_params);
167
}
168
169
Dictionary DebugAdapterParser::req_launch(const Dictionary &p_params) const {
170
Dictionary args = p_params["arguments"];
171
if (args.has("project") && !is_valid_path(args["project"])) {
172
Dictionary variables;
173
variables["clientPath"] = args["project"];
174
variables["editorPath"] = ProjectSettings::get_singleton()->get_resource_path();
175
return prepare_error_response(p_params, DAP::ErrorType::WRONG_PATH, variables);
176
}
177
178
if (args.has("godot/custom_data")) {
179
DebugAdapterProtocol::get_singleton()->get_current_peer()->supportsCustomData = args["godot/custom_data"];
180
}
181
182
DebugAdapterProtocol::get_singleton()->get_current_peer()->pending_launch = p_params;
183
184
return Dictionary();
185
}
186
187
Dictionary DebugAdapterParser::_launch_process(const Dictionary &p_params) const {
188
Dictionary args = p_params["arguments"];
189
ScriptEditorDebugger *dbg = EditorDebuggerNode::get_singleton()->get_default_debugger();
190
if ((bool)args["noDebug"] != dbg->is_skip_breakpoints()) {
191
dbg->debug_skip_breakpoints();
192
}
193
194
String platform_string = args.get("platform", "host");
195
if (platform_string == "host") {
196
EditorRunBar::get_singleton()->play_main_scene();
197
} else {
198
int device = args.get("device", -1);
199
int idx = -1;
200
if (platform_string == "android") {
201
for (int i = 0; i < EditorExport::get_singleton()->get_export_platform_count(); i++) {
202
if (EditorExport::get_singleton()->get_export_platform(i)->get_name() == "Android") {
203
idx = i;
204
break;
205
}
206
}
207
} else if (platform_string == "web") {
208
for (int i = 0; i < EditorExport::get_singleton()->get_export_platform_count(); i++) {
209
if (EditorExport::get_singleton()->get_export_platform(i)->get_name() == "Web") {
210
idx = i;
211
break;
212
}
213
}
214
}
215
216
if (idx == -1) {
217
return prepare_error_response(p_params, DAP::ErrorType::UNKNOWN_PLATFORM);
218
}
219
220
EditorRunBar *run_bar = EditorRunBar::get_singleton();
221
Error err = platform_string == "android" ? run_bar->start_native_device(device * 10000 + idx) : run_bar->start_native_device(idx);
222
if (err) {
223
if (err == ERR_INVALID_PARAMETER && platform_string == "android") {
224
return prepare_error_response(p_params, DAP::ErrorType::MISSING_DEVICE);
225
} else {
226
return prepare_error_response(p_params, DAP::ErrorType::UNKNOWN);
227
}
228
}
229
}
230
231
DebugAdapterProtocol::get_singleton()->get_current_peer()->attached = false;
232
DebugAdapterProtocol::get_singleton()->notify_process();
233
234
return prepare_success_response(p_params);
235
}
236
237
Dictionary DebugAdapterParser::req_attach(const Dictionary &p_params) const {
238
ScriptEditorDebugger *dbg = EditorDebuggerNode::get_singleton()->get_default_debugger();
239
if (!dbg->is_session_active()) {
240
return prepare_error_response(p_params, DAP::ErrorType::NOT_RUNNING);
241
}
242
243
DebugAdapterProtocol::get_singleton()->get_current_peer()->attached = true;
244
DebugAdapterProtocol::get_singleton()->notify_process();
245
return prepare_success_response(p_params);
246
}
247
248
Dictionary DebugAdapterParser::req_restart(const Dictionary &p_params) const {
249
// Extract embedded "arguments" so it can be given to req_launch/req_attach
250
Dictionary params = p_params, args;
251
args = params["arguments"];
252
args = args["arguments"];
253
params["arguments"] = args;
254
255
Dictionary response = DebugAdapterProtocol::get_singleton()->get_current_peer()->attached ? req_attach(params) : _launch_process(params);
256
if (!response["success"]) {
257
response["command"] = p_params["command"];
258
return response;
259
}
260
261
return prepare_success_response(p_params);
262
}
263
264
Dictionary DebugAdapterParser::req_terminate(const Dictionary &p_params) const {
265
EditorRunBar::get_singleton()->stop_playing();
266
267
return prepare_success_response(p_params);
268
}
269
270
Dictionary DebugAdapterParser::req_configurationDone(const Dictionary &p_params) const {
271
Ref<DAPeer> peer = DebugAdapterProtocol::get_singleton()->get_current_peer();
272
if (!peer->pending_launch.is_empty()) {
273
peer->res_queue.push_back(_launch_process(peer->pending_launch));
274
peer->pending_launch.clear();
275
}
276
277
return prepare_success_response(p_params);
278
}
279
280
Dictionary DebugAdapterParser::req_pause(const Dictionary &p_params) const {
281
EditorRunBar::get_singleton()->get_pause_button()->set_pressed(true);
282
EditorDebuggerNode::get_singleton()->_paused();
283
284
DebugAdapterProtocol::get_singleton()->notify_stopped_paused();
285
286
return prepare_success_response(p_params);
287
}
288
289
Dictionary DebugAdapterParser::req_continue(const Dictionary &p_params) const {
290
EditorRunBar::get_singleton()->get_pause_button()->set_pressed(false);
291
EditorDebuggerNode::get_singleton()->_paused();
292
293
DebugAdapterProtocol::get_singleton()->notify_continued();
294
295
return prepare_success_response(p_params);
296
}
297
298
Dictionary DebugAdapterParser::req_threads(const Dictionary &p_params) const {
299
Dictionary response = prepare_success_response(p_params), body;
300
response["body"] = body;
301
302
DAP::Thread thread;
303
304
thread.id = 1; // Hardcoded because Godot only supports debugging one thread at the moment
305
thread.name = "Main";
306
Array arr = { thread.to_json() };
307
body["threads"] = arr;
308
309
return response;
310
}
311
312
Dictionary DebugAdapterParser::req_stackTrace(const Dictionary &p_params) const {
313
if (DebugAdapterProtocol::get_singleton()->_processing_stackdump) {
314
return Dictionary();
315
}
316
317
Dictionary response = prepare_success_response(p_params), body;
318
response["body"] = body;
319
320
bool lines_at_one = DebugAdapterProtocol::get_singleton()->get_current_peer()->linesStartAt1;
321
bool columns_at_one = DebugAdapterProtocol::get_singleton()->get_current_peer()->columnsStartAt1;
322
323
Array arr;
324
DebugAdapterProtocol *dap = DebugAdapterProtocol::get_singleton();
325
for (DAP::StackFrame sf : dap->stackframe_list) {
326
if (!lines_at_one) {
327
sf.line--;
328
}
329
if (!columns_at_one) {
330
sf.column--;
331
}
332
333
arr.push_back(sf.to_json());
334
}
335
336
body["stackFrames"] = arr;
337
return response;
338
}
339
340
Dictionary DebugAdapterParser::req_setBreakpoints(const Dictionary &p_params) const {
341
Dictionary response = prepare_success_response(p_params), body;
342
response["body"] = body;
343
344
Dictionary args = p_params["arguments"];
345
DAP::Source source;
346
source.from_json(args["source"]);
347
348
bool lines_at_one = DebugAdapterProtocol::get_singleton()->get_current_peer()->linesStartAt1;
349
350
if (!is_valid_path(source.path)) {
351
Dictionary variables;
352
variables["clientPath"] = source.path;
353
variables["editorPath"] = ProjectSettings::get_singleton()->get_resource_path();
354
return prepare_error_response(p_params, DAP::ErrorType::WRONG_PATH, variables);
355
}
356
357
// If path contains \, it's a Windows path, so we need to convert it to /, and make the drive letter uppercase
358
if (source.path.contains_char('\\')) {
359
source.path = source.path.replace_char('\\', '/');
360
source.path = source.path.substr(0, 1).to_upper() + source.path.substr(1);
361
}
362
363
Array breakpoints = args["breakpoints"], lines;
364
for (int i = 0; i < breakpoints.size(); i++) {
365
DAP::SourceBreakpoint breakpoint;
366
breakpoint.from_json(breakpoints[i]);
367
368
lines.push_back(breakpoint.line + !lines_at_one);
369
}
370
371
// Always update the source checksum for the requested path, as it might have been modified externally.
372
DebugAdapterProtocol::get_singleton()->update_source(source.path);
373
Array updated_breakpoints = DebugAdapterProtocol::get_singleton()->update_breakpoints(source.path, lines);
374
body["breakpoints"] = updated_breakpoints;
375
376
return response;
377
}
378
379
Dictionary DebugAdapterParser::req_breakpointLocations(const Dictionary &p_params) const {
380
Dictionary response = prepare_success_response(p_params), body;
381
response["body"] = body;
382
Dictionary args = p_params["arguments"];
383
384
DAP::BreakpointLocation location;
385
location.line = args["line"];
386
if (args.has("endLine")) {
387
location.endLine = args["endLine"];
388
}
389
Array locations = { location.to_json() };
390
391
body["breakpoints"] = locations;
392
return response;
393
}
394
395
Dictionary DebugAdapterParser::req_scopes(const Dictionary &p_params) const {
396
Dictionary response = prepare_success_response(p_params), body;
397
response["body"] = body;
398
399
Dictionary args = p_params["arguments"];
400
int frame_id = args["frameId"];
401
Array scope_list;
402
403
HashMap<DebugAdapterProtocol::DAPStackFrameID, Vector<int>>::Iterator E = DebugAdapterProtocol::get_singleton()->scope_list.find(frame_id);
404
if (E) {
405
const Vector<int> &scope_ids = E->value;
406
ERR_FAIL_COND_V(scope_ids.size() != 3, prepare_error_response(p_params, DAP::ErrorType::UNKNOWN));
407
for (int i = 0; i < 3; ++i) {
408
DAP::Scope scope;
409
scope.variablesReference = scope_ids[i];
410
switch (i) {
411
case 0:
412
scope.name = "Locals";
413
scope.presentationHint = "locals";
414
break;
415
case 1:
416
scope.name = "Members";
417
scope.presentationHint = "members";
418
break;
419
case 2:
420
scope.name = "Globals";
421
scope.presentationHint = "globals";
422
}
423
424
scope_list.push_back(scope.to_json());
425
}
426
}
427
428
EditorDebuggerNode::get_singleton()->get_default_debugger()->request_stack_dump(frame_id);
429
DebugAdapterProtocol::get_singleton()->_current_frame = frame_id;
430
431
body["scopes"] = scope_list;
432
return response;
433
}
434
435
Dictionary DebugAdapterParser::req_variables(const Dictionary &p_params) const {
436
// If _remaining_vars > 0, the debuggee is still sending a stack dump to the editor.
437
if (DebugAdapterProtocol::get_singleton()->_remaining_vars > 0) {
438
return Dictionary();
439
}
440
441
Dictionary args = p_params["arguments"];
442
int variable_id = args["variablesReference"];
443
444
if (HashMap<int, Array>::Iterator E = DebugAdapterProtocol::get_singleton()->variable_list.find(variable_id); E) {
445
Dictionary response = prepare_success_response(p_params);
446
Dictionary body;
447
response["body"] = body;
448
449
if (!DebugAdapterProtocol::get_singleton()->get_current_peer()->supportsVariableType) {
450
for (int i = 0; i < E->value.size(); i++) {
451
Dictionary variable = E->value[i];
452
variable.erase("type");
453
}
454
}
455
456
body["variables"] = E ? E->value : Array();
457
return response;
458
} else {
459
// If the requested variable is an object, it needs to be requested from the debuggee.
460
ObjectID object_id = DebugAdapterProtocol::get_singleton()->search_object_id(variable_id);
461
462
if (object_id.is_null()) {
463
return prepare_error_response(p_params, DAP::ErrorType::UNKNOWN);
464
}
465
466
DebugAdapterProtocol::get_singleton()->request_remote_object(object_id);
467
}
468
return Dictionary();
469
}
470
471
Dictionary DebugAdapterParser::req_next(const Dictionary &p_params) const {
472
EditorDebuggerNode::get_singleton()->get_default_debugger()->debug_next();
473
DebugAdapterProtocol::get_singleton()->_stepping = true;
474
475
return prepare_success_response(p_params);
476
}
477
478
Dictionary DebugAdapterParser::req_stepIn(const Dictionary &p_params) const {
479
EditorDebuggerNode::get_singleton()->get_default_debugger()->debug_step();
480
DebugAdapterProtocol::get_singleton()->_stepping = true;
481
482
return prepare_success_response(p_params);
483
}
484
485
Dictionary DebugAdapterParser::req_evaluate(const Dictionary &p_params) const {
486
Dictionary args = p_params["arguments"];
487
String expression = args["expression"];
488
int frame_id = args.has("frameId") ? static_cast<int>(args["frameId"]) : DebugAdapterProtocol::get_singleton()->_current_frame;
489
490
if (HashMap<String, DAP::Variable>::Iterator E = DebugAdapterProtocol::get_singleton()->eval_list.find(expression); E) {
491
Dictionary response = prepare_success_response(p_params);
492
Dictionary body;
493
response["body"] = body;
494
495
DAP::Variable var = E->value;
496
497
body["result"] = var.value;
498
body["variablesReference"] = var.variablesReference;
499
500
// Since an evaluation can alter the state of the debuggee, they are volatile, and should only be used once
501
DebugAdapterProtocol::get_singleton()->eval_list.erase(E->key);
502
return response;
503
} else {
504
DebugAdapterProtocol::get_singleton()->request_remote_evaluate(expression, frame_id);
505
}
506
return Dictionary();
507
}
508
509
Dictionary DebugAdapterParser::req_godot_put_msg(const Dictionary &p_params) const {
510
Dictionary args = p_params["arguments"];
511
512
String msg = args["message"];
513
Array data = args["data"];
514
515
EditorDebuggerNode::get_singleton()->get_default_debugger()->_put_msg(msg, data);
516
517
return prepare_success_response(p_params);
518
}
519
520
Dictionary DebugAdapterParser::ev_initialized() const {
521
Dictionary event = prepare_base_event();
522
event["event"] = "initialized";
523
524
return event;
525
}
526
527
Dictionary DebugAdapterParser::ev_process(const String &p_command) const {
528
Dictionary event = prepare_base_event(), body;
529
event["event"] = "process";
530
event["body"] = body;
531
532
body["name"] = OS::get_singleton()->get_executable_path();
533
body["startMethod"] = p_command;
534
535
return event;
536
}
537
538
Dictionary DebugAdapterParser::ev_terminated() const {
539
Dictionary event = prepare_base_event();
540
event["event"] = "terminated";
541
542
return event;
543
}
544
545
Dictionary DebugAdapterParser::ev_exited(const int &p_exitcode) const {
546
Dictionary event = prepare_base_event(), body;
547
event["event"] = "exited";
548
event["body"] = body;
549
550
body["exitCode"] = p_exitcode;
551
552
return event;
553
}
554
555
Dictionary DebugAdapterParser::ev_stopped() const {
556
Dictionary event = prepare_base_event(), body;
557
event["event"] = "stopped";
558
event["body"] = body;
559
560
body["threadId"] = 1;
561
562
return event;
563
}
564
565
Dictionary DebugAdapterParser::ev_stopped_paused() const {
566
Dictionary event = ev_stopped();
567
Dictionary body = event["body"];
568
569
body["reason"] = "paused";
570
body["description"] = "Paused";
571
572
return event;
573
}
574
575
Dictionary DebugAdapterParser::ev_stopped_exception(const String &p_error) const {
576
Dictionary event = ev_stopped();
577
Dictionary body = event["body"];
578
579
body["reason"] = "exception";
580
body["description"] = "Exception";
581
body["text"] = p_error;
582
583
return event;
584
}
585
586
Dictionary DebugAdapterParser::ev_stopped_breakpoint(const int &p_id) const {
587
Dictionary event = ev_stopped();
588
Dictionary body = event["body"];
589
590
body["reason"] = "breakpoint";
591
body["description"] = "Breakpoint";
592
593
Array breakpoints = { p_id };
594
body["hitBreakpointIds"] = breakpoints;
595
596
return event;
597
}
598
599
Dictionary DebugAdapterParser::ev_stopped_step() const {
600
Dictionary event = ev_stopped();
601
Dictionary body = event["body"];
602
603
body["reason"] = "step";
604
body["description"] = "Breakpoint";
605
606
return event;
607
}
608
609
Dictionary DebugAdapterParser::ev_continued() const {
610
Dictionary event = prepare_base_event(), body;
611
event["event"] = "continued";
612
event["body"] = body;
613
614
body["threadId"] = 1;
615
616
return event;
617
}
618
619
Dictionary DebugAdapterParser::ev_output(const String &p_message, RemoteDebugger::MessageType p_type) const {
620
Dictionary event = prepare_base_event(), body;
621
event["event"] = "output";
622
event["body"] = body;
623
624
body["category"] = (p_type == RemoteDebugger::MessageType::MESSAGE_TYPE_ERROR) ? "stderr" : "stdout";
625
body["output"] = p_message + "\r\n";
626
627
return event;
628
}
629
630
Dictionary DebugAdapterParser::ev_breakpoint(const DAP::Breakpoint &p_breakpoint, const bool &p_enabled) const {
631
Dictionary event = prepare_base_event(), body;
632
event["event"] = "breakpoint";
633
event["body"] = body;
634
635
body["reason"] = p_enabled ? "new" : "removed";
636
body["breakpoint"] = p_breakpoint.to_json();
637
638
return event;
639
}
640
641
Dictionary DebugAdapterParser::ev_custom_data(const String &p_msg, const Array &p_data) const {
642
Dictionary event = prepare_base_event(), body;
643
event["event"] = "godot/custom_data";
644
event["body"] = body;
645
646
body["message"] = p_msg;
647
body["data"] = p_data;
648
649
return event;
650
}
651
652