|
From: K. F. <kfr...@gm...> - 2011-05-01 23:30:31
|
Hello TSalm! On Sun, May 1, 2011 at 5:12 PM, TSalm <TS...@fr...> wrote: > Le 01/05/2011 00:26, K. Frank a écrit : >> Hi TSalm! >> >> On Sat, Apr 30, 2011 at 5:55 PM, TSalm<TS...@fr...> wrote: >>> Hi, >>> >>> Is there away to catch an exception and display his stacktrace ? >> I believe that the answer is no, if I understand your question. >> >> Ordinary, built-in c++ exceptions do not take a snapshot of the >> stack or build a stacktrace as they unwind the stack. This is >> by design, as c++ doesn't want to impose on you the cost of >> building and maintaining this stacktrace. >> ... >> When I'm doing development and debugging, I generally put in assets. >> These cause the program to core dump (or send control back to the >> debugger) right at the point where the error is detected (i.e., the assert >> fails), and then you can look at the state of the stack when the error >> occurred (unless your bug has corrupted the stack...). > > I understand. On an other side, why the -g switch doesn't insert > something to manage this stacktrace when an exception occurs ? I don't know the answer as to why -g doesn't add this functionality. Ultimately it's some design decision. But your suggestion sounds like a good one to me. You could argue that once you use -g, you're not asking for best performance, and you are asking for help debugging things. It seems reasonable for -g to say you're going to take the significant performance hit of having the exception stack unwinding build a stack backtrace as it goes, and report it to the debugger or a core dump should the exception not be handled. (Of course, this would represent new functionality, and considerable effort for the compiler developers.) A feature like this certainly would have saved me significant time and effort debugging in certain situations. > Thanks. Good luck. K. Frank |