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

Getting exception traces across threads

Moderators: larsivi kris

Posted: 03/05/08 01:35:41

I'm using the team0xf backtrace hack with 0.99.5. Is there a way to get a stack trace for an exception that's not coming from the main thread? I'm having a hard time debugging some exceptions. ddbg doesn't catch them either.

Is the trace info stored anywhere, like in the 'info' field? If it is, I guess I could catch the exception, store it in a global variable, and then access the info from the main thread.

Author Message

Posted: 03/05/08 01:55:07

I usually use try and catch in suspicious part of my code in any thread, and use tango.util.log.Log with Hierarchy relative to main thread, and used trace(...) method heavily then save it into file with Appender. It really useful method for me.

Posted: 03/05/08 23:23:31

What I'm looking for is a way to avoid just what you're suggesting, littering my code with try/catch, printf, etc. that's only there for debugging purposes. I've got enough of that in there already.

Being able to get a backtrace for other threads than the main one would be a superb way to debug multithreaded code.

Posted: 03/06/08 04:28:31

You can get a backtrace for other threads, but you have to catch the Exception yourself (and display the msg). One reasonable approach might be to subclass Thread, intercept the run() method, wrap it in a try/catch, and deal with Exceptions as they happen

Posted: 03/07/08 22:24:40

If you join the failed thread then it should rethrow the exception that caused it to terminate. Catch this and it will contain the backtrace.

Posted: 03/14/08 22:46:36

Here's what I get:

Do I need a custom trace handler or something for this to work? There's no backtrace in the exception object.

Posted: 03/15/08 17:51:20

keinfarbton tells me that this doesn't work with the backtrace hack. But it works when using the jive library, which is linux only.

Here's the output from the same test code using jive on linux:

Posted: 03/18/08 17:27:53

I haven't seen the Jive lib -- where is it hosted? I think it could be made to work with flectioned if it doesn't already, but no idea about the backtrace hack. That one requires changes to the code that handles the throwing of exceptions, and I'm not sure offhand if it could be made to work or not.

Posted: 03/18/08 21:27:31

sean wrote:

I haven't seen the Jive lib -- where is it hosted?

TangoUsers - Look for Jive :P

Posted: 03/18/08 22:21:10

Oops! I'd just checked the DSource projects list. In any case, Jive is a nice little package. I don't suppose there's a chance of a Win32 version?

Posted: 03/19/08 00:04:58

I haven't tried Flectioned. Can it be used for getting exception traces for other threads the main one? In that case, any chance that it works with dmd 1.027 and Tango 0.99.5 on Windows?

Posted: 03/19/08 18:31:46

The jive lib is currently not up to date with the Exception changes in -r3145. I have an updated and working version. Contact me to get a copy.

Posted: 03/19/08 18:44:41

Is that for Posix only, keinfarbton?

Posted: 03/19/08 20:53:27

Yes. It uses libbfd for address to symbol resolution.