IOS获取函数调用堆栈信息

导入头文件

#include
#include


如下代码放到方法里即可知道该方法调用的堆栈信息

void* callstack[128];
int frames = backtrace(callstack, 128);
char **strs = backtrace_symbols(callstack, frames);
int i;
NSMutableArray *backtrace = [NSMutableArray arrayWithCapacity:frames];
for (i = 0;i < 4;i++){
[backtrace addObject:[NSString stringWithUTF8String:strs[i]]];
}
free(strs);
NSLog(@"====================堆栈\n %@ \n",backtrace);

你可能感兴趣的:(C,iphone,ipad,ipod,touch)