|
From: TSalm <TS...@fr...> - 2011-05-10 20:21:27
|
Le 09/05/2011 23:27, K. Frank wrote :
> Hello again, TSalm!
>
> It seems that I have given you incorrect information -- exactly
> backwards, in fact.
>
> On Sat, Apr 30, 2011 at 6:26 PM, K. Frank<kfr...@gm...> wrote:
>> 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.
> On the contrary, the answer is yes.
>
> It turns out that using gdb under mingw:
>
> g++ --version: "g++ (TDM-2 mingw32) 4.4.1"
> gdb --version: "GNU gdb (GDB) 7.1"
>
> you can issue the gdb command "catch throw" before running your
> program, and control will be transferred back to the debugger when
> an exception is thrown. The "backtrace" command ("bt") then gives
> the stack trace, and in some simple tests I've tried, the whole stack
> is there -- it hasn't yet been unwound by the exception processing.
>
Thanks. It's really interresting.
If I understand, this pauses when the first exception occurs ( catch or
not ). A cool stuff could be to obtain the stacktrace of the last
exception before the process is stopping. It's certainly possible with GDB.
>> ...
>> The stack gets unwound between where you throw the exception
>> and where you catch it. This can be inconvenient when debugging,
>> because if your code throws an exception deep down in some nested
>> function calls, seeing the stacktrace (at the time the exception was
>> thrown) can help make the bug apparent.
> So I guess the "catch throw" command pauses execution before the
> stack has been unwound.
>
>> ...
>> 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...).
> This statement also seems to be wrong. I've just done some simple
> tests, and when an assertion fails, my program terminates. Neither
> drmingw (version 0.4.4), registered as the post-mortem debugger, nor
> gdb, when used to run the program, shows me the stack after an
> assert fails.
>
> So...
>
> Throw exceptions, and use gdb's "catch throw" and "backtrace" commands
> to see the stack when the exceptions occur.
>
> Sorry for the misinformation.
>
No problem. A great thank to you.
____________
Analyse antivirus effectuée par G Data AntiVirus
|