From b19d9619f86e746e544250525025bfdb99c409db Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Wed, 29 May 2024 09:27:53 +0200 Subject: [PATCH] [utils,unwind] log _Unwind_Backtrace failure --- winpr/libwinpr/utils/unwind/debug.c | 65 ++++++++++++++++++++--------- 1 file changed, 45 insertions(+), 20 deletions(-) diff --git a/winpr/libwinpr/utils/unwind/debug.c b/winpr/libwinpr/utils/unwind/debug.c index c285a0081..314c07d1d 100644 --- a/winpr/libwinpr/utils/unwind/debug.c +++ b/winpr/libwinpr/utils/unwind/debug.c @@ -29,8 +29,13 @@ #include #include "debug.h" +#include +#include "../log.h" + #include +#define TAG WINPR_TAG("utils.unwind") + typedef struct { uintptr_t pc; @@ -44,31 +49,46 @@ typedef struct unwind_info_t* info; } unwind_context_t; -static const char* unwind_reason_str(_Unwind_Reason_Code code) { - switch(code) { - case _URC_NO_REASON: return "_URC_NO_REASON"; -#if defined(__arm__) && !defined(__USING_SJLJ_EXCEPTIONS__) && \ - !defined(__ARM_DWARF_EH__) && !defined(__SEH__) - case _URC_OK: return "_URC_OK"; +static const char* unwind_reason_str(_Unwind_Reason_Code code) +{ + switch (code) + { +#if defined(__arm__) && !defined(__USING_SJLJ_EXCEPTIONS__) && !defined(__ARM_DWARF_EH__) && \ + !defined(__SEH__) + case _URC_OK: + return "_URC_OK"; +#else + case _URC_NO_REASON: + return "_URC_NO_REASON"; #endif - case _URC_FOREIGN_EXCEPTION_CAUGHT: return "_URC_FOREIGN_EXCEPTION_CAUGHT"; - case _URC_FATAL_PHASE2_ERROR: return "_URC_FATAL_PHASE2_ERROR"; - case _URC_FATAL_PHASE1_ERROR: return "_URC_FATAL_PHASE1_ERROR"; - case _URC_NORMAL_STOP: return "_URC_NORMAL_STOP"; - case _URC_END_OF_STACK: return "_URC_END_OF_STACK"; - case _URC_HANDLER_FOUND: return "_URC_HANDLER_FOUND"; - case _URC_INSTALL_CONTEXT: return "_URC_INSTALL_CONTEXT"; - case _URC_CONTINUE_UNWIND: return "_URC_CONTINUE_UNWIND"; -#if defined(__arm__) && !defined(__USING_SJLJ_EXCEPTIONS__) && \ - !defined(__ARM_DWARF_EH__) && !defined(__SEH__) - case _URC_FAILURE: return "_URC_FAILURE"; + case _URC_FOREIGN_EXCEPTION_CAUGHT: + return "_URC_FOREIGN_EXCEPTION_CAUGHT"; + case _URC_FATAL_PHASE2_ERROR: + return "_URC_FATAL_PHASE2_ERROR"; + case _URC_FATAL_PHASE1_ERROR: + return "_URC_FATAL_PHASE1_ERROR"; + case _URC_NORMAL_STOP: + return "_URC_NORMAL_STOP"; + case _URC_END_OF_STACK: + return "_URC_END_OF_STACK"; + case _URC_HANDLER_FOUND: + return "_URC_HANDLER_FOUND"; + case _URC_INSTALL_CONTEXT: + return "_URC_INSTALL_CONTEXT"; + case _URC_CONTINUE_UNWIND: + return "_URC_CONTINUE_UNWIND"; +#if defined(__arm__) && !defined(__USING_SJLJ_EXCEPTIONS__) && !defined(__ARM_DWARF_EH__) && \ + !defined(__SEH__) + case _URC_FAILURE: + return "_URC_FAILURE"; #endif - default: - return "_URC_UNKNOWN"; + default: + return "_URC_UNKNOWN"; } } -static const char* unwind_reason_str_buffer(_Unwind_Reason_Code code, char* buffer, size_t size) { +static const char* unwind_reason_str_buffer(_Unwind_Reason_Code code, char* buffer, size_t size) +{ const char* str = unwind_reason_str(code); _snprintf(buffer, size, "%s [0x%02x]", str, code); return buffer; @@ -103,7 +123,12 @@ void* winpr_unwind_backtrace(DWORD size) rc = _Unwind_Backtrace(unwind_backtrace_callback, ctx); if (rc != _URC_END_OF_STACK) + { + char buffer[64] = { 0 }; + WLog_ERR(TAG, "_Unwind_Backtrace failed with %s", + unwind_reason_str_buffer(rc, buffer, sizeof(buffer))); goto fail; + } return ctx; fail: