D 2.0 Stacktrace

I wrote a small piece of sourcecode that generates stacktraces in D 2.0 under windows. It works both with the pdb and cv debug symbol format. For Exceptions that are derived from the Error or Exception class the trace information is automatically appended, this causes all builtin D errors to get a stacktrace information. The only point where this does not work is the Access Vioaltion error, as it does not call the stacktrace callback function for some reason.

stack trace example

It is very easy to use, just copy the two files from the zip archive to your root source directory and import the stacktrace module inside your main file.

import stacktrace;

void main(string[] argv){

Now all Errors will get trace information.
If you need a backtrace at a certain point in your code just do the following:

module foo;

import stacktrace;

void blup(){
StackTrace trace = new StackTrace();
auto stack = trace.GetCallstack();
foreach(char[] s;stack)

Download: d2stacktrace.zip (12 kb)

It is released under the “Creative Commons by” license. If this licence causes any problems for you, feel free to contact me and we will fix the problem.

XP Users:
If you get a stacktrace with numbers only download a new version of dbghelp.dll (it comes with the windows platform SDK) and put it into your project root directory. That should fix it.

Creative Commons Lizenzvertrag
D2 Stacktrace von Benjamin Thaut steht unter einer Creative Commons Namensnennung 3.0 Unported Lizenz.