2020-02-07 02:52:05 +01:00
|
|
|
/*************************************************************************/
|
|
|
|
/* editor_debugger_node.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
|
|
|
|
/* */
|
|
|
|
/* 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 "editor_debugger_node.h"
|
|
|
|
|
|
|
|
#include "editor/debugger/editor_debugger_tree.h"
|
2020-02-24 06:21:15 +01:00
|
|
|
#include "editor/debugger/script_editor_debugger.h"
|
2020-02-07 02:52:05 +01:00
|
|
|
#include "editor/editor_log.h"
|
|
|
|
#include "editor/editor_node.h"
|
2020-05-18 16:55:49 +02:00
|
|
|
#include "editor/plugins/editor_debugger_plugin.h"
|
2020-02-07 02:52:05 +01:00
|
|
|
#include "editor/plugins/script_editor_plugin.h"
|
2020-02-24 06:21:15 +01:00
|
|
|
#include "scene/gui/menu_button.h"
|
|
|
|
#include "scene/gui/tab_container.h"
|
2020-02-07 02:52:05 +01:00
|
|
|
|
|
|
|
template <typename Func>
|
2020-02-22 05:04:55 +01:00
|
|
|
void _for_all(TabContainer *p_node, const Func &p_func) {
|
2020-02-07 02:52:05 +01:00
|
|
|
for (int i = 0; i < p_node->get_tab_count(); i++) {
|
|
|
|
ScriptEditorDebugger *dbg = Object::cast_to<ScriptEditorDebugger>(p_node->get_tab_control(i));
|
|
|
|
ERR_FAIL_COND(!dbg);
|
|
|
|
p_func(dbg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-02 01:20:12 +02:00
|
|
|
EditorDebuggerNode *EditorDebuggerNode::singleton = nullptr;
|
2020-02-07 02:52:05 +01:00
|
|
|
|
|
|
|
EditorDebuggerNode::EditorDebuggerNode() {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!singleton) {
|
2020-02-07 02:52:05 +01:00
|
|
|
singleton = this;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2020-02-22 05:04:55 +01:00
|
|
|
|
2020-03-12 13:37:40 +01:00
|
|
|
add_theme_constant_override("margin_left", -EditorNode::get_singleton()->get_gui_base()->get_theme_stylebox("BottomPanelDebuggerOverride", "EditorStyles")->get_margin(MARGIN_LEFT));
|
|
|
|
add_theme_constant_override("margin_right", -EditorNode::get_singleton()->get_gui_base()->get_theme_stylebox("BottomPanelDebuggerOverride", "EditorStyles")->get_margin(MARGIN_RIGHT));
|
2020-02-22 05:04:55 +01:00
|
|
|
|
|
|
|
tabs = memnew(TabContainer);
|
|
|
|
tabs->set_tab_align(TabContainer::ALIGN_LEFT);
|
|
|
|
tabs->set_tabs_visible(false);
|
2020-02-21 18:28:45 +01:00
|
|
|
tabs->connect("tab_changed", callable_mp(this, &EditorDebuggerNode::_debugger_changed));
|
2020-02-22 05:04:55 +01:00
|
|
|
add_child(tabs);
|
|
|
|
|
|
|
|
Ref<StyleBoxEmpty> empty;
|
|
|
|
empty.instance();
|
2020-03-12 13:37:40 +01:00
|
|
|
tabs->add_theme_style_override("panel", empty);
|
2020-02-07 02:52:05 +01:00
|
|
|
|
|
|
|
auto_switch_remote_scene_tree = EDITOR_DEF("debugger/auto_switch_to_remote_scene_tree", false);
|
2020-02-22 05:04:55 +01:00
|
|
|
_add_debugger();
|
2020-02-07 02:52:05 +01:00
|
|
|
|
|
|
|
// Remote scene tree
|
|
|
|
remote_scene_tree = memnew(EditorDebuggerTree);
|
2020-02-21 18:28:45 +01:00
|
|
|
remote_scene_tree->connect("object_selected", callable_mp(this, &EditorDebuggerNode::_remote_object_requested));
|
|
|
|
remote_scene_tree->connect("save_node", callable_mp(this, &EditorDebuggerNode::_save_node_requested));
|
2020-02-07 02:52:05 +01:00
|
|
|
EditorNode::get_singleton()->get_scene_tree_dock()->add_remote_tree_editor(remote_scene_tree);
|
2020-02-21 18:28:45 +01:00
|
|
|
EditorNode::get_singleton()->get_scene_tree_dock()->connect("remote_tree_selected", callable_mp(this, &EditorDebuggerNode::request_remote_tree));
|
2020-02-07 02:52:05 +01:00
|
|
|
|
|
|
|
remote_scene_tree_timeout = EDITOR_DEF("debugger/remote_scene_tree_refresh_interval", 1.0);
|
|
|
|
inspect_edited_object_timeout = EDITOR_DEF("debugger/remote_inspect_refresh_interval", 0.2);
|
|
|
|
|
2020-02-22 05:04:55 +01:00
|
|
|
EditorNode *editor = EditorNode::get_singleton();
|
2020-02-07 02:52:05 +01:00
|
|
|
editor->get_undo_redo()->set_method_notify_callback(_method_changeds, this);
|
|
|
|
editor->get_undo_redo()->set_property_notify_callback(_property_changeds, this);
|
2020-02-21 18:28:45 +01:00
|
|
|
editor->get_pause_button()->connect("pressed", callable_mp(this, &EditorDebuggerNode::_paused));
|
2020-02-07 02:52:05 +01:00
|
|
|
}
|
|
|
|
|
2020-02-22 05:04:55 +01:00
|
|
|
ScriptEditorDebugger *EditorDebuggerNode::_add_debugger() {
|
2020-02-07 02:52:05 +01:00
|
|
|
ScriptEditorDebugger *node = memnew(ScriptEditorDebugger(EditorNode::get_singleton()));
|
2020-02-22 05:04:55 +01:00
|
|
|
|
|
|
|
int id = tabs->get_tab_count();
|
2020-02-21 18:28:45 +01:00
|
|
|
node->connect("stop_requested", callable_mp(this, &EditorDebuggerNode::_debugger_wants_stop), varray(id));
|
|
|
|
node->connect("stopped", callable_mp(this, &EditorDebuggerNode::_debugger_stopped), varray(id));
|
|
|
|
node->connect("stack_frame_selected", callable_mp(this, &EditorDebuggerNode::_stack_frame_selected), varray(id));
|
|
|
|
node->connect("error_selected", callable_mp(this, &EditorDebuggerNode::_error_selected), varray(id));
|
|
|
|
node->connect("clear_execution", callable_mp(this, &EditorDebuggerNode::_clear_execution));
|
|
|
|
node->connect("breaked", callable_mp(this, &EditorDebuggerNode::_breaked), varray(id));
|
|
|
|
node->connect("remote_tree_updated", callable_mp(this, &EditorDebuggerNode::_remote_tree_updated), varray(id));
|
|
|
|
node->connect("remote_object_updated", callable_mp(this, &EditorDebuggerNode::_remote_object_updated), varray(id));
|
|
|
|
node->connect("remote_object_property_updated", callable_mp(this, &EditorDebuggerNode::_remote_object_property_updated), varray(id));
|
|
|
|
node->connect("remote_object_requested", callable_mp(this, &EditorDebuggerNode::_remote_object_requested), varray(id));
|
2020-02-22 05:04:55 +01:00
|
|
|
|
|
|
|
if (tabs->get_tab_count() > 0) {
|
|
|
|
get_debugger(0)->clear_style();
|
|
|
|
}
|
|
|
|
|
|
|
|
tabs->add_child(node);
|
|
|
|
|
|
|
|
node->set_name("Session " + itos(tabs->get_tab_count()));
|
|
|
|
if (tabs->get_tab_count() > 1) {
|
|
|
|
node->clear_style();
|
|
|
|
tabs->set_tabs_visible(true);
|
2020-03-12 13:37:40 +01:00
|
|
|
tabs->add_theme_style_override("panel", EditorNode::get_singleton()->get_gui_base()->get_theme_stylebox("DebuggerPanel", "EditorStyles"));
|
2020-02-22 05:04:55 +01:00
|
|
|
}
|
|
|
|
|
2020-05-18 16:55:49 +02:00
|
|
|
if (!debugger_plugins.empty()) {
|
|
|
|
for (Set<Ref<Script>>::Element *i = debugger_plugins.front(); i; i = i->next()) {
|
|
|
|
node->add_debugger_plugin(i->get());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-07 02:52:05 +01:00
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorDebuggerNode::_stack_frame_selected(int p_debugger) {
|
|
|
|
const ScriptEditorDebugger *dbg = get_debugger(p_debugger);
|
|
|
|
ERR_FAIL_COND(!dbg);
|
2020-05-14 16:41:43 +02:00
|
|
|
if (dbg != get_current_debugger()) {
|
2020-02-07 02:52:05 +01:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2020-02-07 02:52:05 +01:00
|
|
|
_text_editor_stack_goto(dbg);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorDebuggerNode::_error_selected(const String &p_file, int p_line, int p_debugger) {
|
|
|
|
Ref<Script> s = ResourceLoader::load(p_file);
|
|
|
|
emit_signal("goto_script_line", s, p_line - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorDebuggerNode::_text_editor_stack_goto(const ScriptEditorDebugger *p_debugger) {
|
|
|
|
const String file = p_debugger->get_stack_script_file();
|
2020-05-14 16:41:43 +02:00
|
|
|
if (file.empty()) {
|
2020-02-07 02:52:05 +01:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2020-02-07 02:52:05 +01:00
|
|
|
stack_script = ResourceLoader::load(file);
|
|
|
|
const int line = p_debugger->get_stack_script_line() - 1;
|
|
|
|
emit_signal("goto_script_line", stack_script, line);
|
|
|
|
emit_signal("set_execution", stack_script, line);
|
|
|
|
stack_script.unref(); // Why?!?
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorDebuggerNode::_bind_methods() {
|
|
|
|
// LiveDebug.
|
|
|
|
ClassDB::bind_method("live_debug_create_node", &EditorDebuggerNode::live_debug_create_node);
|
|
|
|
ClassDB::bind_method("live_debug_instance_node", &EditorDebuggerNode::live_debug_instance_node);
|
|
|
|
ClassDB::bind_method("live_debug_remove_node", &EditorDebuggerNode::live_debug_remove_node);
|
|
|
|
ClassDB::bind_method("live_debug_remove_and_keep_node", &EditorDebuggerNode::live_debug_remove_and_keep_node);
|
|
|
|
ClassDB::bind_method("live_debug_restore_node", &EditorDebuggerNode::live_debug_restore_node);
|
|
|
|
ClassDB::bind_method("live_debug_duplicate_node", &EditorDebuggerNode::live_debug_duplicate_node);
|
|
|
|
ClassDB::bind_method("live_debug_reparent_node", &EditorDebuggerNode::live_debug_reparent_node);
|
|
|
|
|
|
|
|
ADD_SIGNAL(MethodInfo("goto_script_line"));
|
|
|
|
ADD_SIGNAL(MethodInfo("set_execution", PropertyInfo("script"), PropertyInfo(Variant::INT, "line")));
|
|
|
|
ADD_SIGNAL(MethodInfo("clear_execution", PropertyInfo("script")));
|
|
|
|
ADD_SIGNAL(MethodInfo("breaked", PropertyInfo(Variant::BOOL, "reallydid"), PropertyInfo(Variant::BOOL, "can_debug")));
|
|
|
|
}
|
|
|
|
|
|
|
|
EditorDebuggerRemoteObject *EditorDebuggerNode::get_inspected_remote_object() {
|
|
|
|
return Object::cast_to<EditorDebuggerRemoteObject>(ObjectDB::get_instance(EditorNode::get_singleton()->get_editor_history()->get_current()));
|
|
|
|
}
|
|
|
|
|
|
|
|
ScriptEditorDebugger *EditorDebuggerNode::get_debugger(int p_id) const {
|
2020-02-22 05:04:55 +01:00
|
|
|
return Object::cast_to<ScriptEditorDebugger>(tabs->get_tab_control(p_id));
|
2020-02-07 02:52:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ScriptEditorDebugger *EditorDebuggerNode::get_current_debugger() const {
|
2020-02-22 05:04:55 +01:00
|
|
|
return Object::cast_to<ScriptEditorDebugger>(tabs->get_tab_control(tabs->get_current_tab()));
|
2020-02-07 02:52:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ScriptEditorDebugger *EditorDebuggerNode::get_default_debugger() const {
|
2020-02-22 05:04:55 +01:00
|
|
|
return Object::cast_to<ScriptEditorDebugger>(tabs->get_tab_control(0));
|
2020-02-07 02:52:05 +01:00
|
|
|
}
|
|
|
|
|
2020-03-16 09:37:43 +01:00
|
|
|
Error EditorDebuggerNode::start(const String &p_protocol) {
|
2020-02-07 02:52:05 +01:00
|
|
|
stop();
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2020-03-16 09:37:43 +01:00
|
|
|
server = Ref<EditorDebuggerServer>(EditorDebuggerServer::create(p_protocol));
|
2020-02-24 06:21:15 +01:00
|
|
|
const Error err = server->start();
|
2020-02-07 02:52:05 +01:00
|
|
|
if (err != OK) {
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
set_process(true);
|
|
|
|
EditorNode::get_log()->add_message("--- Debugging process started ---", EditorLog::MSG_TYPE_EDITOR);
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorDebuggerNode::stop() {
|
2020-02-24 06:21:15 +01:00
|
|
|
if (server.is_valid()) {
|
2020-02-07 02:52:05 +01:00
|
|
|
server->stop();
|
|
|
|
EditorNode::get_log()->add_message("--- Debugging process stopped ---", EditorLog::MSG_TYPE_EDITOR);
|
2020-02-24 06:21:15 +01:00
|
|
|
server.unref();
|
2020-02-07 02:52:05 +01:00
|
|
|
}
|
|
|
|
// Also close all debugging sessions.
|
2020-02-22 05:04:55 +01:00
|
|
|
_for_all(tabs, [&](ScriptEditorDebugger *dbg) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (dbg->is_session_active()) {
|
2020-02-07 02:52:05 +01:00
|
|
|
dbg->stop();
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2020-02-07 02:52:05 +01:00
|
|
|
});
|
|
|
|
_break_state_changed();
|
|
|
|
if (hide_on_stop) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (is_visible_in_tree()) {
|
2020-02-07 02:52:05 +01:00
|
|
|
EditorNode::get_singleton()->hide_bottom_panel();
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2020-02-07 02:52:05 +01:00
|
|
|
}
|
|
|
|
breakpoints.clear();
|
|
|
|
set_process(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorDebuggerNode::_notification(int p_what) {
|
|
|
|
switch (p_what) {
|
2020-02-22 05:04:55 +01:00
|
|
|
case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
|
|
|
|
if (tabs->get_tab_count() > 1) {
|
2020-03-12 13:37:40 +01:00
|
|
|
add_theme_constant_override("margin_left", -EditorNode::get_singleton()->get_gui_base()->get_theme_stylebox("BottomPanelDebuggerOverride", "EditorStyles")->get_margin(MARGIN_LEFT));
|
|
|
|
add_theme_constant_override("margin_right", -EditorNode::get_singleton()->get_gui_base()->get_theme_stylebox("BottomPanelDebuggerOverride", "EditorStyles")->get_margin(MARGIN_RIGHT));
|
2020-02-22 05:04:55 +01:00
|
|
|
|
2020-03-12 13:37:40 +01:00
|
|
|
tabs->add_theme_style_override("panel", EditorNode::get_singleton()->get_gui_base()->get_theme_stylebox("DebuggerPanel", "EditorStyles"));
|
2020-02-22 05:04:55 +01:00
|
|
|
}
|
|
|
|
} break;
|
2020-02-07 02:52:05 +01:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (p_what != NOTIFICATION_PROCESS || !server.is_valid()) {
|
2020-02-07 02:52:05 +01:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2020-02-07 02:52:05 +01:00
|
|
|
|
2020-02-24 06:21:15 +01:00
|
|
|
if (!server.is_valid() || !server->is_active()) {
|
|
|
|
stop();
|
|
|
|
return;
|
|
|
|
}
|
2020-03-08 12:21:08 +01:00
|
|
|
server->poll();
|
2020-02-24 06:21:15 +01:00
|
|
|
|
2020-02-07 02:52:05 +01:00
|
|
|
// Errors and warnings
|
|
|
|
int error_count = 0;
|
|
|
|
int warning_count = 0;
|
2020-02-22 05:04:55 +01:00
|
|
|
_for_all(tabs, [&](ScriptEditorDebugger *dbg) {
|
2020-02-07 02:52:05 +01:00
|
|
|
error_count += dbg->get_error_count();
|
|
|
|
warning_count += dbg->get_warning_count();
|
|
|
|
});
|
|
|
|
|
|
|
|
if (error_count != last_error_count || warning_count != last_warning_count) {
|
2020-02-22 05:04:55 +01:00
|
|
|
_for_all(tabs, [&](ScriptEditorDebugger *dbg) {
|
2020-02-07 02:52:05 +01:00
|
|
|
dbg->update_tabs();
|
|
|
|
});
|
|
|
|
|
|
|
|
if (error_count == 0 && warning_count == 0) {
|
|
|
|
debugger_button->set_text(TTR("Debugger"));
|
|
|
|
debugger_button->set_icon(Ref<Texture2D>());
|
|
|
|
} else {
|
|
|
|
debugger_button->set_text(TTR("Debugger") + " (" + itos(error_count + warning_count) + ")");
|
2020-05-09 15:29:13 +02:00
|
|
|
if (error_count >= 1 && warning_count >= 1) {
|
|
|
|
debugger_button->set_icon(get_theme_icon("ErrorWarning", "EditorIcons"));
|
|
|
|
} else if (error_count >= 1) {
|
2020-03-12 13:37:40 +01:00
|
|
|
debugger_button->set_icon(get_theme_icon("Error", "EditorIcons"));
|
2020-05-09 15:29:13 +02:00
|
|
|
} else {
|
|
|
|
debugger_button->set_icon(get_theme_icon("Warning", "EditorIcons"));
|
2020-02-07 02:52:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
last_error_count = error_count;
|
|
|
|
last_warning_count = warning_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remote scene tree update
|
|
|
|
remote_scene_tree_timeout -= get_process_delta_time();
|
|
|
|
if (remote_scene_tree_timeout < 0) {
|
|
|
|
remote_scene_tree_timeout = EditorSettings::get_singleton()->get("debugger/remote_scene_tree_refresh_interval");
|
|
|
|
if (remote_scene_tree->is_visible_in_tree()) {
|
|
|
|
get_current_debugger()->request_remote_tree();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remote inspector update
|
|
|
|
inspect_edited_object_timeout -= get_process_delta_time();
|
|
|
|
if (inspect_edited_object_timeout < 0) {
|
|
|
|
inspect_edited_object_timeout = EditorSettings::get_singleton()->get("debugger/remote_inspect_refresh_interval");
|
|
|
|
if (EditorDebuggerRemoteObject *obj = get_inspected_remote_object()) {
|
|
|
|
get_current_debugger()->request_remote_object(obj->remote_object_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Take connections.
|
|
|
|
if (server->is_connection_available()) {
|
2020-04-02 01:20:12 +02:00
|
|
|
ScriptEditorDebugger *debugger = nullptr;
|
2020-02-22 05:04:55 +01:00
|
|
|
_for_all(tabs, [&](ScriptEditorDebugger *dbg) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (debugger || dbg->is_session_active()) {
|
2020-02-07 02:52:05 +01:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2020-02-07 02:52:05 +01:00
|
|
|
debugger = dbg;
|
|
|
|
});
|
2020-04-02 01:20:12 +02:00
|
|
|
if (debugger == nullptr) {
|
2020-02-22 05:04:55 +01:00
|
|
|
if (tabs->get_tab_count() <= 4) { // Max 4 debugging sessions active.
|
|
|
|
debugger = _add_debugger();
|
2020-02-07 02:52:05 +01:00
|
|
|
} else {
|
2020-02-24 06:21:15 +01:00
|
|
|
// We already have too many sessions, disconnecting new clients to prevent them from hanging.
|
|
|
|
server->take_connection()->close();
|
2020-02-07 02:52:05 +01:00
|
|
|
return; // Can't add, stop here.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
EditorNode::get_singleton()->get_pause_button()->set_disabled(false);
|
|
|
|
// Switch to remote tree view if so desired.
|
|
|
|
auto_switch_remote_scene_tree = (bool)EditorSettings::get_singleton()->get("debugger/auto_switch_to_remote_scene_tree");
|
|
|
|
if (auto_switch_remote_scene_tree) {
|
|
|
|
EditorNode::get_singleton()->get_scene_tree_dock()->show_remote_tree();
|
|
|
|
}
|
|
|
|
// Good to go.
|
|
|
|
EditorNode::get_singleton()->get_scene_tree_dock()->show_tab_buttons();
|
|
|
|
debugger->set_editor_remote_tree(remote_scene_tree);
|
|
|
|
debugger->start(server->take_connection());
|
|
|
|
// Send breakpoints.
|
|
|
|
for (Map<Breakpoint, bool>::Element *E = breakpoints.front(); E; E = E->next()) {
|
|
|
|
const Breakpoint &bp = E->key();
|
|
|
|
debugger->set_breakpoint(bp.source, bp.line, E->get());
|
|
|
|
} // Will arrive too late, how does the regular run work?
|
|
|
|
|
|
|
|
debugger->update_live_edit_root();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorDebuggerNode::_debugger_stopped(int p_id) {
|
|
|
|
ScriptEditorDebugger *dbg = get_debugger(p_id);
|
|
|
|
ERR_FAIL_COND(!dbg);
|
|
|
|
|
|
|
|
bool found = false;
|
2020-02-22 05:04:55 +01:00
|
|
|
_for_all(tabs, [&](ScriptEditorDebugger *p_debugger) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (p_debugger->is_session_active()) {
|
2020-02-07 02:52:05 +01:00
|
|
|
found = true;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2020-02-07 02:52:05 +01:00
|
|
|
});
|
|
|
|
if (!found) {
|
|
|
|
EditorNode::get_singleton()->get_pause_button()->set_pressed(false);
|
|
|
|
EditorNode::get_singleton()->get_pause_button()->set_disabled(true);
|
|
|
|
EditorNode::get_singleton()->get_scene_tree_dock()->hide_remote_tree();
|
|
|
|
EditorNode::get_singleton()->get_scene_tree_dock()->hide_tab_buttons();
|
|
|
|
EditorNode::get_singleton()->notify_all_debug_sessions_exited();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorDebuggerNode::_debugger_wants_stop(int p_id) {
|
|
|
|
// Ask editor to kill PID.
|
|
|
|
int pid = get_debugger(p_id)->get_remote_pid();
|
2020-05-14 16:41:43 +02:00
|
|
|
if (pid) {
|
2020-02-07 02:52:05 +01:00
|
|
|
EditorNode::get_singleton()->call_deferred("stop_child_process", pid);
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2020-02-07 02:52:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditorDebuggerNode::_debugger_changed(int p_tab) {
|
|
|
|
if (get_inspected_remote_object()) {
|
|
|
|
// Clear inspected object, you can only inspect objects in selected debugger.
|
|
|
|
// Hopefully, in the future, we will have one inspector per debugger.
|
2020-04-02 01:20:12 +02:00
|
|
|
EditorNode::get_singleton()->push_item(nullptr);
|
2020-02-07 02:52:05 +01:00
|
|
|
}
|
|
|
|
if (remote_scene_tree->is_visible_in_tree()) {
|
|
|
|
get_current_debugger()->request_remote_tree();
|
|
|
|
}
|
|
|
|
if (get_current_debugger()->is_breaked()) {
|
|
|
|
_text_editor_stack_goto(get_current_debugger());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorDebuggerNode::set_script_debug_button(MenuButton *p_button) {
|
|
|
|
script_menu = p_button;
|
|
|
|
script_menu->set_text(TTR("Debug"));
|
|
|
|
script_menu->set_switch_on_hover(true);
|
|
|
|
PopupMenu *p = script_menu->get_popup();
|
|
|
|
p->add_shortcut(ED_GET_SHORTCUT("debugger/step_into"), DEBUG_STEP);
|
|
|
|
p->add_shortcut(ED_GET_SHORTCUT("debugger/step_over"), DEBUG_NEXT);
|
|
|
|
p->add_separator();
|
|
|
|
p->add_shortcut(ED_GET_SHORTCUT("debugger/break"), DEBUG_BREAK);
|
|
|
|
p->add_shortcut(ED_GET_SHORTCUT("debugger/continue"), DEBUG_CONTINUE);
|
|
|
|
p->add_separator();
|
|
|
|
p->add_check_shortcut(ED_GET_SHORTCUT("debugger/keep_debugger_open"), DEBUG_SHOW_KEEP_OPEN);
|
|
|
|
p->add_check_shortcut(ED_GET_SHORTCUT("debugger/debug_with_external_editor"), DEBUG_WITH_EXTERNAL_EDITOR);
|
2020-02-21 18:28:45 +01:00
|
|
|
p->connect("id_pressed", callable_mp(this, &EditorDebuggerNode::_menu_option));
|
2020-02-07 02:52:05 +01:00
|
|
|
|
|
|
|
_break_state_changed();
|
|
|
|
script_menu->show();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorDebuggerNode::_break_state_changed() {
|
|
|
|
const bool breaked = get_current_debugger()->is_breaked();
|
|
|
|
const bool can_debug = get_current_debugger()->is_debuggable();
|
2020-05-14 16:41:43 +02:00
|
|
|
if (breaked) { // Show debugger.
|
2020-02-07 02:52:05 +01:00
|
|
|
EditorNode::get_singleton()->make_bottom_panel_item_visible(this);
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2020-02-07 02:52:05 +01:00
|
|
|
|
|
|
|
// Update script menu.
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!script_menu) {
|
2020-02-07 02:52:05 +01:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2020-02-07 02:52:05 +01:00
|
|
|
PopupMenu *p = script_menu->get_popup();
|
|
|
|
p->set_item_disabled(p->get_item_index(DEBUG_NEXT), !(breaked && can_debug));
|
|
|
|
p->set_item_disabled(p->get_item_index(DEBUG_STEP), !(breaked && can_debug));
|
|
|
|
p->set_item_disabled(p->get_item_index(DEBUG_BREAK), breaked);
|
|
|
|
p->set_item_disabled(p->get_item_index(DEBUG_CONTINUE), !breaked);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorDebuggerNode::_menu_option(int p_id) {
|
|
|
|
switch (p_id) {
|
|
|
|
case DEBUG_NEXT: {
|
|
|
|
debug_next();
|
|
|
|
} break;
|
|
|
|
case DEBUG_STEP: {
|
|
|
|
debug_step();
|
|
|
|
} break;
|
|
|
|
case DEBUG_BREAK: {
|
|
|
|
debug_break();
|
|
|
|
} break;
|
|
|
|
case DEBUG_CONTINUE: {
|
|
|
|
debug_continue();
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case DEBUG_SHOW_KEEP_OPEN: {
|
|
|
|
bool visible = script_menu->get_popup()->is_item_checked(script_menu->get_popup()->get_item_index(DEBUG_SHOW_KEEP_OPEN));
|
|
|
|
hide_on_stop = visible;
|
|
|
|
script_menu->get_popup()->set_item_checked(script_menu->get_popup()->get_item_index(DEBUG_SHOW_KEEP_OPEN), !visible);
|
|
|
|
} break;
|
|
|
|
case DEBUG_WITH_EXTERNAL_EDITOR: {
|
|
|
|
bool checked = !script_menu->get_popup()->is_item_checked(script_menu->get_popup()->get_item_index(DEBUG_WITH_EXTERNAL_EDITOR));
|
|
|
|
debug_with_external_editor = checked;
|
|
|
|
script_menu->get_popup()->set_item_checked(script_menu->get_popup()->get_item_index(DEBUG_WITH_EXTERNAL_EDITOR), checked);
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorDebuggerNode::_paused() {
|
|
|
|
const bool paused = EditorNode::get_singleton()->get_pause_button()->is_pressed();
|
2020-02-22 05:04:55 +01:00
|
|
|
_for_all(tabs, [&](ScriptEditorDebugger *dbg) {
|
2020-02-07 02:52:05 +01:00
|
|
|
if (paused && !dbg->is_breaked()) {
|
|
|
|
dbg->debug_break();
|
|
|
|
} else if (!paused && dbg->is_breaked()) {
|
|
|
|
dbg->debug_continue();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorDebuggerNode::_breaked(bool p_breaked, bool p_can_debug, int p_debugger) {
|
|
|
|
if (get_current_debugger() != get_debugger(p_debugger)) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!p_breaked) {
|
2020-02-07 02:52:05 +01:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2020-02-22 05:04:55 +01:00
|
|
|
tabs->set_current_tab(p_debugger);
|
2020-02-07 02:52:05 +01:00
|
|
|
}
|
|
|
|
_break_state_changed();
|
|
|
|
EditorNode::get_singleton()->get_pause_button()->set_pressed(p_breaked);
|
|
|
|
emit_signal("breaked", p_breaked, p_can_debug);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool EditorDebuggerNode::is_skip_breakpoints() const {
|
|
|
|
return get_default_debugger()->is_skip_breakpoints();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorDebuggerNode::set_breakpoint(const String &p_path, int p_line, bool p_enabled) {
|
|
|
|
breakpoints[Breakpoint(p_path, p_line)] = p_enabled;
|
2020-02-22 05:04:55 +01:00
|
|
|
_for_all(tabs, [&](ScriptEditorDebugger *dbg) {
|
2020-02-07 02:52:05 +01:00
|
|
|
dbg->set_breakpoint(p_path, p_line, p_enabled);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorDebuggerNode::reload_scripts() {
|
2020-02-22 05:04:55 +01:00
|
|
|
_for_all(tabs, [&](ScriptEditorDebugger *dbg) {
|
2020-02-07 02:52:05 +01:00
|
|
|
dbg->reload_scripts();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-02-24 06:21:15 +01:00
|
|
|
void EditorDebuggerNode::debug_next() {
|
|
|
|
get_default_debugger()->debug_next();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorDebuggerNode::debug_step() {
|
|
|
|
get_default_debugger()->debug_step();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorDebuggerNode::debug_break() {
|
|
|
|
get_default_debugger()->debug_break();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorDebuggerNode::debug_continue() {
|
|
|
|
get_default_debugger()->debug_continue();
|
|
|
|
}
|
|
|
|
|
|
|
|
String EditorDebuggerNode::get_var_value(const String &p_var) const {
|
|
|
|
return get_default_debugger()->get_var_value(p_var);
|
|
|
|
}
|
|
|
|
|
2020-02-07 02:52:05 +01:00
|
|
|
// LiveEdit/Inspector
|
|
|
|
void EditorDebuggerNode::request_remote_tree() {
|
|
|
|
get_current_debugger()->request_remote_tree();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorDebuggerNode::_remote_tree_updated(int p_debugger) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (p_debugger != tabs->get_current_tab()) {
|
2020-02-07 02:52:05 +01:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2020-02-07 02:52:05 +01:00
|
|
|
remote_scene_tree->clear();
|
|
|
|
remote_scene_tree->update_scene_tree(get_current_debugger()->get_remote_tree(), p_debugger);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorDebuggerNode::_remote_object_updated(ObjectID p_id, int p_debugger) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (p_debugger != tabs->get_current_tab()) {
|
2020-02-07 02:52:05 +01:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2020-02-07 02:52:05 +01:00
|
|
|
if (EditorDebuggerRemoteObject *obj = get_inspected_remote_object()) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (obj->remote_object_id == p_id) {
|
2020-02-07 02:52:05 +01:00
|
|
|
return; // Already being edited
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2020-02-07 02:52:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
EditorNode::get_singleton()->push_item(get_current_debugger()->get_remote_object(p_id));
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorDebuggerNode::_remote_object_property_updated(ObjectID p_id, const String &p_property, int p_debugger) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (p_debugger != tabs->get_current_tab()) {
|
2020-02-07 02:52:05 +01:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2020-02-07 02:52:05 +01:00
|
|
|
if (EditorDebuggerRemoteObject *obj = get_inspected_remote_object()) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (obj->remote_object_id != p_id) {
|
2020-02-07 02:52:05 +01:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2020-02-07 02:52:05 +01:00
|
|
|
EditorNode::get_singleton()->get_inspector()->update_property(p_property);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorDebuggerNode::_remote_object_requested(ObjectID p_id, int p_debugger) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (p_debugger != tabs->get_current_tab()) {
|
2020-02-07 02:52:05 +01:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2020-02-07 02:52:05 +01:00
|
|
|
inspect_edited_object_timeout = 0.7; // Temporarily disable timeout to avoid multiple requests.
|
|
|
|
get_current_debugger()->request_remote_object(p_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorDebuggerNode::_save_node_requested(ObjectID p_id, const String &p_file, int p_debugger) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (p_debugger != tabs->get_current_tab()) {
|
2020-02-07 02:52:05 +01:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2020-02-07 02:52:05 +01:00
|
|
|
get_current_debugger()->save_node(p_id, p_file);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remote inspector/edit.
|
|
|
|
void EditorDebuggerNode::_method_changeds(void *p_ud, Object *p_base, const StringName &p_name, VARIANT_ARG_DECLARE) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!singleton) {
|
2020-02-07 02:52:05 +01:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2020-02-22 05:04:55 +01:00
|
|
|
_for_all(singleton->tabs, [&](ScriptEditorDebugger *dbg) {
|
2020-02-07 02:52:05 +01:00
|
|
|
dbg->_method_changed(p_base, p_name, VARIANT_ARG_PASS);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorDebuggerNode::_property_changeds(void *p_ud, Object *p_base, const StringName &p_property, const Variant &p_value) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!singleton) {
|
2020-02-07 02:52:05 +01:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2020-02-22 05:04:55 +01:00
|
|
|
_for_all(singleton->tabs, [&](ScriptEditorDebugger *dbg) {
|
2020-02-07 02:52:05 +01:00
|
|
|
dbg->_property_changed(p_base, p_property, p_value);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// LiveDebug
|
|
|
|
void EditorDebuggerNode::set_live_debugging(bool p_enabled) {
|
2020-02-22 05:04:55 +01:00
|
|
|
_for_all(tabs, [&](ScriptEditorDebugger *dbg) {
|
2020-02-07 02:52:05 +01:00
|
|
|
dbg->set_live_debugging(p_enabled);
|
|
|
|
});
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2020-02-07 02:52:05 +01:00
|
|
|
void EditorDebuggerNode::update_live_edit_root() {
|
2020-02-22 05:04:55 +01:00
|
|
|
_for_all(tabs, [&](ScriptEditorDebugger *dbg) {
|
2020-02-07 02:52:05 +01:00
|
|
|
dbg->update_live_edit_root();
|
|
|
|
});
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2020-02-07 02:52:05 +01:00
|
|
|
void EditorDebuggerNode::live_debug_create_node(const NodePath &p_parent, const String &p_type, const String &p_name) {
|
2020-02-22 05:04:55 +01:00
|
|
|
_for_all(tabs, [&](ScriptEditorDebugger *dbg) {
|
2020-02-07 02:52:05 +01:00
|
|
|
dbg->live_debug_create_node(p_parent, p_type, p_name);
|
|
|
|
});
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2020-02-07 02:52:05 +01:00
|
|
|
void EditorDebuggerNode::live_debug_instance_node(const NodePath &p_parent, const String &p_path, const String &p_name) {
|
2020-02-22 05:04:55 +01:00
|
|
|
_for_all(tabs, [&](ScriptEditorDebugger *dbg) {
|
2020-02-07 02:52:05 +01:00
|
|
|
dbg->live_debug_instance_node(p_parent, p_path, p_name);
|
|
|
|
});
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2020-02-07 02:52:05 +01:00
|
|
|
void EditorDebuggerNode::live_debug_remove_node(const NodePath &p_at) {
|
2020-02-22 05:04:55 +01:00
|
|
|
_for_all(tabs, [&](ScriptEditorDebugger *dbg) {
|
2020-02-07 02:52:05 +01:00
|
|
|
dbg->live_debug_remove_node(p_at);
|
|
|
|
});
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2020-02-07 02:52:05 +01:00
|
|
|
void EditorDebuggerNode::live_debug_remove_and_keep_node(const NodePath &p_at, ObjectID p_keep_id) {
|
2020-02-22 05:04:55 +01:00
|
|
|
_for_all(tabs, [&](ScriptEditorDebugger *dbg) {
|
2020-02-07 02:52:05 +01:00
|
|
|
dbg->live_debug_remove_and_keep_node(p_at, p_keep_id);
|
|
|
|
});
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2020-02-07 02:52:05 +01:00
|
|
|
void EditorDebuggerNode::live_debug_restore_node(ObjectID p_id, const NodePath &p_at, int p_at_pos) {
|
2020-02-22 05:04:55 +01:00
|
|
|
_for_all(tabs, [&](ScriptEditorDebugger *dbg) {
|
2020-02-07 02:52:05 +01:00
|
|
|
dbg->live_debug_restore_node(p_id, p_at, p_at_pos);
|
|
|
|
});
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2020-02-07 02:52:05 +01:00
|
|
|
void EditorDebuggerNode::live_debug_duplicate_node(const NodePath &p_at, const String &p_new_name) {
|
2020-02-22 05:04:55 +01:00
|
|
|
_for_all(tabs, [&](ScriptEditorDebugger *dbg) {
|
2020-02-07 02:52:05 +01:00
|
|
|
dbg->live_debug_duplicate_node(p_at, p_new_name);
|
|
|
|
});
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2020-02-07 02:52:05 +01:00
|
|
|
void EditorDebuggerNode::live_debug_reparent_node(const NodePath &p_at, const NodePath &p_new_place, const String &p_new_name, int p_at_pos) {
|
2020-02-22 05:04:55 +01:00
|
|
|
_for_all(tabs, [&](ScriptEditorDebugger *dbg) {
|
2020-02-07 02:52:05 +01:00
|
|
|
dbg->live_debug_reparent_node(p_at, p_new_place, p_new_name, p_at_pos);
|
|
|
|
});
|
|
|
|
}
|
2020-05-18 16:55:49 +02:00
|
|
|
|
|
|
|
void EditorDebuggerNode::add_debugger_plugin(const Ref<Script> &p_script) {
|
|
|
|
ERR_FAIL_COND_MSG(debugger_plugins.has(p_script), "Debugger plugin already exists.");
|
|
|
|
ERR_FAIL_COND_MSG(p_script.is_null(), "Debugger plugin script is null");
|
|
|
|
ERR_FAIL_COND_MSG(String(p_script->get_instance_base_type()) == "", "Debugger plugin script has error.");
|
|
|
|
ERR_FAIL_COND_MSG(String(p_script->get_instance_base_type()) != "EditorDebuggerPlugin", "Base type of debugger plugin is not 'EditorDebuggerPlugin'.");
|
|
|
|
ERR_FAIL_COND_MSG(!p_script->is_tool(), "Debugger plugin script is not in tool mode.");
|
|
|
|
debugger_plugins.insert(p_script);
|
|
|
|
for (int i = 0; get_debugger(i); i++) {
|
|
|
|
get_debugger(i)->add_debugger_plugin(p_script);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorDebuggerNode::remove_debugger_plugin(const Ref<Script> &p_script) {
|
|
|
|
ERR_FAIL_COND_MSG(!debugger_plugins.has(p_script), "Debugger plugin doesn't exists.");
|
|
|
|
debugger_plugins.erase(p_script);
|
|
|
|
for (int i = 0; get_debugger(i); i++) {
|
|
|
|
get_debugger(i)->remove_debugger_plugin(p_script);
|
|
|
|
}
|
|
|
|
}
|