script_editor_debugger.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. /*************************************************************************/
  2. /* script_editor_debugger.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 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 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. };
  75. AcceptDialog *msgdialog;
  76. Button *debugger_button;
  77. LineEdit *clicked_ctrl;
  78. LineEdit *clicked_ctrl_type;
  79. LineEdit *live_edit_root;
  80. Button *le_set;
  81. Button *le_clear;
  82. Button *export_csv;
  83. bool updating_scene_tree;
  84. float inspect_scene_tree_timeout;
  85. float inspect_edited_object_timeout;
  86. bool auto_switch_remote_scene_tree;
  87. ObjectID inspected_object_id;
  88. String last_filter;
  89. ScriptEditorDebuggerVariables *variables;
  90. Map<ObjectID, ScriptEditorDebuggerInspectedObject *> remote_objects;
  91. Set<RES> remote_dependencies;
  92. Set<ObjectID> unfold_cache;
  93. VBoxContainer *errors_tab;
  94. Tree *error_tree;
  95. Tree *inspect_scene_tree;
  96. Button *clearbutton;
  97. PopupMenu *item_menu;
  98. EditorFileDialog *file_dialog;
  99. enum FileDialogMode {
  100. SAVE_MONITORS_CSV,
  101. SAVE_VRAM_CSV,
  102. SAVE_NODE,
  103. };
  104. FileDialogMode file_dialog_mode;
  105. int error_count;
  106. int warning_count;
  107. int last_error_count;
  108. int last_warning_count;
  109. bool hide_on_stop;
  110. bool enable_external_editor;
  111. bool skip_breakpoints_value = false;
  112. Ref<Script> stack_script;
  113. TabContainer *tabs;
  114. Label *reason;
  115. Button *skip_breakpoints;
  116. Button *copy;
  117. Button *step;
  118. Button *next;
  119. Button *back;
  120. Button *forward;
  121. Button *dobreak;
  122. Button *docontinue;
  123. List<Vector<float> > perf_history;
  124. Vector<float> perf_max;
  125. Vector<TreeItem *> perf_items;
  126. Map<int, String> profiler_signature;
  127. Tree *perf_monitors;
  128. Control *perf_draw;
  129. Label *info_message;
  130. Tree *vmem_tree;
  131. Button *vmem_refresh;
  132. Button *vmem_export;
  133. LineEdit *vmem_total;
  134. Tree *stack_dump;
  135. EditorInspector *inspector;
  136. Ref<TCP_Server> server;
  137. Ref<StreamPeerTCP> connection;
  138. Ref<PacketPeerStream> ppeer;
  139. String message_type;
  140. Array message;
  141. int pending_in_queue;
  142. HashMap<NodePath, int> node_path_cache;
  143. int last_path_id;
  144. Map<String, int> res_path_cache;
  145. EditorProfiler *profiler;
  146. EditorNetworkProfiler *network_profiler;
  147. EditorNode *editor;
  148. bool breaked;
  149. bool live_debug;
  150. CameraOverride camera_override;
  151. void _performance_draw();
  152. void _performance_select();
  153. void _stack_dump_frame_selected();
  154. void _output_clear();
  155. void _scene_tree_folded(Object *obj);
  156. void _scene_tree_selected();
  157. void _scene_tree_rmb_selected(const Vector2 &p_position);
  158. void _file_selected(const String &p_file);
  159. void _scene_tree_request();
  160. void _parse_message(const String &p_msg, const Array &p_data);
  161. void _set_reason_text(const String &p_reason, MessageType p_type);
  162. void _scene_tree_property_select_object(ObjectID p_object);
  163. void _scene_tree_property_value_edited(const String &p_prop, const Variant &p_value);
  164. int _update_scene_tree(TreeItem *parent, const Array &nodes, int current_index);
  165. void _video_mem_request();
  166. void _video_mem_export();
  167. int _get_node_path_cache(const NodePath &p_path);
  168. int _get_res_path_cache(const String &p_path);
  169. void _live_edit_set();
  170. void _live_edit_clear();
  171. void _method_changed(Object *p_base, const StringName &p_name, VARIANT_ARG_DECLARE);
  172. void _property_changed(Object *p_base, const StringName &p_property, const Variant &p_value);
  173. void _error_activated();
  174. void _error_selected();
  175. void _expand_errors_list();
  176. void _collapse_errors_list();
  177. void _profiler_activate(bool p_enable);
  178. void _profiler_seeked();
  179. void _network_profiler_activate(bool p_enable);
  180. void _paused();
  181. void _set_remote_object(ObjectID p_id, ScriptEditorDebuggerInspectedObject *p_obj);
  182. void _clear_remote_objects();
  183. void _clear_errors_list();
  184. void _error_tree_item_rmb_selected(const Vector2 &p_pos);
  185. void _item_menu_id_pressed(int p_option);
  186. void _tab_changed(int p_tab);
  187. void _export_csv();
  188. void _clear_execution();
  189. protected:
  190. void _notification(int p_what);
  191. static void _bind_methods();
  192. public:
  193. void start();
  194. void pause();
  195. void unpause();
  196. void stop();
  197. void debug_skip_breakpoints();
  198. void debug_copy();
  199. void debug_next();
  200. void debug_step();
  201. void debug_break();
  202. void debug_continue();
  203. String get_var_value(const String &p_var) const;
  204. void set_live_debugging(bool p_enable);
  205. static void _method_changeds(void *p_ud, Object *p_base, const StringName &p_name, VARIANT_ARG_DECLARE);
  206. static void _property_changeds(void *p_ud, Object *p_base, const StringName &p_property, const Variant &p_value);
  207. void live_debug_create_node(const NodePath &p_parent, const String &p_type, const String &p_name);
  208. void live_debug_instance_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. CameraOverride get_camera_override() const;
  215. void set_camera_override(CameraOverride p_override);
  216. void set_breakpoint(const String &p_path, int p_line, bool p_enabled);
  217. void update_live_edit_root();
  218. void set_hide_on_stop(bool p_hide);
  219. bool get_debug_with_external_editor() const;
  220. void set_debug_with_external_editor(bool p_enabled);
  221. Ref<Script> get_dump_stack_script() const;
  222. void set_tool_button(Button *p_tb) { debugger_button = p_tb; }
  223. void reload_scripts();
  224. bool is_skip_breakpoints();
  225. virtual Size2 get_minimum_size() const;
  226. ScriptEditorDebugger(EditorNode *p_editor = NULL);
  227. ~ScriptEditorDebugger();
  228. };
  229. #endif // SCRIPT_EDITOR_DEBUGGER_H