Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact


Moderators: larsivi kris

Posted: 04/08/09 05:07:26

Hi, I see that Tango now has stacktrace built in. That's great addition! What is the status of that? Is it usable already and if so - how? Maybe a little example?

Thanks, bobef

Author Message

Posted: 04/08/09 10:54:00 -- Modified: 04/08/09 10:56:42 by

With DMD 1.041 and later, you only need to import tango.core.stacktrace.TraceExceptions?. Here's what I do to be able to use older compilers too:

// Workaround for a bug in dmd < 1.041.
static if (__VERSION__ < 1041) {
    debug import tango.core.stacktrace.StackTrace;
    debug version = bug2673;
debug import tango.core.stacktrace.TraceExceptions;

/* ... */

// in main()
version (bug2673)

Like the old stacktrace, it still won't show the call where the exception actually originated. To get that you need a debug build of the base tango lib. But linking to tango-base-dmd-d.lib won't work due to issue #1574, but might work on other platforms than Windows.

Posted: 04/08/09 13:42:04

Thanks, but I don't see in your example how you actually get the trace info? For example I want something like this (pseudo code):

try {
catch(Object o) {

Posted: 04/08/09 16:04:48 -- Modified: 04/08/09 16:06:34 by

Sorry, forgot that part. :)

catch(Exception e) {
    e.writeOut((char[] s) { Trace.format(s); });

By the way, you need Tango svn to get traced exceptions, I use rev. 4498.

Posted: 05/08/09 13:37:44

When I try to compile your example with DMD 1.043 with the latest Tango trunk version I'll get this error:

dsss_objs/D/tango.core.stacktrace.StackTrace?.o: In function `_D5tango4core10stacktrace10StackTrace24dladdrSymbolizeFrameInfoFKS9Exception9FrameInfoPS5tango4core10stacktrace10StackTrace12TraceContextAaZb': /usr/local/dmd/bin/../import/tango/core/stacktrace/StackTrace.d:231: undefined reference to `dladdr' collect2: ld returned 1 exit status

Help appreciated?

Posted: 05/08/09 15:34:58

Seems like you need to link libdl?

Posted: 05/09/09 09:51:37

:-) thx. solved.