Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/editor/debugger/editor_debugger_node.h
9903 views
1
/**************************************************************************/
2
/* editor_debugger_node.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 "editor/debugger/editor_debugger_server.h"
35
#include "scene/gui/margin_container.h"
36
37
class Button;
38
class DebugAdapterParser;
39
class EditorDebuggerPlugin;
40
class EditorDebuggerTree;
41
class EditorDebuggerRemoteObjects;
42
class MenuButton;
43
class ScriptEditorDebugger;
44
class TabContainer;
45
class UndoRedo;
46
47
class EditorDebuggerNode : public MarginContainer {
48
GDCLASS(EditorDebuggerNode, MarginContainer);
49
50
public:
51
enum CameraOverride {
52
OVERRIDE_NONE,
53
OVERRIDE_INGAME,
54
OVERRIDE_EDITORS,
55
};
56
57
private:
58
enum Options {
59
DEBUG_NEXT,
60
DEBUG_STEP,
61
DEBUG_BREAK,
62
DEBUG_CONTINUE,
63
DEBUG_WITH_EXTERNAL_EDITOR,
64
};
65
66
class Breakpoint {
67
public:
68
String source;
69
int line = 0;
70
71
static uint32_t hash(const Breakpoint &p_val) {
72
uint32_t h = HashMapHasherDefault::hash(p_val.source);
73
return hash_murmur3_one_32(p_val.line, h);
74
}
75
bool operator==(const Breakpoint &p_b) const {
76
return (line == p_b.line && source == p_b.source);
77
}
78
79
bool operator<(const Breakpoint &p_b) const {
80
if (line == p_b.line) {
81
return source < p_b.source;
82
}
83
return line < p_b.line;
84
}
85
86
Breakpoint() {}
87
88
Breakpoint(const String &p_source, int p_line) {
89
line = p_line;
90
source = p_source;
91
}
92
};
93
94
Ref<EditorDebuggerServer> server;
95
TabContainer *tabs = nullptr;
96
Button *debugger_button = nullptr;
97
MenuButton *script_menu = nullptr;
98
99
Ref<Script> stack_script; // Why?!?
100
101
bool initializing = true;
102
int last_error_count = 0;
103
int last_warning_count = 0;
104
105
bool inspect_edited_object_wait = false;
106
float inspect_edited_object_timeout = 0;
107
EditorDebuggerTree *remote_scene_tree = nullptr;
108
bool remote_scene_tree_wait = false;
109
float remote_scene_tree_timeout = 0.0;
110
bool remote_scene_tree_clear_msg = true;
111
bool auto_switch_remote_scene_tree = false;
112
bool debug_with_external_editor = false;
113
bool keep_open = false;
114
String current_uri;
115
116
bool debug_mute_audio = false;
117
118
CameraOverride camera_override = OVERRIDE_NONE;
119
HashMap<Breakpoint, bool, Breakpoint> breakpoints;
120
121
HashSet<Ref<EditorDebuggerPlugin>> debugger_plugins;
122
123
ScriptEditorDebugger *_add_debugger();
124
void _update_errors();
125
126
friend class DebuggerEditorPlugin;
127
friend class DebugAdapterParser;
128
static EditorDebuggerNode *singleton;
129
EditorDebuggerNode();
130
131
protected:
132
void _debugger_stopped(int p_id);
133
void _debugger_wants_stop(int p_id);
134
void _debugger_changed(int p_tab);
135
void _debug_data(const String &p_msg, const Array &p_data, int p_debugger);
136
void _remote_tree_select_requested(const TypedArray<int64_t> &p_ids, int p_debugger);
137
void _remote_tree_clear_selection_requested(int p_debugger);
138
void _remote_tree_updated(int p_debugger);
139
void _remote_tree_button_pressed(Object *p_item, int p_column, int p_id, MouseButton p_button);
140
void _remote_objects_updated(EditorDebuggerRemoteObjects *p_objs, int p_debugger);
141
void _remote_object_property_updated(ObjectID p_id, const String &p_property, int p_debugger);
142
void _remote_objects_requested(const TypedArray<uint64_t> &p_ids, int p_debugger);
143
void _remote_selection_cleared(int p_debugger);
144
void _save_node_requested(ObjectID p_id, const String &p_file, int p_debugger);
145
146
void _breakpoint_set_in_tree(Ref<RefCounted> p_script, int p_line, bool p_enabled, int p_debugger);
147
void _breakpoints_cleared_in_tree(int p_debugger);
148
149
void _clear_execution(Ref<RefCounted> p_script) {
150
emit_signal(SNAME("clear_execution"), p_script);
151
}
152
153
void _text_editor_stack_goto(const ScriptEditorDebugger *p_debugger);
154
void _text_editor_stack_clear(const ScriptEditorDebugger *p_debugger);
155
void _stack_frame_selected(int p_debugger);
156
void _error_selected(const String &p_file, int p_line, int p_debugger);
157
void _breaked(bool p_breaked, bool p_can_debug, const String &p_message, bool p_has_stackdump, int p_debugger);
158
void _paused();
159
void _break_state_changed();
160
void _menu_option(int p_id);
161
void _update_debug_options();
162
163
protected:
164
void _notification(int p_what);
165
static void _bind_methods();
166
167
public:
168
static EditorDebuggerNode *get_singleton() { return singleton; }
169
void register_undo_redo(UndoRedo *p_undo_redo);
170
171
ScriptEditorDebugger *get_previous_debugger() const;
172
ScriptEditorDebugger *get_current_debugger() const;
173
ScriptEditorDebugger *get_default_debugger() const;
174
ScriptEditorDebugger *get_debugger(int p_debugger) const;
175
176
void debug_next();
177
void debug_step();
178
void debug_break();
179
void debug_continue();
180
181
void set_script_debug_button(MenuButton *p_button);
182
183
void set_tool_button(Button *p_button) {
184
debugger_button = p_button;
185
}
186
187
String get_var_value(const String &p_var) const;
188
Ref<Script> get_dump_stack_script() const { return stack_script; } // Why do we need this?
189
190
bool get_debug_with_external_editor() { return debug_with_external_editor; }
191
192
bool is_skip_breakpoints() const;
193
bool is_ignore_error_breaks() const;
194
void set_breakpoint(const String &p_path, int p_line, bool p_enabled);
195
void set_breakpoints(const String &p_path, const Array &p_lines);
196
void reload_all_scripts();
197
void reload_scripts(const Vector<String> &p_script_paths);
198
199
// Remote inspector/edit.
200
void request_remote_tree();
201
void set_remote_selection(const TypedArray<int64_t> &p_ids);
202
void clear_remote_tree_selection();
203
void stop_waiting_inspection();
204
bool match_remote_selection(const TypedArray<uint64_t> &p_ids) const;
205
static void _methods_changed(void *p_ud, Object *p_base, const StringName &p_name, const Variant **p_args, int p_argcount);
206
static void _properties_changed(void *p_ud, Object *p_base, const StringName &p_property, const Variant &p_value);
207
208
// LiveDebug
209
void set_live_debugging(bool p_enabled);
210
void update_live_edit_root();
211
void live_debug_create_node(const NodePath &p_parent, const String &p_type, const String &p_name);
212
void live_debug_instantiate_node(const NodePath &p_parent, const String &p_path, const String &p_name);
213
void live_debug_remove_node(const NodePath &p_at);
214
void live_debug_remove_and_keep_node(const NodePath &p_at, ObjectID p_keep_id);
215
void live_debug_restore_node(ObjectID p_id, const NodePath &p_at, int p_at_pos);
216
void live_debug_duplicate_node(const NodePath &p_at, const String &p_new_name);
217
void live_debug_reparent_node(const NodePath &p_at, const NodePath &p_new_place, const String &p_new_name, int p_at_pos);
218
219
void set_debug_mute_audio(bool p_mute);
220
bool get_debug_mute_audio() const;
221
222
void set_camera_override(CameraOverride p_override);
223
CameraOverride get_camera_override();
224
225
String get_server_uri() const;
226
227
void set_keep_open(bool p_keep_open);
228
Error start(const String &p_uri = "tcp://");
229
void stop(bool p_force = false);
230
231
bool plugins_capture(ScriptEditorDebugger *p_debugger, const String &p_message, const Array &p_data);
232
void add_debugger_plugin(const Ref<EditorDebuggerPlugin> &p_plugin);
233
void remove_debugger_plugin(const Ref<EditorDebuggerPlugin> &p_plugin);
234
};
235
236