editor_debugger_node.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. /**************************************************************************/
  2. /* editor_debugger_node.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #pragma once
  31. #include "core/object/script_language.h"
  32. #include "editor/debugger/editor_debugger_server.h"
  33. #include "scene/gui/margin_container.h"
  34. class Button;
  35. class DebugAdapterParser;
  36. class EditorDebuggerPlugin;
  37. class EditorDebuggerTree;
  38. class EditorDebuggerRemoteObjects;
  39. class MenuButton;
  40. class ScriptEditorDebugger;
  41. class TabContainer;
  42. class UndoRedo;
  43. class EditorDebuggerNode : public MarginContainer {
  44. GDCLASS(EditorDebuggerNode, MarginContainer);
  45. public:
  46. enum CameraOverride {
  47. OVERRIDE_NONE,
  48. OVERRIDE_INGAME,
  49. OVERRIDE_EDITORS,
  50. };
  51. private:
  52. enum Options {
  53. DEBUG_NEXT,
  54. DEBUG_STEP,
  55. DEBUG_BREAK,
  56. DEBUG_CONTINUE,
  57. DEBUG_WITH_EXTERNAL_EDITOR,
  58. };
  59. class Breakpoint {
  60. public:
  61. String source;
  62. int line = 0;
  63. static uint32_t hash(const Breakpoint &p_val) {
  64. uint32_t h = HashMapHasherDefault::hash(p_val.source);
  65. return hash_murmur3_one_32(p_val.line, h);
  66. }
  67. bool operator==(const Breakpoint &p_b) const {
  68. return (line == p_b.line && source == p_b.source);
  69. }
  70. bool operator<(const Breakpoint &p_b) const {
  71. if (line == p_b.line) {
  72. return source < p_b.source;
  73. }
  74. return line < p_b.line;
  75. }
  76. Breakpoint() {}
  77. Breakpoint(const String &p_source, int p_line) {
  78. line = p_line;
  79. source = p_source;
  80. }
  81. };
  82. Ref<EditorDebuggerServer> server;
  83. TabContainer *tabs = nullptr;
  84. Button *debugger_button = nullptr;
  85. MenuButton *script_menu = nullptr;
  86. Ref<Script> stack_script; // Why?!?
  87. bool initializing = true;
  88. int last_error_count = 0;
  89. int last_warning_count = 0;
  90. bool inspect_edited_object_wait = false;
  91. float inspect_edited_object_timeout = 0;
  92. EditorDebuggerTree *remote_scene_tree = nullptr;
  93. bool remote_scene_tree_wait = false;
  94. float remote_scene_tree_timeout = 0.0;
  95. bool remote_scene_tree_clear_msg = true;
  96. bool auto_switch_remote_scene_tree = false;
  97. bool debug_with_external_editor = false;
  98. bool keep_open = false;
  99. String current_uri;
  100. bool debug_mute_audio = false;
  101. CameraOverride camera_override = OVERRIDE_NONE;
  102. HashMap<Breakpoint, bool, Breakpoint> breakpoints;
  103. HashSet<Ref<EditorDebuggerPlugin>> debugger_plugins;
  104. ScriptEditorDebugger *_add_debugger();
  105. void _update_errors();
  106. friend class DebuggerEditorPlugin;
  107. friend class DebugAdapterParser;
  108. static EditorDebuggerNode *singleton;
  109. EditorDebuggerNode();
  110. protected:
  111. void _debugger_stopped(int p_id);
  112. void _debugger_wants_stop(int p_id);
  113. void _debugger_changed(int p_tab);
  114. void _debug_data(const String &p_msg, const Array &p_data, int p_debugger);
  115. void _remote_tree_select_requested(const TypedArray<int64_t> &p_ids, int p_debugger);
  116. void _remote_tree_clear_selection_requested(int p_debugger);
  117. void _remote_tree_updated(int p_debugger);
  118. void _remote_tree_button_pressed(Object *p_item, int p_column, int p_id, MouseButton p_button);
  119. void _remote_objects_updated(EditorDebuggerRemoteObjects *p_objs, int p_debugger);
  120. void _remote_object_property_updated(ObjectID p_id, const String &p_property, int p_debugger);
  121. void _remote_objects_requested(const TypedArray<uint64_t> &p_ids, int p_debugger);
  122. void _remote_selection_cleared(int p_debugger);
  123. void _save_node_requested(ObjectID p_id, const String &p_file, int p_debugger);
  124. void _breakpoint_set_in_tree(Ref<RefCounted> p_script, int p_line, bool p_enabled, int p_debugger);
  125. void _breakpoints_cleared_in_tree(int p_debugger);
  126. void _clear_execution(Ref<RefCounted> p_script) {
  127. emit_signal(SNAME("clear_execution"), p_script);
  128. }
  129. void _text_editor_stack_goto(const ScriptEditorDebugger *p_debugger);
  130. void _text_editor_stack_clear(const ScriptEditorDebugger *p_debugger);
  131. void _stack_frame_selected(int p_debugger);
  132. void _error_selected(const String &p_file, int p_line, int p_debugger);
  133. void _breaked(bool p_breaked, bool p_can_debug, const String &p_message, bool p_has_stackdump, int p_debugger);
  134. void _paused();
  135. void _break_state_changed();
  136. void _menu_option(int p_id);
  137. void _update_debug_options();
  138. protected:
  139. void _notification(int p_what);
  140. static void _bind_methods();
  141. public:
  142. static EditorDebuggerNode *get_singleton() { return singleton; }
  143. void register_undo_redo(UndoRedo *p_undo_redo);
  144. ScriptEditorDebugger *get_previous_debugger() const;
  145. ScriptEditorDebugger *get_current_debugger() const;
  146. ScriptEditorDebugger *get_default_debugger() const;
  147. ScriptEditorDebugger *get_debugger(int p_debugger) const;
  148. void debug_next();
  149. void debug_step();
  150. void debug_break();
  151. void debug_continue();
  152. void set_script_debug_button(MenuButton *p_button);
  153. void set_tool_button(Button *p_button) {
  154. debugger_button = p_button;
  155. }
  156. String get_var_value(const String &p_var) const;
  157. Ref<Script> get_dump_stack_script() const { return stack_script; } // Why do we need this?
  158. bool get_debug_with_external_editor() { return debug_with_external_editor; }
  159. bool is_skip_breakpoints() const;
  160. bool is_ignore_error_breaks() const;
  161. void set_breakpoint(const String &p_path, int p_line, bool p_enabled);
  162. void set_breakpoints(const String &p_path, const Array &p_lines);
  163. void reload_all_scripts();
  164. void reload_scripts(const Vector<String> &p_script_paths);
  165. // Remote inspector/edit.
  166. void request_remote_tree();
  167. void set_remote_selection(const TypedArray<int64_t> &p_ids);
  168. void clear_remote_tree_selection();
  169. void stop_waiting_inspection();
  170. bool match_remote_selection(const TypedArray<uint64_t> &p_ids) const;
  171. static void _methods_changed(void *p_ud, Object *p_base, const StringName &p_name, const Variant **p_args, int p_argcount);
  172. static void _properties_changed(void *p_ud, Object *p_base, const StringName &p_property, const Variant &p_value);
  173. // LiveDebug
  174. void set_live_debugging(bool p_enabled);
  175. void update_live_edit_root();
  176. void live_debug_create_node(const NodePath &p_parent, const String &p_type, const String &p_name);
  177. void live_debug_instantiate_node(const NodePath &p_parent, const String &p_path, const String &p_name);
  178. void live_debug_remove_node(const NodePath &p_at);
  179. void live_debug_remove_and_keep_node(const NodePath &p_at, ObjectID p_keep_id);
  180. void live_debug_restore_node(ObjectID p_id, const NodePath &p_at, int p_at_pos);
  181. void live_debug_duplicate_node(const NodePath &p_at, const String &p_new_name);
  182. void live_debug_reparent_node(const NodePath &p_at, const NodePath &p_new_place, const String &p_new_name, int p_at_pos);
  183. void set_debug_mute_audio(bool p_mute);
  184. bool get_debug_mute_audio() const;
  185. void set_camera_override(CameraOverride p_override);
  186. CameraOverride get_camera_override();
  187. String get_server_uri() const;
  188. void set_keep_open(bool p_keep_open);
  189. Error start(const String &p_uri = "tcp://");
  190. void stop(bool p_force = false);
  191. bool plugins_capture(ScriptEditorDebugger *p_debugger, const String &p_message, const Array &p_data);
  192. void add_debugger_plugin(const Ref<EditorDebuggerPlugin> &p_plugin);
  193. void remove_debugger_plugin(const Ref<EditorDebuggerPlugin> &p_plugin);
  194. };