script_editor_debugger.h 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  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/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 "scene/gui/button.h"
  37. #include "scene/gui/margin_container.h"
  38. class Tree;
  39. class LineEdit;
  40. class TabContainer;
  41. class RichTextLabel;
  42. class TextureButton;
  43. class AcceptDialog;
  44. class TreeItem;
  45. class HSplitContainer;
  46. class ItemList;
  47. class EditorProfiler;
  48. class EditorFileDialog;
  49. class EditorVisualProfiler;
  50. class EditorPerformanceProfiler;
  51. class SceneDebuggerTree;
  52. class EditorDebuggerPlugin;
  53. class DebugAdapterProtocol;
  54. class DebugAdapterParser;
  55. class ScriptEditorDebugger : public MarginContainer {
  56. GDCLASS(ScriptEditorDebugger, MarginContainer);
  57. friend class EditorDebuggerNode;
  58. friend class DebugAdapterProtocol;
  59. friend class DebugAdapterParser;
  60. private:
  61. enum MessageType {
  62. MESSAGE_ERROR,
  63. MESSAGE_WARNING,
  64. MESSAGE_SUCCESS,
  65. };
  66. enum ProfilerType {
  67. PROFILER_VISUAL,
  68. PROFILER_SCRIPTS_SERVERS
  69. };
  70. enum Actions {
  71. ACTION_COPY_ERROR,
  72. ACTION_OPEN_SOURCE,
  73. ACTION_DELETE_BREAKPOINT,
  74. ACTION_DELETE_BREAKPOINTS_IN_FILE,
  75. ACTION_DELETE_ALL_BREAKPOINTS,
  76. };
  77. AcceptDialog *msgdialog = nullptr;
  78. LineEdit *clicked_ctrl = nullptr;
  79. LineEdit *clicked_ctrl_type = nullptr;
  80. LineEdit *live_edit_root = nullptr;
  81. Button *le_set = nullptr;
  82. Button *le_clear = nullptr;
  83. Button *export_csv = nullptr;
  84. VBoxContainer *errors_tab = nullptr;
  85. Tree *error_tree = nullptr;
  86. Button *expand_all_button = nullptr;
  87. Button *collapse_all_button = nullptr;
  88. Button *clear_button = nullptr;
  89. PopupMenu *item_menu = nullptr;
  90. Tree *breakpoints_tree = nullptr;
  91. PopupMenu *breakpoints_menu = nullptr;
  92. EditorFileDialog *file_dialog = nullptr;
  93. enum FileDialogPurpose {
  94. SAVE_MONITORS_CSV,
  95. SAVE_VRAM_CSV,
  96. };
  97. FileDialogPurpose file_dialog_purpose;
  98. int error_count;
  99. int warning_count;
  100. bool skip_breakpoints_value = false;
  101. Ref<Script> stack_script;
  102. TabContainer *tabs = nullptr;
  103. Label *reason = nullptr;
  104. Button *skip_breakpoints = nullptr;
  105. Button *copy = nullptr;
  106. Button *step = nullptr;
  107. Button *next = nullptr;
  108. Button *dobreak = nullptr;
  109. Button *docontinue = nullptr;
  110. // Reference to "Remote" tab in scene tree. Needed by _live_edit_set and buttons state.
  111. // Each debugger should have it's tree in the future I guess.
  112. const Tree *editor_remote_tree = nullptr;
  113. HashMap<int, String> profiler_signature;
  114. Tree *vmem_tree = nullptr;
  115. Button *vmem_refresh = nullptr;
  116. Button *vmem_export = nullptr;
  117. LineEdit *vmem_total = nullptr;
  118. Tree *stack_dump = nullptr;
  119. LineEdit *search = nullptr;
  120. EditorDebuggerInspector *inspector = nullptr;
  121. SceneDebuggerTree *scene_tree = nullptr;
  122. Ref<RemoteDebuggerPeer> peer;
  123. HashMap<NodePath, int> node_path_cache;
  124. int last_path_id;
  125. HashMap<String, int> res_path_cache;
  126. EditorProfiler *profiler = nullptr;
  127. EditorVisualProfiler *visual_profiler = nullptr;
  128. EditorPerformanceProfiler *performance_profiler = nullptr;
  129. OS::ProcessID remote_pid = 0;
  130. bool breaked = false;
  131. bool can_debug = false;
  132. bool move_to_foreground = true;
  133. bool can_request_idle_draw = false;
  134. bool live_debug;
  135. EditorDebuggerNode::CameraOverride camera_override;
  136. void _stack_dump_frame_selected();
  137. void _file_selected(const String &p_file);
  138. void _parse_message(const String &p_msg, const Array &p_data);
  139. void _set_reason_text(const String &p_reason, MessageType p_type);
  140. void _update_buttons_state();
  141. void _remote_object_selected(ObjectID p_object);
  142. void _remote_object_edited(ObjectID, const String &p_prop, const Variant &p_value);
  143. void _remote_object_property_updated(ObjectID p_id, const String &p_property);
  144. void _video_mem_request();
  145. void _video_mem_export();
  146. int _get_node_path_cache(const NodePath &p_path);
  147. int _get_res_path_cache(const String &p_path);
  148. void _live_edit_set();
  149. void _live_edit_clear();
  150. void _method_changed(Object *p_base, const StringName &p_name, const Variant **p_args, int p_argcount);
  151. void _property_changed(Object *p_base, const StringName &p_property, const Variant &p_value);
  152. void _error_activated();
  153. void _error_selected();
  154. void _expand_errors_list();
  155. void _collapse_errors_list();
  156. void _profiler_activate(bool p_enable, int p_profiler);
  157. void _profiler_seeked();
  158. void _clear_errors_list();
  159. void _breakpoints_item_rmb_selected(const Vector2 &p_pos, MouseButton p_button);
  160. void _error_tree_item_rmb_selected(const Vector2 &p_pos, MouseButton p_button);
  161. void _item_menu_id_pressed(int p_option);
  162. void _tab_changed(int p_tab);
  163. void _put_msg(String p_message, Array p_data);
  164. void _export_csv();
  165. void _clear_execution();
  166. void _stop_and_notify();
  167. void _set_breakpoint(const String &p_path, const int &p_line, const bool &p_enabled);
  168. void _clear_breakpoints();
  169. void _breakpoint_tree_clicked();
  170. String _format_frame_text(const ScriptLanguage::StackInfo *info);
  171. protected:
  172. void _notification(int p_what);
  173. static void _bind_methods();
  174. public:
  175. void request_remote_object(ObjectID p_obj_id);
  176. void update_remote_object(ObjectID p_obj_id, const String &p_prop, const Variant &p_value);
  177. Object *get_remote_object(ObjectID p_id);
  178. // Needed by _live_edit_set, buttons state.
  179. void set_editor_remote_tree(const Tree *p_tree) { editor_remote_tree = p_tree; }
  180. void request_remote_tree();
  181. const SceneDebuggerTree *get_remote_tree();
  182. void start(Ref<RemoteDebuggerPeer> p_peer);
  183. void stop();
  184. void debug_skip_breakpoints();
  185. void debug_copy();
  186. void debug_next();
  187. void debug_step();
  188. void debug_break();
  189. void debug_continue();
  190. bool is_breaked() const { return breaked; }
  191. bool is_debuggable() const { return can_debug; }
  192. bool is_session_active() { return peer.is_valid() && peer->is_peer_connected(); };
  193. int get_remote_pid() const { return remote_pid; }
  194. bool is_move_to_foreground() const;
  195. void set_move_to_foreground(const bool &p_move_to_foreground);
  196. int get_error_count() const { return error_count; }
  197. int get_warning_count() const { return warning_count; }
  198. String get_stack_script_file() const;
  199. int get_stack_script_line() const;
  200. int get_stack_script_frame() const;
  201. bool request_stack_dump(const int &p_frame);
  202. void update_tabs();
  203. void clear_style();
  204. String get_var_value(const String &p_var) const;
  205. void save_node(ObjectID p_id, const String &p_file);
  206. void set_live_debugging(bool p_enable);
  207. void live_debug_create_node(const NodePath &p_parent, const String &p_type, const String &p_name);
  208. void live_debug_instantiate_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. EditorDebuggerNode::CameraOverride get_camera_override() const;
  215. void set_camera_override(EditorDebuggerNode::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 reload_scripts();
  219. bool is_skip_breakpoints();
  220. virtual Size2 get_minimum_size() const override;
  221. void add_debugger_tab(Control *p_control);
  222. void remove_debugger_tab(Control *p_control);
  223. void send_message(const String &p_message, const Array &p_args);
  224. void toggle_profiler(const String &p_profiler, bool p_enable, const Array &p_data);
  225. ScriptEditorDebugger();
  226. ~ScriptEditorDebugger();
  227. };
  228. #endif // SCRIPT_EDITOR_DEBUGGER_H