From e538ecf3d7cc78de8933918464f39f35107a8bc2 Mon Sep 17 00:00:00 2001 From: Anairkoen Schno Date: Thu, 27 Feb 2020 21:07:27 -0600 Subject: [PATCH] Fixed uncaught error printing --- Doorstop/Proxy/main.c | 18 ++++++++++-------- Doorstop/Proxy/mono.h | 2 ++ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/Doorstop/Proxy/main.c b/Doorstop/Proxy/main.c index a5be31dd..d78db0f4 100644 --- a/Doorstop/Proxy/main.c +++ b/Doorstop/Proxy/main.c @@ -62,13 +62,14 @@ void unhandledException(void* exc, void* data) DEBUG_BREAK; LOG("An error occurred stringifying uncaught error: %s\n", str); - size_t len = MultiByteToWideChar(CP_UTF8, 0, str, -1, NULL, 0); + /*size_t len = MultiByteToWideChar(CP_UTF8, 0, str, -1, NULL, 0); wchar_t* wstr = memalloc(sizeof(wchar_t) * len); - MultiByteToWideChar(CP_UTF8, 0, str, -1, wstr, len); + MultiByteToWideChar(CP_UTF8, 0, str, -1, wstr, len);*/ + wchar_t* wstr = mono_string_to_utf16(monostr); - ASSERT_F(FALSE, L"Uncaught exception; stringify failed: %s", wstr); + ASSERT_F(FALSE, L"Uncaught exception; stringify failed: %wS", wstr); - memfree(wstr); + mono_free(wstr); mono_free(str); } #else @@ -80,17 +81,18 @@ void unhandledException(void* exc, void* data) DEBUG_BREAK; LOG("Uncaught exception: %s\n", str); - size_t len = MultiByteToWideChar(CP_UTF8, 0, str, -1, NULL, 0); + /*size_t len = MultiByteToWideChar(CP_UTF8, 0, str, -1, NULL, 0); wchar_t* wstr = memalloc(sizeof(wchar_t) * len); - MultiByteToWideChar(CP_UTF8, 0, str, -1, wstr, len); + MultiByteToWideChar(CP_UTF8, 0, str, -1, wstr, len);*/ + wchar_t* wstr = mono_string_to_utf16(mstr); #ifdef _VERBOSE ASSERT(FALSE, L"Uncaught exception; see doorstop.log for details"); #else - ASSERT_F(FALSE, L"Uncaught exception: %s", wstr); + ASSERT_F(FALSE, L"Uncaught exception: %wS", wstr); #endif - memfree(wstr); + mono_free(wstr); mono_free(str); ReleaseMutex(unhandledMutex); diff --git a/Doorstop/Proxy/mono.h b/Doorstop/Proxy/mono.h index f218adbe..6eb41f41 100644 --- a/Doorstop/Proxy/mono.h +++ b/Doorstop/Proxy/mono.h @@ -64,6 +64,7 @@ void* (*mono_object_to_string)(void* obj, void** exc); void (*mono_dllmap_insert)(void* assemblyImage, const char* dll, const char* func, const char* tdll, const char* tfunc); char* (*mono_string_to_utf8)(void* str); +wchar_t* (*mono_string_to_utf16)(void* str); void (*mono_free)(void*); /* Installs a function which is called when the runtime encounters an unhandled exception. @@ -102,6 +103,7 @@ inline void loadMonoFunctions(HMODULE monoLib) GET_MONO_PROC(mono_array_addr_with_size); GET_MONO_PROC(mono_object_to_string); GET_MONO_PROC(mono_string_to_utf8); + GET_MONO_PROC(mono_string_to_utf16); GET_MONO_PROC(mono_free); GET_MONO_PROC(mono_dllmap_insert); GET_MONO_PROC(mono_install_unhandled_exception_hook);