在監(jiān)控的函數(shù)里添加下段代碼
最終函數(shù)調(diào)用信息依照順序存在NSMutableArray backtrace 中
還需要添加頭文件
#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 < frames;i++){
[backtrace addObject:[NSString stringWithUTF8String:strs[i]]];
}
free(strs);
NSLog(@"====================堆棧\n %@ \n",backtrace);