script_editor_debugger.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 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/gui/box_container.h"
  37. #include "scene/gui/button.h"
  38. class Tree;
  39. class EditorNode;
  40. class ScriptEditorDebuggerVariables;
  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 ScriptEditorDebuggerInspectedObject;
  51. class ScriptEditorDebugger : public Control {
  52. GDCLASS(ScriptEditorDebugger, Control);
  53. enum MessageType {
  54. MESSAGE_ERROR,
  55. MESSAGE_WARNING,
  56. MESSAGE_SUCCESS,
  57. };
  58. enum ItemMenu {
  59. ITEM_MENU_COPY_ERROR,
  60. ITEM_MENU_SAVE_REMOTE_NODE,
  61. ITEM_MENU_COPY_NODE_PATH,
  62. };
  63. AcceptDialog *msgdialog;
  64. Button *debugger_button;
  65. LineEdit *clicked_ctrl;
  66. LineEdit *clicked_ctrl_type;
  67. LineEdit *live_edit_root;
  68. Button *le_set;
  69. Button *le_clear;
  70. Button *export_csv;
  71. bool updating_scene_tree;
  72. float inspect_scene_tree_timeout;
  73. float inspect_edited_object_timeout;
  74. bool auto_switch_remote_scene_tree;
  75. ObjectID inspected_object_id;
  76. ScriptEditorDebuggerVariables *variables;
  77. Map<ObjectID, ScriptEditorDebuggerInspectedObject *> remote_objects;
  78. Set<ObjectID> unfold_cache;
  79. VBoxContainer *errors_tab;
  80. Tree *error_tree;
  81. Tree *inspect_scene_tree;
  82. Button *clearbutton;
  83. PopupMenu *item_menu;
  84. EditorFileDialog *file_dialog;
  85. enum FileDialogMode {
  86. SAVE_CSV,
  87. SAVE_NODE,
  88. };
  89. FileDialogMode file_dialog_mode;
  90. int error_count;
  91. int warning_count;
  92. int last_error_count;
  93. int last_warning_count;
  94. bool hide_on_stop;
  95. bool enable_external_editor;
  96. Ref<Script> stack_script;
  97. TabContainer *tabs;
  98. Label *reason;
  99. Button *copy;
  100. Button *step;
  101. Button *next;
  102. Button *back;
  103. Button *forward;
  104. Button *dobreak;
  105. Button *docontinue;
  106. List<Vector<float> > perf_history;
  107. Vector<float> perf_max;
  108. Vector<TreeItem *> perf_items;
  109. Map<int, String> profiler_signature;
  110. Tree *perf_monitors;
  111. Control *perf_draw;
  112. Tree *vmem_tree;
  113. Button *vmem_refresh;
  114. LineEdit *vmem_total;
  115. Tree *stack_dump;
  116. EditorInspector *inspector;
  117. Ref<TCP_Server> server;
  118. Ref<StreamPeerTCP> connection;
  119. Ref<PacketPeerStream> ppeer;
  120. String message_type;
  121. Array message;
  122. int pending_in_queue;
  123. HashMap<NodePath, int> node_path_cache;
  124. int last_path_id;
  125. Map<String, int> res_path_cache;
  126. EditorProfiler *profiler;
  127. EditorNode *editor;
  128. bool breaked;
  129. bool live_debug;
  130. void _performance_draw();
  131. void _performance_select();
  132. void _stack_dump_frame_selected();
  133. void _output_clear();
  134. void _scene_tree_folded(Object *obj);
  135. void _scene_tree_selected();
  136. void _scene_tree_rmb_selected(const Vector2 &p_position);
  137. void _file_selected(const String &p_file);
  138. void _scene_tree_request();
  139. void _parse_message(const String &p_msg, const Array &p_data);
  140. void _set_reason_text(const String &p_reason, MessageType p_type);
  141. void _scene_tree_property_select_object(ObjectID p_object);
  142. void _scene_tree_property_value_edited(const String &p_prop, const Variant &p_value);
  143. void _video_mem_request();
  144. int _get_node_path_cache(const NodePath &p_path);
  145. int _get_res_path_cache(const String &p_path);
  146. void _live_edit_set();
  147. void _live_edit_clear();
  148. void _method_changed(Object *p_base, const StringName &p_name, VARIANT_ARG_DECLARE);
  149. void _property_changed(Object *p_base, const StringName &p_property, const Variant &p_value);
  150. void _error_activated();
  151. void _error_selected();
  152. void _expand_errors_list();
  153. void _collapse_errors_list();
  154. void _profiler_activate(bool p_enable);
  155. void _profiler_seeked();
  156. void _paused();
  157. void _set_remote_object(ObjectID p_id, ScriptEditorDebuggerInspectedObject *p_obj);
  158. void _clear_remote_objects();
  159. void _clear_errors_list();
  160. void _error_tree_item_rmb_selected(const Vector2 &p_pos);
  161. void _item_menu_id_pressed(int p_option);
  162. void _export_csv();
  163. void _clear_execution();
  164. protected:
  165. void _notification(int p_what);
  166. static void _bind_methods();
  167. public:
  168. void start();
  169. void pause();
  170. void unpause();
  171. void stop();
  172. void debug_copy();
  173. void debug_next();
  174. void debug_step();
  175. void debug_break();
  176. void debug_continue();
  177. String get_var_value(const String &p_var) const;
  178. void set_live_debugging(bool p_enable);
  179. static void _method_changeds(void *p_ud, Object *p_base, const StringName &p_name, VARIANT_ARG_DECLARE);
  180. static void _property_changeds(void *p_ud, Object *p_base, const StringName &p_property, const Variant &p_value);
  181. void live_debug_create_node(const NodePath &p_parent, const String &p_type, const String &p_name);
  182. void live_debug_instance_node(const NodePath &p_parent, const String &p_path, const String &p_name);
  183. void live_debug_remove_node(const NodePath &p_at);
  184. void live_debug_remove_and_keep_node(const NodePath &p_at, ObjectID p_keep_id);
  185. void live_debug_restore_node(ObjectID p_id, const NodePath &p_at, int p_at_pos);
  186. void live_debug_duplicate_node(const NodePath &p_at, const String &p_new_name);
  187. void live_debug_reparent_node(const NodePath &p_at, const NodePath &p_new_place, const String &p_new_name, int p_at_pos);
  188. void set_breakpoint(const String &p_path, int p_line, bool p_enabled);
  189. void update_live_edit_root();
  190. void set_hide_on_stop(bool p_hide);
  191. bool get_debug_with_external_editor() const;
  192. void set_debug_with_external_editor(bool p_enabled);
  193. Ref<Script> get_dump_stack_script() const;
  194. void set_tool_button(Button *p_tb) { debugger_button = p_tb; }
  195. void reload_scripts();
  196. virtual Size2 get_minimum_size() const;
  197. ScriptEditorDebugger(EditorNode *p_editor = NULL);
  198. ~ScriptEditorDebugger();
  199. };
  200. #endif // SCRIPT_EDITOR_DEBUGGER_H