Skip to content

Commit

Permalink
Implement autoload evaluation in evaluator
Browse files Browse the repository at this point in the history
Evaluating in watches still crashes
  • Loading branch information
rxlecky committed Apr 10, 2020
1 parent 6db0424 commit 093a366
Show file tree
Hide file tree
Showing 13 changed files with 43 additions and 13 deletions.
17 changes: 9 additions & 8 deletions core/script_language.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -435,9 +435,6 @@ void ScriptDebugger::set_watch_expression(int p_stack_level, int p_index, const

WatchData &watch = watches.write[p_index];
ScriptLanguage *const lang = get_break_language();

ERR_FAIL_COND(lang->debug_get_stack_level_count() <= 0)

ExpressionContext context = get_expression_context(p_stack_level);

if (watch.expression->parse(p_expression, context.input_names) != OK) {
Expand Down Expand Up @@ -612,13 +609,19 @@ bool ScriptDebugger::_evaluate_watches(int p_stack_level, int p_watch) {
}

ScriptDebugger::ExpressionContext ScriptDebugger::get_expression_context(int p_stack_level) {
ERR_FAIL_INDEX_V(p_stack_level, break_lang->debug_get_stack_level_count(), ExpressionContext());
ERR_FAIL_COND_V(p_stack_level >= break_lang->debug_get_stack_level_count(), ExpressionContext());
ExpressionContext context;

List<Variant> vals;
List<String> vars;

break_lang->debug_get_stack_level_locals(p_stack_level, &vars, &vals);
if (p_stack_level > 0) {
context.base = break_lang->debug_get_stack_level_instance(p_stack_level)->get_owner();

break_lang->debug_get_stack_level_locals(p_stack_level, &vars, &vals);
}

break_lang->debug_get_named_globals(&vars, &vals);

ERR_FAIL_COND_V(vals.size() != vars.size(), ExpressionContext());

Expand All @@ -641,13 +644,11 @@ ScriptDebugger::ExpressionContext ScriptDebugger::get_expression_context(int p_s
} while (vars_it);
}

context.base = break_lang->debug_get_stack_level_instance(p_stack_level)->get_owner();

return context;
}

bool ScriptDebugger::evaluate_expression(int p_level, const String &p_expression, String &p_result) {
ERR_FAIL_INDEX_V(p_level, break_lang->debug_get_stack_level_count(), false);
ERR_FAIL_COND_V(p_level >= break_lang->debug_get_stack_level_count(), false);

Expression expr;
ExpressionContext context = get_expression_context(p_level);
Expand Down
1 change: 1 addition & 0 deletions core/script_language.h
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ class ScriptLanguage {
virtual void debug_get_stack_level_members(int p_level, List<String> *p_members, List<Variant> *p_values, int p_max_subitems = -1, int p_max_depth = -1) = 0;
virtual ScriptInstance *debug_get_stack_level_instance(int p_level) { return NULL; }
virtual void debug_get_globals(List<String> *p_globals, List<Variant> *p_values, int p_max_subitems = -1, int p_max_depth = -1) = 0;
virtual void debug_get_named_globals(List<String> *p_globals, List<Variant> *p_values) = 0;

struct StackInfo {
String file;
Expand Down
14 changes: 9 additions & 5 deletions editor/script_editor_debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -498,10 +498,14 @@ bool ScriptEditorDebugger::_execute_expression(const String &p_expression) {
ERR_FAIL_COND_V(connection.is_null(), false);
ERR_FAIL_COND_V(!connection->is_connected_to_host(), false);

TreeItem *ti = stack_dump->get_selected();
if (!p_expression.empty() && ti) {
Dictionary d = ti->get_metadata(0);
int frame = d["frame"];
if (!p_expression.empty()) {
int frame = -1;
TreeItem *ti = stack_dump->get_selected();
if (ti) {
Dictionary d = ti->get_metadata(0);
frame = d["frame"];
}

Array msg;
msg.push_back("execute_expression");
msg.push_back(frame);
Expand All @@ -514,7 +518,7 @@ bool ScriptEditorDebugger::_execute_expression(const String &p_expression) {
}

void ScriptEditorDebugger::_print_expression(const String &p_expression, const String &p_error_text) {
if (connection.is_null() || !connection->is_connected_to_host() || !breaked) {
if (connection.is_null() || !connection->is_connected_to_host()) {
evaluator->set_result(p_error_text, true);
} else {
if (!_execute_expression(p_expression)) {
Expand Down
2 changes: 2 additions & 0 deletions main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1675,6 +1675,7 @@ bool Main::start() {
if (global_var) {
for (int i = 0; i < ScriptServer::get_language_count(); i++) {
ScriptServer::get_language(i)->add_global_constant(name, Variant());
ScriptServer::get_language(i)->add_named_global_constant(name, Variant());
}
}
}
Expand Down Expand Up @@ -1723,6 +1724,7 @@ bool Main::start() {
if (global_var) {
for (int i = 0; i < ScriptServer::get_language_count(); i++) {
ScriptServer::get_language(i)->add_global_constant(name, n);
ScriptServer::get_language(i)->add_named_global_constant(name, n);
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions modules/gdnative/nativescript/nativescript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1161,6 +1161,8 @@ void NativeScriptLanguage::debug_get_stack_level_members(int p_level, List<Strin
}
void NativeScriptLanguage::debug_get_globals(List<String> *p_locals, List<Variant> *p_values, int p_max_subitems, int p_max_depth) {
}
void NativeScriptLanguage::debug_get_named_globals(List<String> *p_locals, List<Variant> *p_values) {
}
// Debugging stuff end.

void NativeScriptLanguage::reload_all_scripts() {
Expand Down
1 change: 1 addition & 0 deletions modules/gdnative/nativescript/nativescript.h
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ class NativeScriptLanguage : public ScriptLanguage {
virtual void debug_get_stack_level_locals(int p_level, List<String> *p_locals, List<Variant> *p_values, int p_max_subitems, int p_max_depth);
virtual void debug_get_stack_level_members(int p_level, List<String> *p_members, List<Variant> *p_values, int p_max_subitems, int p_max_depth);
virtual void debug_get_globals(List<String> *p_locals, List<Variant> *p_values, int p_max_subitems, int p_max_depth);
virtual void debug_get_named_globals(List<String> *p_locals, List<Variant> *p_values);
virtual void reload_all_scripts();
virtual void reload_tool_script(const Ref<Script> &p_script, bool p_soft_reload);
virtual void get_recognized_extensions(List<String> *p_extensions) const;
Expand Down
3 changes: 3 additions & 0 deletions modules/gdnative/pluginscript/pluginscript_language.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,9 @@ void PluginScriptLanguage::debug_get_globals(List<String> *p_locals, List<Varian
}
}

void PluginScriptLanguage::debug_get_named_globals(List<String> *p_globals, List<Variant> *p_values) {
}

void PluginScriptLanguage::reload_all_scripts() {
// TODO
}
Expand Down
1 change: 1 addition & 0 deletions modules/gdnative/pluginscript/pluginscript_language.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ class PluginScriptLanguage : public ScriptLanguage {
virtual void debug_get_stack_level_locals(int p_level, List<String> *p_locals, List<Variant> *p_values, int p_max_subitems = -1, int p_max_depth = -1);
virtual void debug_get_stack_level_members(int p_level, List<String> *p_members, List<Variant> *p_values, int p_max_subitems = -1, int p_max_depth = -1);
virtual void debug_get_globals(List<String> *p_locals, List<Variant> *p_values, int p_max_subitems = -1, int p_max_depth = -1);
virtual void debug_get_named_globals(List<String> *p_globals, List<Variant> *p_values);

// virtual Vector<StackInfo> debug_get_current_stack_info() { return Vector<StackInfo>(); }

Expand Down
1 change: 1 addition & 0 deletions modules/gdscript/gdscript.h
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,7 @@ class GDScriptLanguage : public ScriptLanguage {
virtual void debug_get_stack_level_members(int p_level, List<String> *p_members, List<Variant> *p_values, int p_max_subitems = -1, int p_max_depth = -1);
virtual ScriptInstance *debug_get_stack_level_instance(int p_level);
virtual void debug_get_globals(List<String> *p_globals, List<Variant> *p_values, int p_max_subitems = -1, int p_max_depth = -1);
virtual void debug_get_named_globals(List<String> *p_globals, List<Variant> *p_values);

virtual void reload_all_scripts();
virtual void reload_tool_script(const Ref<Script> &p_script, bool p_soft_reload);
Expand Down
8 changes: 8 additions & 0 deletions modules/gdscript/gdscript_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,14 @@ void GDScriptLanguage::debug_get_globals(List<String> *p_globals, List<Variant>
}
}

void GDScriptLanguage::debug_get_named_globals(List<String> *p_globals, List<Variant> *p_values) {

for (const Map<StringName, Variant>::Element *E = get_named_globals_map().front(); E; E = E->next()) {
p_globals->push_back(E->key());
p_values->push_back(E->value());
}
}

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

p_extensions->push_back("gd");
Expand Down
2 changes: 2 additions & 0 deletions modules/visual_script/visual_script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2676,6 +2676,8 @@ void VisualScriptLanguage::debug_get_globals(List<String> *p_locals, List<Varian
//no globals are really reachable in gdscript
}

void VisualScriptLanguage::debug_get_named_globals(List<String> *p_globals, List<Variant> *p_values) {}

void VisualScriptLanguage::reload_all_scripts() {
}
void VisualScriptLanguage::reload_tool_script(const Ref<Script> &p_script, bool p_soft_reload) {
Expand Down
1 change: 1 addition & 0 deletions modules/visual_script/visual_script.h
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,7 @@ class VisualScriptLanguage : public ScriptLanguage {
virtual void debug_get_stack_level_locals(int p_level, List<String> *p_locals, List<Variant> *p_values, int p_max_subitems = -1, int p_max_depth = -1);
virtual void debug_get_stack_level_members(int p_level, List<String> *p_members, List<Variant> *p_values, int p_max_subitems = -1, int p_max_depth = -1);
virtual void debug_get_globals(List<String> *p_locals, List<Variant> *p_values, int p_max_subitems = -1, int p_max_depth = -1);
virtual void debug_get_named_globals(List<String> *p_locals, List<Variant> *p_values);

virtual void reload_all_scripts();
virtual void reload_tool_script(const Ref<Script> &p_script, bool p_soft_reload);
Expand Down
3 changes: 3 additions & 0 deletions scene/debugger/script_debugger_remote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,9 @@ void ScriptDebuggerRemote::_poll_events() {
} else if (command == "request_video_mem") {

_send_video_memory();
} else if (command == "execute_expression") {

_execute_expression(cmd[1], cmd[2]);
} else if (command == "watch_tracking") {

int index = cmd[1];
Expand Down

0 comments on commit 093a366

Please sign in to comment.