Overview
Comment: | Only use _Unwind_Backtrace() if we have DWARF EH. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
2bdac84cf3a962423a6f134be2a0f32f |
User & Date: | js on 2013-08-20 19:03:44 |
Other Links: | manifest | tags |
Context
2013-08-22
| ||
12:38 | Fix ObjFW.h. check-in: cbe0df82d9 user: js tags: trunk | |
2013-08-20
| ||
19:03 | Only use _Unwind_Backtrace() if we have DWARF EH. check-in: 2bdac84cf3 user: js tags: trunk | |
2013-08-15
| ||
20:23 | OFZIPArchiveEntry: Export the extra field. check-in: bf0db50a84 user: js tags: trunk | |
Changes
Modified src/exceptions/OFException.m from [84994201ec] to [9b10a5e2e6].
︙ | ︙ | |||
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | #import "autorelease.h" #if defined(_WIN32) && defined(OF_HAVE_SOCKETS) # include <errno.h> # include <winerror.h> #endif struct _Unwind_Context; typedef enum { _URC_OK = 0, _URC_END_OF_STACK = 5 }_Unwind_Reason_Code; struct backtrace_ctx { void **backtrace; uint_fast8_t i; }; extern _Unwind_Reason_Code _Unwind_Backtrace( _Unwind_Reason_Code(*)(struct _Unwind_Context*, void*), void*); | > | | | | | | > | 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | #import "autorelease.h" #if defined(_WIN32) && defined(OF_HAVE_SOCKETS) # include <errno.h> # include <winerror.h> #endif #ifdef HAVE_DWARF_EXCEPTIONS struct _Unwind_Context; typedef enum { _URC_OK = 0, _URC_END_OF_STACK = 5 }_Unwind_Reason_Code; struct backtrace_ctx { void **backtrace; uint_fast8_t i; }; extern _Unwind_Reason_Code _Unwind_Backtrace( _Unwind_Reason_Code(*)(struct _Unwind_Context*, void*), void*); # if defined(__arm__) || defined(__ARM__) extern int _Unwind_VRS_Get(struct _Unwind_Context*, int, uint32_t, int, void*); # else extern uintptr_t _Unwind_GetIP(struct _Unwind_Context*); # 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__) uintptr_t ip; _Unwind_VRS_Get(ctx, 0, 15, 0, &ip); bt->backtrace[bt->i++] = (void*)(ip & ~1); # else bt->backtrace[bt->i++] = (void*)_Unwind_GetIP(ctx); # endif return _URC_OK; } return _URC_END_OF_STACK; } #endif #if defined(_WIN32) && defined(OF_HAVE_SOCKETS) int of_wsaerr_to_errno(int wsaerr) { switch (wsaerr) { case WSAEACCES: |
︙ | ︙ | |||
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | @implementation OFException + (instancetype)exception { return [[[self alloc] init] autorelease]; } - init { struct backtrace_ctx ctx; self = [super init]; ctx.backtrace = _backtrace; ctx.i = 0; _Unwind_Backtrace(backtrace_callback, &ctx); return self; } - (OFString*)description { return [OFString stringWithFormat: @"An exception of type %@ occurred!", [self class]]; } - (OFArray*)backtrace { OFMutableArray *backtrace = [OFMutableArray array]; void *pool = objc_autoreleasePoolPush(); uint_fast8_t i; for (i = 0; i < OF_BACKTRACE_SIZE && _backtrace[i] != NULL; i++) { | > > > | | > > > | 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | @implementation OFException + (instancetype)exception { return [[[self alloc] init] autorelease]; } #ifdef HAVE_DWARF_EXCEPTIONS - init { struct backtrace_ctx ctx; self = [super init]; ctx.backtrace = _backtrace; 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 Dl_info info; if (dladdr(_backtrace[i], &info)) { ptrdiff_t offset = (char*)_backtrace[i] - (char*)info.dli_saddr; if (info.dli_sname == NULL) info.dli_sname = "??"; [backtrace addObject: [OFString stringWithFormat: @"%p <%s+%td> at %s", _backtrace[i], info.dli_sname, offset, info.dli_fname]]; } else # endif [backtrace addObject: [OFString stringWithFormat: @"%p", _backtrace[i]]]; } objc_autoreleasePoolPop(pool); [backtrace makeImmutable]; return backtrace; #else return nil; #endif } @end |