Skip to content

Commit 4d43531

Browse files
committed
Merge pull request godotengine#97218 from wenqiangwang/local_debuggger_expr_evalulation
Add support for `print` command in local (command line `-d`) debugger
2 parents 179321a + 9a94353 commit 4d43531

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

core/debugger/local_debugger.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,10 @@ void LocalDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) {
208208
print_variables(members, values, variable_prefix);
209209

210210
} else if (line.begins_with("p") || line.begins_with("print")) {
211-
if (line.get_slice_count(" ") <= 1) {
212-
print_line("Usage: print <expre>");
211+
if (line.find_char(' ') < 0) {
212+
print_line("Usage: print <expression>");
213213
} else {
214-
String expr = line.get_slicec(' ', 2);
214+
String expr = line.split(" ", true, 1)[1];
215215
String res = script_lang->debug_parse_stack_level_expression(current_frame, expr);
216216
print_line(res);
217217
}

modules/gdscript/gdscript_editor.cpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include "core/config/engine.h"
4444
#include "core/core_constants.h"
4545
#include "core/io/file_access.h"
46+
#include "core/math/expression.h"
4647

4748
#ifdef TOOLS_ENABLED
4849
#include "core/config/project_settings.h"
@@ -427,7 +428,30 @@ void GDScriptLanguage::debug_get_globals(List<String> *p_globals, List<Variant>
427428
}
428429

429430
String GDScriptLanguage::debug_parse_stack_level_expression(int p_level, const String &p_expression, int p_max_subitems, int p_max_depth) {
430-
return "";
431+
List<String> names;
432+
List<Variant> values;
433+
debug_get_stack_level_locals(p_level, &names, &values, p_max_subitems, p_max_depth);
434+
435+
Vector<String> name_vector;
436+
for (const String &name : names) {
437+
name_vector.push_back(name);
438+
}
439+
440+
Array value_array;
441+
for (const Variant &value : values) {
442+
value_array.push_back(value);
443+
}
444+
445+
Expression expression;
446+
if (expression.parse(p_expression, name_vector) == OK) {
447+
ScriptInstance *instance = debug_get_stack_level_instance(p_level);
448+
if (instance) {
449+
Variant return_val = expression.execute(value_array, instance->get_owner());
450+
return return_val.get_construct_string();
451+
}
452+
}
453+
454+
return String();
431455
}
432456

433457
void GDScriptLanguage::get_recognized_extensions(List<String> *p_extensions) const {

0 commit comments

Comments
 (0)