initial commit, 4.5 stable
Some checks failed
🔗 GHA / 📊 Static checks (push) Has been cancelled
🔗 GHA / 🤖 Android (push) Has been cancelled
🔗 GHA / 🍏 iOS (push) Has been cancelled
🔗 GHA / 🐧 Linux (push) Has been cancelled
🔗 GHA / 🍎 macOS (push) Has been cancelled
🔗 GHA / 🏁 Windows (push) Has been cancelled
🔗 GHA / 🌐 Web (push) Has been cancelled
Some checks failed
🔗 GHA / 📊 Static checks (push) Has been cancelled
🔗 GHA / 🤖 Android (push) Has been cancelled
🔗 GHA / 🍏 iOS (push) Has been cancelled
🔗 GHA / 🐧 Linux (push) Has been cancelled
🔗 GHA / 🍎 macOS (push) Has been cancelled
🔗 GHA / 🏁 Windows (push) Has been cancelled
🔗 GHA / 🌐 Web (push) Has been cancelled
This commit is contained in:
6
editor/debugger/debug_adapter/SCsub
Normal file
6
editor/debugger/debug_adapter/SCsub
Normal file
@@ -0,0 +1,6 @@
|
||||
#!/usr/bin/env python
|
||||
from misc.utility.scons_hints import *
|
||||
|
||||
Import("env")
|
||||
|
||||
env.add_source_files(env.editor_sources, "*.cpp")
|
650
editor/debugger/debug_adapter/debug_adapter_parser.cpp
Normal file
650
editor/debugger/debug_adapter/debug_adapter_parser.cpp
Normal file
@@ -0,0 +1,650 @@
|
||||
/**************************************************************************/
|
||||
/* debug_adapter_parser.cpp */
|
||||
/**************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/**************************************************************************/
|
||||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
||||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#include "debug_adapter_parser.h"
|
||||
|
||||
#include "editor/debugger/debug_adapter/debug_adapter_types.h"
|
||||
#include "editor/debugger/editor_debugger_node.h"
|
||||
#include "editor/debugger/script_editor_debugger.h"
|
||||
#include "editor/export/editor_export_platform.h"
|
||||
#include "editor/run/editor_run_bar.h"
|
||||
#include "editor/script/script_editor_plugin.h"
|
||||
|
||||
void DebugAdapterParser::_bind_methods() {
|
||||
// Requests
|
||||
ClassDB::bind_method(D_METHOD("req_initialize", "params"), &DebugAdapterParser::req_initialize);
|
||||
ClassDB::bind_method(D_METHOD("req_disconnect", "params"), &DebugAdapterParser::req_disconnect);
|
||||
ClassDB::bind_method(D_METHOD("req_launch", "params"), &DebugAdapterParser::req_launch);
|
||||
ClassDB::bind_method(D_METHOD("req_attach", "params"), &DebugAdapterParser::req_attach);
|
||||
ClassDB::bind_method(D_METHOD("req_restart", "params"), &DebugAdapterParser::req_restart);
|
||||
ClassDB::bind_method(D_METHOD("req_terminate", "params"), &DebugAdapterParser::req_terminate);
|
||||
ClassDB::bind_method(D_METHOD("req_configurationDone", "params"), &DebugAdapterParser::req_configurationDone);
|
||||
ClassDB::bind_method(D_METHOD("req_pause", "params"), &DebugAdapterParser::req_pause);
|
||||
ClassDB::bind_method(D_METHOD("req_continue", "params"), &DebugAdapterParser::req_continue);
|
||||
ClassDB::bind_method(D_METHOD("req_threads", "params"), &DebugAdapterParser::req_threads);
|
||||
ClassDB::bind_method(D_METHOD("req_stackTrace", "params"), &DebugAdapterParser::req_stackTrace);
|
||||
ClassDB::bind_method(D_METHOD("req_setBreakpoints", "params"), &DebugAdapterParser::req_setBreakpoints);
|
||||
ClassDB::bind_method(D_METHOD("req_breakpointLocations", "params"), &DebugAdapterParser::req_breakpointLocations);
|
||||
ClassDB::bind_method(D_METHOD("req_scopes", "params"), &DebugAdapterParser::req_scopes);
|
||||
ClassDB::bind_method(D_METHOD("req_variables", "params"), &DebugAdapterParser::req_variables);
|
||||
ClassDB::bind_method(D_METHOD("req_next", "params"), &DebugAdapterParser::req_next);
|
||||
ClassDB::bind_method(D_METHOD("req_stepIn", "params"), &DebugAdapterParser::req_stepIn);
|
||||
ClassDB::bind_method(D_METHOD("req_evaluate", "params"), &DebugAdapterParser::req_evaluate);
|
||||
ClassDB::bind_method(D_METHOD("req_godot/put_msg", "params"), &DebugAdapterParser::req_godot_put_msg);
|
||||
}
|
||||
|
||||
Dictionary DebugAdapterParser::prepare_base_event() const {
|
||||
Dictionary event;
|
||||
event["type"] = "event";
|
||||
|
||||
return event;
|
||||
}
|
||||
|
||||
Dictionary DebugAdapterParser::prepare_success_response(const Dictionary &p_params) const {
|
||||
Dictionary response;
|
||||
response["type"] = "response";
|
||||
response["request_seq"] = p_params["seq"];
|
||||
response["command"] = p_params["command"];
|
||||
response["success"] = true;
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
Dictionary DebugAdapterParser::prepare_error_response(const Dictionary &p_params, DAP::ErrorType err_type, const Dictionary &variables) const {
|
||||
Dictionary response, body;
|
||||
response["type"] = "response";
|
||||
response["request_seq"] = p_params["seq"];
|
||||
response["command"] = p_params["command"];
|
||||
response["success"] = false;
|
||||
response["body"] = body;
|
||||
|
||||
DAP::Message message;
|
||||
String error, error_desc;
|
||||
switch (err_type) {
|
||||
case DAP::ErrorType::WRONG_PATH:
|
||||
error = "wrong_path";
|
||||
error_desc = "The editor and client are working on different paths; the client is on \"{clientPath}\", but the editor is on \"{editorPath}\"";
|
||||
break;
|
||||
case DAP::ErrorType::NOT_RUNNING:
|
||||
error = "not_running";
|
||||
error_desc = "Can't attach to a running session since there isn't one.";
|
||||
break;
|
||||
case DAP::ErrorType::TIMEOUT:
|
||||
error = "timeout";
|
||||
error_desc = "Timeout reached while processing a request.";
|
||||
break;
|
||||
case DAP::ErrorType::UNKNOWN_PLATFORM:
|
||||
error = "unknown_platform";
|
||||
error_desc = "The specified platform is unknown.";
|
||||
break;
|
||||
case DAP::ErrorType::MISSING_DEVICE:
|
||||
error = "missing_device";
|
||||
error_desc = "There's no connected device with specified id.";
|
||||
break;
|
||||
case DAP::ErrorType::UNKNOWN:
|
||||
default:
|
||||
error = "unknown";
|
||||
error_desc = "An unknown error has occurred when processing the request.";
|
||||
break;
|
||||
}
|
||||
|
||||
message.id = err_type;
|
||||
message.format = error_desc;
|
||||
message.variables = variables;
|
||||
response["message"] = error;
|
||||
body["error"] = message.to_json();
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
Dictionary DebugAdapterParser::req_initialize(const Dictionary &p_params) const {
|
||||
Dictionary response = prepare_success_response(p_params);
|
||||
Dictionary args = p_params["arguments"];
|
||||
|
||||
Ref<DAPeer> peer = DebugAdapterProtocol::get_singleton()->get_current_peer();
|
||||
|
||||
peer->linesStartAt1 = args.get("linesStartAt1", false);
|
||||
peer->columnsStartAt1 = args.get("columnsStartAt1", false);
|
||||
peer->supportsVariableType = args.get("supportsVariableType", false);
|
||||
peer->supportsInvalidatedEvent = args.get("supportsInvalidatedEvent", false);
|
||||
|
||||
DAP::Capabilities caps;
|
||||
response["body"] = caps.to_json();
|
||||
|
||||
DebugAdapterProtocol::get_singleton()->notify_initialized();
|
||||
|
||||
if (DebugAdapterProtocol::get_singleton()->_sync_breakpoints) {
|
||||
// Send all current breakpoints
|
||||
List<String> breakpoints;
|
||||
ScriptEditor::get_singleton()->get_breakpoints(&breakpoints);
|
||||
for (const String &breakpoint : breakpoints) {
|
||||
String path = breakpoint.left(breakpoint.find_char(':', 6)); // Skip initial part of path, aka "res://"
|
||||
int line = breakpoint.substr(path.size()).to_int();
|
||||
|
||||
DebugAdapterProtocol::get_singleton()->on_debug_breakpoint_toggled(path, line, true);
|
||||
}
|
||||
} else {
|
||||
// Remove all current breakpoints
|
||||
EditorDebuggerNode::get_singleton()->get_default_debugger()->_clear_breakpoints();
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
Dictionary DebugAdapterParser::req_disconnect(const Dictionary &p_params) const {
|
||||
if (!DebugAdapterProtocol::get_singleton()->get_current_peer()->attached) {
|
||||
EditorRunBar::get_singleton()->stop_playing();
|
||||
}
|
||||
|
||||
return prepare_success_response(p_params);
|
||||
}
|
||||
|
||||
Dictionary DebugAdapterParser::req_launch(const Dictionary &p_params) const {
|
||||
Dictionary args = p_params["arguments"];
|
||||
if (args.has("project") && !is_valid_path(args["project"])) {
|
||||
Dictionary variables;
|
||||
variables["clientPath"] = args["project"];
|
||||
variables["editorPath"] = ProjectSettings::get_singleton()->get_resource_path();
|
||||
return prepare_error_response(p_params, DAP::ErrorType::WRONG_PATH, variables);
|
||||
}
|
||||
|
||||
if (args.has("godot/custom_data")) {
|
||||
DebugAdapterProtocol::get_singleton()->get_current_peer()->supportsCustomData = args["godot/custom_data"];
|
||||
}
|
||||
|
||||
DebugAdapterProtocol::get_singleton()->get_current_peer()->pending_launch = p_params;
|
||||
|
||||
return Dictionary();
|
||||
}
|
||||
|
||||
Dictionary DebugAdapterParser::_launch_process(const Dictionary &p_params) const {
|
||||
Dictionary args = p_params["arguments"];
|
||||
ScriptEditorDebugger *dbg = EditorDebuggerNode::get_singleton()->get_default_debugger();
|
||||
if ((bool)args["noDebug"] != dbg->is_skip_breakpoints()) {
|
||||
dbg->debug_skip_breakpoints();
|
||||
}
|
||||
|
||||
String platform_string = args.get("platform", "host");
|
||||
if (platform_string == "host") {
|
||||
EditorRunBar::get_singleton()->play_main_scene();
|
||||
} else {
|
||||
int device = args.get("device", -1);
|
||||
int idx = -1;
|
||||
if (platform_string == "android") {
|
||||
for (int i = 0; i < EditorExport::get_singleton()->get_export_platform_count(); i++) {
|
||||
if (EditorExport::get_singleton()->get_export_platform(i)->get_name() == "Android") {
|
||||
idx = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (platform_string == "web") {
|
||||
for (int i = 0; i < EditorExport::get_singleton()->get_export_platform_count(); i++) {
|
||||
if (EditorExport::get_singleton()->get_export_platform(i)->get_name() == "Web") {
|
||||
idx = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (idx == -1) {
|
||||
return prepare_error_response(p_params, DAP::ErrorType::UNKNOWN_PLATFORM);
|
||||
}
|
||||
|
||||
EditorRunBar *run_bar = EditorRunBar::get_singleton();
|
||||
Error err = platform_string == "android" ? run_bar->start_native_device(device * 10000 + idx) : run_bar->start_native_device(idx);
|
||||
if (err) {
|
||||
if (err == ERR_INVALID_PARAMETER && platform_string == "android") {
|
||||
return prepare_error_response(p_params, DAP::ErrorType::MISSING_DEVICE);
|
||||
} else {
|
||||
return prepare_error_response(p_params, DAP::ErrorType::UNKNOWN);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DebugAdapterProtocol::get_singleton()->get_current_peer()->attached = false;
|
||||
DebugAdapterProtocol::get_singleton()->notify_process();
|
||||
|
||||
return prepare_success_response(p_params);
|
||||
}
|
||||
|
||||
Dictionary DebugAdapterParser::req_attach(const Dictionary &p_params) const {
|
||||
ScriptEditorDebugger *dbg = EditorDebuggerNode::get_singleton()->get_default_debugger();
|
||||
if (!dbg->is_session_active()) {
|
||||
return prepare_error_response(p_params, DAP::ErrorType::NOT_RUNNING);
|
||||
}
|
||||
|
||||
DebugAdapterProtocol::get_singleton()->get_current_peer()->attached = true;
|
||||
DebugAdapterProtocol::get_singleton()->notify_process();
|
||||
return prepare_success_response(p_params);
|
||||
}
|
||||
|
||||
Dictionary DebugAdapterParser::req_restart(const Dictionary &p_params) const {
|
||||
// Extract embedded "arguments" so it can be given to req_launch/req_attach
|
||||
Dictionary params = p_params, args;
|
||||
args = params["arguments"];
|
||||
args = args["arguments"];
|
||||
params["arguments"] = args;
|
||||
|
||||
Dictionary response = DebugAdapterProtocol::get_singleton()->get_current_peer()->attached ? req_attach(params) : _launch_process(params);
|
||||
if (!response["success"]) {
|
||||
response["command"] = p_params["command"];
|
||||
return response;
|
||||
}
|
||||
|
||||
return prepare_success_response(p_params);
|
||||
}
|
||||
|
||||
Dictionary DebugAdapterParser::req_terminate(const Dictionary &p_params) const {
|
||||
EditorRunBar::get_singleton()->stop_playing();
|
||||
|
||||
return prepare_success_response(p_params);
|
||||
}
|
||||
|
||||
Dictionary DebugAdapterParser::req_configurationDone(const Dictionary &p_params) const {
|
||||
Ref<DAPeer> peer = DebugAdapterProtocol::get_singleton()->get_current_peer();
|
||||
if (!peer->pending_launch.is_empty()) {
|
||||
peer->res_queue.push_back(_launch_process(peer->pending_launch));
|
||||
peer->pending_launch.clear();
|
||||
}
|
||||
|
||||
return prepare_success_response(p_params);
|
||||
}
|
||||
|
||||
Dictionary DebugAdapterParser::req_pause(const Dictionary &p_params) const {
|
||||
EditorRunBar::get_singleton()->get_pause_button()->set_pressed(true);
|
||||
EditorDebuggerNode::get_singleton()->_paused();
|
||||
|
||||
DebugAdapterProtocol::get_singleton()->notify_stopped_paused();
|
||||
|
||||
return prepare_success_response(p_params);
|
||||
}
|
||||
|
||||
Dictionary DebugAdapterParser::req_continue(const Dictionary &p_params) const {
|
||||
EditorRunBar::get_singleton()->get_pause_button()->set_pressed(false);
|
||||
EditorDebuggerNode::get_singleton()->_paused();
|
||||
|
||||
DebugAdapterProtocol::get_singleton()->notify_continued();
|
||||
|
||||
return prepare_success_response(p_params);
|
||||
}
|
||||
|
||||
Dictionary DebugAdapterParser::req_threads(const Dictionary &p_params) const {
|
||||
Dictionary response = prepare_success_response(p_params), body;
|
||||
response["body"] = body;
|
||||
|
||||
DAP::Thread thread;
|
||||
|
||||
thread.id = 1; // Hardcoded because Godot only supports debugging one thread at the moment
|
||||
thread.name = "Main";
|
||||
Array arr = { thread.to_json() };
|
||||
body["threads"] = arr;
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
Dictionary DebugAdapterParser::req_stackTrace(const Dictionary &p_params) const {
|
||||
if (DebugAdapterProtocol::get_singleton()->_processing_stackdump) {
|
||||
return Dictionary();
|
||||
}
|
||||
|
||||
Dictionary response = prepare_success_response(p_params), body;
|
||||
response["body"] = body;
|
||||
|
||||
bool lines_at_one = DebugAdapterProtocol::get_singleton()->get_current_peer()->linesStartAt1;
|
||||
bool columns_at_one = DebugAdapterProtocol::get_singleton()->get_current_peer()->columnsStartAt1;
|
||||
|
||||
Array arr;
|
||||
DebugAdapterProtocol *dap = DebugAdapterProtocol::get_singleton();
|
||||
for (DAP::StackFrame sf : dap->stackframe_list) {
|
||||
if (!lines_at_one) {
|
||||
sf.line--;
|
||||
}
|
||||
if (!columns_at_one) {
|
||||
sf.column--;
|
||||
}
|
||||
|
||||
arr.push_back(sf.to_json());
|
||||
}
|
||||
|
||||
body["stackFrames"] = arr;
|
||||
return response;
|
||||
}
|
||||
|
||||
Dictionary DebugAdapterParser::req_setBreakpoints(const Dictionary &p_params) const {
|
||||
Dictionary response = prepare_success_response(p_params), body;
|
||||
response["body"] = body;
|
||||
|
||||
Dictionary args = p_params["arguments"];
|
||||
DAP::Source source;
|
||||
source.from_json(args["source"]);
|
||||
|
||||
bool lines_at_one = DebugAdapterProtocol::get_singleton()->get_current_peer()->linesStartAt1;
|
||||
|
||||
if (!is_valid_path(source.path)) {
|
||||
Dictionary variables;
|
||||
variables["clientPath"] = source.path;
|
||||
variables["editorPath"] = ProjectSettings::get_singleton()->get_resource_path();
|
||||
return prepare_error_response(p_params, DAP::ErrorType::WRONG_PATH, variables);
|
||||
}
|
||||
|
||||
// If path contains \, it's a Windows path, so we need to convert it to /, and make the drive letter uppercase
|
||||
if (source.path.contains_char('\\')) {
|
||||
source.path = source.path.replace_char('\\', '/');
|
||||
source.path = source.path.substr(0, 1).to_upper() + source.path.substr(1);
|
||||
}
|
||||
|
||||
Array breakpoints = args["breakpoints"], lines;
|
||||
for (int i = 0; i < breakpoints.size(); i++) {
|
||||
DAP::SourceBreakpoint breakpoint;
|
||||
breakpoint.from_json(breakpoints[i]);
|
||||
|
||||
lines.push_back(breakpoint.line + !lines_at_one);
|
||||
}
|
||||
|
||||
// Always update the source checksum for the requested path, as it might have been modified externally.
|
||||
DebugAdapterProtocol::get_singleton()->update_source(source.path);
|
||||
Array updated_breakpoints = DebugAdapterProtocol::get_singleton()->update_breakpoints(source.path, lines);
|
||||
body["breakpoints"] = updated_breakpoints;
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
Dictionary DebugAdapterParser::req_breakpointLocations(const Dictionary &p_params) const {
|
||||
Dictionary response = prepare_success_response(p_params), body;
|
||||
response["body"] = body;
|
||||
Dictionary args = p_params["arguments"];
|
||||
|
||||
DAP::BreakpointLocation location;
|
||||
location.line = args["line"];
|
||||
if (args.has("endLine")) {
|
||||
location.endLine = args["endLine"];
|
||||
}
|
||||
Array locations = { location.to_json() };
|
||||
|
||||
body["breakpoints"] = locations;
|
||||
return response;
|
||||
}
|
||||
|
||||
Dictionary DebugAdapterParser::req_scopes(const Dictionary &p_params) const {
|
||||
Dictionary response = prepare_success_response(p_params), body;
|
||||
response["body"] = body;
|
||||
|
||||
Dictionary args = p_params["arguments"];
|
||||
int frame_id = args["frameId"];
|
||||
Array scope_list;
|
||||
|
||||
HashMap<DebugAdapterProtocol::DAPStackFrameID, Vector<int>>::Iterator E = DebugAdapterProtocol::get_singleton()->scope_list.find(frame_id);
|
||||
if (E) {
|
||||
const Vector<int> &scope_ids = E->value;
|
||||
ERR_FAIL_COND_V(scope_ids.size() != 3, prepare_error_response(p_params, DAP::ErrorType::UNKNOWN));
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
DAP::Scope scope;
|
||||
scope.variablesReference = scope_ids[i];
|
||||
switch (i) {
|
||||
case 0:
|
||||
scope.name = "Locals";
|
||||
scope.presentationHint = "locals";
|
||||
break;
|
||||
case 1:
|
||||
scope.name = "Members";
|
||||
scope.presentationHint = "members";
|
||||
break;
|
||||
case 2:
|
||||
scope.name = "Globals";
|
||||
scope.presentationHint = "globals";
|
||||
}
|
||||
|
||||
scope_list.push_back(scope.to_json());
|
||||
}
|
||||
}
|
||||
|
||||
EditorDebuggerNode::get_singleton()->get_default_debugger()->request_stack_dump(frame_id);
|
||||
DebugAdapterProtocol::get_singleton()->_current_frame = frame_id;
|
||||
|
||||
body["scopes"] = scope_list;
|
||||
return response;
|
||||
}
|
||||
|
||||
Dictionary DebugAdapterParser::req_variables(const Dictionary &p_params) const {
|
||||
// If _remaining_vars > 0, the debuggee is still sending a stack dump to the editor.
|
||||
if (DebugAdapterProtocol::get_singleton()->_remaining_vars > 0) {
|
||||
return Dictionary();
|
||||
}
|
||||
|
||||
Dictionary args = p_params["arguments"];
|
||||
int variable_id = args["variablesReference"];
|
||||
|
||||
if (HashMap<int, Array>::Iterator E = DebugAdapterProtocol::get_singleton()->variable_list.find(variable_id); E) {
|
||||
Dictionary response = prepare_success_response(p_params);
|
||||
Dictionary body;
|
||||
response["body"] = body;
|
||||
|
||||
if (!DebugAdapterProtocol::get_singleton()->get_current_peer()->supportsVariableType) {
|
||||
for (int i = 0; i < E->value.size(); i++) {
|
||||
Dictionary variable = E->value[i];
|
||||
variable.erase("type");
|
||||
}
|
||||
}
|
||||
|
||||
body["variables"] = E ? E->value : Array();
|
||||
return response;
|
||||
} else {
|
||||
// If the requested variable is an object, it needs to be requested from the debuggee.
|
||||
ObjectID object_id = DebugAdapterProtocol::get_singleton()->search_object_id(variable_id);
|
||||
|
||||
if (object_id.is_null()) {
|
||||
return prepare_error_response(p_params, DAP::ErrorType::UNKNOWN);
|
||||
}
|
||||
|
||||
DebugAdapterProtocol::get_singleton()->request_remote_object(object_id);
|
||||
}
|
||||
return Dictionary();
|
||||
}
|
||||
|
||||
Dictionary DebugAdapterParser::req_next(const Dictionary &p_params) const {
|
||||
EditorDebuggerNode::get_singleton()->get_default_debugger()->debug_next();
|
||||
DebugAdapterProtocol::get_singleton()->_stepping = true;
|
||||
|
||||
return prepare_success_response(p_params);
|
||||
}
|
||||
|
||||
Dictionary DebugAdapterParser::req_stepIn(const Dictionary &p_params) const {
|
||||
EditorDebuggerNode::get_singleton()->get_default_debugger()->debug_step();
|
||||
DebugAdapterProtocol::get_singleton()->_stepping = true;
|
||||
|
||||
return prepare_success_response(p_params);
|
||||
}
|
||||
|
||||
Dictionary DebugAdapterParser::req_evaluate(const Dictionary &p_params) const {
|
||||
Dictionary args = p_params["arguments"];
|
||||
String expression = args["expression"];
|
||||
int frame_id = args.has("frameId") ? static_cast<int>(args["frameId"]) : DebugAdapterProtocol::get_singleton()->_current_frame;
|
||||
|
||||
if (HashMap<String, DAP::Variable>::Iterator E = DebugAdapterProtocol::get_singleton()->eval_list.find(expression); E) {
|
||||
Dictionary response = prepare_success_response(p_params);
|
||||
Dictionary body;
|
||||
response["body"] = body;
|
||||
|
||||
DAP::Variable var = E->value;
|
||||
|
||||
body["result"] = var.value;
|
||||
body["variablesReference"] = var.variablesReference;
|
||||
|
||||
// Since an evaluation can alter the state of the debuggee, they are volatile, and should only be used once
|
||||
DebugAdapterProtocol::get_singleton()->eval_list.erase(E->key);
|
||||
return response;
|
||||
} else {
|
||||
DebugAdapterProtocol::get_singleton()->request_remote_evaluate(expression, frame_id);
|
||||
}
|
||||
return Dictionary();
|
||||
}
|
||||
|
||||
Dictionary DebugAdapterParser::req_godot_put_msg(const Dictionary &p_params) const {
|
||||
Dictionary args = p_params["arguments"];
|
||||
|
||||
String msg = args["message"];
|
||||
Array data = args["data"];
|
||||
|
||||
EditorDebuggerNode::get_singleton()->get_default_debugger()->_put_msg(msg, data);
|
||||
|
||||
return prepare_success_response(p_params);
|
||||
}
|
||||
|
||||
Dictionary DebugAdapterParser::ev_initialized() const {
|
||||
Dictionary event = prepare_base_event();
|
||||
event["event"] = "initialized";
|
||||
|
||||
return event;
|
||||
}
|
||||
|
||||
Dictionary DebugAdapterParser::ev_process(const String &p_command) const {
|
||||
Dictionary event = prepare_base_event(), body;
|
||||
event["event"] = "process";
|
||||
event["body"] = body;
|
||||
|
||||
body["name"] = OS::get_singleton()->get_executable_path();
|
||||
body["startMethod"] = p_command;
|
||||
|
||||
return event;
|
||||
}
|
||||
|
||||
Dictionary DebugAdapterParser::ev_terminated() const {
|
||||
Dictionary event = prepare_base_event();
|
||||
event["event"] = "terminated";
|
||||
|
||||
return event;
|
||||
}
|
||||
|
||||
Dictionary DebugAdapterParser::ev_exited(const int &p_exitcode) const {
|
||||
Dictionary event = prepare_base_event(), body;
|
||||
event["event"] = "exited";
|
||||
event["body"] = body;
|
||||
|
||||
body["exitCode"] = p_exitcode;
|
||||
|
||||
return event;
|
||||
}
|
||||
|
||||
Dictionary DebugAdapterParser::ev_stopped() const {
|
||||
Dictionary event = prepare_base_event(), body;
|
||||
event["event"] = "stopped";
|
||||
event["body"] = body;
|
||||
|
||||
body["threadId"] = 1;
|
||||
|
||||
return event;
|
||||
}
|
||||
|
||||
Dictionary DebugAdapterParser::ev_stopped_paused() const {
|
||||
Dictionary event = ev_stopped();
|
||||
Dictionary body = event["body"];
|
||||
|
||||
body["reason"] = "paused";
|
||||
body["description"] = "Paused";
|
||||
|
||||
return event;
|
||||
}
|
||||
|
||||
Dictionary DebugAdapterParser::ev_stopped_exception(const String &p_error) const {
|
||||
Dictionary event = ev_stopped();
|
||||
Dictionary body = event["body"];
|
||||
|
||||
body["reason"] = "exception";
|
||||
body["description"] = "Exception";
|
||||
body["text"] = p_error;
|
||||
|
||||
return event;
|
||||
}
|
||||
|
||||
Dictionary DebugAdapterParser::ev_stopped_breakpoint(const int &p_id) const {
|
||||
Dictionary event = ev_stopped();
|
||||
Dictionary body = event["body"];
|
||||
|
||||
body["reason"] = "breakpoint";
|
||||
body["description"] = "Breakpoint";
|
||||
|
||||
Array breakpoints = { p_id };
|
||||
body["hitBreakpointIds"] = breakpoints;
|
||||
|
||||
return event;
|
||||
}
|
||||
|
||||
Dictionary DebugAdapterParser::ev_stopped_step() const {
|
||||
Dictionary event = ev_stopped();
|
||||
Dictionary body = event["body"];
|
||||
|
||||
body["reason"] = "step";
|
||||
body["description"] = "Breakpoint";
|
||||
|
||||
return event;
|
||||
}
|
||||
|
||||
Dictionary DebugAdapterParser::ev_continued() const {
|
||||
Dictionary event = prepare_base_event(), body;
|
||||
event["event"] = "continued";
|
||||
event["body"] = body;
|
||||
|
||||
body["threadId"] = 1;
|
||||
|
||||
return event;
|
||||
}
|
||||
|
||||
Dictionary DebugAdapterParser::ev_output(const String &p_message, RemoteDebugger::MessageType p_type) const {
|
||||
Dictionary event = prepare_base_event(), body;
|
||||
event["event"] = "output";
|
||||
event["body"] = body;
|
||||
|
||||
body["category"] = (p_type == RemoteDebugger::MessageType::MESSAGE_TYPE_ERROR) ? "stderr" : "stdout";
|
||||
body["output"] = p_message + "\r\n";
|
||||
|
||||
return event;
|
||||
}
|
||||
|
||||
Dictionary DebugAdapterParser::ev_breakpoint(const DAP::Breakpoint &p_breakpoint, const bool &p_enabled) const {
|
||||
Dictionary event = prepare_base_event(), body;
|
||||
event["event"] = "breakpoint";
|
||||
event["body"] = body;
|
||||
|
||||
body["reason"] = p_enabled ? "new" : "removed";
|
||||
body["breakpoint"] = p_breakpoint.to_json();
|
||||
|
||||
return event;
|
||||
}
|
||||
|
||||
Dictionary DebugAdapterParser::ev_custom_data(const String &p_msg, const Array &p_data) const {
|
||||
Dictionary event = prepare_base_event(), body;
|
||||
event["event"] = "godot/custom_data";
|
||||
event["body"] = body;
|
||||
|
||||
body["message"] = p_msg;
|
||||
body["data"] = p_data;
|
||||
|
||||
return event;
|
||||
}
|
104
editor/debugger/debug_adapter/debug_adapter_parser.h
Normal file
104
editor/debugger/debug_adapter/debug_adapter_parser.h
Normal file
@@ -0,0 +1,104 @@
|
||||
/**************************************************************************/
|
||||
/* debug_adapter_parser.h */
|
||||
/**************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/**************************************************************************/
|
||||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
||||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "core/config/project_settings.h"
|
||||
#include "core/debugger/remote_debugger.h"
|
||||
#include "debug_adapter_protocol.h"
|
||||
#include "debug_adapter_types.h"
|
||||
|
||||
struct DAPeer;
|
||||
class DebugAdapterProtocol;
|
||||
|
||||
class DebugAdapterParser : public Object {
|
||||
GDCLASS(DebugAdapterParser, Object);
|
||||
|
||||
private:
|
||||
friend DebugAdapterProtocol;
|
||||
|
||||
_FORCE_INLINE_ bool is_valid_path(const String &p_path) const {
|
||||
// If path contains \, it's a Windows path, so we need to convert it to /, and check as case-insensitive.
|
||||
if (p_path.contains_char('\\')) {
|
||||
String project_path = ProjectSettings::get_singleton()->get_resource_path();
|
||||
String path = p_path.replace_char('\\', '/');
|
||||
return path.containsn(project_path);
|
||||
}
|
||||
return p_path.begins_with(ProjectSettings::get_singleton()->get_resource_path());
|
||||
}
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
Dictionary prepare_base_event() const;
|
||||
Dictionary prepare_success_response(const Dictionary &p_params) const;
|
||||
Dictionary prepare_error_response(const Dictionary &p_params, DAP::ErrorType err_type, const Dictionary &variables = Dictionary()) const;
|
||||
|
||||
Dictionary ev_stopped() const;
|
||||
|
||||
public:
|
||||
// Requests
|
||||
Dictionary req_initialize(const Dictionary &p_params) const;
|
||||
Dictionary req_launch(const Dictionary &p_params) const;
|
||||
Dictionary req_disconnect(const Dictionary &p_params) const;
|
||||
Dictionary req_attach(const Dictionary &p_params) const;
|
||||
Dictionary req_restart(const Dictionary &p_params) const;
|
||||
Dictionary req_terminate(const Dictionary &p_params) const;
|
||||
Dictionary req_configurationDone(const Dictionary &p_params) const;
|
||||
Dictionary req_pause(const Dictionary &p_params) const;
|
||||
Dictionary req_continue(const Dictionary &p_params) const;
|
||||
Dictionary req_threads(const Dictionary &p_params) const;
|
||||
Dictionary req_stackTrace(const Dictionary &p_params) const;
|
||||
Dictionary req_setBreakpoints(const Dictionary &p_params) const;
|
||||
Dictionary req_breakpointLocations(const Dictionary &p_params) const;
|
||||
Dictionary req_scopes(const Dictionary &p_params) const;
|
||||
Dictionary req_variables(const Dictionary &p_params) const;
|
||||
Dictionary req_next(const Dictionary &p_params) const;
|
||||
Dictionary req_stepIn(const Dictionary &p_params) const;
|
||||
Dictionary req_evaluate(const Dictionary &p_params) const;
|
||||
Dictionary req_godot_put_msg(const Dictionary &p_params) const;
|
||||
|
||||
// Internal requests
|
||||
Dictionary _launch_process(const Dictionary &p_params) const;
|
||||
|
||||
// Events
|
||||
Dictionary ev_initialized() const;
|
||||
Dictionary ev_process(const String &p_command) const;
|
||||
Dictionary ev_terminated() const;
|
||||
Dictionary ev_exited(const int &p_exitcode) const;
|
||||
Dictionary ev_stopped_paused() const;
|
||||
Dictionary ev_stopped_exception(const String &p_error) const;
|
||||
Dictionary ev_stopped_breakpoint(const int &p_id) const;
|
||||
Dictionary ev_stopped_step() const;
|
||||
Dictionary ev_continued() const;
|
||||
Dictionary ev_output(const String &p_message, RemoteDebugger::MessageType p_type) const;
|
||||
Dictionary ev_custom_data(const String &p_msg, const Array &p_data) const;
|
||||
Dictionary ev_breakpoint(const DAP::Breakpoint &p_breakpoint, const bool &p_enabled) const;
|
||||
};
|
1269
editor/debugger/debug_adapter/debug_adapter_protocol.cpp
Normal file
1269
editor/debugger/debug_adapter/debug_adapter_protocol.cpp
Normal file
File diff suppressed because it is too large
Load Diff
175
editor/debugger/debug_adapter/debug_adapter_protocol.h
Normal file
175
editor/debugger/debug_adapter/debug_adapter_protocol.h
Normal file
@@ -0,0 +1,175 @@
|
||||
/**************************************************************************/
|
||||
/* debug_adapter_protocol.h */
|
||||
/**************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/**************************************************************************/
|
||||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
||||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "core/debugger/debugger_marshalls.h"
|
||||
#include "core/io/stream_peer_tcp.h"
|
||||
#include "core/io/tcp_server.h"
|
||||
|
||||
#include "debug_adapter_parser.h"
|
||||
#include "debug_adapter_types.h"
|
||||
#include "scene/debugger/scene_debugger.h"
|
||||
|
||||
#define DAP_MAX_BUFFER_SIZE 4194304 // 4MB
|
||||
#define DAP_MAX_CLIENTS 8
|
||||
|
||||
class DebugAdapterParser;
|
||||
|
||||
struct DAPeer : RefCounted {
|
||||
Ref<StreamPeerTCP> connection;
|
||||
|
||||
uint8_t req_buf[DAP_MAX_BUFFER_SIZE];
|
||||
int req_pos = 0;
|
||||
bool has_header = false;
|
||||
int content_length = 0;
|
||||
List<Dictionary> res_queue;
|
||||
int seq = 0;
|
||||
uint64_t timestamp = 0;
|
||||
|
||||
// Client specific info
|
||||
bool linesStartAt1 = false;
|
||||
bool columnsStartAt1 = false;
|
||||
bool supportsVariableType = false;
|
||||
bool supportsInvalidatedEvent = false;
|
||||
bool supportsCustomData = false;
|
||||
|
||||
// Internal client info
|
||||
bool attached = false;
|
||||
Dictionary pending_launch;
|
||||
|
||||
Error handle_data();
|
||||
Error send_data();
|
||||
Vector<uint8_t> format_output(const Dictionary &p_params) const;
|
||||
};
|
||||
|
||||
class DebugAdapterProtocol : public Object {
|
||||
GDCLASS(DebugAdapterProtocol, Object)
|
||||
|
||||
friend class DebugAdapterParser;
|
||||
|
||||
using DAPVarID = int;
|
||||
using DAPStackFrameID = int;
|
||||
|
||||
private:
|
||||
static DebugAdapterProtocol *singleton;
|
||||
DebugAdapterParser *parser = nullptr;
|
||||
|
||||
List<Ref<DAPeer>> clients;
|
||||
Ref<TCPServer> server;
|
||||
|
||||
Error on_client_connected();
|
||||
void on_client_disconnected(const Ref<DAPeer> &p_peer);
|
||||
void on_debug_paused();
|
||||
void on_debug_stopped();
|
||||
void on_debug_output(const String &p_message, int p_type);
|
||||
void on_debug_breaked(const bool &p_reallydid, const bool &p_can_debug, const String &p_reason, const bool &p_has_stackdump);
|
||||
void on_debug_breakpoint_toggled(const String &p_path, const int &p_line, const bool &p_enabled);
|
||||
void on_debug_stack_dump(const Array &p_stack_dump);
|
||||
void on_debug_stack_frame_vars(const int &p_size);
|
||||
void on_debug_stack_frame_var(const Array &p_data);
|
||||
void on_debug_data(const String &p_msg, const Array &p_data);
|
||||
|
||||
void reset_current_info();
|
||||
void reset_ids();
|
||||
void reset_stack_info();
|
||||
|
||||
int parse_variant(const Variant &p_var);
|
||||
void parse_object(SceneDebuggerObject &p_obj);
|
||||
const Variant parse_object_variable(const SceneDebuggerObject::SceneDebuggerProperty &p_property);
|
||||
void parse_evaluation(DebuggerMarshalls::ScriptStackVariable &p_var);
|
||||
|
||||
ObjectID search_object_id(DAPVarID p_var_id);
|
||||
bool request_remote_object(const ObjectID &p_object_id);
|
||||
bool request_remote_evaluate(const String &p_eval, int p_stack_frame);
|
||||
|
||||
const DAP::Source &fetch_source(const String &p_path);
|
||||
void update_source(const String &p_path);
|
||||
|
||||
bool _initialized = false;
|
||||
bool _processing_breakpoint = false;
|
||||
bool _stepping = false;
|
||||
bool _processing_stackdump = false;
|
||||
int _remaining_vars = 0;
|
||||
int _current_frame = 0;
|
||||
uint64_t _request_timeout = 5000;
|
||||
bool _sync_breakpoints = false;
|
||||
|
||||
String _current_request;
|
||||
Ref<DAPeer> _current_peer;
|
||||
|
||||
int breakpoint_id = 0;
|
||||
int stackframe_id = 0;
|
||||
DAPVarID variable_id = 0;
|
||||
List<DAP::Breakpoint> breakpoint_list;
|
||||
HashMap<String, DAP::Source> breakpoint_source_list;
|
||||
List<DAP::StackFrame> stackframe_list;
|
||||
HashMap<DAPStackFrameID, Vector<int>> scope_list;
|
||||
HashMap<DAPVarID, Array> variable_list;
|
||||
|
||||
HashMap<ObjectID, DAPVarID> object_list;
|
||||
HashSet<ObjectID> object_pending_set;
|
||||
|
||||
HashMap<String, DAP::Variable> eval_list;
|
||||
HashSet<String> eval_pending_list;
|
||||
|
||||
public:
|
||||
friend class DebugAdapterServer;
|
||||
|
||||
_FORCE_INLINE_ static DebugAdapterProtocol *get_singleton() { return singleton; }
|
||||
_FORCE_INLINE_ bool is_active() const { return _initialized && clients.size() > 0; }
|
||||
|
||||
bool process_message(const String &p_text);
|
||||
|
||||
String get_current_request() const { return _current_request; }
|
||||
Ref<DAPeer> get_current_peer() const { return _current_peer; }
|
||||
|
||||
void notify_initialized();
|
||||
void notify_process();
|
||||
void notify_terminated();
|
||||
void notify_exited(const int &p_exitcode = 0);
|
||||
void notify_stopped_paused();
|
||||
void notify_stopped_exception(const String &p_error);
|
||||
void notify_stopped_breakpoint(const int &p_id);
|
||||
void notify_stopped_step();
|
||||
void notify_continued();
|
||||
void notify_output(const String &p_message, RemoteDebugger::MessageType p_type);
|
||||
void notify_custom_data(const String &p_msg, const Array &p_data);
|
||||
void notify_breakpoint(const DAP::Breakpoint &p_breakpoint, const bool &p_enabled);
|
||||
|
||||
Array update_breakpoints(const String &p_path, const Array &p_lines);
|
||||
|
||||
void poll();
|
||||
Error start(int p_port, const IPAddress &p_bind_ip);
|
||||
void stop();
|
||||
|
||||
DebugAdapterProtocol();
|
||||
~DebugAdapterProtocol();
|
||||
};
|
94
editor/debugger/debug_adapter/debug_adapter_server.cpp
Normal file
94
editor/debugger/debug_adapter/debug_adapter_server.cpp
Normal file
@@ -0,0 +1,94 @@
|
||||
/**************************************************************************/
|
||||
/* debug_adapter_server.cpp */
|
||||
/**************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/**************************************************************************/
|
||||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
||||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#include "debug_adapter_server.h"
|
||||
|
||||
#include "editor/editor_log.h"
|
||||
#include "editor/editor_node.h"
|
||||
#include "editor/settings/editor_settings.h"
|
||||
|
||||
int DebugAdapterServer::port_override = -1;
|
||||
|
||||
DebugAdapterServer::DebugAdapterServer() {
|
||||
// TODO: Move to editor_settings.cpp
|
||||
_EDITOR_DEF("network/debug_adapter/remote_port", remote_port);
|
||||
_EDITOR_DEF("network/debug_adapter/request_timeout", protocol._request_timeout);
|
||||
_EDITOR_DEF("network/debug_adapter/sync_breakpoints", protocol._sync_breakpoints);
|
||||
}
|
||||
|
||||
void DebugAdapterServer::_notification(int p_what) {
|
||||
switch (p_what) {
|
||||
case NOTIFICATION_ENTER_TREE: {
|
||||
start();
|
||||
} break;
|
||||
|
||||
case NOTIFICATION_EXIT_TREE: {
|
||||
stop();
|
||||
} break;
|
||||
|
||||
case NOTIFICATION_INTERNAL_PROCESS: {
|
||||
// The main loop can be run again during request processing, which modifies internal state of the protocol.
|
||||
// Thus, "polling" is needed to prevent it from parsing other requests while the current one isn't finished.
|
||||
if (started && !polling) {
|
||||
polling = true;
|
||||
protocol.poll();
|
||||
polling = false;
|
||||
}
|
||||
} break;
|
||||
|
||||
case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
|
||||
if (!EditorSettings::get_singleton()->check_changed_settings_in_group("network/debug_adapter")) {
|
||||
break;
|
||||
}
|
||||
protocol._request_timeout = EDITOR_GET("network/debug_adapter/request_timeout");
|
||||
protocol._sync_breakpoints = EDITOR_GET("network/debug_adapter/sync_breakpoints");
|
||||
int port = (DebugAdapterServer::port_override > -1) ? DebugAdapterServer::port_override : (int)_EDITOR_GET("network/debug_adapter/remote_port");
|
||||
if (port != remote_port) {
|
||||
stop();
|
||||
start();
|
||||
}
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
void DebugAdapterServer::start() {
|
||||
remote_port = (DebugAdapterServer::port_override > -1) ? DebugAdapterServer::port_override : (int)_EDITOR_GET("network/debug_adapter/remote_port");
|
||||
if (protocol.start(remote_port, IPAddress("127.0.0.1")) == OK) {
|
||||
EditorNode::get_log()->add_message("--- Debug adapter server started on port " + itos(remote_port) + " ---", EditorLog::MSG_TYPE_EDITOR);
|
||||
set_process_internal(true);
|
||||
started = true;
|
||||
}
|
||||
}
|
||||
|
||||
void DebugAdapterServer::stop() {
|
||||
protocol.stop();
|
||||
started = false;
|
||||
EditorNode::get_log()->add_message("--- Debug adapter server stopped ---", EditorLog::MSG_TYPE_EDITOR);
|
||||
}
|
55
editor/debugger/debug_adapter/debug_adapter_server.h
Normal file
55
editor/debugger/debug_adapter/debug_adapter_server.h
Normal file
@@ -0,0 +1,55 @@
|
||||
/**************************************************************************/
|
||||
/* debug_adapter_server.h */
|
||||
/**************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/**************************************************************************/
|
||||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
||||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "debug_adapter_protocol.h"
|
||||
#include "editor/plugins/editor_plugin.h"
|
||||
|
||||
class DebugAdapterServer : public EditorPlugin {
|
||||
GDCLASS(DebugAdapterServer, EditorPlugin);
|
||||
|
||||
DebugAdapterProtocol protocol;
|
||||
|
||||
int remote_port = 6006;
|
||||
bool thread_running = false;
|
||||
bool started = false;
|
||||
bool polling = false;
|
||||
static void thread_func(void *p_userdata);
|
||||
|
||||
private:
|
||||
void _notification(int p_what);
|
||||
|
||||
public:
|
||||
static int port_override;
|
||||
DebugAdapterServer();
|
||||
void start();
|
||||
void stop();
|
||||
};
|
278
editor/debugger/debug_adapter/debug_adapter_types.h
Normal file
278
editor/debugger/debug_adapter/debug_adapter_types.h
Normal file
@@ -0,0 +1,278 @@
|
||||
/**************************************************************************/
|
||||
/* debug_adapter_types.h */
|
||||
/**************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/**************************************************************************/
|
||||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
||||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "core/io/file_access.h"
|
||||
|
||||
namespace DAP {
|
||||
|
||||
enum ErrorType {
|
||||
UNKNOWN,
|
||||
WRONG_PATH,
|
||||
NOT_RUNNING,
|
||||
TIMEOUT,
|
||||
UNKNOWN_PLATFORM,
|
||||
MISSING_DEVICE
|
||||
};
|
||||
|
||||
struct Checksum {
|
||||
String algorithm;
|
||||
String checksum;
|
||||
|
||||
_FORCE_INLINE_ Dictionary to_json() const {
|
||||
Dictionary dict;
|
||||
dict["algorithm"] = algorithm;
|
||||
dict["checksum"] = checksum;
|
||||
|
||||
return dict;
|
||||
}
|
||||
};
|
||||
|
||||
struct Source {
|
||||
private:
|
||||
Array _checksums;
|
||||
|
||||
public:
|
||||
String name;
|
||||
String path;
|
||||
|
||||
void compute_checksums() {
|
||||
ERR_FAIL_COND(path.is_empty());
|
||||
|
||||
_checksums.clear();
|
||||
|
||||
// MD5
|
||||
Checksum md5;
|
||||
md5.algorithm = "MD5";
|
||||
md5.checksum = FileAccess::get_md5(path);
|
||||
|
||||
// SHA-256
|
||||
Checksum sha256;
|
||||
sha256.algorithm = "SHA256";
|
||||
sha256.checksum = FileAccess::get_sha256(path);
|
||||
|
||||
_checksums.push_back(md5.to_json());
|
||||
_checksums.push_back(sha256.to_json());
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ void from_json(const Dictionary &p_params) {
|
||||
name = p_params["name"];
|
||||
path = p_params["path"];
|
||||
_checksums = p_params["checksums"];
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ Dictionary to_json() const {
|
||||
Dictionary dict;
|
||||
dict["name"] = name;
|
||||
dict["path"] = path;
|
||||
dict["checksums"] = _checksums;
|
||||
|
||||
return dict;
|
||||
}
|
||||
};
|
||||
|
||||
struct Breakpoint {
|
||||
int id = 0;
|
||||
bool verified = false;
|
||||
const Source *source = nullptr;
|
||||
int line = 0;
|
||||
|
||||
Breakpoint() = default; // Empty constructor is invalid, but is necessary because Godot's collections don't support rvalues.
|
||||
Breakpoint(const Source &p_source) :
|
||||
source(&p_source) {}
|
||||
|
||||
bool operator==(const Breakpoint &p_other) const {
|
||||
return source == p_other.source && line == p_other.line;
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ Dictionary to_json() const {
|
||||
Dictionary dict;
|
||||
dict["id"] = id;
|
||||
dict["verified"] = verified;
|
||||
if (source) {
|
||||
dict["source"] = source->to_json();
|
||||
}
|
||||
dict["line"] = line;
|
||||
|
||||
return dict;
|
||||
}
|
||||
};
|
||||
|
||||
struct BreakpointLocation {
|
||||
int line = 0;
|
||||
int endLine = -1;
|
||||
|
||||
_FORCE_INLINE_ Dictionary to_json() const {
|
||||
Dictionary dict;
|
||||
dict["line"] = line;
|
||||
if (endLine >= 0) {
|
||||
dict["endLine"] = endLine;
|
||||
}
|
||||
|
||||
return dict;
|
||||
}
|
||||
};
|
||||
|
||||
struct Capabilities {
|
||||
bool supportsConfigurationDoneRequest = true;
|
||||
bool supportsEvaluateForHovers = true;
|
||||
bool supportsSetVariable = true;
|
||||
String supportedChecksumAlgorithms[2] = { "MD5", "SHA256" };
|
||||
bool supportsRestartRequest = true;
|
||||
bool supportsValueFormattingOptions = true;
|
||||
bool supportTerminateDebuggee = true;
|
||||
bool supportSuspendDebuggee = true;
|
||||
bool supportsTerminateRequest = true;
|
||||
bool supportsBreakpointLocationsRequest = true;
|
||||
|
||||
_FORCE_INLINE_ Dictionary to_json() const {
|
||||
Dictionary dict;
|
||||
dict["supportsConfigurationDoneRequest"] = supportsConfigurationDoneRequest;
|
||||
dict["supportsEvaluateForHovers"] = supportsEvaluateForHovers;
|
||||
dict["supportsSetVariable"] = supportsSetVariable;
|
||||
dict["supportsRestartRequest"] = supportsRestartRequest;
|
||||
dict["supportsValueFormattingOptions"] = supportsValueFormattingOptions;
|
||||
dict["supportTerminateDebuggee"] = supportTerminateDebuggee;
|
||||
dict["supportSuspendDebuggee"] = supportSuspendDebuggee;
|
||||
dict["supportsTerminateRequest"] = supportsTerminateRequest;
|
||||
dict["supportsBreakpointLocationsRequest"] = supportsBreakpointLocationsRequest;
|
||||
|
||||
Array arr = { supportedChecksumAlgorithms[0], supportedChecksumAlgorithms[1] };
|
||||
dict["supportedChecksumAlgorithms"] = arr;
|
||||
|
||||
return dict;
|
||||
}
|
||||
};
|
||||
|
||||
struct Message {
|
||||
int id = 0;
|
||||
String format;
|
||||
bool sendTelemetry = false; // Just in case :)
|
||||
bool showUser = false;
|
||||
Dictionary variables;
|
||||
|
||||
_FORCE_INLINE_ Dictionary to_json() const {
|
||||
Dictionary dict;
|
||||
dict["id"] = id;
|
||||
dict["format"] = format;
|
||||
dict["sendTelemetry"] = sendTelemetry;
|
||||
dict["showUser"] = showUser;
|
||||
dict["variables"] = variables;
|
||||
|
||||
return dict;
|
||||
}
|
||||
};
|
||||
|
||||
struct Scope {
|
||||
String name;
|
||||
String presentationHint;
|
||||
int variablesReference = 0;
|
||||
bool expensive = false;
|
||||
|
||||
_FORCE_INLINE_ Dictionary to_json() const {
|
||||
Dictionary dict;
|
||||
dict["name"] = name;
|
||||
dict["presentationHint"] = presentationHint;
|
||||
dict["variablesReference"] = variablesReference;
|
||||
dict["expensive"] = expensive;
|
||||
|
||||
return dict;
|
||||
}
|
||||
};
|
||||
|
||||
struct SourceBreakpoint {
|
||||
int line = 0;
|
||||
|
||||
_FORCE_INLINE_ void from_json(const Dictionary &p_params) {
|
||||
line = p_params["line"];
|
||||
}
|
||||
};
|
||||
|
||||
struct StackFrame {
|
||||
int id = 0;
|
||||
String name;
|
||||
const Source *source = nullptr;
|
||||
int line = 0;
|
||||
int column = 0;
|
||||
|
||||
StackFrame() = default; // Empty constructor is invalid, but is necessary because Godot's collections don't support rvalues.
|
||||
StackFrame(const Source &p_source) :
|
||||
source(&p_source) {}
|
||||
|
||||
static uint32_t hash(const StackFrame &p_frame) {
|
||||
return hash_murmur3_one_32(p_frame.id);
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ Dictionary to_json() const {
|
||||
Dictionary dict;
|
||||
dict["id"] = id;
|
||||
dict["name"] = name;
|
||||
if (source) {
|
||||
dict["source"] = source->to_json();
|
||||
}
|
||||
dict["line"] = line;
|
||||
dict["column"] = column;
|
||||
|
||||
return dict;
|
||||
}
|
||||
};
|
||||
|
||||
struct Thread {
|
||||
int id = 0;
|
||||
String name;
|
||||
|
||||
_FORCE_INLINE_ Dictionary to_json() const {
|
||||
Dictionary dict;
|
||||
dict["id"] = id;
|
||||
dict["name"] = name;
|
||||
|
||||
return dict;
|
||||
}
|
||||
};
|
||||
|
||||
struct Variable {
|
||||
String name;
|
||||
String value;
|
||||
String type;
|
||||
int variablesReference = 0;
|
||||
|
||||
_FORCE_INLINE_ Dictionary to_json() const {
|
||||
Dictionary dict;
|
||||
dict["name"] = name;
|
||||
dict["value"] = value;
|
||||
dict["type"] = type;
|
||||
dict["variablesReference"] = variablesReference;
|
||||
|
||||
return dict;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace DAP
|
Reference in New Issue
Block a user