您的位置:首页 > 移动开发 > IOS开发

How to NSLog a Call stack when a program is running?

2016-01-24 20:01 423 查看
Of course there is. If you can use the Cocoa framework:

NSLog(@"%@", [NSThread callStackSymbols]);

(Documentation.)

If you can't use it:

#include <execinfo.h>

int size = 256;
void *stack[size];
size = backtrace(stack, size);

char **syms = backtrace_symbols(stack, size);
for (int i = 0; i < size; i++) {
printf("Frame #%d: %s\n", i, syms[i]);
}
free(syms);

(Documentation.)

参考http://stackoverflow.com/questions/13319551/how-to-nslog-a-call-stack-when-a-program-is-running
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  IOS 调试技巧