editor_debugger_node.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /*************************************************************************/
  2. /* editor_debugger_node.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
  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. #ifndef EDITOR_DEBUGGER_NODE_H
  31. #define EDITOR_DEBUGGER_NODE_H
  32. #include "editor/debugger/editor_debugger_server.h"
  33. #include "scene/gui/margin_container.h"
  34. class Button;
  35. class DebugAdapterParser;
  36. class EditorDebuggerTree;
  37. class EditorDebuggerRemoteObject;
  38. class MenuButton;
  39. class ScriptEditorDebugger;
  40. class TabContainer;
  41. class EditorDebuggerNode : public MarginContainer {
  42. GDCLASS(EditorDebuggerNode, MarginContainer);
  43. public:
  44. enum CameraOverride {
  45. OVERRIDE_NONE,
  46. OVERRIDE_2D,
  47. OVERRIDE_3D_1, // 3D Viewport 1
  48. OVERRIDE_3D_2, // 3D Viewport 2
  49. OVERRIDE_3D_3, // 3D Viewport 3
  50. OVERRIDE_3D_4 // 3D Viewport 4
  51. };
  52. private:
  53. enum Options {
  54. DEBUG_NEXT,
  55. DEBUG_STEP,
  56. DEBUG_BREAK,
  57. DEBUG_CONTINUE,
  58. DEBUG_KEEP_DEBUGGER_OPEN,
  59. DEBUG_WITH_EXTERNAL_EDITOR,
  60. };
  61. class Breakpoint {
  62. public:
  63. String source;
  64. int line = 0;
  65. bool operator<(const Breakpoint &p_b) const {
  66. if (line == p_b.line) {
  67. return source < p_b.source;
  68. }
  69. return line < p_b.line;
  70. }
  71. Breakpoint() {}
  72. Breakpoint(const String &p_source, int p_line) {
  73. line = p_line;
  74. source = p_source;
  75. }
  76. };
  77. Ref<EditorDebuggerServer> server;
  78. TabContainer *tabs = nullptr;
  79. Button *debugger_button = nullptr;
  80. MenuButton *script_menu = nullptr;
  81. Ref<Script> stack_script; // Why?!?
  82. int last_error_count = 0;
  83. int last_warning_count = 0;
  84. float inspect_edited_object_timeout = 0;
  85. EditorDebuggerTree *remote_scene_tree = nullptr;
  86. float remote_scene_tree_timeout = 0.0;
  87. bool auto_switch_remote_scene_tree = false;
  88. bool debug_with_external_editor = false;
  89. bool hide_on_stop = true;
  90. CameraOverride camera_override = OVERRIDE_NONE;
  91. Map<Breakpoint, bool> breakpoints;
  92. Set<Ref<Script>> debugger_plugins;
  93. ScriptEditorDebugger *_add_debugger();
  94. EditorDebuggerRemoteObject *get_inspected_remote_object();
  95. friend class DebuggerEditorPlugin;
  96. friend class DebugAdapterParser;
  97. static EditorDebuggerNode *singleton;
  98. EditorDebuggerNode();
  99. protected:
  100. void _debugger_stopped(int p_id);
  101. void _debugger_wants_stop(int p_id);
  102. void _debugger_changed(int p_tab);
  103. void _remote_tree_updated(int p_debugger);
  104. void _remote_object_updated(ObjectID p_id, int p_debugger);
  105. void _remote_object_property_updated(ObjectID p_id, const String &p_property, int p_debugger);
  106. void _remote_object_requested(ObjectID p_id, int p_debugger);
  107. void _save_node_requested(ObjectID p_id, const String &p_file, int p_debugger);
  108. void _clear_execution(Ref<RefCounted> p_script) {
  109. emit_signal(SNAME("clear_execution"), p_script);
  110. }
  111. void _text_editor_stack_goto(const ScriptEditorDebugger *p_debugger);
  112. void _stack_frame_selected(int p_debugger);
  113. void _error_selected(const String &p_file, int p_line, int p_debugger);
  114. void _breaked(bool p_breaked, bool p_can_debug, String p_message, bool p_has_stackdump, int p_debugger);
  115. void _paused();
  116. void _break_state_changed();
  117. void _menu_option(int p_id);
  118. void _update_debug_options();
  119. protected:
  120. void _notification(int p_what);
  121. static void _bind_methods();
  122. public:
  123. static EditorDebuggerNode *get_singleton() { return singleton; }
  124. ScriptEditorDebugger *get_current_debugger() const;
  125. ScriptEditorDebugger *get_default_debugger() const;
  126. ScriptEditorDebugger *get_debugger(int p_debugger) const;
  127. void debug_next();
  128. void debug_step();
  129. void debug_break();
  130. void debug_continue();
  131. void set_script_debug_button(MenuButton *p_button);
  132. void set_tool_button(Button *p_button) {
  133. debugger_button = p_button;
  134. }
  135. String get_var_value(const String &p_var) const;
  136. Ref<Script> get_dump_stack_script() const { return stack_script; } // Why do we need this?
  137. bool get_debug_with_external_editor() { return debug_with_external_editor; }
  138. bool is_skip_breakpoints() const;
  139. void set_breakpoint(const String &p_path, int p_line, bool p_enabled);
  140. void set_breakpoints(const String &p_path, Array p_lines);
  141. void reload_scripts();
  142. // Remote inspector/edit.
  143. void request_remote_tree();
  144. static void _method_changeds(void *p_ud, Object *p_base, const StringName &p_name, const Variant **p_args, int p_argcount);
  145. static void _property_changeds(void *p_ud, Object *p_base, const StringName &p_property, const Variant &p_value);
  146. // LiveDebug
  147. void set_live_debugging(bool p_enabled);
  148. void update_live_edit_root();
  149. void live_debug_create_node(const NodePath &p_parent, const String &p_type, const String &p_name);
  150. void live_debug_instance_node(const NodePath &p_parent, const String &p_path, const String &p_name);
  151. void live_debug_remove_node(const NodePath &p_at);
  152. void live_debug_remove_and_keep_node(const NodePath &p_at, ObjectID p_keep_id);
  153. void live_debug_restore_node(ObjectID p_id, const NodePath &p_at, int p_at_pos);
  154. void live_debug_duplicate_node(const NodePath &p_at, const String &p_new_name);
  155. void live_debug_reparent_node(const NodePath &p_at, const NodePath &p_new_place, const String &p_new_name, int p_at_pos);
  156. void set_camera_override(CameraOverride p_override);
  157. CameraOverride get_camera_override();
  158. String get_server_uri() const;
  159. Error start(const String &p_uri = "tcp://");
  160. void stop();
  161. void add_debugger_plugin(const Ref<Script> &p_script);
  162. void remove_debugger_plugin(const Ref<Script> &p_script);
  163. };
  164. #endif // EDITOR_DEBUGGER_NODE_H