Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
这里有一个很好的答案“打印调用函数的名称”这个问题:
将调用函数的名称打印到调试日志
是否可以更进一步,找到调用者的调用者?
是的。修改您链接的示例:
void *addr[3]; int nframes = backtrace(addr, sizeof(addr) / sizeof(*addr)); char **syms = backtrace_symbols(addr, nframes); NSLog(@"%s: caller of caller: %s", __func__, syms[2]);