Reputation: 86057
There's a great answer to the question "Print the name of the calling function" here:
Print the name of the calling function to the debug log
Is it possible to go one step further and find the caller of the caller?
Upvotes: 2
Views: 479
Reputation:
Yap. Modifying the example you linked:
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]);
Upvotes: 2