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);
Thus, every time a function breakpoint __NSAutoreleaseNoPoolis called, it should be called print_backtrace. (Everything is inside the same binary file. I am not trying to catch the breakpoint of individual processes.)
I think I can somehow do it through ptrace. Is there an easy to use and easy library?
I'm currently looking for a solution for MacOSX, but cross-platform would be nice, of course.
source
share