Snowcrash
Snowcrash

Reputation: 86057

Print name of the caller of the calling function

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

Answers (1)

user529758
user529758

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

Related Questions