Reputation: 12317
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?
I could do with some full code examples but am having trouble finding them.
Upvotes: 0
Views: 493
Reputation: 17037
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);
}
Upvotes: 1