1

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.

Albert
  • 65,406
  • 61
  • 242
  • 386

1 Answers1

0

I just found one lib (I even had used it a few years ago...): mach_override

I also found this debuglib but didn't tried.

See here for a demonstration for __NSAutoreleaseNoPool: It automatically executes print_backtrace.

Albert
  • 65,406
  • 61
  • 242
  • 386