From 5be356b72f5b765cdec069c2c4a4011a42fabc47 Mon Sep 17 00:00:00 2001 From: Ignacio Etcheverry Date: Tue, 9 Jan 2018 17:19:03 +0100 Subject: [PATCH] Mono: Implement stack info for errors and exceptions --- core/script_debugger_local.cpp | 5 ++ core/script_debugger_local.h | 1 + core/script_debugger_remote.cpp | 83 ++++++++++---------- core/script_debugger_remote.h | 1 + core/script_language.h | 4 +- editor/script_editor_debugger.cpp | 15 ++-- modules/gdscript/gdscript.h | 4 +- modules/mono/csharp_script.cpp | 72 ++++++++++++++++- modules/mono/csharp_script.h | 4 +- modules/mono/glue/cs_files/DebuggingUtils.cs | 77 ++++++++++++++++++ modules/mono/mono_gd/gd_mono.cpp | 2 +- modules/mono/mono_gd/gd_mono_class.cpp | 14 ++-- modules/mono/mono_gd/gd_mono_class.h | 6 +- modules/mono/mono_gd/gd_mono_utils.cpp | 73 ++++++++++++++++- modules/mono/mono_gd/gd_mono_utils.h | 24 ++++-- 15 files changed, 311 insertions(+), 74 deletions(-) create mode 100644 modules/mono/glue/cs_files/DebuggingUtils.cs diff --git a/core/script_debugger_local.cpp b/core/script_debugger_local.cpp index 57463a662d81..0da377453e2a 100644 --- a/core/script_debugger_local.cpp +++ b/core/script_debugger_local.cpp @@ -294,6 +294,11 @@ void ScriptDebuggerLocal::send_message(const String &p_message, const Array &p_a print_line("MESSAGE: '" + p_message + "' - " + String(Variant(p_args))); } +void ScriptDebuggerLocal::send_error(const String &p_func, const String &p_file, int p_line, const String &p_err, const String &p_descr, ErrorHandlerType p_type, const Vector &p_stack_info) { + + print_line("ERROR: '" + (p_descr.empty() ? p_err : p_descr) + "'"); +} + ScriptDebuggerLocal::ScriptDebuggerLocal() { profiling = false; diff --git a/core/script_debugger_local.h b/core/script_debugger_local.h index c93120331dbb..c87bc90bb4dd 100644 --- a/core/script_debugger_local.h +++ b/core/script_debugger_local.h @@ -44,6 +44,7 @@ class ScriptDebuggerLocal : public ScriptDebugger { public: void debug(ScriptLanguage *p_script, bool p_can_continue); virtual void send_message(const String &p_message, const Array &p_args); + virtual void send_error(const String &p_func, const String &p_file, int p_line, const String &p_err, const String &p_descr, ErrorHandlerType p_type, const Vector &p_stack_info); virtual bool is_profiling() const { return profiling; } virtual void add_profiling_frame_data(const StringName &p_name, const Array &p_data) {} diff --git a/core/script_debugger_remote.cpp b/core/script_debugger_remote.cpp index e3dc8eb53a24..a297bb738fce 100644 --- a/core/script_debugger_remote.cpp +++ b/core/script_debugger_remote.cpp @@ -432,22 +432,6 @@ void ScriptDebuggerRemote::_err_handler(void *ud, const char *p_func, const char if (p_type == ERR_HANDLER_SCRIPT) return; //ignore script errors, those go through debugger - ScriptDebuggerRemote *sdr = (ScriptDebuggerRemote *)ud; - - OutputError oe; - oe.error = p_err; - oe.error_descr = p_descr; - oe.source_file = p_file; - oe.source_line = p_line; - oe.source_func = p_func; - oe.warning = p_type == ERR_HANDLER_WARNING; - uint64_t time = OS::get_singleton()->get_ticks_msec(); - oe.hr = time / 3600000; - oe.min = (time / 60000) % 60; - oe.sec = (time / 1000) % 60; - oe.msec = time % 1000; - Array cstack; - Vector si; for (int i = 0; i < ScriptServer::get_language_count(); i++) { @@ -456,32 +440,8 @@ void ScriptDebuggerRemote::_err_handler(void *ud, const char *p_func, const char break; } - cstack.resize(si.size() * 2); - for (int i = 0; i < si.size(); i++) { - String path; - int line = 0; - if (si[i].script.is_valid()) { - path = si[i].script->get_path(); - line = si[i].line; - } - cstack[i * 2 + 0] = path; - cstack[i * 2 + 1] = line; - } - - oe.callstack = cstack; - - sdr->mutex->lock(); - - if (!sdr->locking && sdr->tcp_client->is_connected_to_host()) { - - if (sdr->errors.size() >= sdr->max_errors_per_frame) { - sdr->n_errors_dropped++; - } else { - sdr->errors.push_back(oe); - } - } - - sdr->mutex->unlock(); + ScriptDebuggerRemote *sdr = (ScriptDebuggerRemote *)ud; + sdr->send_error(p_func, p_file, p_line, p_err, p_descr, p_type, si); } bool ScriptDebuggerRemote::_parse_live_edit(const Array &p_command) { @@ -928,6 +888,45 @@ void ScriptDebuggerRemote::send_message(const String &p_message, const Array &p_ mutex->unlock(); } +void ScriptDebuggerRemote::send_error(const String &p_func, const String &p_file, int p_line, const String &p_err, const String &p_descr, ErrorHandlerType p_type, const Vector &p_stack_info) { + + OutputError oe; + oe.error = p_err; + oe.error_descr = p_descr; + oe.source_file = p_file; + oe.source_line = p_line; + oe.source_func = p_func; + oe.warning = p_type == ERR_HANDLER_WARNING; + uint64_t time = OS::get_singleton()->get_ticks_msec(); + oe.hr = time / 3600000; + oe.min = (time / 60000) % 60; + oe.sec = (time / 1000) % 60; + oe.msec = time % 1000; + Array cstack; + + cstack.resize(p_stack_info.size() * 3); + for (int i = 0; i < p_stack_info.size(); i++) { + cstack[i * 3 + 0] = p_stack_info[i].file; + cstack[i * 3 + 1] = p_stack_info[i].func; + cstack[i * 3 + 2] = p_stack_info[i].line; + } + + oe.callstack = cstack; + + mutex->lock(); + + if (!locking && tcp_client->is_connected_to_host()) { + + if (errors.size() >= max_errors_per_frame) { + n_errors_dropped++; + } else { + errors.push_back(oe); + } + } + + mutex->unlock(); +} + void ScriptDebuggerRemote::_print_handler(void *p_this, const String &p_string, bool p_error) { ScriptDebuggerRemote *sdr = (ScriptDebuggerRemote *)p_this; diff --git a/core/script_debugger_remote.h b/core/script_debugger_remote.h index 924d5de2c4cd..2c4e29f172b0 100644 --- a/core/script_debugger_remote.h +++ b/core/script_debugger_remote.h @@ -157,6 +157,7 @@ public: virtual void request_quit(); virtual void send_message(const String &p_message, const Array &p_args); + virtual void send_error(const String &p_func, const String &p_file, int p_line, const String &p_err, const String &p_descr, ErrorHandlerType p_type, const Vector &p_stack_info); virtual void set_request_scene_tree_message_func(RequestSceneTreeMessageFunc p_func, void *p_udata); virtual void set_live_edit_funcs(LiveEditFuncs *p_funcs); diff --git a/core/script_language.h b/core/script_language.h index 6bf2129f9b4a..66614a293c1f 100644 --- a/core/script_language.h +++ b/core/script_language.h @@ -254,7 +254,8 @@ public: virtual String debug_parse_stack_level_expression(int p_level, const String &p_expression, int p_max_subitems = -1, int p_max_depth = -1) = 0; struct StackInfo { - Ref