script_editor_debugger.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  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/object/script_language.h"
  33. #include "core/os/os.h"
  34. #include "editor/debugger/editor_debugger_inspector.h"
  35. #include "editor/debugger/editor_debugger_node.h"
  36. #include "editor/debugger/editor_debugger_server.h"
  37. #include "scene/gui/button.h"
  38. #include "scene/gui/margin_container.h"
  39. class Tree;
  40. class LineEdit;
  41. class TabContainer;
  42. class RichTextLabel;
  43. class TextureButton;
  44. class AcceptDialog;
  45. class TreeItem;
  46. class HSplitContainer;
  47. class ItemList;
  48. class EditorProfiler;
  49. class EditorFileDialog;
  50. class EditorVisualProfiler;
  51. class EditorPerformanceProfiler;
  52. class SceneDebuggerTree;
  53. class EditorDebuggerPlugin;
  54. class DebugAdapterProtocol;
  55. class DebugAdapterParser;
  56. class EditorExpressionEvaluator;
  57. class ScriptEditorDebugger : public MarginContainer {
  58. GDCLASS(ScriptEditorDebugger, MarginContainer);
  59. friend class EditorDebuggerNode;
  60. friend class DebugAdapterProtocol;
  61. friend class DebugAdapterParser;
  62. private:
  63. enum MessageType {
  64. MESSAGE_ERROR,
  65. MESSAGE_WARNING,
  66. MESSAGE_SUCCESS,
  67. };
  68. enum ProfilerType {
  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. HashMap<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. OptionButton *threads = nullptr;
  123. EditorDebuggerInspector *inspector = nullptr;
  124. SceneDebuggerTree *scene_tree = nullptr;
  125. Ref<RemoteDebuggerPeer> peer;
  126. HashMap<NodePath, int> node_path_cache;
  127. int last_path_id;
  128. HashMap<String, int> res_path_cache;
  129. EditorProfiler *profiler = nullptr;
  130. EditorVisualProfiler *visual_profiler = nullptr;
  131. EditorPerformanceProfiler *performance_profiler = nullptr;
  132. EditorExpressionEvaluator *expression_evaluator = nullptr;
  133. OS::ProcessID remote_pid = 0;
  134. bool move_to_foreground = true;
  135. bool can_request_idle_draw = false;
  136. bool live_debug;
  137. uint64_t debugging_thread_id = Thread::UNASSIGNED_ID;
  138. struct ThreadDebugged {
  139. String name;
  140. String error;
  141. bool can_debug = false;
  142. bool has_stackdump = false;
  143. uint32_t debug_order = 0;
  144. uint64_t thread_id = Thread::UNASSIGNED_ID; // for order
  145. };
  146. struct ThreadSort {
  147. bool operator()(const ThreadDebugged *a, const ThreadDebugged *b) const {
  148. return a->debug_order < b->debug_order;
  149. }
  150. };
  151. HashMap<uint64_t, ThreadDebugged> threads_debugged;
  152. bool thread_list_updating = false;
  153. void _select_thread(int p_index);
  154. EditorDebuggerNode::CameraOverride camera_override;
  155. void _stack_dump_frame_selected();
  156. void _file_selected(const String &p_file);
  157. void _parse_message(const String &p_msg, uint64_t p_thread_id, const Array &p_data);
  158. void _set_reason_text(const String &p_reason, MessageType p_type);
  159. void _update_buttons_state();
  160. void _remote_object_selected(ObjectID p_object);
  161. void _remote_object_edited(ObjectID, const String &p_prop, const Variant &p_value);
  162. void _remote_object_property_updated(ObjectID p_id, const String &p_property);
  163. void _video_mem_request();
  164. void _video_mem_export();
  165. void _resources_reimported(const PackedStringArray &p_resources);
  166. int _get_node_path_cache(const NodePath &p_path);
  167. int _get_res_path_cache(const String &p_path);
  168. void _live_edit_set();
  169. void _live_edit_clear();
  170. void _method_changed(Object *p_base, const StringName &p_name, const Variant **p_args, int p_argcount);
  171. void _property_changed(Object *p_base, const StringName &p_property, const Variant &p_value);
  172. void _error_activated();
  173. void _error_selected();
  174. void _expand_errors_list();
  175. void _collapse_errors_list();
  176. void _profiler_activate(bool p_enable, int p_profiler);
  177. void _profiler_seeked();
  178. void _clear_errors_list();
  179. void _breakpoints_item_rmb_selected(const Vector2 &p_pos, MouseButton p_button);
  180. void _error_tree_item_rmb_selected(const Vector2 &p_pos, MouseButton p_button);
  181. void _item_menu_id_pressed(int p_option);
  182. void _tab_changed(int p_tab);
  183. void _put_msg(const String &p_message, const Array &p_data, uint64_t p_thread_id = Thread::MAIN_ID);
  184. void _export_csv();
  185. void _clear_execution();
  186. void _stop_and_notify();
  187. void _set_breakpoint(const String &p_path, const int &p_line, const bool &p_enabled);
  188. void _clear_breakpoints();
  189. void _breakpoint_tree_clicked();
  190. String _format_frame_text(const ScriptLanguage::StackInfo *info);
  191. void _thread_debug_enter(uint64_t p_thread_id);
  192. protected:
  193. void _notification(int p_what);
  194. static void _bind_methods();
  195. public:
  196. void request_remote_object(ObjectID p_obj_id);
  197. void update_remote_object(ObjectID p_obj_id, const String &p_prop, const Variant &p_value);
  198. Object *get_remote_object(ObjectID p_id);
  199. // Needed by _live_edit_set, buttons state.
  200. void set_editor_remote_tree(const Tree *p_tree) { editor_remote_tree = p_tree; }
  201. void request_remote_tree();
  202. const SceneDebuggerTree *get_remote_tree();
  203. void request_remote_evaluate(const String &p_expression, int p_stack_frame);
  204. void start(Ref<RemoteDebuggerPeer> p_peer);
  205. void stop();
  206. void debug_skip_breakpoints();
  207. void debug_copy();
  208. void debug_next();
  209. void debug_step();
  210. void debug_break();
  211. void debug_continue();
  212. bool is_breaked() const { return threads_debugged.size() > 0; }
  213. bool is_debuggable() const { return threads_debugged.size() > 0 && threads_debugged[debugging_thread_id].can_debug; }
  214. bool is_session_active() { return peer.is_valid() && peer->is_peer_connected(); }
  215. int get_remote_pid() const { return remote_pid; }
  216. bool is_move_to_foreground() const;
  217. void set_move_to_foreground(const bool &p_move_to_foreground);
  218. int get_error_count() const { return error_count; }
  219. int get_warning_count() const { return warning_count; }
  220. String get_stack_script_file() const;
  221. int get_stack_script_line() const;
  222. int get_stack_script_frame() const;
  223. bool request_stack_dump(const int &p_frame);
  224. void update_tabs();
  225. void clear_style();
  226. String get_var_value(const String &p_var) const;
  227. void save_node(ObjectID p_id, const String &p_file);
  228. void set_live_debugging(bool p_enable);
  229. void live_debug_create_node(const NodePath &p_parent, const String &p_type, const String &p_name);
  230. void live_debug_instantiate_node(const NodePath &p_parent, const String &p_path, const String &p_name);
  231. void live_debug_remove_node(const NodePath &p_at);
  232. void live_debug_remove_and_keep_node(const NodePath &p_at, ObjectID p_keep_id);
  233. void live_debug_restore_node(ObjectID p_id, const NodePath &p_at, int p_at_pos);
  234. void live_debug_duplicate_node(const NodePath &p_at, const String &p_new_name);
  235. void live_debug_reparent_node(const NodePath &p_at, const NodePath &p_new_place, const String &p_new_name, int p_at_pos);
  236. EditorDebuggerNode::CameraOverride get_camera_override() const;
  237. void set_camera_override(EditorDebuggerNode::CameraOverride p_override);
  238. void set_breakpoint(const String &p_path, int p_line, bool p_enabled);
  239. void update_live_edit_root();
  240. void reload_all_scripts();
  241. void reload_scripts(const Vector<String> &p_script_paths);
  242. bool is_skip_breakpoints();
  243. virtual Size2 get_minimum_size() const override;
  244. void add_debugger_tab(Control *p_control);
  245. void remove_debugger_tab(Control *p_control);
  246. int get_current_debugger_tab() const;
  247. void switch_to_debugger(int p_debugger_tab_idx);
  248. void send_message(const String &p_message, const Array &p_args);
  249. void toggle_profiler(const String &p_profiler, bool p_enable, const Array &p_data);
  250. ScriptEditorDebugger();
  251. ~ScriptEditorDebugger();
  252. };
  253. #endif // SCRIPT_EDITOR_DEBUGGER_H