script_editor_debugger.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. /**************************************************************************/
  2. /* script_editor_debugger.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. #ifndef SCRIPT_EDITOR_DEBUGGER_H
  31. #define SCRIPT_EDITOR_DEBUGGER_H
  32. #include "core/io/packet_peer.h"
  33. #include "core/io/tcp_server.h"
  34. #include "editor/editor_inspector.h"
  35. #include "editor/property_editor.h"
  36. #include "scene/3d/camera.h"
  37. #include "scene/gui/box_container.h"
  38. #include "scene/gui/button.h"
  39. class Tree;
  40. class EditorNode;
  41. class ScriptEditorDebuggerVariables;
  42. class LineEdit;
  43. class TabContainer;
  44. class RichTextLabel;
  45. class TextureButton;
  46. class AcceptDialog;
  47. class TreeItem;
  48. class HSplitContainer;
  49. class ItemList;
  50. class EditorProfiler;
  51. class EditorNetworkProfiler;
  52. class ScriptEditorDebuggerInspectedObject;
  53. class ScriptEditorDebugger : public MarginContainer {
  54. GDCLASS(ScriptEditorDebugger, MarginContainer);
  55. public:
  56. enum CameraOverride {
  57. OVERRIDE_NONE,
  58. OVERRIDE_2D,
  59. OVERRIDE_3D_1, // 3D Viewport 1
  60. OVERRIDE_3D_2, // 3D Viewport 2
  61. OVERRIDE_3D_3, // 3D Viewport 3
  62. OVERRIDE_3D_4 // 3D Viewport 4
  63. };
  64. private:
  65. enum MessageType {
  66. MESSAGE_ERROR,
  67. MESSAGE_WARNING,
  68. MESSAGE_SUCCESS,
  69. };
  70. enum ItemMenu {
  71. ITEM_MENU_COPY_ERROR,
  72. ITEM_MENU_SAVE_REMOTE_NODE,
  73. ITEM_MENU_COPY_NODE_PATH,
  74. ITEM_MENU_OPEN_SOURCE,
  75. };
  76. AcceptDialog *msgdialog;
  77. Button *debugger_button;
  78. LineEdit *clicked_ctrl;
  79. LineEdit *clicked_ctrl_type;
  80. LineEdit *live_edit_root;
  81. Button *le_set;
  82. Button *le_clear;
  83. Button *export_csv;
  84. bool updating_scene_tree;
  85. float inspect_scene_tree_timeout;
  86. float inspect_edited_object_timeout;
  87. bool auto_switch_remote_scene_tree;
  88. ObjectID inspected_object_id;
  89. String last_filter;
  90. ScriptEditorDebuggerVariables *variables;
  91. Map<ObjectID, ScriptEditorDebuggerInspectedObject *> remote_objects;
  92. Set<RES> remote_dependencies;
  93. Set<ObjectID> unfold_cache;
  94. VBoxContainer *errors_tab;
  95. Tree *error_tree;
  96. Tree *inspect_scene_tree;
  97. Button *clearbutton;
  98. PopupMenu *item_menu;
  99. EditorFileDialog *file_dialog;
  100. enum FileDialogMode {
  101. SAVE_MONITORS_CSV,
  102. SAVE_VRAM_CSV,
  103. SAVE_NODE,
  104. };
  105. FileDialogMode file_dialog_mode;
  106. int error_count;
  107. int warning_count;
  108. int last_error_count;
  109. int last_warning_count;
  110. bool hide_on_stop;
  111. int remote_port;
  112. bool enable_external_editor;
  113. bool skip_breakpoints_value = false;
  114. Ref<Script> stack_script;
  115. TabContainer *tabs;
  116. Label *reason;
  117. Button *skip_breakpoints;
  118. Button *copy;
  119. Button *step;
  120. Button *next;
  121. Button *back;
  122. Button *forward;
  123. Button *dobreak;
  124. Button *docontinue;
  125. List<Vector<float>> perf_history;
  126. Vector<float> perf_max;
  127. Vector<TreeItem *> perf_items;
  128. Map<int, String> profiler_signature;
  129. Tree *perf_monitors;
  130. Control *perf_draw;
  131. Label *info_message;
  132. Tree *vmem_tree;
  133. Button *vmem_refresh;
  134. Button *vmem_export;
  135. LineEdit *vmem_total;
  136. Tree *stack_dump;
  137. LineEdit *search;
  138. EditorInspector *inspector;
  139. Ref<TCP_Server> server;
  140. Ref<StreamPeerTCP> connection;
  141. Ref<PacketPeerStream> ppeer;
  142. String message_type;
  143. Array message;
  144. int pending_in_queue;
  145. HashMap<NodePath, int> node_path_cache;
  146. int last_path_id;
  147. Map<String, int> res_path_cache;
  148. EditorProfiler *profiler;
  149. EditorNetworkProfiler *network_profiler;
  150. EditorNode *editor;
  151. bool breaked;
  152. bool live_debug;
  153. CameraOverride camera_override;
  154. void _performance_draw();
  155. void _performance_select();
  156. void _stack_dump_frame_selected();
  157. void _output_clear();
  158. void _scene_tree_folded(Object *obj);
  159. void _scene_tree_selected();
  160. void _scene_tree_rmb_selected(const Vector2 &p_position);
  161. void _file_selected(const String &p_file);
  162. void _scene_tree_request();
  163. void _parse_message(const String &p_msg, const Array &p_data);
  164. void _set_reason_text(const String &p_reason, MessageType p_type);
  165. void _scene_tree_property_select_object(ObjectID p_object);
  166. void _scene_tree_property_value_edited(const String &p_prop, const Variant &p_value);
  167. int _update_scene_tree(TreeItem *parent, const Array &nodes, int current_index);
  168. void _video_mem_request();
  169. void _video_mem_export();
  170. int _get_node_path_cache(const NodePath &p_path);
  171. int _get_res_path_cache(const String &p_path);
  172. void _live_edit_set();
  173. void _live_edit_clear();
  174. void _method_changed(Object *p_base, const StringName &p_name, VARIANT_ARG_DECLARE);
  175. void _property_changed(Object *p_base, const StringName &p_property, const Variant &p_value);
  176. void _error_activated();
  177. void _error_selected();
  178. void _expand_errors_list();
  179. void _collapse_errors_list();
  180. void _profiler_activate(bool p_enable);
  181. void _profiler_seeked();
  182. void _network_profiler_activate(bool p_enable);
  183. void _paused();
  184. void _set_remote_object(ObjectID p_id, ScriptEditorDebuggerInspectedObject *p_obj);
  185. void _clear_remote_objects();
  186. void _clear_errors_list();
  187. void _error_tree_item_rmb_selected(const Vector2 &p_pos);
  188. void _item_menu_id_pressed(int p_option);
  189. void _tab_changed(int p_tab);
  190. void _export_csv();
  191. void _clear_execution();
  192. protected:
  193. void _notification(int p_what);
  194. static void _bind_methods();
  195. public:
  196. void start(int p_port = -1, const IP_Address &p_bind_address = IP_Address("*"));
  197. void pause();
  198. void unpause();
  199. void stop();
  200. void debug_skip_breakpoints();
  201. void debug_copy();
  202. void debug_next();
  203. void debug_step();
  204. void debug_break();
  205. void debug_continue();
  206. String get_var_value(const String &p_var) const;
  207. void set_live_debugging(bool p_enable);
  208. static void _method_changeds(void *p_ud, Object *p_base, const StringName &p_name, VARIANT_ARG_DECLARE);
  209. static void _property_changeds(void *p_ud, Object *p_base, const StringName &p_property, const Variant &p_value);
  210. void live_debug_create_node(const NodePath &p_parent, const String &p_type, const String &p_name);
  211. void live_debug_instance_node(const NodePath &p_parent, const String &p_path, const String &p_name);
  212. void live_debug_remove_node(const NodePath &p_at);
  213. void live_debug_remove_and_keep_node(const NodePath &p_at, ObjectID p_keep_id);
  214. void live_debug_restore_node(ObjectID p_id, const NodePath &p_at, int p_at_pos);
  215. void live_debug_duplicate_node(const NodePath &p_at, const String &p_new_name);
  216. void live_debug_reparent_node(const NodePath &p_at, const NodePath &p_new_place, const String &p_new_name, int p_at_pos);
  217. CameraOverride get_camera_override() const;
  218. void set_camera_override(CameraOverride p_override);
  219. void set_breakpoint(const String &p_path, int p_line, bool p_enabled);
  220. void update_live_edit_root();
  221. void set_hide_on_stop(bool p_hide);
  222. bool get_debug_with_external_editor() const;
  223. String get_connection_string() const;
  224. void set_debug_with_external_editor(bool p_enabled);
  225. Ref<Script> get_dump_stack_script() const;
  226. void set_tool_button(Button *p_tb) { debugger_button = p_tb; }
  227. void reload_scripts();
  228. bool is_skip_breakpoints();
  229. virtual Size2 get_minimum_size() const;
  230. ScriptEditorDebugger(EditorNode *p_editor = nullptr);
  231. ~ScriptEditorDebugger();
  232. };
  233. #endif // SCRIPT_EDITOR_DEBUGGER_H