[mono] get stacktraces for all inner exceptions

(cherry picked from commit 89af6c2cd7)
This commit is contained in:
Paul Joannon 2018-02-24 16:36:48 +01:00 committed by Hein-Pieter van Braam
parent c0386f0124
commit 58a7d78c22
1 changed files with 43 additions and 24 deletions

View File

@ -420,6 +420,15 @@ void print_unhandled_exception(MonoObject *p_exc, bool p_recursion_caution) {
if (!ScriptDebugger::get_singleton()) if (!ScriptDebugger::get_singleton())
return; return;
ScriptLanguage::StackInfo separator;
separator.file = "";
separator.func = "--- " + TTR("End of inner exception stack trace") + " ---";
separator.line = 0;
Vector<ScriptLanguage::StackInfo> si;
String exc_msg = "";
while (p_exc != NULL) {
GDMonoClass *st_klass = CACHED_CLASS(System_Diagnostics_StackTrace); GDMonoClass *st_klass = CACHED_CLASS(System_Diagnostics_StackTrace);
MonoObject *stack_trace = mono_object_new(mono_domain_get(), st_klass->get_mono_ptr()); MonoObject *stack_trace = mono_object_new(mono_domain_get(), st_klass->get_mono_ptr());
@ -442,15 +451,25 @@ void print_unhandled_exception(MonoObject *p_exc, bool p_recursion_caution) {
} }
} }
Vector<ScriptLanguage::StackInfo> si; Vector<ScriptLanguage::StackInfo> _si;
if (stack_trace != NULL && !p_recursion_caution) if (stack_trace != NULL && !p_recursion_caution) {
si = CSharpLanguage::get_singleton()->stack_trace_get_info(stack_trace); _si = CSharpLanguage::get_singleton()->stack_trace_get_info(stack_trace);
for (int i = _si.size() - 1; i >= 0; i--)
si.insert(0, _si[i]);
}
exc_msg += (exc_msg.length() > 0 ? " ---> " : "") + GDMonoUtils::get_exception_name_and_message(p_exc);
GDMonoProperty *p_prop = GDMono::get_singleton()->get_class(mono_object_get_class(p_exc))->get_property("InnerException");
p_exc = p_prop != NULL ? p_prop->get_value(p_exc) : NULL;
if (p_exc != NULL)
si.insert(0, separator);
}
String file = si.size() ? si[0].file : __FILE__; String file = si.size() ? si[0].file : __FILE__;
String func = si.size() ? si[0].func : FUNCTION_STR; String func = si.size() ? si[0].func : FUNCTION_STR;
int line = si.size() ? si[0].line : __LINE__; int line = si.size() ? si[0].line : __LINE__;
String error_msg = "Unhandled exception"; String error_msg = "Unhandled exception";
String exc_msg = GDMonoUtils::get_exception_name_and_message(p_exc);
ScriptDebugger::get_singleton()->send_error(func, file, line, error_msg, exc_msg, ERR_HANDLER_ERROR, si); ScriptDebugger::get_singleton()->send_error(func, file, line, error_msg, exc_msg, ERR_HANDLER_ERROR, si);
#endif #endif