I actually ran into this myself while working on a pet game project, and here's what I do.

First, let's start with a simple program that segfaults due to a null pointer.

// File seg.d
class Dummy {
    int a;
}

void main() {
    Dummy d;
    d.a = 3;
}

You compile and run the program with expected results.

 $ dmd seg.d
 $ ./seg
 Segmentation fault

If you have an older version of gdb, you should compile your program to include C compatible symbols.

 $ dmd -gc seg.d

Now run your program through gdb.
 $ gdb seg
 (gdb) run
 Starting program: /home/vnayar/projects/Demo/seg
 [Thread debugging using libthread_db enabled]

 Program received signal SIGSEGV, Segmentation fault.
 _Dmain () at seg.d:7
 7           d.a = 3;

And now you're good to go.

 - Vijay

On Mon, 6 Feb 2012, simendsjo wrote:

I get an segfault in druntime, but have no idea where to start looking.
_D4core7runtime18runModuleUnitTestsUZb19unittestSegvHandlerUiPS4core3sys5posix6signal9siginfo_tPvZv+0x3c

I cannot seem to find a way to enable line numbers in traces (adding -g adds line numbers in win, but not linux), and I cannot find any debug build of libphobos2.a - is it included? what is it called?

PS: using dmd 2.057 on kubuntu x64 using the deb package from digitalmars.com

Reply via email to