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