From ecb2e8297c64c0f909878f379b408a3a17779715 Mon Sep 17 00:00:00 2001 From: Fabio Alessandrelli Date: Sun, 29 Aug 2021 02:13:58 +0200 Subject: [PATCH 1/2] [Editor] Editor debugger binds according to editor settings. --- editor/debugger/editor_debugger_node.cpp | 8 ++++---- editor/debugger/editor_debugger_node.h | 2 +- editor/debugger/editor_debugger_server.cpp | 17 ++++++++++++----- editor/debugger/editor_debugger_server.h | 2 +- .../editor_debugger_server_websocket.cpp | 14 +++++++++++--- .../editor_debugger_server_websocket.h | 2 +- 6 files changed, 30 insertions(+), 15 deletions(-) diff --git a/editor/debugger/editor_debugger_node.cpp b/editor/debugger/editor_debugger_node.cpp index a9cb1a0131..fc747ef2f7 100644 --- a/editor/debugger/editor_debugger_node.cpp +++ b/editor/debugger/editor_debugger_node.cpp @@ -182,16 +182,16 @@ ScriptEditorDebugger *EditorDebuggerNode::get_default_debugger() const { return Object::cast_to(tabs->get_tab_control(0)); } -Error EditorDebuggerNode::start(const String &p_protocol) { +Error EditorDebuggerNode::start(const String &p_uri) { stop(); + ERR_FAIL_COND_V(p_uri.find("://") < 0, ERR_INVALID_PARAMETER); if (EDITOR_GET("run/output/always_open_output_on_play")) { EditorNode::get_singleton()->make_bottom_panel_item_visible(EditorNode::get_log()); } else { EditorNode::get_singleton()->make_bottom_panel_item_visible(this); } - - server = Ref(EditorDebuggerServer::create(p_protocol)); - const Error err = server->start(); + server = Ref(EditorDebuggerServer::create(p_uri.substr(0, p_uri.find("://") + 3))); + const Error err = server->start(p_uri); if (err != OK) { return err; } diff --git a/editor/debugger/editor_debugger_node.h b/editor/debugger/editor_debugger_node.h index 39a95326be..4d9e846834 100644 --- a/editor/debugger/editor_debugger_node.h +++ b/editor/debugger/editor_debugger_node.h @@ -188,7 +188,7 @@ public: void set_camera_override(CameraOverride p_override); CameraOverride get_camera_override(); - Error start(const String &p_protocol = "tcp://"); + Error start(const String &p_uri = "tcp://"); void stop(); diff --git a/editor/debugger/editor_debugger_server.cpp b/editor/debugger/editor_debugger_server.cpp index e8524e0702..8c3833af50 100644 --- a/editor/debugger/editor_debugger_server.cpp +++ b/editor/debugger/editor_debugger_server.cpp @@ -45,7 +45,7 @@ private: public: static EditorDebuggerServer *create(const String &p_protocol); virtual void poll() {} - virtual Error start(); + virtual Error start(const String &p_uri); virtual void stop(); virtual bool is_active() const; virtual bool is_connection_available() const; @@ -63,11 +63,18 @@ EditorDebuggerServerTCP::EditorDebuggerServerTCP() { server.instantiate(); } -Error EditorDebuggerServerTCP::start() { - int remote_port = (int)EditorSettings::get_singleton()->get("network/debug/remote_port"); - const Error err = server->listen(remote_port); +Error EditorDebuggerServerTCP::start(const String &p_uri) { + int bind_port = (int)EditorSettings::get_singleton()->get("network/debug/remote_port"); + String bind_host = (String)EditorSettings::get_singleton()->get("network/debug/remote_host"); + if (!p_uri.is_empty() && p_uri != "tcp://") { + String scheme, path; + Error err = p_uri.parse_url(scheme, bind_host, bind_port, path); + ERR_FAIL_COND_V(err != OK, ERR_INVALID_PARAMETER); + ERR_FAIL_COND_V(!bind_host.is_valid_ip_address() && bind_host != "*", ERR_INVALID_PARAMETER); + } + const Error err = server->listen(bind_port, bind_host); if (err != OK) { - EditorNode::get_log()->add_message(String("Error listening on port ") + itos(remote_port), EditorLog::MSG_TYPE_ERROR); + EditorNode::get_log()->add_message(String("Error listening on port ") + itos(bind_port), EditorLog::MSG_TYPE_ERROR); return err; } return err; diff --git a/editor/debugger/editor_debugger_server.h b/editor/debugger/editor_debugger_server.h index 6216d0df3d..844d1a9e5a 100644 --- a/editor/debugger/editor_debugger_server.h +++ b/editor/debugger/editor_debugger_server.h @@ -48,7 +48,7 @@ public: static void register_protocol_handler(const String &p_protocol, CreateServerFunc p_func); static EditorDebuggerServer *create(const String &p_protocol); virtual void poll() = 0; - virtual Error start() = 0; + virtual Error start(const String &p_uri = "") = 0; virtual void stop() = 0; virtual bool is_active() const = 0; virtual bool is_connection_available() const = 0; diff --git a/modules/websocket/editor_debugger_server_websocket.cpp b/modules/websocket/editor_debugger_server_websocket.cpp index 2e61cbfc08..d248433d82 100644 --- a/modules/websocket/editor_debugger_server_websocket.cpp +++ b/modules/websocket/editor_debugger_server_websocket.cpp @@ -48,11 +48,19 @@ void EditorDebuggerServerWebSocket::poll() { server->poll(); } -Error EditorDebuggerServerWebSocket::start() { - int remote_port = (int)EditorSettings::get_singleton()->get("network/debug/remote_port"); +Error EditorDebuggerServerWebSocket::start(const String &p_uri) { + int bind_port = (int)EditorSettings::get_singleton()->get("network/debug/remote_port"); + String bind_host = EditorSettings::get_singleton()->get("network/debug/remote_host"); + if (!p_uri.is_empty() && p_uri != "ws://") { + String scheme, path; + Error err = p_uri.parse_url(scheme, bind_host, bind_port, path); + ERR_FAIL_COND_V(err != OK, ERR_INVALID_PARAMETER); + ERR_FAIL_COND_V(!bind_host.is_valid_ip_address() && bind_host != "*", ERR_INVALID_PARAMETER); + } + server->set_bind_ip(bind_host); Vector compatible_protocols; compatible_protocols.push_back("binary"); // compatibility with EMSCRIPTEN TCP-to-WebSocket layer. - return server->listen(remote_port, compatible_protocols); + return server->listen(bind_port, compatible_protocols); } void EditorDebuggerServerWebSocket::stop() { diff --git a/modules/websocket/editor_debugger_server_websocket.h b/modules/websocket/editor_debugger_server_websocket.h index d9543bb647..14ab0109b2 100644 --- a/modules/websocket/editor_debugger_server_websocket.h +++ b/modules/websocket/editor_debugger_server_websocket.h @@ -48,7 +48,7 @@ public: void _peer_disconnected(int p_peer, bool p_was_clean); void poll() override; - Error start() override; + Error start(const String &p_uri) override; void stop() override; bool is_active() const override; bool is_connection_available() const override; From 4123612eeb54b8cf1e689be05c01fc1ead972d36 Mon Sep 17 00:00:00 2001 From: Fabio Alessandrelli Date: Sun, 29 Aug 2021 01:58:15 +0200 Subject: [PATCH 2/2] [Editor] Add "--debug-server " option. Allow starting the editor debugger server for the given protocol (and optionally bound to the given ip/port combination: godot -e --debug-server tcp://*:8080 --- main/main.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/main/main.cpp b/main/main.cpp index 44c0ba4902..cd2849adc0 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -145,6 +145,7 @@ static bool auto_quit = false; static OS::ProcessID allow_focus_steal_pid = 0; #ifdef TOOLS_ENABLED static bool auto_build_solutions = false; +static String debug_server_uri; #endif // Display @@ -286,6 +287,7 @@ void Main::print_help(const char *p_binary) { #ifdef TOOLS_ENABLED OS::get_singleton()->print(" -e, --editor Start the editor instead of running the scene.\n"); OS::get_singleton()->print(" -p, --project-manager Start the project manager, even if a project is auto-detected.\n"); + OS::get_singleton()->print(" --debug-server Start the editor debug server (://[:], e.g. tcp://127.0.0.1:6007)\n"); #endif OS::get_singleton()->print(" -q, --quit Quit after the first iteration.\n"); OS::get_singleton()->print(" -l, --language Use a specific locale ( being a two-letter code).\n"); @@ -874,6 +876,18 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph } else if (I->get() == "-p" || I->get() == "--project-manager") { // starts project manager project_manager = true; + } else if (I->get() == "--debug-server") { + if (I->next()) { + debug_server_uri = I->next()->get(); + if (debug_server_uri.find("://") == -1) { // wrong address + OS::get_singleton()->print("Invalid debug server uri. It should be of the form ://:.\n"); + goto error; + } + N = I->next()->next(); + } else { + OS::get_singleton()->print("Missing remote debug server uri, aborting.\n"); + goto error; + } } else if (I->get() == "--build-solutions") { // Build the scripting solution such C# auto_build_solutions = true; @@ -2346,6 +2360,9 @@ bool Main::start() { } } DisplayServer::get_singleton()->set_context(DisplayServer::CONTEXT_EDITOR); + if (!debug_server_uri.is_empty()) { + EditorDebuggerNode::get_singleton()->start(debug_server_uri); + } } #endif if (!editor) {