Skip to content

Instantly share code, notes, and snippets.

@aldrinmartoq
Last active December 26, 2015 00:29
Show Gist options
  • Save aldrinmartoq/7064011 to your computer and use it in GitHub Desktop.
Save aldrinmartoq/7064011 to your computer and use it in GitHub Desktop.
#include <dlfcn.h>
#include <execinfo.h>
// Uso: callmemaybe(2) así por ser…
__attribute__((noinline)) NSString *callmemaybe(int item) {
void *bt[1024];
int bt_size;
bt_size = backtrace(bt, 1024);
if (bt_size > (item + 1)) {
Dl_info info;
dladdr(bt[item], &info);
if (info.dli_sname != NULL) {
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"-\\[(\\w+).*"
options:NSRegularExpressionCaseInsensitive error:nil];
NSString *ret = [NSString stringWithUTF8String:info.dli_sname];
return [regex stringByReplacingMatchesInString:[NSString stringWithUTF8String:info.dli_sname]
options:0
range:NSMakeRange(0, [ret length])
withTemplate:@"[$1]"];
}
}
return @"NPI";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment