Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/editor/debugger/script_editor_debugger.h
20778 views
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
31
#pragma once
32
33
#include "core/object/script_language.h"
34
#include "core/os/os.h"
35
#include "editor/debugger/editor_debugger_inspector.h"
36
#include "editor/debugger/editor_debugger_node.h"
37
#include "scene/gui/margin_container.h"
38
39
class Button;
40
class Tree;
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 EditorFileDialog;
51
class EditorVisualProfiler;
52
class EditorPerformanceProfiler;
53
class SceneDebuggerTree;
54
class EditorDebuggerPlugin;
55
class DebugAdapterProtocol;
56
class DebugAdapterParser;
57
class EditorExpressionEvaluator;
58
59
class ScriptEditorDebugger : public MarginContainer {
60
GDCLASS(ScriptEditorDebugger, MarginContainer);
61
62
friend class EditorDebuggerNode;
63
friend class DebugAdapterProtocol;
64
friend class DebugAdapterParser;
65
66
private:
67
enum MessageType {
68
MESSAGE_ERROR,
69
MESSAGE_WARNING,
70
MESSAGE_SUCCESS,
71
};
72
73
enum ProfilerType {
74
PROFILER_VISUAL,
75
PROFILER_SCRIPTS_SERVERS
76
};
77
78
enum Actions {
79
ACTION_COPY_ERROR,
80
ACTION_OPEN_SOURCE,
81
ACTION_DELETE_BREAKPOINT,
82
ACTION_DELETE_BREAKPOINTS_IN_FILE,
83
ACTION_DELETE_ALL_BREAKPOINTS,
84
};
85
86
enum VMemMenu {
87
VMEM_MENU_SHOW_IN_FILESYSTEM,
88
VMEM_MENU_SHOW_IN_EXPLORER,
89
VMEM_MENU_OWNERS,
90
};
91
92
AcceptDialog *msgdialog = nullptr;
93
94
LineEdit *clicked_ctrl = nullptr;
95
LineEdit *clicked_ctrl_type = nullptr;
96
LineEdit *live_edit_root = nullptr;
97
Button *le_set = nullptr;
98
Button *le_clear = nullptr;
99
Button *export_csv = nullptr;
100
101
VBoxContainer *errors_tab = nullptr;
102
Tree *error_tree = nullptr;
103
Button *expand_all_button = nullptr;
104
Button *collapse_all_button = nullptr;
105
Button *clear_button = nullptr;
106
PopupMenu *item_menu = nullptr;
107
108
Tree *breakpoints_tree = nullptr;
109
PopupMenu *breakpoints_menu = nullptr;
110
111
EditorFileDialog *file_dialog = nullptr;
112
enum FileDialogPurpose {
113
SAVE_MONITORS_CSV,
114
SAVE_VRAM_CSV,
115
};
116
FileDialogPurpose file_dialog_purpose = SAVE_MONITORS_CSV;
117
118
int error_count;
119
int warning_count;
120
121
bool skip_breakpoints_value = false;
122
bool ignore_error_breaks_value = false;
123
Ref<Script> stack_script;
124
125
TabContainer *tabs = nullptr;
126
127
RichTextLabel *reason = nullptr;
128
129
Button *skip_breakpoints = nullptr;
130
Button *ignore_error_breaks = nullptr;
131
Button *copy = nullptr;
132
Button *step = nullptr;
133
Button *next = nullptr;
134
Button *out = nullptr;
135
Button *dobreak = nullptr;
136
Button *docontinue = nullptr;
137
// Reference to "Remote" tab in scene tree. Needed by _live_edit_set and buttons state.
138
// Each debugger should have it's tree in the future I guess.
139
const Tree *editor_remote_tree = nullptr;
140
141
HashMap<int, String> profiler_signature;
142
143
Tree *vmem_tree = nullptr;
144
Button *vmem_refresh = nullptr;
145
Button *vmem_export = nullptr;
146
LineEdit *vmem_total = nullptr;
147
TextureRect *vmem_notice_icon = nullptr;
148
PopupMenu *vmem_item_menu = nullptr;
149
150
Tree *stack_dump = nullptr;
151
LineEdit *search = nullptr;
152
OptionButton *threads = nullptr;
153
EditorDebuggerInspector *inspector = nullptr;
154
SceneDebuggerTree *scene_tree = nullptr;
155
156
Ref<RemoteDebuggerPeer> peer;
157
158
HashMap<NodePath, int> node_path_cache;
159
int last_path_id = 0;
160
HashMap<String, int> res_path_cache;
161
162
EditorProfiler *profiler = nullptr;
163
EditorVisualProfiler *visual_profiler = nullptr;
164
EditorPerformanceProfiler *performance_profiler = nullptr;
165
EditorExpressionEvaluator *expression_evaluator = nullptr;
166
167
OS::ProcessID remote_pid = 0;
168
bool move_to_foreground = true;
169
bool can_request_idle_draw = false;
170
171
bool live_debug = true;
172
173
uint64_t debugging_thread_id = Thread::UNASSIGNED_ID;
174
175
struct ThreadDebugged {
176
String name;
177
String error;
178
bool can_debug = false;
179
bool has_stackdump = false;
180
uint32_t debug_order = 0;
181
uint64_t thread_id = Thread::UNASSIGNED_ID; // for order
182
};
183
184
struct ThreadSort {
185
bool operator()(const ThreadDebugged *a, const ThreadDebugged *b) const {
186
return a->debug_order < b->debug_order;
187
}
188
};
189
190
HashMap<uint64_t, ThreadDebugged> threads_debugged;
191
bool thread_list_updating = false;
192
193
void _select_thread(int p_index);
194
195
bool debug_mute_audio = false;
196
bool audio_muted_on_break = false;
197
void _mute_audio_on_break(bool p_mute);
198
void _send_debug_mute_audio_msg(bool p_mute);
199
200
EditorDebuggerNode::CameraOverride camera_override;
201
202
void _stack_dump_frame_selected();
203
204
void _file_selected(const String &p_file);
205
206
/// Message handler function for _parse_message.
207
typedef void (ScriptEditorDebugger::*ParseMessageFunc)(uint64_t p_thread_id, const Array &p_data);
208
static HashMap<String, ParseMessageFunc> parse_message_handlers;
209
static void _init_parse_message_handlers();
210
211
void _msg_debug_enter(uint64_t p_thread_id, const Array &p_data);
212
void _msg_debug_exit(uint64_t p_thread_id, const Array &p_data);
213
void _msg_set_pid(uint64_t p_thread_id, const Array &p_data);
214
void _msg_scene_click_ctrl(uint64_t p_thread_id, const Array &p_data);
215
void _msg_scene_scene_tree(uint64_t p_thread_id, const Array &p_data);
216
void _msg_scene_inspect_objects(uint64_t p_thread_id, const Array &p_data);
217
#ifndef DISABLE_DEPRECATED
218
void _msg_scene_inspect_object(uint64_t p_thread_id, const Array &p_data);
219
#endif // DISABLE_DEPRECATED
220
void _msg_scene_debug_mute_audio(uint64_t p_thread_id, const Array &p_data);
221
void _msg_servers_memory_usage(uint64_t p_thread_id, const Array &p_data);
222
void _msg_servers_drawn(uint64_t p_thread_id, const Array &p_data);
223
void _msg_stack_dump(uint64_t p_thread_id, const Array &p_data);
224
void _msg_stack_frame_vars(uint64_t p_thread_id, const Array &p_data);
225
void _msg_stack_frame_var(uint64_t p_thread_id, const Array &p_data);
226
void _msg_output(uint64_t p_thread_id, const Array &p_data);
227
void _msg_performance_profile_frame(uint64_t p_thread_id, const Array &p_data);
228
void _msg_visual_hardware_info(uint64_t p_thread_id, const Array &p_data);
229
void _msg_visual_profile_frame(uint64_t p_thread_id, const Array &p_data);
230
void _msg_error(uint64_t p_thread_id, const Array &p_data);
231
void _msg_servers_function_signature(uint64_t p_thread_id, const Array &p_data);
232
void _msg_servers_profile_common(const Array &p_data, const bool p_final);
233
void _msg_servers_profile_frame(uint64_t p_thread_id, const Array &p_data);
234
void _msg_servers_profile_total(uint64_t p_thread_id, const Array &p_data);
235
void _msg_request_quit(uint64_t p_thread_id, const Array &p_data);
236
void _msg_remote_objects_selected(uint64_t p_thread_id, const Array &p_data);
237
void _msg_remote_nothing_selected(uint64_t p_thread_id, const Array &p_data);
238
void _msg_remote_selection_invalidated(uint64_t p_thread_id, const Array &p_data);
239
void _msg_show_selection_limit_warning(uint64_t p_thread_id, const Array &p_data);
240
void _msg_performance_profile_names(uint64_t p_thread_id, const Array &p_data);
241
void _msg_filesystem_update_file(uint64_t p_thread_id, const Array &p_data);
242
void _msg_evaluation_return(uint64_t p_thread_id, const Array &p_data);
243
void _msg_window_title(uint64_t p_thread_id, const Array &p_data);
244
void _msg_embed_suspend_toggle(uint64_t p_thread_id, const Array &p_data);
245
void _msg_embed_next_frame(uint64_t p_thread_id, const Array &p_data);
246
247
void _parse_message(const String &p_msg, uint64_t p_thread_id, const Array &p_data);
248
void _set_reason_text(const String &p_reason, MessageType p_type);
249
void _update_reason_content_height();
250
void _update_buttons_state();
251
void _remote_object_selected(ObjectID p_object);
252
void _remote_objects_edited(const String &p_prop, const TypedDictionary<uint64_t, Variant> &p_values, const String &p_field);
253
void _remote_object_property_updated(ObjectID p_id, const String &p_property);
254
255
void _video_mem_request();
256
void _video_mem_export();
257
258
void _resources_reimported(const PackedStringArray &p_resources);
259
260
int _get_node_path_cache(const NodePath &p_path);
261
262
int _get_res_path_cache(const String &p_path);
263
264
void _live_edit_set();
265
void _live_edit_clear();
266
267
void _method_changed(Object *p_base, const StringName &p_name, const Variant **p_args, int p_argcount);
268
void _property_changed(Object *p_base, const StringName &p_property, const Variant &p_value);
269
270
void _error_activated();
271
void _error_selected();
272
273
void _expand_errors_list();
274
void _collapse_errors_list();
275
276
void _vmem_item_activated();
277
void _vmem_tree_rmb_selected(const Vector2 &p_pos, MouseButton p_button);
278
void _vmem_item_menu_id_pressed(int p_option);
279
280
void _profiler_activate(bool p_enable, int p_profiler);
281
void _profiler_seeked();
282
283
void _clear_errors_list();
284
285
void _breakpoints_item_rmb_selected(const Vector2 &p_pos, MouseButton p_button);
286
void _error_tree_item_rmb_selected(const Vector2 &p_pos, MouseButton p_button);
287
void _item_menu_id_pressed(int p_option);
288
void _tab_changed(int p_tab);
289
290
void _put_msg(const String &p_message, const Array &p_data, uint64_t p_thread_id = Thread::MAIN_ID);
291
void _export_csv();
292
293
void _clear_execution();
294
void _stop_and_notify();
295
296
void _set_breakpoint(const String &p_path, const int &p_line, const bool &p_enabled);
297
void _clear_breakpoints();
298
299
void _breakpoint_tree_clicked();
300
301
String _format_frame_text(const ScriptLanguage::StackInfo *info);
302
303
void _thread_debug_enter(uint64_t p_thread_id);
304
305
protected:
306
void _notification(int p_what);
307
static void _bind_methods();
308
309
public:
310
enum EmbedShortcutAction {
311
EMBED_SUSPEND_TOGGLE,
312
EMBED_NEXT_FRAME,
313
};
314
315
void request_remote_objects(const TypedArray<uint64_t> &p_obj_ids, bool p_update_selection = true);
316
void update_remote_object(ObjectID p_obj_id, const String &p_prop, const Variant &p_value, const String &p_field = "");
317
318
void clear_inspector(bool p_send_msg = true);
319
320
// Needed by _live_edit_set, buttons state.
321
void set_editor_remote_tree(const Tree *p_tree) { editor_remote_tree = p_tree; }
322
323
void request_remote_tree();
324
const SceneDebuggerTree *get_remote_tree();
325
326
void request_remote_evaluate(const String &p_expression, int p_stack_frame);
327
328
void start(Ref<RemoteDebuggerPeer> p_peer);
329
void stop();
330
331
void debug_skip_breakpoints();
332
void debug_ignore_error_breaks();
333
void debug_copy();
334
335
void debug_out();
336
void debug_next();
337
void debug_step();
338
void debug_break();
339
void debug_continue();
340
bool is_breaked() const { return threads_debugged.size() > 0; }
341
bool is_debuggable() const { return threads_debugged.size() > 0 && threads_debugged[debugging_thread_id].can_debug; }
342
bool is_session_active() { return peer.is_valid() && peer->is_peer_connected(); }
343
int get_remote_pid() const { return remote_pid; }
344
345
bool is_move_to_foreground() const;
346
void set_move_to_foreground(const bool &p_move_to_foreground);
347
348
int get_error_count() const { return error_count; }
349
int get_warning_count() const { return warning_count; }
350
String get_stack_script_file() const;
351
int get_stack_script_line() const;
352
int get_stack_script_frame() const;
353
354
bool request_stack_dump(const int &p_frame);
355
356
void update_tabs();
357
void clear_style();
358
String get_var_value(const String &p_var) const;
359
360
void save_node(ObjectID p_id, const String &p_file);
361
void set_live_debugging(bool p_enable);
362
363
void live_debug_create_node(const NodePath &p_parent, const String &p_type, const String &p_name);
364
void live_debug_instantiate_node(const NodePath &p_parent, const String &p_path, const String &p_name);
365
void live_debug_remove_node(const NodePath &p_at);
366
void live_debug_remove_and_keep_node(const NodePath &p_at, ObjectID p_keep_id);
367
void live_debug_restore_node(ObjectID p_id, const NodePath &p_at, int p_at_pos);
368
void live_debug_duplicate_node(const NodePath &p_at, const String &p_new_name);
369
void live_debug_reparent_node(const NodePath &p_at, const NodePath &p_new_place, const String &p_new_name, int p_at_pos);
370
371
bool get_debug_mute_audio() const;
372
void set_debug_mute_audio(bool p_mute);
373
374
EditorDebuggerNode::CameraOverride get_camera_override() const;
375
void set_camera_override(EditorDebuggerNode::CameraOverride p_override);
376
377
void set_breakpoint(const String &p_path, int p_line, bool p_enabled);
378
379
void update_live_edit_root();
380
381
void reload_all_scripts();
382
void reload_scripts(const Vector<String> &p_script_paths);
383
384
bool is_skip_breakpoints() const;
385
bool is_ignore_error_breaks() const;
386
387
virtual Size2 get_minimum_size() const override;
388
389
void add_debugger_tab(Control *p_control);
390
void remove_debugger_tab(Control *p_control);
391
int get_current_debugger_tab() const;
392
void switch_to_debugger(int p_debugger_tab_idx);
393
394
void send_message(const String &p_message, const Array &p_args);
395
void toggle_profiler(const String &p_profiler, bool p_enable, const Array &p_data);
396
397
ScriptEditorDebugger();
398
~ScriptEditorDebugger();
399
};
400
401