* Customizing uncaught exception messages
@ 2008-05-15 7:16 Yang Zhang
2008-05-15 9:48 ` me22
2008-05-15 14:46 ` Joel Dice
0 siblings, 2 replies; 6+ messages in thread
From: Yang Zhang @ 2008-05-15 7:16 UTC (permalink / raw)
To: gcc-help
Hi, is it possible to get more informative error messages for uncaught
exceptions? For instance, I'm interested in getting Java-like
tracebacks with file and line numbers. Currently what I see is far from
that, e.g.:
terminate called after throwing an instance of 'std::logic_error'
what(): basic_string::_S_construct NULL not valid
Is there any way to hook into the exception handling mechanisms and
produce such a traceback? If the solution is platform-dependent, I am
using GNU/Linux with gcc 4.2.3.
Thanks!
--
Yang Zhang
http://www.mit.edu/~y_z/
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Customizing uncaught exception messages
2008-05-15 7:16 Customizing uncaught exception messages Yang Zhang
@ 2008-05-15 9:48 ` me22
2008-05-15 15:40 ` Yang Zhang
2008-05-15 14:46 ` Joel Dice
1 sibling, 1 reply; 6+ messages in thread
From: me22 @ 2008-05-15 9:48 UTC (permalink / raw)
To: Yang Zhang; +Cc: gcc-help
On Thu, May 15, 2008 at 2:03 AM, Yang Zhang <yanghatespam@gmail.com> wrote:
> Hi, is it possible to get more informative error messages for uncaught
> exceptions? For instance, I'm interested in getting Java-like tracebacks
> with file and line numbers. Currently what I see is far from that, e.g.:
>
> terminate called after throwing an instance of 'std::logic_error'
> what(): basic_string::_S_construct NULL not valid
>
> Is there any way to hook into the exception handling mechanisms and produce
> such a traceback? If the solution is platform-dependent, I am using
> GNU/Linux with gcc 4.2.3.
>
The information isn't stored anywhere, so by the time you get an
exception falling out of main and calling terminate, it's no longer
available.
Your debugger might let you automatically break on throws...
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Customizing uncaught exception messages
2008-05-15 7:16 Customizing uncaught exception messages Yang Zhang
2008-05-15 9:48 ` me22
@ 2008-05-15 14:46 ` Joel Dice
2008-05-15 16:01 ` Yang Zhang
1 sibling, 1 reply; 6+ messages in thread
From: Joel Dice @ 2008-05-15 14:46 UTC (permalink / raw)
To: Yang Zhang; +Cc: gcc-help
On Thu, 15 May 2008, Yang Zhang wrote:
> Hi, is it possible to get more informative error messages for uncaught
> exceptions? For instance, I'm interested in getting Java-like tracebacks
> with file and line numbers. Currently what I see is far from that, e.g.:
>
> terminate called after throwing an instance of 'std::logic_error'
> what(): basic_string::_S_construct NULL not valid
>
> Is there any way to hook into the exception handling mechanisms and produce
> such a traceback? If the solution is platform-dependent, I am using
> GNU/Linux with gcc 4.2.3.
In cases where the exception is thrown by your own code, you may be able
to use backtrace() and backtrace_symbols(), declared in execinfo.h, to
capture the stack trace before unwinding. Then use addr2line (a command
line utility included in binutils) to get the line numbers.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Customizing uncaught exception messages
2008-05-15 9:48 ` me22
@ 2008-05-15 15:40 ` Yang Zhang
0 siblings, 0 replies; 6+ messages in thread
From: Yang Zhang @ 2008-05-15 15:40 UTC (permalink / raw)
To: me22; +Cc: gcc-help
me22 wrote:
> On Thu, May 15, 2008 at 2:03 AM, Yang Zhang <yanghatespam@gmail.com> wrote:
>> Hi, is it possible to get more informative error messages for uncaught
>> exceptions? For instance, I'm interested in getting Java-like tracebacks
>> with file and line numbers. Currently what I see is far from that, e.g.:
>>
>> terminate called after throwing an instance of 'std::logic_error'
>> what(): basic_string::_S_construct NULL not valid
>>
>> Is there any way to hook into the exception handling mechanisms and produce
>> such a traceback? If the solution is platform-dependent, I am using
>> GNU/Linux with gcc 4.2.3.
>>
>
> The information isn't stored anywhere, so by the time you get an
> exception falling out of main and calling terminate, it's no longer
> available.
>
> Your debugger might let you automatically break on throws...
How does gdb manage to hook into the exception-throwing mechanisms to
trigger breakpoints? Would I be able to use the same approach to hook
it up to code that simply stores the backtrace somewhere (perhaps
thread-local storage), and then hook into the uncaught exception handler
to print this stored backtrace?
--
Yang Zhang
http://www.mit.edu/~y_z/
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Customizing uncaught exception messages
2008-05-15 14:46 ` Joel Dice
@ 2008-05-15 16:01 ` Yang Zhang
2008-05-15 16:05 ` Ian Lance Taylor
0 siblings, 1 reply; 6+ messages in thread
From: Yang Zhang @ 2008-05-15 16:01 UTC (permalink / raw)
To: Joel Dice; +Cc: gcc-help
Joel Dice wrote:
> On Thu, 15 May 2008, Yang Zhang wrote:
>
>> Hi, is it possible to get more informative error messages for uncaught
>> exceptions? For instance, I'm interested in getting Java-like
>> tracebacks with file and line numbers. Currently what I see is far
>> from that, e.g.:
>>
>> terminate called after throwing an instance of 'std::logic_error'
>> what(): basic_string::_S_construct NULL not valid
>>
>> Is there any way to hook into the exception handling mechanisms and
>> produce such a traceback? If the solution is platform-dependent, I am
>> using GNU/Linux with gcc 4.2.3.
>
> In cases where the exception is thrown by your own code, you may be able
> to use backtrace() and backtrace_symbols(), declared in execinfo.h, to
> capture the stack trace before unwinding. Then use addr2line (a command
> line utility included in binutils) to get the line numbers.
I guess my question boils down to: how do I do the first thing you
mentioned - that is, cause all throws to trigger my own code (which e.g.
calls backtrace())? I've used backtrace() and addr2line before, but I
just don't know enough about how C++ exceptions work.
--
Yang Zhang
http://www.mit.edu/~y_z/
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Customizing uncaught exception messages
2008-05-15 16:01 ` Yang Zhang
@ 2008-05-15 16:05 ` Ian Lance Taylor
0 siblings, 0 replies; 6+ messages in thread
From: Ian Lance Taylor @ 2008-05-15 16:05 UTC (permalink / raw)
To: Yang Zhang; +Cc: Joel Dice, gcc-help
Yang Zhang <yanghatespam@gmail.com> writes:
> I guess my question boils down to: how do I do the first thing you
> mentioned - that is, cause all throws to trigger my own code (which
> e.g. calls backtrace())? I've used backtrace() and addr2line before,
> but I just don't know enough about how C++ exceptions work.
Use the standard set_terminate function to create your own terminate
handler. It will be called for exceptions which aren't caught.
If you want to be called for exception which are caught, you need to
hook into __cxa_throw.
Ian
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2008-05-15 16:01 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-05-15 7:16 Customizing uncaught exception messages Yang Zhang
2008-05-15 9:48 ` me22
2008-05-15 15:40 ` Yang Zhang
2008-05-15 14:46 ` Joel Dice
2008-05-15 16:01 ` Yang Zhang
2008-05-15 16:05 ` Ian Lance Taylor
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).