mirror of
https://github.com/godotengine/godot.git
synced 2026-01-03 18:11:19 +03:00
Refactor ScriptDebugger.
EngineDebugger is the new interface to access the debugger.
It tries to be as agnostic as possible on the data that various
subsystems can expose.
It allows 2 types of interactions:
- Profilers:
A subsystem can register a profiler, assigning it a unique name.
That name can be used to activate the profiler or add data to it.
The registered profiler can be composed of up to 3 functions:
- Toggle: called when the profiler is activated/deactivated.
- Add: called whenever data is added to the debugger
(via `EngineDebugger::profiler_add_frame_data`)
- Tick: called every frame (during idle), receives frame times.
- Captures: (Only relevant in remote debugger for now)
A subsystem can register a capture, assigning it a unique name.
When receiving a message, the remote debugger will check if it starts
with `[prefix]:` and call the associated capture with name `prefix`.
Port MultiplayerAPI, Servers, Scripts, Visual, Performance to the new
profiler system.
Port SceneDebugger and RemoteDebugger to the new capture system.
The LocalDebugger also uses the new profiler system for scripts
profiling.
This commit is contained in:
@@ -315,7 +315,7 @@ ScriptInstance *GDScript::instance_create(Object *p_this) {
|
||||
if (top->native.is_valid()) {
|
||||
if (!ClassDB::is_parent_class(p_this->get_class_name(), top->native->get_name())) {
|
||||
|
||||
if (ScriptDebugger::get_singleton()) {
|
||||
if (EngineDebugger::is_active()) {
|
||||
GDScriptLanguage::get_singleton()->debug_break_parse(get_path(), 1, "Script inherits from native type '" + String(top->native->get_name()) + "', so it can't be instanced in object of type: '" + p_this->get_class() + "'");
|
||||
}
|
||||
ERR_FAIL_V_MSG(NULL, "Script inherits from native type '" + String(top->native->get_name()) + "', so it can't be instanced in object of type '" + p_this->get_class() + "'" + ".");
|
||||
@@ -556,7 +556,7 @@ Error GDScript::reload(bool p_keep_state) {
|
||||
GDScriptParser parser;
|
||||
Error err = parser.parse(source, basedir, false, path);
|
||||
if (err) {
|
||||
if (ScriptDebugger::get_singleton()) {
|
||||
if (EngineDebugger::is_active()) {
|
||||
GDScriptLanguage::get_singleton()->debug_break_parse(get_path(), parser.get_error_line(), "Parser Error: " + parser.get_error());
|
||||
}
|
||||
_err_print_error("GDScript::reload", path.empty() ? "built-in" : (const char *)path.utf8().get_data(), parser.get_error_line(), ("Parse Error: " + parser.get_error()).utf8().get_data(), ERR_HANDLER_SCRIPT);
|
||||
@@ -571,7 +571,7 @@ Error GDScript::reload(bool p_keep_state) {
|
||||
if (err) {
|
||||
|
||||
if (can_run) {
|
||||
if (ScriptDebugger::get_singleton()) {
|
||||
if (EngineDebugger::is_active()) {
|
||||
GDScriptLanguage::get_singleton()->debug_break_parse(get_path(), compiler.get_error_line(), "Parser Error: " + compiler.get_error());
|
||||
}
|
||||
_err_print_error("GDScript::reload", path.empty() ? "built-in" : (const char *)path.utf8().get_data(), compiler.get_error_line(), ("Compile Error: " + compiler.get_error()).utf8().get_data(), ERR_HANDLER_SCRIPT);
|
||||
@@ -583,9 +583,9 @@ Error GDScript::reload(bool p_keep_state) {
|
||||
#ifdef DEBUG_ENABLED
|
||||
for (const List<GDScriptWarning>::Element *E = parser.get_warnings().front(); E; E = E->next()) {
|
||||
const GDScriptWarning &warning = E->get();
|
||||
if (ScriptDebugger::get_singleton()) {
|
||||
if (EngineDebugger::is_active()) {
|
||||
Vector<ScriptLanguage::StackInfo> si;
|
||||
ScriptDebugger::get_singleton()->send_error("", get_path(), warning.line, warning.get_name(), warning.get_message(), ERR_HANDLER_WARNING, si);
|
||||
EngineDebugger::get_script_debugger()->send_error("", get_path(), warning.line, warning.get_name(), warning.get_message(), ERR_HANDLER_WARNING, si);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -2201,7 +2201,7 @@ GDScriptLanguage::GDScriptLanguage() {
|
||||
int dmcs = GLOBAL_DEF("debug/settings/gdscript/max_call_stack", 1024);
|
||||
ProjectSettings::get_singleton()->set_custom_property_info("debug/settings/gdscript/max_call_stack", PropertyInfo(Variant::INT, "debug/settings/gdscript/max_call_stack", PROPERTY_HINT_RANGE, "1024,4096,1,or_greater")); //minimum is 1024
|
||||
|
||||
if (ScriptDebugger::get_singleton()) {
|
||||
if (EngineDebugger::is_active()) {
|
||||
//debugging enabled!
|
||||
|
||||
_debug_max_call_stack = dmcs;
|
||||
|
||||
@@ -31,6 +31,8 @@
|
||||
#ifndef GDSCRIPT_H
|
||||
#define GDSCRIPT_H
|
||||
|
||||
#include "core/debugger/engine_debugger.h"
|
||||
#include "core/debugger/script_debugger.h"
|
||||
#include "core/io/resource_loader.h"
|
||||
#include "core/io/resource_saver.h"
|
||||
#include "core/script_language.h"
|
||||
@@ -393,13 +395,13 @@ public:
|
||||
if (Thread::get_main_id() != Thread::get_caller_id())
|
||||
return; //no support for other threads than main for now
|
||||
|
||||
if (ScriptDebugger::get_singleton()->get_lines_left() > 0 && ScriptDebugger::get_singleton()->get_depth() >= 0)
|
||||
ScriptDebugger::get_singleton()->set_depth(ScriptDebugger::get_singleton()->get_depth() + 1);
|
||||
if (EngineDebugger::get_script_debugger()->get_lines_left() > 0 && EngineDebugger::get_script_debugger()->get_depth() >= 0)
|
||||
EngineDebugger::get_script_debugger()->set_depth(EngineDebugger::get_script_debugger()->get_depth() + 1);
|
||||
|
||||
if (_debug_call_stack_pos >= _debug_max_call_stack) {
|
||||
//stack overflow
|
||||
_debug_error = "Stack Overflow (Stack Size: " + itos(_debug_max_call_stack) + ")";
|
||||
ScriptDebugger::get_singleton()->debug(this);
|
||||
EngineDebugger::get_script_debugger()->debug(this);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -416,13 +418,13 @@ public:
|
||||
if (Thread::get_main_id() != Thread::get_caller_id())
|
||||
return; //no support for other threads than main for now
|
||||
|
||||
if (ScriptDebugger::get_singleton()->get_lines_left() > 0 && ScriptDebugger::get_singleton()->get_depth() >= 0)
|
||||
ScriptDebugger::get_singleton()->set_depth(ScriptDebugger::get_singleton()->get_depth() - 1);
|
||||
if (EngineDebugger::get_script_debugger()->get_lines_left() > 0 && EngineDebugger::get_script_debugger()->get_depth() >= 0)
|
||||
EngineDebugger::get_script_debugger()->set_depth(EngineDebugger::get_script_debugger()->get_depth() - 1);
|
||||
|
||||
if (_debug_call_stack_pos == 0) {
|
||||
|
||||
_debug_error = "Stack Underflow (Engine Bug)";
|
||||
ScriptDebugger::get_singleton()->debug(this);
|
||||
EngineDebugger::get_script_debugger()->debug(this);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -1579,7 +1579,7 @@ Error GDScriptCompiler::_parse_function(GDScript *p_script, const GDScriptParser
|
||||
codegen.stack_max = 0;
|
||||
codegen.current_line = 0;
|
||||
codegen.call_max = 0;
|
||||
codegen.debug_stack = ScriptDebugger::get_singleton() != NULL;
|
||||
codegen.debug_stack = EngineDebugger::is_active();
|
||||
Vector<StringName> argnames;
|
||||
|
||||
int stack_level = 0;
|
||||
@@ -1765,7 +1765,7 @@ Error GDScriptCompiler::_parse_function(GDScript *p_script, const GDScriptParser
|
||||
gdfunc->_call_size = codegen.call_max;
|
||||
gdfunc->name = func_name;
|
||||
#ifdef DEBUG_ENABLED
|
||||
if (ScriptDebugger::get_singleton()) {
|
||||
if (EngineDebugger::is_active()) {
|
||||
String signature;
|
||||
//path
|
||||
if (p_script->get_path() != String())
|
||||
|
||||
@@ -221,12 +221,12 @@ Script *GDScriptLanguage::create_script() const {
|
||||
bool GDScriptLanguage::debug_break_parse(const String &p_file, int p_line, const String &p_error) {
|
||||
//break because of parse error
|
||||
|
||||
if (ScriptDebugger::get_singleton() && Thread::get_caller_id() == Thread::get_main_id()) {
|
||||
if (EngineDebugger::is_active() && Thread::get_caller_id() == Thread::get_main_id()) {
|
||||
|
||||
_debug_parse_err_line = p_line;
|
||||
_debug_parse_err_file = p_file;
|
||||
_debug_error = p_error;
|
||||
ScriptDebugger::get_singleton()->debug(this, false, true);
|
||||
EngineDebugger::get_script_debugger()->debug(this, false, true);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
@@ -235,13 +235,13 @@ bool GDScriptLanguage::debug_break_parse(const String &p_file, int p_line, const
|
||||
|
||||
bool GDScriptLanguage::debug_break(const String &p_error, bool p_allow_continue) {
|
||||
|
||||
if (ScriptDebugger::get_singleton() && Thread::get_caller_id() == Thread::get_main_id()) {
|
||||
if (EngineDebugger::is_active() && Thread::get_caller_id() == Thread::get_main_id()) {
|
||||
|
||||
_debug_parse_err_line = -1;
|
||||
_debug_parse_err_file = "";
|
||||
_debug_error = p_error;
|
||||
bool is_error_breakpoint = p_error != "Breakpoint";
|
||||
ScriptDebugger::get_singleton()->debug(this, p_allow_continue, is_error_breakpoint);
|
||||
EngineDebugger::get_script_debugger()->debug(this, p_allow_continue, is_error_breakpoint);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
|
||||
@@ -391,7 +391,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
|
||||
|
||||
#ifdef DEBUG_ENABLED
|
||||
|
||||
if (ScriptDebugger::get_singleton())
|
||||
if (EngineDebugger::is_active())
|
||||
GDScriptLanguage::get_singleton()->enter_function(p_instance, this, stack, &ip, &line);
|
||||
|
||||
#define GD_ERR_BREAK(m_cond) \
|
||||
@@ -1522,7 +1522,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
|
||||
|
||||
OPCODE(OPCODE_BREAKPOINT) {
|
||||
#ifdef DEBUG_ENABLED
|
||||
if (ScriptDebugger::get_singleton()) {
|
||||
if (EngineDebugger::is_active()) {
|
||||
GDScriptLanguage::get_singleton()->debug_break("Breakpoint Statement", true);
|
||||
}
|
||||
#endif
|
||||
@@ -1536,26 +1536,26 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
|
||||
line = _code_ptr[ip + 1];
|
||||
ip += 2;
|
||||
|
||||
if (ScriptDebugger::get_singleton()) {
|
||||
if (EngineDebugger::is_active()) {
|
||||
// line
|
||||
bool do_break = false;
|
||||
|
||||
if (ScriptDebugger::get_singleton()->get_lines_left() > 0) {
|
||||
if (EngineDebugger::get_script_debugger()->get_lines_left() > 0) {
|
||||
|
||||
if (ScriptDebugger::get_singleton()->get_depth() <= 0)
|
||||
ScriptDebugger::get_singleton()->set_lines_left(ScriptDebugger::get_singleton()->get_lines_left() - 1);
|
||||
if (ScriptDebugger::get_singleton()->get_lines_left() <= 0)
|
||||
if (EngineDebugger::get_script_debugger()->get_depth() <= 0)
|
||||
EngineDebugger::get_script_debugger()->set_lines_left(EngineDebugger::get_script_debugger()->get_lines_left() - 1);
|
||||
if (EngineDebugger::get_script_debugger()->get_lines_left() <= 0)
|
||||
do_break = true;
|
||||
}
|
||||
|
||||
if (ScriptDebugger::get_singleton()->is_breakpoint(line, source))
|
||||
if (EngineDebugger::get_script_debugger()->is_breakpoint(line, source))
|
||||
do_break = true;
|
||||
|
||||
if (do_break) {
|
||||
GDScriptLanguage::get_singleton()->debug_break("Breakpoint", true);
|
||||
}
|
||||
|
||||
ScriptDebugger::get_singleton()->line_poll();
|
||||
EngineDebugger::get_singleton()->line_poll();
|
||||
}
|
||||
}
|
||||
DISPATCH_OPCODE;
|
||||
@@ -1622,7 +1622,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
|
||||
// When it's the last resume it will postpone the exit from stack,
|
||||
// so the debugger knows which function triggered the resume of the next function (if any)
|
||||
if (!p_state || yielded) {
|
||||
if (ScriptDebugger::get_singleton())
|
||||
if (EngineDebugger::is_active())
|
||||
GDScriptLanguage::get_singleton()->exit_function();
|
||||
#endif
|
||||
|
||||
@@ -1884,7 +1884,7 @@ Variant GDScriptFunctionState::resume(const Variant &p_arg) {
|
||||
}
|
||||
|
||||
#ifdef DEBUG_ENABLED
|
||||
if (ScriptDebugger::get_singleton())
|
||||
if (EngineDebugger::is_active())
|
||||
GDScriptLanguage::get_singleton()->exit_function();
|
||||
if (state.stack_size) {
|
||||
//free stack
|
||||
|
||||
Reference in New Issue
Block a user