[utils,unwind] log _Unwind_Backtrace failure

This commit is contained in:
Armin Novak 2024-05-29 09:27:53 +02:00
parent 1dcac1618c
commit b19d9619f8
No known key found for this signature in database
GPG Key ID: 2CF4A2D2D3D72105

View File

@ -29,8 +29,13 @@
#include <winpr/string.h>
#include "debug.h"
#include <winpr/wlog.h>
#include "../log.h"
#include <dlfcn.h>
#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: