From d79e28c3021a4410f41a3bbff111d56b28f155ef Mon Sep 17 00:00:00 2001 From: Fabio Alessandrelli Date: Mon, 16 Mar 2020 09:37:43 +0100 Subject: [PATCH] Support multiple debug protocols. --- editor/debugger/editor_debugger_node.cpp | 12 ++----- editor/debugger/editor_debugger_node.h | 2 +- editor/debugger/editor_debugger_server.cpp | 27 +++++++++++++-- editor/debugger/editor_debugger_server.h | 12 ++++++- editor/debugger/script_editor_debugger.cpp | 2 ++ editor/editor_export.cpp | 4 +-- editor/editor_export.h | 1 + editor/editor_node.cpp | 39 ++++++++++++---------- editor/editor_node.h | 3 +- editor/editor_run.cpp | 2 +- editor/editor_run_native.cpp | 4 +-- editor/plugins/debugger_editor_plugin.cpp | 4 +++ main/main.cpp | 7 ++-- 13 files changed, 78 insertions(+), 41 deletions(-) diff --git a/editor/debugger/editor_debugger_node.cpp b/editor/debugger/editor_debugger_node.cpp index 75512143364..5bfb79806e0 100644 --- a/editor/debugger/editor_debugger_node.cpp +++ b/editor/debugger/editor_debugger_node.cpp @@ -173,7 +173,7 @@ ScriptEditorDebugger *EditorDebuggerNode::get_default_debugger() const { return Object::cast_to(tabs->get_tab_control(0)); } -Error EditorDebuggerNode::start() { +Error EditorDebuggerNode::start(const String &p_protocol) { stop(); if (EDITOR_GET("run/output/always_open_output_on_play")) { EditorNode::get_singleton()->make_bottom_panel_item_visible(EditorNode::get_log()); @@ -181,7 +181,7 @@ Error EditorDebuggerNode::start() { EditorNode::get_singleton()->make_bottom_panel_item_visible(this); } - server = Ref(EditorDebuggerServer::create_default()); + server = Ref(EditorDebuggerServer::create(p_protocol)); const Error err = server->start(); if (err != OK) { return err; @@ -213,14 +213,6 @@ void EditorDebuggerNode::stop() { void EditorDebuggerNode::_notification(int p_what) { switch (p_what) { - case NOTIFICATION_ENTER_TREE: { - EditorNode::get_singleton()->connect("play_pressed", callable_mp(this, &EditorDebuggerNode::start)); - EditorNode::get_singleton()->connect("stop_pressed", callable_mp(this, &EditorDebuggerNode::stop)); - } break; - case NOTIFICATION_EXIT_TREE: { - EditorNode::get_singleton()->disconnect("play_pressed", callable_mp(this, &EditorDebuggerNode::start)); - EditorNode::get_singleton()->disconnect("stop_pressed", callable_mp(this, &EditorDebuggerNode::stop)); - } break; case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: { if (tabs->get_tab_count() > 1) { add_theme_constant_override("margin_left", -EditorNode::get_singleton()->get_gui_base()->get_theme_stylebox("BottomPanelDebuggerOverride", "EditorStyles")->get_margin(MARGIN_LEFT)); diff --git a/editor/debugger/editor_debugger_node.h b/editor/debugger/editor_debugger_node.h index 9467442c9a1..7546febd05b 100644 --- a/editor/debugger/editor_debugger_node.h +++ b/editor/debugger/editor_debugger_node.h @@ -183,7 +183,7 @@ public: void set_camera_override(CameraOverride p_override) { camera_override = p_override; } CameraOverride get_camera_override() { return camera_override; } - Error start(); + Error start(const String &p_protocol = "tcp://"); void stop(); }; diff --git a/editor/debugger/editor_debugger_server.cpp b/editor/debugger/editor_debugger_server.cpp index c80988a6621..33f20d9a12e 100644 --- a/editor/debugger/editor_debugger_server.cpp +++ b/editor/debugger/editor_debugger_server.cpp @@ -44,6 +44,7 @@ private: Ref server; public: + static EditorDebuggerServer *create(const String &p_protocol); virtual void poll() {} virtual Error start(); virtual void stop(); @@ -54,6 +55,11 @@ public: EditorDebuggerServerTCP(); }; +EditorDebuggerServer *EditorDebuggerServerTCP::create(const String &p_protocol) { + ERR_FAIL_COND_V(p_protocol != "tcp://", nullptr); + return memnew(EditorDebuggerServerTCP); +} + EditorDebuggerServerTCP::EditorDebuggerServerTCP() { server.instance(); } @@ -85,6 +91,23 @@ Ref EditorDebuggerServerTCP::take_connection() { return memnew(RemoteDebuggerPeerTCP(server->take_connection())); } -EditorDebuggerServer *EditorDebuggerServer::create_default() { - return memnew(EditorDebuggerServerTCP); +/// EditorDebuggerServer +Map EditorDebuggerServer::protocols; + +EditorDebuggerServer *EditorDebuggerServer::create(const String &p_protocol) { + ERR_FAIL_COND_V(!protocols.has(p_protocol), nullptr); + return protocols[p_protocol](p_protocol); +} + +void EditorDebuggerServer::register_protocol_handler(const String &p_protocol, CreateServerFunc p_func) { + ERR_FAIL_COND(protocols.has(p_protocol)); + protocols[p_protocol] = p_func; +} + +void EditorDebuggerServer::initialize() { + register_protocol_handler("tcp://", EditorDebuggerServerTCP::create); +} + +void EditorDebuggerServer::deinitialize() { + protocols.clear(); } diff --git a/editor/debugger/editor_debugger_server.h b/editor/debugger/editor_debugger_server.h index e9798c90b3d..515ffce6289 100644 --- a/editor/debugger/editor_debugger_server.h +++ b/editor/debugger/editor_debugger_server.h @@ -37,7 +37,17 @@ class EditorDebuggerServer : public Reference { public: - static EditorDebuggerServer *create_default(); + typedef EditorDebuggerServer *(*CreateServerFunc)(const String &p_uri); + +private: + static Map protocols; + +public: + static void initialize(); + static void deinitialize(); + + 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 void stop() = 0; diff --git a/editor/debugger/script_editor_debugger.cpp b/editor/debugger/script_editor_debugger.cpp index af79de2991a..3ed271c7c6e 100644 --- a/editor/debugger/script_editor_debugger.cpp +++ b/editor/debugger/script_editor_debugger.cpp @@ -846,6 +846,8 @@ void ScriptEditorDebugger::_notification(int p_what) { if (is_session_active()) { + peer->poll(); + if (camera_override == CameraOverride::OVERRIDE_2D) { CanvasItemEditor *editor = CanvasItemEditor::get_singleton(); diff --git a/editor/editor_export.cpp b/editor/editor_export.cpp index e8167070d4c..24a69fe0038 100644 --- a/editor/editor_export.cpp +++ b/editor/editor_export.cpp @@ -284,7 +284,7 @@ void EditorExportPlatform::gen_debug_flags(Vector &r_flags, int p_flags) r_flags.push_back("--remote-debug"); - r_flags.push_back(host + ":" + String::num(remote_port)); + r_flags.push_back(get_debug_protocol() + host + ":" + String::num(remote_port)); List breakpoints; ScriptEditor::get_singleton()->get_breakpoints(&breakpoints); @@ -1127,7 +1127,7 @@ void EditorExportPlatform::gen_export_flags(Vector &r_flags, int p_flags r_flags.push_back("--remote-debug"); - r_flags.push_back(host + ":" + String::num(remote_port)); + r_flags.push_back(get_debug_protocol() + host + ":" + String::num(remote_port)); List breakpoints; ScriptEditor::get_singleton()->get_breakpoints(&breakpoints); diff --git a/editor/editor_export.h b/editor/editor_export.h index f47fe9c95e1..50d1ff66c6b 100644 --- a/editor/editor_export.h +++ b/editor/editor_export.h @@ -270,6 +270,7 @@ public: virtual Error export_zip(const Ref &p_preset, bool p_debug, const String &p_path, int p_flags = 0); virtual void get_platform_features(List *r_features) = 0; virtual void resolve_platform_feature_priorities(const Ref &p_preset, Set &p_features) = 0; + virtual String get_debug_protocol() const { return "tcp://"; } EditorExportPlatform(); }; diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 1b1ce4ec37a..abb639254a1 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -2072,9 +2072,11 @@ void EditorNode::_run(bool p_current, const String &p_custom) { args = ProjectSettings::get_singleton()->get("editor/main_run_args"); skip_breakpoints = EditorDebuggerNode::get_singleton()->is_skip_breakpoints(); + EditorDebuggerNode::get_singleton()->start(); Error error = editor_run.run(run_filename, args, breakpoints, skip_breakpoints); if (error != OK) { + EditorDebuggerNode::get_singleton()->stop(); show_accept(TTR("Could not start subprocess!"), TTR("OK")); return; } @@ -2096,6 +2098,24 @@ void EditorNode::_run(bool p_current, const String &p_custom) { _playing_edited = p_current; } +void EditorNode::_run_native(const Ref &p_preset) { + + bool autosave = EDITOR_GET("run/auto_save/save_before_running"); + if (autosave) { + _menu_option_confirm(FILE_SAVE_ALL_SCENES, false); + } + if (run_native->is_deploy_debug_remote_enabled()) { + _menu_option_confirm(RUN_STOP, true); + + if (!call_build()) + return; // build failed + + EditorDebuggerNode::get_singleton()->start(p_preset->get_platform()->get_debug_protocol()); + emit_signal("play_pressed"); + editor_run.run_native_notify(); + } +} + void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { if (!p_confirmed) //this may be a hack.. @@ -2464,6 +2484,7 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { } } } + EditorDebuggerNode::get_singleton()->stop(); emit_signal("stop_pressed"); } break; @@ -2482,22 +2503,6 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { _run(true); } break; - case RUN_PLAY_NATIVE: { - - bool autosave = EDITOR_GET("run/auto_save/save_before_running"); - if (autosave) { - _menu_option_confirm(FILE_SAVE_ALL_SCENES, false); - } - if (run_native->is_deploy_debug_remote_enabled()) { - _menu_option_confirm(RUN_STOP, true); - - if (!call_build()) - break; // build failed - - emit_signal("play_pressed"); - editor_run.run_native_notify(); - } - } break; case RUN_SCENE_SETTINGS: { run_settings_dialog->popup_run_settings(); @@ -6346,7 +6351,7 @@ EditorNode::EditorNode() { run_native = memnew(EditorRunNative); play_hb->add_child(run_native); - run_native->connect("native_run", callable_mp(this, &EditorNode::_menu_option), varray(RUN_PLAY_NATIVE)); + run_native->connect("native_run", callable_mp(this, &EditorNode::_run_native)); play_scene_button = memnew(ToolButton); play_hb->add_child(play_scene_button); diff --git a/editor/editor_node.h b/editor/editor_node.h index c6f04b07495..11f40089362 100644 --- a/editor/editor_node.h +++ b/editor/editor_node.h @@ -32,6 +32,7 @@ #define EDITOR_NODE_H #include "editor/editor_data.h" +#include "editor/editor_export.h" #include "editor/editor_folding.h" #include "editor/editor_run.h" #include "editor/inspector_dock.h" @@ -161,7 +162,6 @@ private: RUN_STOP, RUN_PLAY_SCENE, - RUN_PLAY_NATIVE, RUN_PLAY_CUSTOM_SCENE, RUN_SCENE_SETTINGS, RUN_SETTINGS, @@ -492,6 +492,7 @@ private: void _quick_run(); void _run(bool p_current = false, const String &p_custom = ""); + void _run_native(const Ref &p_preset); void _save_optimized(); void _import_action(const String &p_action); diff --git a/editor/editor_run.cpp b/editor/editor_run.cpp index b4ddb7ebfa3..01156d98094 100644 --- a/editor/editor_run.cpp +++ b/editor/editor_run.cpp @@ -53,7 +53,7 @@ Error EditorRun::run(const String &p_scene, const String &p_custom_args, const L } args.push_back("--remote-debug"); - args.push_back(remote_host + ":" + String::num(remote_port)); + args.push_back("tcp://" + remote_host + ":" + String::num(remote_port)); args.push_back("--allow_focus_steal_pid"); args.push_back(itos(OS::get_singleton()->get_process_id())); diff --git a/editor/editor_run_native.cpp b/editor/editor_run_native.cpp index 464666ac6ae..d4450acea25 100644 --- a/editor/editor_run_native.cpp +++ b/editor/editor_run_native.cpp @@ -133,7 +133,7 @@ void EditorRunNative::_run_native(int p_idx, int p_platform) { return; } - emit_signal("native_run"); + emit_signal("native_run", preset); int flags = 0; @@ -160,7 +160,7 @@ void EditorRunNative::resume_run_native() { void EditorRunNative::_bind_methods() { - ADD_SIGNAL(MethodInfo("native_run")); + ADD_SIGNAL(MethodInfo("native_run", PropertyInfo(Variant::OBJECT, "preset", PROPERTY_HINT_RESOURCE_TYPE, "EditorExportPreset"))); } bool EditorRunNative::is_deploy_debug_remote_enabled() const { diff --git a/editor/plugins/debugger_editor_plugin.cpp b/editor/plugins/debugger_editor_plugin.cpp index 2b0d3f2582b..e0d345663cc 100644 --- a/editor/plugins/debugger_editor_plugin.cpp +++ b/editor/plugins/debugger_editor_plugin.cpp @@ -32,11 +32,14 @@ #include "core/os/keyboard.h" #include "editor/debugger/editor_debugger_node.h" +#include "editor/debugger/editor_debugger_server.h" #include "editor/editor_node.h" #include "editor/fileserver/editor_file_server.h" #include "scene/gui/menu_button.h" DebuggerEditorPlugin::DebuggerEditorPlugin(EditorNode *p_editor, MenuButton *p_debug_menu) { + EditorDebuggerServer::initialize(); + ED_SHORTCUT("debugger/step_into", TTR("Step Into"), KEY_F11); ED_SHORTCUT("debugger/step_over", TTR("Step Over"), KEY_F10); ED_SHORTCUT("debugger/break", TTR("Break")); @@ -96,6 +99,7 @@ DebuggerEditorPlugin::DebuggerEditorPlugin(EditorNode *p_editor, MenuButton *p_d } DebuggerEditorPlugin::~DebuggerEditorPlugin() { + EditorDebuggerServer::deinitialize(); memdelete(file_server); } diff --git a/main/main.cpp b/main/main.cpp index 83c3e190a83..958d964b353 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -324,7 +324,7 @@ void Main::print_help(const char *p_binary) { OS::get_singleton()->print(" -b, --breakpoints Breakpoint list as source::line comma-separated pairs, no spaces (use %%20 instead).\n"); OS::get_singleton()->print(" --profiling Enable profiling in the script debugger.\n"); OS::get_singleton()->print(" --gpu-abort Abort on GPU errors (usually validation layer errors), may help see the problem if your system freezes.\n"); - OS::get_singleton()->print(" --remote-debug
Remote debug (: address).\n"); + OS::get_singleton()->print(" --remote-debug Remote debug (://[:], e.g. tcp://127.0.0.1:6007).\n"); #if defined(DEBUG_ENABLED) && !defined(SERVER_ENABLED) OS::get_singleton()->print(" --debug-collisions Show collision shapes when running the scene.\n"); OS::get_singleton()->print(" --debug-navigation Show navigation polygons when running the scene.\n"); @@ -844,11 +844,10 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph if (I->next()) { debug_uri = I->next()->get(); - if (debug_uri.find(":") == -1) { // wrong address - OS::get_singleton()->print("Invalid debug host address, it should be of the form :.\n"); + if (debug_uri.find("://") == -1) { // wrong address + OS::get_singleton()->print("Invalid debug host address, it should be of the form ://:.\n"); goto error; } - debug_uri = "tcp://" + debug_uri; // will support multiple protocols eventually. N = I->next()->next(); } else { OS::get_singleton()->print("Missing remote debug host address, aborting.\n");