Debugging
Graham St Jack
Graham.StJack at internode.on.net
Tue Jul 13 14:47:51 PDT 2010
On Tue, 13 Jul 2010 15:29:35 -0400, Jesse Phillips wrote:
> 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++.
Yes - it was a contrived example designed to deliberately segfault.
>
> 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.
Thanks - I have been doing that, but like I said, it is hard work
mentally demangling the names.
>
> 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
I didn't know about that, thanks. It looks like a more convenient way of
debugging segfaults than running the program in gdb directly. I will give
it a go.
More information about the Digitalmars-d
mailing list