Index: src/exceptions/OFException.m ================================================================== --- src/exceptions/OFException.m +++ src/exceptions/OFException.m @@ -33,10 +33,11 @@ #if defined(_WIN32) && defined(OF_HAVE_SOCKETS) # include # include #endif +#ifdef HAVE_DWARF_EXCEPTIONS struct _Unwind_Context; typedef enum { _URC_OK = 0, _URC_END_OF_STACK = 5 }_Unwind_Reason_Code; @@ -46,35 +47,36 @@ uint_fast8_t i; }; extern _Unwind_Reason_Code _Unwind_Backtrace( _Unwind_Reason_Code(*)(struct _Unwind_Context*, void*), void*); -#if defined(__arm__) || defined(__ARM__) +# if defined(__arm__) || defined(__ARM__) extern int _Unwind_VRS_Get(struct _Unwind_Context*, int, uint32_t, int, void*); -#else +# else extern uintptr_t _Unwind_GetIP(struct _Unwind_Context*); -#endif +# endif static _Unwind_Reason_Code backtrace_callback(struct _Unwind_Context *ctx, void *data) { struct backtrace_ctx *bt = data; if (bt->i < OF_BACKTRACE_SIZE) { -#if defined(__arm__) || defined(__ARM__) +# if defined(__arm__) || defined(__ARM__) uintptr_t ip; _Unwind_VRS_Get(ctx, 0, 15, 0, &ip); bt->backtrace[bt->i++] = (void*)(ip & ~1); -#else +# else bt->backtrace[bt->i++] = (void*)_Unwind_GetIP(ctx); -#endif +# endif return _URC_OK; } return _URC_END_OF_STACK; } +#endif #if defined(_WIN32) && defined(OF_HAVE_SOCKETS) int of_wsaerr_to_errno(int wsaerr) { @@ -107,10 +109,11 @@ + (instancetype)exception { return [[[self alloc] init] autorelease]; } +#ifdef HAVE_DWARF_EXCEPTIONS - init { struct backtrace_ctx ctx; self = [super init]; @@ -119,25 +122,27 @@ ctx.i = 0; _Unwind_Backtrace(backtrace_callback, &ctx); return self; } +#endif - (OFString*)description { return [OFString stringWithFormat: @"An exception of type %@ occurred!", [self class]]; } - (OFArray*)backtrace { +#ifdef HAVE_DWARF_EXCEPTIONS OFMutableArray *backtrace = [OFMutableArray array]; void *pool = objc_autoreleasePoolPush(); uint_fast8_t i; for (i = 0; i < OF_BACKTRACE_SIZE && _backtrace[i] != NULL; i++) { -#ifdef HAVE_DLADDR +# ifdef HAVE_DLADDR Dl_info info; if (dladdr(_backtrace[i], &info)) { ptrdiff_t offset = (char*)_backtrace[i] - (char*)info.dli_saddr; @@ -149,17 +154,20 @@ [OFString stringWithFormat: @"%p <%s+%td> at %s", _backtrace[i], info.dli_sname, offset, info.dli_fname]]; } else -#endif +# endif [backtrace addObject: [OFString stringWithFormat: @"%p", _backtrace[i]]]; } objc_autoreleasePoolPop(pool); [backtrace makeImmutable]; return backtrace; +#else + return nil; +#endif } @end