My high-level goal is something like this:
void print_backtrace() {
void *callstack[128];
int framesC = backtrace(callstack, sizeof(callstack));
printf("backtrace() returned %d addresses\n", framesC);
char** strs = backtrace_symbols(callstack, framesC);
for(int i = 0; i < framesC; ++i) {
if(strs[i])
printf("%s\n", strs[i]);
else
break;
}
free(strs);
}
install_breakpoint_handler("__NSAutoreleaseNoPool", print_backtrace);
So, each time the __NSAutoreleaseNoPool
function breakpoint is catched, print_backtrace
should be called. (All within the same binary. I'm not trying to catch the breakpoint of separate processes.)
I guess I can somehow do this via ptrace
. Is there some easy-to-use and lightweight library?
Currently I'm searching for a MacOSX solution, but cross-platform would be nice of course.