28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
#import "OFArray.h"
#import "OFLocale.h"
#ifdef OF_HAVE_THREADS
# import "OFPlainMutex.h"
#endif
#import "OFString.h"
#import "OFSystemInfo.h"
#import "OFInitializationFailedException.h"
#import "OFLockFailedException.h"
#import "OFUnlockFailedException.h"
#if defined(OF_WINDOWS) && defined(OF_HAVE_SOCKETS)
# include <winerror.h>
|
>
|
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
#import "OFArray.h"
#import "OFLocale.h"
#ifdef OF_HAVE_THREADS
# import "OFPlainMutex.h"
#endif
#import "OFString.h"
#import "OFSystemInfo.h"
#import "OFValue.h"
#import "OFInitializationFailedException.h"
#import "OFLockFailedException.h"
#import "OFUnlockFailedException.h"
#if defined(OF_WINDOWS) && defined(OF_HAVE_SOCKETS)
# include <winerror.h>
|
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
|
#ifdef HAVE__UNWIND_BACKTRACE
static _Unwind_Reason_Code
backtraceCallback(struct _Unwind_Context *ctx, void *data)
{
struct BacktraceCtx *bt = data;
if (bt->i < OFBacktraceSize) {
# ifndef HAVE_ARM_EHABI_EXCEPTIONS
bt->backtrace[bt->i++] = (void *)_Unwind_GetIP(ctx);
# else
uintptr_t ip;
_Unwind_VRS_Get(ctx, 0, 15, 0, &ip);
bt->backtrace[bt->i++] = (void *)(ip & ~1);
|
|
|
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
|
#ifdef HAVE__UNWIND_BACKTRACE
static _Unwind_Reason_Code
backtraceCallback(struct _Unwind_Context *ctx, void *data)
{
struct BacktraceCtx *bt = data;
if (bt->i < OFStackTraceSize) {
# ifndef HAVE_ARM_EHABI_EXCEPTIONS
bt->backtrace[bt->i++] = (void *)_Unwind_GetIP(ctx);
# else
uintptr_t ip;
_Unwind_VRS_Get(ctx, 0, 15, 0, &ip);
bt->backtrace[bt->i++] = (void *)(ip & ~1);
|
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
|
#ifdef HAVE__UNWIND_BACKTRACE
- (instancetype)init
{
struct BacktraceCtx ctx;
self = [super init];
ctx.backtrace = _backtrace;
ctx.i = 0;
_Unwind_Backtrace(backtraceCallback, &ctx);
return self;
}
#endif
- (OFString *)description
{
return [OFString stringWithFormat:
@"An exception of type %@ occurred!", self.class];
}
- (OFArray OF_GENERIC(OFString *) *)backtrace
{
#ifdef HAVE__UNWIND_BACKTRACE
OFMutableArray OF_GENERIC(OFString *) *backtrace =
[OFMutableArray array];
void *pool = objc_autoreleasePoolPush();
for (uint8_t i = 0; i < OFBacktraceSize && _backtrace[i] != NULL; i++) {
# ifdef HAVE_DLADDR
Dl_info info;
if (dladdr(_backtrace[i], &info)) {
OFString *frame;
if (info.dli_sname != NULL) {
ptrdiff_t offset = (char *)_backtrace[i] -
(char *)info.dli_saddr;
frame = [OFString stringWithFormat:
@"%p <%s+%td> at %s",
_backtrace[i], info.dli_sname, offset,
info.dli_fname];
} else
frame = [OFString stringWithFormat:
@"%p <?" @"?> at %s",
_backtrace[i], info.dli_fname];
[backtrace addObject: frame];
} else
# endif
[backtrace addObject:
[OFString stringWithFormat: @"%p", _backtrace[i]]];
}
objc_autoreleasePoolPop(pool);
[backtrace makeImmutable];
return backtrace;
#else
return nil;
#endif
}
@end
|
|
|
|
>
|
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
|
|
>
|
|
<
|
|
>
>
|
<
|
|
<
|
|
|
|
|
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
|
#ifdef HAVE__UNWIND_BACKTRACE
- (instancetype)init
{
struct BacktraceCtx ctx;
self = [super init];
ctx.backtrace = _stackTrace;
ctx.i = 0;
_Unwind_Backtrace(backtraceCallback, &ctx);
return self;
}
#endif
- (OFString *)description
{
return [OFString stringWithFormat:
@"An exception of type %@ occurred!", self.class];
}
- (OFArray OF_GENERIC(OFValue *) *)stackTraceAddresses
{
#ifdef HAVE__UNWIND_BACKTRACE
OFMutableArray OF_GENERIC(OFValue *) *stackTrace =
[OFMutableArray array];
void *pool = objc_autoreleasePoolPush();
for (uint_fast8_t i = 0; i < OFStackTraceSize &&
_stackTrace[i] != NULL; i++)
[stackTrace addObject:
[OFValue valueWithPointer: _stackTrace[i]]];
objc_autoreleasePoolPop(pool);
[stackTrace makeImmutable];
return stackTrace;
#else
return nil;
#endif
}
- (OFArray OF_GENERIC(OFString *) *)stackTraceSymbols
{
#if defined(HAVE__UNWIND_BACKTRACE) && defined(HAVE_DLADDR)
OFMutableArray OF_GENERIC(OFString *) *stackTrace =
[OFMutableArray array];
void *pool = objc_autoreleasePoolPush();
for (uint_fast8_t i = 0; i < OFStackTraceSize &&
_stackTrace[i] != NULL; i++) {
Dl_info info;
if (dladdr(_stackTrace[i], &info)) {
ptrdiff_t offset = (char *)_stackTrace[i] -
(char *)info.dli_saddr;
OFString *frame;
if (info.dli_fname != NULL && info.dli_sname != NULL)
frame = [OFString stringWithFormat:
@"%s`%s+%td",
info.dli_fname, info.dli_sname, offset];
else if (info.dli_sname != NULL)
frame = [OFString stringWithFormat:
@"%s+%td", info.dli_sname, offset];
else if (info.dli_fname != NULL)
frame = [OFString stringWithFormat:
@"%s`%p", info.dli_fname, _stackTrace[i]];
else
frame = [OFString stringWithFormat:
@"%p", _stackTrace[i]];
[stackTrace addObject: frame];
} else
[stackTrace addObject:
[OFString stringWithFormat: @"%p", _stackTrace[i]]];
}
objc_autoreleasePoolPop(pool);
[stackTrace makeImmutable];
return stackTrace;
#else
return nil;
#endif
}
@end
|