script_editor_debugger.h 9.8 KB

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