script_editor_debugger.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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-2020 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2020 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/os/os.h"
  33. #include "editor/debugger/editor_debugger_inspector.h"
  34. #include "editor/debugger/editor_debugger_node.h"
  35. #include "editor/debugger/editor_debugger_server.h"
  36. #include "editor/editor_file_dialog.h"
  37. #include "scene/gui/button.h"
  38. #include "scene/gui/margin_container.h"
  39. class Tree;
  40. class EditorNode;
  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 EditorVisualProfiler;
  51. class EditorNetworkProfiler;
  52. class SceneDebuggerTree;
  53. class ScriptEditorDebugger : public MarginContainer {
  54. GDCLASS(ScriptEditorDebugger, MarginContainer);
  55. friend class EditorDebuggerNode;
  56. private:
  57. enum MessageType {
  58. MESSAGE_ERROR,
  59. MESSAGE_WARNING,
  60. MESSAGE_SUCCESS,
  61. };
  62. AcceptDialog *msgdialog;
  63. LineEdit *clicked_ctrl;
  64. LineEdit *clicked_ctrl_type;
  65. LineEdit *live_edit_root;
  66. Button *le_set;
  67. Button *le_clear;
  68. Button *export_csv;
  69. VBoxContainer *errors_tab;
  70. Tree *error_tree;
  71. Button *clearbutton;
  72. PopupMenu *item_menu;
  73. EditorFileDialog *file_dialog;
  74. int error_count;
  75. int warning_count;
  76. bool skip_breakpoints_value = false;
  77. Ref<Script> stack_script;
  78. TabContainer *tabs;
  79. Label *reason;
  80. Button *skip_breakpoints;
  81. Button *copy;
  82. Button *step;
  83. Button *next;
  84. Button *dobreak;
  85. Button *docontinue;
  86. // Reference to "Remote" tab in scene tree. Needed by _live_edit_set and buttons state.
  87. // Each debugger should have it's tree in the future I guess.
  88. const Tree *editor_remote_tree = NULL;
  89. List<Vector<float> > perf_history;
  90. Vector<float> perf_max;
  91. Vector<TreeItem *> perf_items;
  92. Map<int, String> profiler_signature;
  93. Tree *perf_monitors;
  94. Control *perf_draw;
  95. Label *info_message;
  96. Tree *vmem_tree;
  97. Button *vmem_refresh;
  98. LineEdit *vmem_total;
  99. Tree *stack_dump;
  100. EditorDebuggerInspector *inspector;
  101. SceneDebuggerTree *scene_tree;
  102. Ref<EditorDebuggerPeer> peer;
  103. HashMap<NodePath, int> node_path_cache;
  104. int last_path_id;
  105. Map<String, int> res_path_cache;
  106. EditorProfiler *profiler;
  107. EditorVisualProfiler *visual_profiler;
  108. EditorNetworkProfiler *network_profiler;
  109. EditorNode *editor;
  110. OS::ProcessID remote_pid = 0;
  111. bool breaked = false;
  112. bool can_debug = false;
  113. bool live_debug;
  114. EditorDebuggerNode::CameraOverride camera_override;
  115. void _performance_draw();
  116. void _performance_select();
  117. void _stack_dump_frame_selected();
  118. void _file_selected(const String &p_file);
  119. void _parse_message(const String &p_msg, const Array &p_data);
  120. void _set_reason_text(const String &p_reason, MessageType p_type);
  121. void _update_buttons_state();
  122. void _remote_object_selected(ObjectID p_object);
  123. void _remote_object_edited(ObjectID, const String &p_prop, const Variant &p_value);
  124. void _remote_object_property_updated(ObjectID p_id, const String &p_property);
  125. void _video_mem_request();
  126. int _get_node_path_cache(const NodePath &p_path);
  127. int _get_res_path_cache(const String &p_path);
  128. void _live_edit_set();
  129. void _live_edit_clear();
  130. void _method_changed(Object *p_base, const StringName &p_name, VARIANT_ARG_DECLARE);
  131. void _property_changed(Object *p_base, const StringName &p_property, const Variant &p_value);
  132. void _error_activated();
  133. void _error_selected();
  134. void _expand_errors_list();
  135. void _collapse_errors_list();
  136. void _visual_profiler_activate(bool p_enable);
  137. void _profiler_activate(bool p_enable);
  138. void _profiler_seeked();
  139. void _network_profiler_activate(bool p_enable);
  140. void _clear_errors_list();
  141. void _error_tree_item_rmb_selected(const Vector2 &p_pos);
  142. void _item_menu_id_pressed(int p_option);
  143. void _tab_changed(int p_tab);
  144. void _put_msg(String p_message, Array p_data);
  145. void _export_csv();
  146. void _clear_execution();
  147. void _stop_and_notify();
  148. protected:
  149. void _notification(int p_what);
  150. static void _bind_methods();
  151. public:
  152. void request_remote_object(ObjectID p_obj_id);
  153. void update_remote_object(ObjectID p_obj_id, const String &p_prop, const Variant &p_value);
  154. Object *get_remote_object(ObjectID p_id);
  155. // Needed by _live_edit_set, buttons state.
  156. void set_editor_remote_tree(const Tree *p_tree) { editor_remote_tree = p_tree; }
  157. void request_remote_tree();
  158. const SceneDebuggerTree *get_remote_tree();
  159. void start(Ref<EditorDebuggerPeer> p_peer);
  160. void stop();
  161. void debug_skip_breakpoints();
  162. void debug_copy();
  163. void debug_next();
  164. void debug_step();
  165. void debug_break();
  166. void debug_continue();
  167. bool is_breaked() const { return breaked; }
  168. bool is_debuggable() const { return can_debug; }
  169. bool is_session_active() { return peer.is_valid() && peer->is_peer_connected(); };
  170. int get_remote_pid() const { return remote_pid; }
  171. int get_error_count() const { return error_count; }
  172. int get_warning_count() const { return warning_count; }
  173. String get_stack_script_file() const;
  174. int get_stack_script_line() const;
  175. int get_stack_script_frame() const;
  176. void update_tabs();
  177. void clear_style();
  178. String get_var_value(const String &p_var) const;
  179. void save_node(ObjectID p_id, const String &p_file);
  180. void set_live_debugging(bool p_enable);
  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. EditorDebuggerNode::CameraOverride get_camera_override() const;
  189. void set_camera_override(EditorDebuggerNode::CameraOverride p_override);
  190. void set_breakpoint(const String &p_path, int p_line, bool p_enabled);
  191. void update_live_edit_root();
  192. void reload_scripts();
  193. bool is_skip_breakpoints();
  194. virtual Size2 get_minimum_size() const;
  195. ScriptEditorDebugger(EditorNode *p_editor = NULL);
  196. ~ScriptEditorDebugger();
  197. };
  198. #endif // SCRIPT_EDITOR_DEBUGGER_H