2020-02-07 02:52:05 +01:00
|
|
|
/**************************************************************************/
|
|
|
|
/* editor_debugger_node.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. */
|
|
|
|
/**************************************************************************/
|
|
|
|
|
|
|
|
#ifndef EDITOR_DEBUGGER_NODE_H
|
|
|
|
#define EDITOR_DEBUGGER_NODE_H
|
|
|
|
|
2023-09-06 21:02:52 +02:00
|
|
|
#include "core/object/script_language.h"
|
2020-02-24 06:21:15 +01:00
|
|
|
#include "editor/debugger/editor_debugger_server.h"
|
|
|
|
#include "scene/gui/margin_container.h"
|
2020-02-07 02:52:05 +01:00
|
|
|
|
2020-02-24 06:21:15 +01:00
|
|
|
class Button;
|
2021-06-04 20:39:38 +02:00
|
|
|
class DebugAdapterParser;
|
2022-10-03 15:21:25 +02:00
|
|
|
class EditorDebuggerPlugin;
|
2020-02-07 02:52:05 +01:00
|
|
|
class EditorDebuggerTree;
|
2020-02-24 06:21:15 +01:00
|
|
|
class EditorDebuggerRemoteObject;
|
|
|
|
class MenuButton;
|
|
|
|
class ScriptEditorDebugger;
|
|
|
|
class TabContainer;
|
2022-03-25 18:06:46 +01:00
|
|
|
class UndoRedo;
|
2020-02-07 02:52:05 +01:00
|
|
|
|
2020-02-22 05:04:55 +01:00
|
|
|
class EditorDebuggerNode : public MarginContainer {
|
|
|
|
GDCLASS(EditorDebuggerNode, MarginContainer);
|
2020-02-07 02:52:05 +01:00
|
|
|
|
2020-02-24 06:21:15 +01:00
|
|
|
public:
|
|
|
|
enum CameraOverride {
|
|
|
|
OVERRIDE_NONE,
|
|
|
|
OVERRIDE_2D,
|
|
|
|
OVERRIDE_3D_1, // 3D Viewport 1
|
|
|
|
OVERRIDE_3D_2, // 3D Viewport 2
|
|
|
|
OVERRIDE_3D_3, // 3D Viewport 3
|
|
|
|
OVERRIDE_3D_4 // 3D Viewport 4
|
|
|
|
};
|
|
|
|
|
2020-02-07 02:52:05 +01:00
|
|
|
private:
|
|
|
|
enum Options {
|
|
|
|
DEBUG_NEXT,
|
|
|
|
DEBUG_STEP,
|
|
|
|
DEBUG_BREAK,
|
|
|
|
DEBUG_CONTINUE,
|
|
|
|
DEBUG_WITH_EXTERNAL_EDITOR,
|
|
|
|
};
|
|
|
|
|
|
|
|
class Breakpoint {
|
|
|
|
public:
|
|
|
|
String source;
|
|
|
|
int line = 0;
|
|
|
|
|
2022-05-13 15:04:37 +02:00
|
|
|
static uint32_t hash(const Breakpoint &p_val) {
|
|
|
|
uint32_t h = HashMapHasherDefault::hash(p_val.source);
|
2022-06-18 16:20:55 +02:00
|
|
|
return hash_murmur3_one_32(p_val.line, h);
|
2022-05-13 15:04:37 +02:00
|
|
|
}
|
|
|
|
bool operator==(const Breakpoint &p_b) const {
|
|
|
|
return (line == p_b.line && source == p_b.source);
|
|
|
|
}
|
|
|
|
|
2020-02-07 02:52:05 +01:00
|
|
|
bool operator<(const Breakpoint &p_b) const {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (line == p_b.line) {
|
2020-02-23 14:10:24 +01:00
|
|
|
return source < p_b.source;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2020-02-07 02:52:05 +01:00
|
|
|
return line < p_b.line;
|
|
|
|
}
|
|
|
|
|
2020-05-12 17:01:17 +02:00
|
|
|
Breakpoint() {}
|
2020-02-07 02:52:05 +01:00
|
|
|
|
|
|
|
Breakpoint(const String &p_source, int p_line) {
|
|
|
|
line = p_line;
|
|
|
|
source = p_source;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-02-24 06:21:15 +01:00
|
|
|
Ref<EditorDebuggerServer> server;
|
2020-04-02 01:20:12 +02:00
|
|
|
TabContainer *tabs = nullptr;
|
|
|
|
Button *debugger_button = nullptr;
|
|
|
|
MenuButton *script_menu = nullptr;
|
2020-02-07 02:52:05 +01:00
|
|
|
|
|
|
|
Ref<Script> stack_script; // Why?!?
|
|
|
|
|
|
|
|
int last_error_count = 0;
|
|
|
|
int last_warning_count = 0;
|
|
|
|
|
|
|
|
float inspect_edited_object_timeout = 0;
|
2020-04-02 01:20:12 +02:00
|
|
|
EditorDebuggerTree *remote_scene_tree = nullptr;
|
2020-02-07 02:52:05 +01:00
|
|
|
float remote_scene_tree_timeout = 0.0;
|
|
|
|
bool auto_switch_remote_scene_tree = false;
|
|
|
|
bool debug_with_external_editor = false;
|
2022-11-24 22:03:29 +01:00
|
|
|
bool keep_open = false;
|
|
|
|
String current_uri;
|
|
|
|
|
2020-02-24 06:21:15 +01:00
|
|
|
CameraOverride camera_override = OVERRIDE_NONE;
|
2022-05-13 15:04:37 +02:00
|
|
|
HashMap<Breakpoint, bool, Breakpoint> breakpoints;
|
2020-02-07 02:52:05 +01:00
|
|
|
|
2022-10-03 15:21:25 +02:00
|
|
|
HashSet<Ref<EditorDebuggerPlugin>> debugger_plugins;
|
2020-05-18 16:55:49 +02:00
|
|
|
|
2020-02-22 05:04:55 +01:00
|
|
|
ScriptEditorDebugger *_add_debugger();
|
2020-02-07 02:52:05 +01:00
|
|
|
EditorDebuggerRemoteObject *get_inspected_remote_object();
|
2022-06-06 01:27:09 +02:00
|
|
|
void _update_errors();
|
2020-02-07 02:52:05 +01:00
|
|
|
|
|
|
|
friend class DebuggerEditorPlugin;
|
2021-06-04 20:39:38 +02:00
|
|
|
friend class DebugAdapterParser;
|
2020-02-07 02:52:05 +01:00
|
|
|
static EditorDebuggerNode *singleton;
|
|
|
|
EditorDebuggerNode();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void _debugger_stopped(int p_id);
|
|
|
|
void _debugger_wants_stop(int p_id);
|
|
|
|
void _debugger_changed(int p_tab);
|
|
|
|
void _remote_tree_updated(int p_debugger);
|
2022-08-31 00:52:05 +02:00
|
|
|
void _remote_tree_button_pressed(Object *p_item, int p_column, int p_id, MouseButton p_button);
|
2020-02-07 02:52:05 +01:00
|
|
|
void _remote_object_updated(ObjectID p_id, int p_debugger);
|
|
|
|
void _remote_object_property_updated(ObjectID p_id, const String &p_property, int p_debugger);
|
|
|
|
void _remote_object_requested(ObjectID p_id, int p_debugger);
|
|
|
|
void _save_node_requested(ObjectID p_id, const String &p_file, int p_debugger);
|
|
|
|
|
2023-10-05 18:45:27 +02:00
|
|
|
void _breakpoint_set_in_tree(Ref<RefCounted> p_script, int p_line, bool p_enabled, int p_debugger);
|
|
|
|
void _breakpoints_cleared_in_tree(int p_debugger);
|
|
|
|
|
2022-05-03 01:43:50 +02:00
|
|
|
void _clear_execution(Ref<RefCounted> p_script) {
|
2021-07-17 23:22:52 +02:00
|
|
|
emit_signal(SNAME("clear_execution"), p_script);
|
2020-02-07 02:52:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void _text_editor_stack_goto(const ScriptEditorDebugger *p_debugger);
|
2023-10-05 18:45:27 +02:00
|
|
|
void _text_editor_stack_clear(const ScriptEditorDebugger *p_debugger);
|
2020-02-07 02:52:05 +01:00
|
|
|
void _stack_frame_selected(int p_debugger);
|
|
|
|
void _error_selected(const String &p_file, int p_line, int p_debugger);
|
2024-02-15 17:25:58 +01:00
|
|
|
void _breaked(bool p_breaked, bool p_can_debug, const String &p_message, bool p_has_stackdump, int p_debugger);
|
2020-02-07 02:52:05 +01:00
|
|
|
void _paused();
|
|
|
|
void _break_state_changed();
|
|
|
|
void _menu_option(int p_id);
|
2020-11-17 13:03:37 +01:00
|
|
|
void _update_debug_options();
|
2020-02-07 02:52:05 +01:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void _notification(int p_what);
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
public:
|
|
|
|
static EditorDebuggerNode *get_singleton() { return singleton; }
|
2022-03-25 18:06:46 +01:00
|
|
|
void register_undo_redo(UndoRedo *p_undo_redo);
|
2020-02-07 02:52:05 +01:00
|
|
|
|
2023-10-05 18:45:27 +02:00
|
|
|
ScriptEditorDebugger *get_previous_debugger() const;
|
2020-02-07 02:52:05 +01:00
|
|
|
ScriptEditorDebugger *get_current_debugger() const;
|
|
|
|
ScriptEditorDebugger *get_default_debugger() const;
|
|
|
|
ScriptEditorDebugger *get_debugger(int p_debugger) const;
|
|
|
|
|
2020-02-24 06:21:15 +01:00
|
|
|
void debug_next();
|
|
|
|
void debug_step();
|
|
|
|
void debug_break();
|
|
|
|
void debug_continue();
|
2020-02-07 02:52:05 +01:00
|
|
|
|
|
|
|
void set_script_debug_button(MenuButton *p_button);
|
|
|
|
|
|
|
|
void set_tool_button(Button *p_button) {
|
|
|
|
debugger_button = p_button;
|
|
|
|
}
|
|
|
|
|
2020-02-24 06:21:15 +01:00
|
|
|
String get_var_value(const String &p_var) const;
|
2020-02-07 02:52:05 +01:00
|
|
|
Ref<Script> get_dump_stack_script() const { return stack_script; } // Why do we need this?
|
|
|
|
|
|
|
|
bool get_debug_with_external_editor() { return debug_with_external_editor; }
|
|
|
|
|
|
|
|
bool is_skip_breakpoints() const;
|
|
|
|
void set_breakpoint(const String &p_path, int p_line, bool p_enabled);
|
2024-02-15 17:25:58 +01:00
|
|
|
void set_breakpoints(const String &p_path, const Array &p_lines);
|
2023-12-30 08:06:54 +01:00
|
|
|
void reload_all_scripts();
|
|
|
|
void reload_scripts(const Vector<String> &p_script_paths);
|
2020-02-07 02:52:05 +01:00
|
|
|
|
|
|
|
// Remote inspector/edit.
|
|
|
|
void request_remote_tree();
|
2022-03-09 14:58:40 +01:00
|
|
|
static void _method_changeds(void *p_ud, Object *p_base, const StringName &p_name, const Variant **p_args, int p_argcount);
|
2020-02-07 02:52:05 +01:00
|
|
|
static void _property_changeds(void *p_ud, Object *p_base, const StringName &p_property, const Variant &p_value);
|
|
|
|
|
|
|
|
// LiveDebug
|
|
|
|
void set_live_debugging(bool p_enabled);
|
|
|
|
void update_live_edit_root();
|
|
|
|
void live_debug_create_node(const NodePath &p_parent, const String &p_type, const String &p_name);
|
2022-11-16 00:13:39 +01:00
|
|
|
void live_debug_instantiate_node(const NodePath &p_parent, const String &p_path, const String &p_name);
|
2020-02-07 02:52:05 +01:00
|
|
|
void live_debug_remove_node(const NodePath &p_at);
|
|
|
|
void live_debug_remove_and_keep_node(const NodePath &p_at, ObjectID p_keep_id);
|
|
|
|
void live_debug_restore_node(ObjectID p_id, const NodePath &p_at, int p_at_pos);
|
|
|
|
void live_debug_duplicate_node(const NodePath &p_at, const String &p_new_name);
|
|
|
|
void live_debug_reparent_node(const NodePath &p_at, const NodePath &p_new_place, const String &p_new_name, int p_at_pos);
|
|
|
|
|
2021-08-21 20:24:09 +02:00
|
|
|
void set_camera_override(CameraOverride p_override);
|
|
|
|
CameraOverride get_camera_override();
|
2020-02-07 02:52:05 +01:00
|
|
|
|
2021-09-30 04:06:28 +02:00
|
|
|
String get_server_uri() const;
|
2020-02-07 02:52:05 +01:00
|
|
|
|
2022-11-24 22:03:29 +01:00
|
|
|
void set_keep_open(bool p_keep_open);
|
2021-09-30 04:06:28 +02:00
|
|
|
Error start(const String &p_uri = "tcp://");
|
2022-11-24 22:03:29 +01:00
|
|
|
void stop(bool p_force = false);
|
2020-05-18 16:55:49 +02:00
|
|
|
|
2022-10-03 15:21:25 +02:00
|
|
|
bool plugins_capture(ScriptEditorDebugger *p_debugger, const String &p_message, const Array &p_data);
|
|
|
|
void add_debugger_plugin(const Ref<EditorDebuggerPlugin> &p_plugin);
|
|
|
|
void remove_debugger_plugin(const Ref<EditorDebuggerPlugin> &p_plugin);
|
2020-02-07 02:52:05 +01:00
|
|
|
};
|
2022-07-23 23:41:51 +02:00
|
|
|
|
2020-02-07 02:52:05 +01:00
|
|
|
#endif // EDITOR_DEBUGGER_NODE_H
|