From bc054292d52c364496d12dc44772a12c9b66746c Mon Sep 17 00:00:00 2001 From: TsFreddie Date: Thu, 10 Jul 2025 23:21:02 +0800 Subject: [PATCH] Add step out to script debugger --- core/debugger/local_debugger.cpp | 4 ++++ core/debugger/remote_debugger.cpp | 5 +++++ editor/debugger/debugger_editor_plugin.cpp | 1 + editor/debugger/script_editor_debugger.cpp | 16 ++++++++++++++++ editor/debugger/script_editor_debugger.h | 2 ++ editor/icons/DebugOut.svg | 1 + 6 files changed, 29 insertions(+) create mode 100644 editor/icons/DebugOut.svg diff --git a/core/debugger/local_debugger.cpp b/core/debugger/local_debugger.cpp index fb09c39c2d0..52b73077593 100644 --- a/core/debugger/local_debugger.cpp +++ b/core/debugger/local_debugger.cpp @@ -224,6 +224,10 @@ void LocalDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) { script_debugger->set_depth(0); script_debugger->set_lines_left(1); break; + } else if (line == "o" || line == "out") { + script_debugger->set_depth(1); + script_debugger->set_lines_left(1); + break; } else if (line == "fin" || line == "finish") { String current_function = script_lang->debug_get_stack_level_function(0); diff --git a/core/debugger/remote_debugger.cpp b/core/debugger/remote_debugger.cpp index 76b19a3903a..98f46fb18cd 100644 --- a/core/debugger/remote_debugger.cpp +++ b/core/debugger/remote_debugger.cpp @@ -458,6 +458,11 @@ void RemoteDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) { script_debugger->set_lines_left(1); break; + } else if (command == "out") { + script_debugger->set_depth(1); + script_debugger->set_lines_left(1); + break; + } else if (command == "continue") { script_debugger->set_depth(-1); script_debugger->set_lines_left(-1); diff --git a/editor/debugger/debugger_editor_plugin.cpp b/editor/debugger/debugger_editor_plugin.cpp index ba036d2ad45..ea7a4b16dc5 100644 --- a/editor/debugger/debugger_editor_plugin.cpp +++ b/editor/debugger/debugger_editor_plugin.cpp @@ -47,6 +47,7 @@ DebuggerEditorPlugin::DebuggerEditorPlugin(PopupMenu *p_debug_menu) { ED_SHORTCUT("debugger/step_into", TTRC("Step Into"), Key::F11); ED_SHORTCUT("debugger/step_over", TTRC("Step Over"), Key::F10); + ED_SHORTCUT("debugger/step_out", TTRC("Step Out"), KeyModifierMask::ALT | Key::F11); ED_SHORTCUT("debugger/break", TTRC("Break")); ED_SHORTCUT("debugger/continue", TTRC("Continue"), Key::F12); ED_SHORTCUT("debugger/debug_with_external_editor", TTRC("Debug with External Editor")); diff --git a/editor/debugger/script_editor_debugger.cpp b/editor/debugger/script_editor_debugger.cpp index 1839a67c38b..573bdc8f75a 100644 --- a/editor/debugger/script_editor_debugger.cpp +++ b/editor/debugger/script_editor_debugger.cpp @@ -111,6 +111,13 @@ void ScriptEditorDebugger::debug_ignore_error_breaks() { _put_msg("set_ignore_error_breaks", msg); } +void ScriptEditorDebugger::debug_out() { + ERR_FAIL_COND(!is_breaked()); + + _put_msg("out", Array(), debugging_thread_id); + _clear_execution(); +} + void ScriptEditorDebugger::debug_next() { ERR_FAIL_COND(!is_breaked()); @@ -1049,6 +1056,7 @@ void ScriptEditorDebugger::_notification(int p_what) { copy->set_button_icon(get_editor_theme_icon(SNAME("ActionCopy"))); step->set_button_icon(get_editor_theme_icon(SNAME("DebugStep"))); next->set_button_icon(get_editor_theme_icon(SNAME("DebugNext"))); + out->set_button_icon(get_editor_theme_icon(SNAME("DebugOut"))); dobreak->set_button_icon(get_editor_theme_icon(SNAME("Pause"))); docontinue->set_button_icon(get_editor_theme_icon(SNAME("DebugContinue"))); vmem_notice_icon->set_texture(get_editor_theme_icon(SNAME("NodeInfo"))); @@ -1221,6 +1229,7 @@ void ScriptEditorDebugger::_update_buttons_state() { vmem_refresh->set_disabled(!active); step->set_disabled(!active || !is_breaked() || !is_debuggable()); next->set_disabled(!active || !is_breaked() || !is_debuggable()); + out->set_disabled(!active || !is_breaked() || !is_debuggable()); copy->set_disabled(!active || !is_breaked()); docontinue->set_disabled(!active || !is_breaked()); dobreak->set_disabled(!active || is_breaked()); @@ -2040,6 +2049,13 @@ ScriptEditorDebugger::ScriptEditorDebugger() { next->set_shortcut(ED_GET_SHORTCUT("debugger/step_over")); next->connect(SceneStringName(pressed), callable_mp(this, &ScriptEditorDebugger::debug_next)); + out = memnew(Button); + out->set_theme_type_variation(SceneStringName(FlatButton)); + hbc->add_child(out); + out->set_tooltip_text(TTRC("Step Out")); + out->set_shortcut(ED_GET_SHORTCUT("debugger/step_out")); + out->connect(SceneStringName(pressed), callable_mp(this, &ScriptEditorDebugger::debug_out)); + hbc->add_child(memnew(VSeparator)); dobreak = memnew(Button); diff --git a/editor/debugger/script_editor_debugger.h b/editor/debugger/script_editor_debugger.h index beef460c7fc..01f042fa79e 100644 --- a/editor/debugger/script_editor_debugger.h +++ b/editor/debugger/script_editor_debugger.h @@ -125,6 +125,7 @@ private: Button *copy = nullptr; Button *step = nullptr; Button *next = nullptr; + Button *out = nullptr; Button *dobreak = nullptr; Button *docontinue = nullptr; // Reference to "Remote" tab in scene tree. Needed by _live_edit_set and buttons state. @@ -315,6 +316,7 @@ public: void debug_ignore_error_breaks(); void debug_copy(); + void debug_out(); void debug_next(); void debug_step(); void debug_break(); diff --git a/editor/icons/DebugOut.svg b/editor/icons/DebugOut.svg new file mode 100644 index 00000000000..d70903e05db --- /dev/null +++ b/editor/icons/DebugOut.svg @@ -0,0 +1 @@ +