| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "core/object/script_language.h" |
| 34 |
#include "editor/debugger/editor_debugger_server.h" |
| 35 |
#include "editor/docks/editor_dock.h" |
| 36 |
|
| 37 |
class Button; |
| 38 |
class DebugAdapterParser; |
| 39 |
class EditorDebuggerPlugin; |
| 40 |
class EditorDebuggerTree; |
| 41 |
class EditorDebuggerRemoteObjects; |
| 42 |
class MenuButton; |
| 43 |
class ScriptEditorDebugger; |
| 44 |
class TabContainer; |
| 45 |
class UndoRedo; |
| 46 |
|
| 47 |
class EditorDebuggerNode : public EditorDock { |
| 48 |
GDCLASS(EditorDebuggerNode, EditorDock); |
| 49 |
|
| 50 |
public: |
| 51 |
enum CameraOverride { |
| 52 |
OVERRIDE_NONE, |
| 53 |
OVERRIDE_INGAME, |
| 54 |
OVERRIDE_EDITORS, |
| 55 |
}; |
| 56 |
|
| 57 |
private: |
| 58 |
enum Options { |
| 59 |
DEBUG_NEXT, |
| 60 |
DEBUG_STEP, |
| 61 |
DEBUG_BREAK, |
| 62 |
DEBUG_CONTINUE, |
| 63 |
DEBUG_WITH_EXTERNAL_EDITOR, |
| 64 |
}; |
| 65 |
|
| 66 |
class Breakpoint { |
| 67 |
public: |
| 68 |
String source; |
| 69 |
int line = 0; |
| 70 |
|
| 71 |
static uint32_t hash(const Breakpoint &p_val) { |
| 72 |
uint32_t h = HashMapHasherDefault::hash(p_val.source); |
| 73 |
return hash_murmur3_one_32(p_val.line, h); |
| 74 |
} |
| 75 |
bool operator==(const Breakpoint &p_b) const { |
| 76 |
return (line == p_b.line && source == p_b.source); |
| 77 |
} |
| 78 |
|
| 79 |
bool operator<(const Breakpoint &p_b) const { |
| 80 |
if (line == p_b.line) { |
| 81 |
return source < p_b.source; |
| 82 |
} |
| 83 |
return line < p_b.line; |
| 84 |
} |
| 85 |
|
| 86 |
Breakpoint() {} |
| 87 |
|
| 88 |
Breakpoint(const String &p_source, int p_line) { |
| 89 |
line = p_line; |
| 90 |
source = p_source; |
| 91 |
} |
| 92 |
}; |
| 93 |
|
| 94 |
Ref<EditorDebuggerServer> server; |
| 95 |
TabContainer *tabs = nullptr; |
| 96 |
MenuButton *script_menu = nullptr; |
| 97 |
|
| 98 |
Ref<Script> stack_script; |
| 99 |
|
| 100 |
bool initializing = true; |
| 101 |
int last_error_count = 0; |
| 102 |
int last_warning_count = 0; |
| 103 |
|
| 104 |
bool inspect_edited_object_wait = false; |
| 105 |
float inspect_edited_object_timeout = 0; |
| 106 |
EditorDebuggerTree *remote_scene_tree = nullptr; |
| 107 |
bool remote_scene_tree_wait = false; |
| 108 |
float remote_scene_tree_timeout = 0.0; |
| 109 |
bool remote_scene_tree_clear_msg = true; |
| 110 |
bool auto_switch_remote_scene_tree = false; |
| 111 |
bool debug_with_external_editor = false; |
| 112 |
bool keep_open = false; |
| 113 |
String current_uri; |
| 114 |
|
| 115 |
bool debug_mute_audio = false; |
| 116 |
|
| 117 |
CameraOverride camera_override = OVERRIDE_NONE; |
| 118 |
HashMap<Breakpoint, bool, Breakpoint> breakpoints; |
| 119 |
|
| 120 |
HashSet<Ref<EditorDebuggerPlugin>> debugger_plugins; |
| 121 |
|
| 122 |
ScriptEditorDebugger *_add_debugger(); |
| 123 |
void _update_errors(); |
| 124 |
void _update_margins(); |
| 125 |
|
| 126 |
friend class DebuggerEditorPlugin; |
| 127 |
friend class DebugAdapterParser; |
| 128 |
static EditorDebuggerNode *singleton; |
| 129 |
EditorDebuggerNode(); |
| 130 |
|
| 131 |
protected: |
| 132 |
void _debugger_stopped(int p_id); |
| 133 |
void _debugger_wants_stop(int p_id); |
| 134 |
void _debugger_changed(int p_tab); |
| 135 |
void _debug_data(const String &p_msg, const Array &p_data, int p_debugger); |
| 136 |
void _remote_tree_select_requested(const TypedArray<int64_t> &p_ids, int p_debugger); |
| 137 |
void _remote_tree_clear_selection_requested(int p_debugger); |
| 138 |
void _remote_tree_updated(int p_debugger); |
| 139 |
void _remote_tree_button_pressed(Object *p_item, int p_column, int p_id, MouseButton p_button); |
| 140 |
void _remote_objects_updated(EditorDebuggerRemoteObjects *p_objs, int p_debugger); |
| 141 |
void _remote_object_property_updated(ObjectID p_id, const String &p_property, int p_debugger); |
| 142 |
void _remote_objects_requested(const TypedArray<uint64_t> &p_ids, int p_debugger); |
| 143 |
void _remote_selection_cleared(int p_debugger); |
| 144 |
void _save_node_requested(ObjectID p_id, const String &p_file, int p_debugger); |
| 145 |
|
| 146 |
void _breakpoint_set_in_tree(Ref<RefCounted> p_script, int p_line, bool p_enabled, int p_debugger); |
| 147 |
void _breakpoints_cleared_in_tree(int p_debugger); |
| 148 |
|
| 149 |
void _clear_execution(Ref<RefCounted> p_script) { |
| 150 |
emit_signal(SNAME("clear_execution"), p_script); |
| 151 |
} |
| 152 |
|
| 153 |
void _text_editor_stack_goto(const ScriptEditorDebugger *p_debugger); |
| 154 |
void _text_editor_stack_clear(const ScriptEditorDebugger *p_debugger); |
| 155 |
void _stack_frame_selected(int p_debugger); |
| 156 |
void _error_selected(const String &p_file, int p_line, int p_debugger); |
| 157 |
void _breaked(bool p_breaked, bool p_can_debug, const String &p_message, bool p_has_stackdump, int p_debugger); |
| 158 |
void _paused(); |
| 159 |
void _break_state_changed(); |
| 160 |
void _menu_option(int p_id); |
| 161 |
void _update_debug_options(); |
| 162 |
|
| 163 |
protected: |
| 164 |
void _notification(int p_what); |
| 165 |
static void _bind_methods(); |
| 166 |
|
| 167 |
public: |
| 168 |
static EditorDebuggerNode *get_singleton() { return singleton; } |
| 169 |
void register_undo_redo(UndoRedo *p_undo_redo); |
| 170 |
|
| 171 |
ScriptEditorDebugger *get_previous_debugger() const; |
| 172 |
ScriptEditorDebugger *get_current_debugger() const; |
| 173 |
ScriptEditorDebugger *get_default_debugger() const; |
| 174 |
ScriptEditorDebugger *get_debugger(int p_debugger) const; |
| 175 |
|
| 176 |
void debug_next(); |
| 177 |
void debug_step(); |
| 178 |
void debug_break(); |
| 179 |
void debug_continue(); |
| 180 |
|
| 181 |
void set_script_debug_button(MenuButton *p_button); |
| 182 |
|
| 183 |
String get_var_value(const String &p_var) const; |
| 184 |
Ref<Script> get_dump_stack_script() const { return stack_script; } |
| 185 |
|
| 186 |
bool get_debug_with_external_editor() { return debug_with_external_editor; } |
| 187 |
|
| 188 |
bool is_skip_breakpoints() const; |
| 189 |
bool is_ignore_error_breaks() const; |
| 190 |
void set_breakpoint(const String &p_path, int p_line, bool p_enabled); |
| 191 |
void set_breakpoints(const String &p_path, const Array &p_lines); |
| 192 |
void reload_all_scripts(); |
| 193 |
void reload_scripts(const Vector<String> &p_script_paths); |
| 194 |
|
| 195 |
|
| 196 |
void request_remote_tree(); |
| 197 |
void set_remote_selection(const TypedArray<int64_t> &p_ids); |
| 198 |
void clear_remote_tree_selection(); |
| 199 |
void stop_waiting_inspection(); |
| 200 |
bool match_remote_selection(const TypedArray<uint64_t> &p_ids) const; |
| 201 |
static void _methods_changed(void *p_ud, Object *p_base, const StringName &p_name, const Variant **p_args, int p_argcount); |
| 202 |
static void _properties_changed(void *p_ud, Object *p_base, const StringName &p_property, const Variant &p_value); |
| 203 |
|
| 204 |
|
| 205 |
void set_live_debugging(bool p_enabled); |
| 206 |
void update_live_edit_root(); |
| 207 |
void live_debug_create_node(const NodePath &p_parent, const String &p_type, const String &p_name); |
| 208 |
void live_debug_instantiate_node(const NodePath &p_parent, const String &p_path, const String &p_name); |
| 209 |
void live_debug_remove_node(const NodePath &p_at); |
| 210 |
void live_debug_remove_and_keep_node(const NodePath &p_at, ObjectID p_keep_id); |
| 211 |
void live_debug_restore_node(ObjectID p_id, const NodePath &p_at, int p_at_pos); |
| 212 |
void live_debug_duplicate_node(const NodePath &p_at, const String &p_new_name); |
| 213 |
void live_debug_reparent_node(const NodePath &p_at, const NodePath &p_new_place, const String &p_new_name, int p_at_pos); |
| 214 |
|
| 215 |
void set_debug_mute_audio(bool p_mute); |
| 216 |
bool get_debug_mute_audio() const; |
| 217 |
|
| 218 |
void set_camera_override(CameraOverride p_override); |
| 219 |
CameraOverride get_camera_override(); |
| 220 |
|
| 221 |
String get_server_uri() const; |
| 222 |
|
| 223 |
void set_keep_open(bool p_keep_open); |
| 224 |
Error start(const String &p_uri = "tcp://"); |
| 225 |
void stop(bool p_force = false); |
| 226 |
|
| 227 |
bool plugins_capture(ScriptEditorDebugger *p_debugger, const String &p_message, const Array &p_data); |
| 228 |
void add_debugger_plugin(const Ref<EditorDebuggerPlugin> &p_plugin); |
| 229 |
void remove_debugger_plugin(const Ref<EditorDebuggerPlugin> &p_plugin); |
| 230 |
}; |