Last active
December 26, 2015 00:29
-
-
Save aldrinmartoq/7064011 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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