Debugging

Jesse Phillips jessekphillips+D at gmail.com
Tue Jul 13 12:29:35 PDT 2010


Graham St Jack Wrote:

> Specifically:
> 
> Stack Trace:
> ------------
> 
> I can't get the D2 stack-trace to work properly. All I get is something 
> like this, which isn't helpful:
> 
> Segmentation fault
> 
> The code I used to generate this was:
> import std.stdio;
> import std.file;
> void foo(File file) {
>     file.flush;
> }
> void main(string[] args) {
>     File file;
>     foo(file);
> }
> Is stack-trace support broken, or do I have to do something to enable it?

While you aren't asking why, 'file' is initialized to null and is not a stack allocated class as it would be in C++.

The first step to debugging is to use the -gc flag instead of -g. The unreleased version of GDB has the patch for D mangling, otherwise you need the symbols to mimic C. Then you can run your program with GDB.

As you should be familiar with. You can get the stack trace form GDB if you enable core dumps: $ ulimit -c 5000 && dmd -gc test.d && ./test && gdb ./test core


More information about the Digitalmars-d mailing list