views:

61

answers:

1

I want to get a BackTrace from my crashing C++ Mac application however I am new to the Mac and am not sure how best to go about it.

I found a question on stackoverflow that details its usage: getting the current stack trace on mac os x

However my problem is that I do not see where the code is meant to live?

  1. Does it go in the main.cpp?
  2. Does it live in the catch part of a try catch block?

I could do with some full code examples but am having trouble finding them.

+1  A: 

The code referred to in the other question needs to go where it will get executed after the crash. Depending on what is happening that could either be in a catch block if an exception is getting thrown, or in a signal handler if the program is crashing because of, for example, a seg fault or bus error.

Here is an example for catching signals. It would go in main().

static void CatchSignal(int num) {
// code to execute when signal is caught
}

void InstallSignalHandler(const int which[15]) {
     for (int i = 1; i < 15; i++) 
         if (which[i] != 0 && which[i] != SIGABRT)
            signal(which[i],CatchSignal);
}
KeithB
Its on a Bus error whilst the application is idle. So can someone provide an example of adding to to the signal handler?
Phil Hannent