| 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 "core/os/os.h" |
| 35 |
#include "editor/debugger/editor_debugger_inspector.h" |
| 36 |
#include "editor/debugger/editor_debugger_node.h" |
| 37 |
#include "scene/gui/margin_container.h" |
| 38 |
|
| 39 |
class Button; |
| 40 |
class Tree; |
| 41 |
class LineEdit; |
| 42 |
class TabContainer; |
| 43 |
class RichTextLabel; |
| 44 |
class TextureButton; |
| 45 |
class AcceptDialog; |
| 46 |
class TreeItem; |
| 47 |
class HSplitContainer; |
| 48 |
class ItemList; |
| 49 |
class EditorProfiler; |
| 50 |
class EditorFileDialog; |
| 51 |
class EditorVisualProfiler; |
| 52 |
class EditorPerformanceProfiler; |
| 53 |
class SceneDebuggerTree; |
| 54 |
class EditorDebuggerPlugin; |
| 55 |
class DebugAdapterProtocol; |
| 56 |
class DebugAdapterParser; |
| 57 |
class EditorExpressionEvaluator; |
| 58 |
|
| 59 |
class ScriptEditorDebugger : public MarginContainer { |
| 60 |
GDCLASS(ScriptEditorDebugger, MarginContainer); |
| 61 |
|
| 62 |
friend class EditorDebuggerNode; |
| 63 |
friend class DebugAdapterProtocol; |
| 64 |
friend class DebugAdapterParser; |
| 65 |
|
| 66 |
private: |
| 67 |
enum MessageType { |
| 68 |
MESSAGE_ERROR, |
| 69 |
MESSAGE_WARNING, |
| 70 |
MESSAGE_SUCCESS, |
| 71 |
}; |
| 72 |
|
| 73 |
enum ProfilerType { |
| 74 |
PROFILER_VISUAL, |
| 75 |
PROFILER_SCRIPTS_SERVERS |
| 76 |
}; |
| 77 |
|
| 78 |
enum Actions { |
| 79 |
ACTION_COPY_ERROR, |
| 80 |
ACTION_OPEN_SOURCE, |
| 81 |
ACTION_DELETE_BREAKPOINT, |
| 82 |
ACTION_DELETE_BREAKPOINTS_IN_FILE, |
| 83 |
ACTION_DELETE_ALL_BREAKPOINTS, |
| 84 |
}; |
| 85 |
|
| 86 |
AcceptDialog *msgdialog = nullptr; |
| 87 |
|
| 88 |
LineEdit *clicked_ctrl = nullptr; |
| 89 |
LineEdit *clicked_ctrl_type = nullptr; |
| 90 |
LineEdit *live_edit_root = nullptr; |
| 91 |
Button *le_set = nullptr; |
| 92 |
Button *le_clear = nullptr; |
| 93 |
Button *export_csv = nullptr; |
| 94 |
|
| 95 |
VBoxContainer *errors_tab = nullptr; |
| 96 |
Tree *error_tree = nullptr; |
| 97 |
Button *expand_all_button = nullptr; |
| 98 |
Button *collapse_all_button = nullptr; |
| 99 |
Button *clear_button = nullptr; |
| 100 |
PopupMenu *item_menu = nullptr; |
| 101 |
|
| 102 |
Tree *breakpoints_tree = nullptr; |
| 103 |
PopupMenu *breakpoints_menu = nullptr; |
| 104 |
|
| 105 |
EditorFileDialog *file_dialog = nullptr; |
| 106 |
enum FileDialogPurpose { |
| 107 |
SAVE_MONITORS_CSV, |
| 108 |
SAVE_VRAM_CSV, |
| 109 |
}; |
| 110 |
FileDialogPurpose file_dialog_purpose = SAVE_MONITORS_CSV; |
| 111 |
|
| 112 |
int error_count; |
| 113 |
int warning_count; |
| 114 |
|
| 115 |
bool skip_breakpoints_value = false; |
| 116 |
bool ignore_error_breaks_value = false; |
| 117 |
Ref<Script> stack_script; |
| 118 |
|
| 119 |
TabContainer *tabs = nullptr; |
| 120 |
|
| 121 |
RichTextLabel *reason = nullptr; |
| 122 |
|
| 123 |
Button *skip_breakpoints = nullptr; |
| 124 |
Button *ignore_error_breaks = nullptr; |
| 125 |
Button *copy = nullptr; |
| 126 |
Button *step = nullptr; |
| 127 |
Button *next = nullptr; |
| 128 |
Button *out = nullptr; |
| 129 |
Button *dobreak = nullptr; |
| 130 |
Button *docontinue = nullptr; |
| 131 |
|
| 132 |
|
| 133 |
const Tree *editor_remote_tree = nullptr; |
| 134 |
|
| 135 |
HashMap<int, String> profiler_signature; |
| 136 |
|
| 137 |
Tree *vmem_tree = nullptr; |
| 138 |
Button *vmem_refresh = nullptr; |
| 139 |
Button *vmem_export = nullptr; |
| 140 |
LineEdit *vmem_total = nullptr; |
| 141 |
TextureRect *vmem_notice_icon = nullptr; |
| 142 |
|
| 143 |
Tree *stack_dump = nullptr; |
| 144 |
LineEdit *search = nullptr; |
| 145 |
OptionButton *threads = nullptr; |
| 146 |
EditorDebuggerInspector *inspector = nullptr; |
| 147 |
SceneDebuggerTree *scene_tree = nullptr; |
| 148 |
|
| 149 |
Ref<RemoteDebuggerPeer> peer; |
| 150 |
|
| 151 |
HashMap<NodePath, int> node_path_cache; |
| 152 |
int last_path_id = 0; |
| 153 |
HashMap<String, int> res_path_cache; |
| 154 |
|
| 155 |
EditorProfiler *profiler = nullptr; |
| 156 |
EditorVisualProfiler *visual_profiler = nullptr; |
| 157 |
EditorPerformanceProfiler *performance_profiler = nullptr; |
| 158 |
EditorExpressionEvaluator *expression_evaluator = nullptr; |
| 159 |
|
| 160 |
OS::ProcessID remote_pid = 0; |
| 161 |
bool move_to_foreground = true; |
| 162 |
bool can_request_idle_draw = false; |
| 163 |
|
| 164 |
bool live_debug = true; |
| 165 |
|
| 166 |
uint64_t debugging_thread_id = Thread::UNASSIGNED_ID; |
| 167 |
|
| 168 |
struct ThreadDebugged { |
| 169 |
String name; |
| 170 |
String error; |
| 171 |
bool can_debug = false; |
| 172 |
bool has_stackdump = false; |
| 173 |
uint32_t debug_order = 0; |
| 174 |
uint64_t thread_id = Thread::UNASSIGNED_ID; |
| 175 |
}; |
| 176 |
|
| 177 |
struct ThreadSort { |
| 178 |
bool operator()(const ThreadDebugged *a, const ThreadDebugged *b) const { |
| 179 |
return a->debug_order < b->debug_order; |
| 180 |
} |
| 181 |
}; |
| 182 |
|
| 183 |
HashMap<uint64_t, ThreadDebugged> threads_debugged; |
| 184 |
bool thread_list_updating = false; |
| 185 |
|
| 186 |
void _select_thread(int p_index); |
| 187 |
|
| 188 |
bool debug_mute_audio = false; |
| 189 |
bool audio_muted_on_break = false; |
| 190 |
void _mute_audio_on_break(bool p_mute); |
| 191 |
void _send_debug_mute_audio_msg(bool p_mute); |
| 192 |
|
| 193 |
EditorDebuggerNode::CameraOverride camera_override; |
| 194 |
|
| 195 |
void _stack_dump_frame_selected(); |
| 196 |
|
| 197 |
void _file_selected(const String &p_file); |
| 198 |
|
| 199 |
|
| 200 |
typedef void (ScriptEditorDebugger::*ParseMessageFunc)(uint64_t p_thread_id, const Array &p_data); |
| 201 |
static HashMap<String, ParseMessageFunc> parse_message_handlers; |
| 202 |
static void _init_parse_message_handlers(); |
| 203 |
|
| 204 |
void _msg_debug_enter(uint64_t p_thread_id, const Array &p_data); |
| 205 |
void _msg_debug_exit(uint64_t p_thread_id, const Array &p_data); |
| 206 |
void _msg_set_pid(uint64_t p_thread_id, const Array &p_data); |
| 207 |
void _msg_scene_click_ctrl(uint64_t p_thread_id, const Array &p_data); |
| 208 |
void _msg_scene_scene_tree(uint64_t p_thread_id, const Array &p_data); |
| 209 |
void _msg_scene_inspect_objects(uint64_t p_thread_id, const Array &p_data); |
| 210 |
#ifndef DISABLE_DEPRECATED |
| 211 |
void _msg_scene_inspect_object(uint64_t p_thread_id, const Array &p_data); |
| 212 |
#endif |
| 213 |
void _msg_scene_debug_mute_audio(uint64_t p_thread_id, const Array &p_data); |
| 214 |
void _msg_servers_memory_usage(uint64_t p_thread_id, const Array &p_data); |
| 215 |
void _msg_servers_drawn(uint64_t p_thread_id, const Array &p_data); |
| 216 |
void _msg_stack_dump(uint64_t p_thread_id, const Array &p_data); |
| 217 |
void _msg_stack_frame_vars(uint64_t p_thread_id, const Array &p_data); |
| 218 |
void _msg_stack_frame_var(uint64_t p_thread_id, const Array &p_data); |
| 219 |
void _msg_output(uint64_t p_thread_id, const Array &p_data); |
| 220 |
void _msg_performance_profile_frame(uint64_t p_thread_id, const Array &p_data); |
| 221 |
void _msg_visual_hardware_info(uint64_t p_thread_id, const Array &p_data); |
| 222 |
void _msg_visual_profile_frame(uint64_t p_thread_id, const Array &p_data); |
| 223 |
void _msg_error(uint64_t p_thread_id, const Array &p_data); |
| 224 |
void _msg_servers_function_signature(uint64_t p_thread_id, const Array &p_data); |
| 225 |
void _msg_servers_profile_common(const Array &p_data, const bool p_final); |
| 226 |
void _msg_servers_profile_frame(uint64_t p_thread_id, const Array &p_data); |
| 227 |
void _msg_servers_profile_total(uint64_t p_thread_id, const Array &p_data); |
| 228 |
void _msg_request_quit(uint64_t p_thread_id, const Array &p_data); |
| 229 |
void _msg_remote_objects_selected(uint64_t p_thread_id, const Array &p_data); |
| 230 |
void _msg_remote_nothing_selected(uint64_t p_thread_id, const Array &p_data); |
| 231 |
void _msg_remote_selection_invalidated(uint64_t p_thread_id, const Array &p_data); |
| 232 |
void _msg_show_selection_limit_warning(uint64_t p_thread_id, const Array &p_data); |
| 233 |
void _msg_performance_profile_names(uint64_t p_thread_id, const Array &p_data); |
| 234 |
void _msg_filesystem_update_file(uint64_t p_thread_id, const Array &p_data); |
| 235 |
void _msg_evaluation_return(uint64_t p_thread_id, const Array &p_data); |
| 236 |
void _msg_window_title(uint64_t p_thread_id, const Array &p_data); |
| 237 |
void _msg_embed_suspend_toggle(uint64_t p_thread_id, const Array &p_data); |
| 238 |
void _msg_embed_next_frame(uint64_t p_thread_id, const Array &p_data); |
| 239 |
|
| 240 |
void _parse_message(const String &p_msg, uint64_t p_thread_id, const Array &p_data); |
| 241 |
void _set_reason_text(const String &p_reason, MessageType p_type); |
| 242 |
void _update_reason_content_height(); |
| 243 |
void _update_buttons_state(); |
| 244 |
void _remote_object_selected(ObjectID p_object); |
| 245 |
void _remote_objects_edited(const String &p_prop, const TypedDictionary<uint64_t, Variant> &p_values, const String &p_field); |
| 246 |
void _remote_object_property_updated(ObjectID p_id, const String &p_property); |
| 247 |
|
| 248 |
void _video_mem_request(); |
| 249 |
void _video_mem_export(); |
| 250 |
|
| 251 |
void _resources_reimported(const PackedStringArray &p_resources); |
| 252 |
|
| 253 |
int _get_node_path_cache(const NodePath &p_path); |
| 254 |
|
| 255 |
int _get_res_path_cache(const String &p_path); |
| 256 |
|
| 257 |
void _live_edit_set(); |
| 258 |
void _live_edit_clear(); |
| 259 |
|
| 260 |
void _method_changed(Object *p_base, const StringName &p_name, const Variant **p_args, int p_argcount); |
| 261 |
void _property_changed(Object *p_base, const StringName &p_property, const Variant &p_value); |
| 262 |
|
| 263 |
void _error_activated(); |
| 264 |
void _error_selected(); |
| 265 |
|
| 266 |
void _expand_errors_list(); |
| 267 |
void _collapse_errors_list(); |
| 268 |
|
| 269 |
void _vmem_item_activated(); |
| 270 |
|
| 271 |
void _profiler_activate(bool p_enable, int p_profiler); |
| 272 |
void _profiler_seeked(); |
| 273 |
|
| 274 |
void _clear_errors_list(); |
| 275 |
|
| 276 |
void _breakpoints_item_rmb_selected(const Vector2 &p_pos, MouseButton p_button); |
| 277 |
void _error_tree_item_rmb_selected(const Vector2 &p_pos, MouseButton p_button); |
| 278 |
void _item_menu_id_pressed(int p_option); |
| 279 |
void _tab_changed(int p_tab); |
| 280 |
|
| 281 |
void _put_msg(const String &p_message, const Array &p_data, uint64_t p_thread_id = Thread::MAIN_ID); |
| 282 |
void _export_csv(); |
| 283 |
|
| 284 |
void _clear_execution(); |
| 285 |
void _stop_and_notify(); |
| 286 |
|
| 287 |
void _set_breakpoint(const String &p_path, const int &p_line, const bool &p_enabled); |
| 288 |
void _clear_breakpoints(); |
| 289 |
|
| 290 |
void _breakpoint_tree_clicked(); |
| 291 |
|
| 292 |
String _format_frame_text(const ScriptLanguage::StackInfo *info); |
| 293 |
|
| 294 |
void _thread_debug_enter(uint64_t p_thread_id); |
| 295 |
|
| 296 |
protected: |
| 297 |
void _notification(int p_what); |
| 298 |
static void _bind_methods(); |
| 299 |
|
| 300 |
public: |
| 301 |
enum EmbedShortcutAction { |
| 302 |
EMBED_SUSPEND_TOGGLE, |
| 303 |
EMBED_NEXT_FRAME, |
| 304 |
}; |
| 305 |
|
| 306 |
void request_remote_objects(const TypedArray<uint64_t> &p_obj_ids, bool p_update_selection = true); |
| 307 |
void update_remote_object(ObjectID p_obj_id, const String &p_prop, const Variant &p_value, const String &p_field = ""); |
| 308 |
|
| 309 |
void clear_inspector(bool p_send_msg = true); |
| 310 |
|
| 311 |
|
| 312 |
void set_editor_remote_tree(const Tree *p_tree) { editor_remote_tree = p_tree; } |
| 313 |
|
| 314 |
void request_remote_tree(); |
| 315 |
const SceneDebuggerTree *get_remote_tree(); |
| 316 |
|
| 317 |
void request_remote_evaluate(const String &p_expression, int p_stack_frame); |
| 318 |
|
| 319 |
void start(Ref<RemoteDebuggerPeer> p_peer); |
| 320 |
void stop(); |
| 321 |
|
| 322 |
void debug_skip_breakpoints(); |
| 323 |
void debug_ignore_error_breaks(); |
| 324 |
void debug_copy(); |
| 325 |
|
| 326 |
void debug_out(); |
| 327 |
void debug_next(); |
| 328 |
void debug_step(); |
| 329 |
void debug_break(); |
| 330 |
void debug_continue(); |
| 331 |
bool is_breaked() const { return threads_debugged.size() > 0; } |
| 332 |
bool is_debuggable() const { return threads_debugged.size() > 0 && threads_debugged[debugging_thread_id].can_debug; } |
| 333 |
bool is_session_active() { return peer.is_valid() && peer->is_peer_connected(); } |
| 334 |
int get_remote_pid() const { return remote_pid; } |
| 335 |
|
| 336 |
bool is_move_to_foreground() const; |
| 337 |
void set_move_to_foreground(const bool &p_move_to_foreground); |
| 338 |
|
| 339 |
int get_error_count() const { return error_count; } |
| 340 |
int get_warning_count() const { return warning_count; } |
| 341 |
String get_stack_script_file() const; |
| 342 |
int get_stack_script_line() const; |
| 343 |
int get_stack_script_frame() const; |
| 344 |
|
| 345 |
bool request_stack_dump(const int &p_frame); |
| 346 |
|
| 347 |
void update_tabs(); |
| 348 |
void clear_style(); |
| 349 |
String get_var_value(const String &p_var) const; |
| 350 |
|
| 351 |
void save_node(ObjectID p_id, const String &p_file); |
| 352 |
void set_live_debugging(bool p_enable); |
| 353 |
|
| 354 |
void live_debug_create_node(const NodePath &p_parent, const String &p_type, const String &p_name); |
| 355 |
void live_debug_instantiate_node(const NodePath &p_parent, const String &p_path, const String &p_name); |
| 356 |
void live_debug_remove_node(const NodePath &p_at); |
| 357 |
void live_debug_remove_and_keep_node(const NodePath &p_at, ObjectID p_keep_id); |
| 358 |
void live_debug_restore_node(ObjectID p_id, const NodePath &p_at, int p_at_pos); |
| 359 |
void live_debug_duplicate_node(const NodePath &p_at, const String &p_new_name); |
| 360 |
void live_debug_reparent_node(const NodePath &p_at, const NodePath &p_new_place, const String &p_new_name, int p_at_pos); |
| 361 |
|
| 362 |
bool get_debug_mute_audio() const; |
| 363 |
void set_debug_mute_audio(bool p_mute); |
| 364 |
|
| 365 |
EditorDebuggerNode::CameraOverride get_camera_override() const; |
| 366 |
void set_camera_override(EditorDebuggerNode::CameraOverride p_override); |
| 367 |
|
| 368 |
void set_breakpoint(const String &p_path, int p_line, bool p_enabled); |
| 369 |
|
| 370 |
void update_live_edit_root(); |
| 371 |
|
| 372 |
void reload_all_scripts(); |
| 373 |
void reload_scripts(const Vector<String> &p_script_paths); |
| 374 |
|
| 375 |
bool is_skip_breakpoints() const; |
| 376 |
bool is_ignore_error_breaks() const; |
| 377 |
|
| 378 |
virtual Size2 get_minimum_size() const override; |
| 379 |
|
| 380 |
void add_debugger_tab(Control *p_control); |
| 381 |
void remove_debugger_tab(Control *p_control); |
| 382 |
int get_current_debugger_tab() const; |
| 383 |
void switch_to_debugger(int p_debugger_tab_idx); |
| 384 |
|
| 385 |
void send_message(const String &p_message, const Array &p_args); |
| 386 |
void toggle_profiler(const String &p_profiler, bool p_enable, const Array &p_data); |
| 387 |
|
| 388 |
ScriptEditorDebugger(); |
| 389 |
~ScriptEditorDebugger(); |
| 390 |
}; |