script_editor_debugger.h 7.5 KB

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