diff options
author | kobewi <kobewi4e@gmail.com> | 2024-09-30 17:48:27 +0200 |
---|---|---|
committer | kobewi <kobewi4e@gmail.com> | 2024-10-01 15:36:09 +0200 |
commit | 645abdbb801c29ba93adefb01e422dc66fb22fc2 (patch) | |
tree | 4ec0f41c819b576328edd288a72fb7b5844c387d /core/debugger | |
parent | e3213aaef5e0e72b8272e65d989d3d8222be17ca (diff) | |
download | redot-engine-645abdbb801c29ba93adefb01e422dc66fb22fc2.tar.gz |
Add expression evaluater to debugger (REPL)
Co-authored-by: rohanrhu <rohanrhu2@gmail.com>
Diffstat (limited to 'core/debugger')
-rw-r--r-- | core/debugger/remote_debugger.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/core/debugger/remote_debugger.cpp b/core/debugger/remote_debugger.cpp index e2ed7245a2..fc1b7b74f9 100644 --- a/core/debugger/remote_debugger.cpp +++ b/core/debugger/remote_debugger.cpp @@ -37,6 +37,7 @@ #include "core/debugger/script_debugger.h" #include "core/input/input.h" #include "core/io/resource_loader.h" +#include "core/math/expression.h" #include "core/object/script_language.h" #include "core/os/os.h" #include "servers/display_server.h" @@ -529,6 +530,41 @@ void RemoteDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) { } else if (command == "set_skip_breakpoints") { ERR_FAIL_COND(data.is_empty()); script_debugger->set_skip_breakpoints(data[0]); + } else if (command == "evaluate") { + String expression_str = data[0]; + int frame = data[1]; + + ScriptInstance *breaked_instance = script_debugger->get_break_language()->debug_get_stack_level_instance(frame); + if (!breaked_instance) { + break; + } + + List<String> locals; + List<Variant> local_vals; + + script_debugger->get_break_language()->debug_get_stack_level_locals(frame, &locals, &local_vals); + ERR_FAIL_COND(locals.size() != local_vals.size()); + + PackedStringArray locals_vector; + for (const String &S : locals) { + locals_vector.append(S); + } + + Array local_vals_array; + for (const Variant &V : local_vals) { + local_vals_array.append(V); + } + + Expression expression; + expression.parse(expression_str, locals_vector); + const Variant return_val = expression.execute(local_vals_array, breaked_instance->get_owner()); + + DebuggerMarshalls::ScriptStackVariable stvar; + stvar.name = expression_str; + stvar.value = return_val; + stvar.type = 3; + + send_message("evaluation_return", stvar.serialize()); } else { bool captured = false; ERR_CONTINUE(_try_capture(command, data, captured) != OK); |