Fix D's segfaults!

Jonathan M Davis via Digitalmars-d digitalmars-d at puremagic.com
Sun Aug 20 13:20:30 PDT 2017


On Sunday, August 20, 2017 12:35:45 Ali Çehreli via Digitalmars-d wrote:
> On 08/20/2017 12:14 PM, Johnson Jones wrote:
>  >>> Dmd needs to be modified so that errors try to show from the source
>  >>> code. This should be obvious the reasons, if it is not possible, make
>  >>> it possible! There are no excuses why dmd should make me go on an
>  >>> easter egg hunt when a seg fault occurs.
>
> You can open an enhancement request at
>
>    https://issues.dlang.org/enter_bug.cgi
>
> I don't know how well it works with D but what I used to do with C++ was
> to put a break point at Exception constructor, which would give me the
> useful stack to go back to my own code.

With the stacktrace, he should be able to know where in his code the problem
is right now. But he doesn't seem to have any debug information whatsoever,
so his stack trace is useless. If I run the program

    module test;

    import std.file;

    void main()
    {
        rename("does_not_exist_1", "does_not_exist_2");
    }

on my system (which is FreeBSD), I get

std.file.FileException at std/file.d(763): does_not_exist_2: No such file or 
directory
----------------
??:? @trusted bool std.file.cenforce!(bool).cenforce(bool, const(char)[], 
const(char)*, immutable(char)[], ulong) [0x476c26]
??:? @trusted void std.file.renameImpl(const(char)[], const(char)[], 
const(char)*, const(char)*) [0x4759e6]
??:? @safe void std.file.rename!(immutable(char)[], immutable(char)
[]).rename(immutable(char)[], immutable(char)[]) [0x470304]
??:? _Dmain [0x470202]

which is much better but still not where it should be. The line numbers are
missing, and for some reason, the module name isn't on _Dmain. However, if I
do

    module test;

    import std.file;

    void main()
    {
        foo();
    }

    void foo()
    {
        rename("does_not_exist_1", "does_not_exist_2");
    }

then I get

std.file.FileException at std/file.d(763): does_not_exist_2: No such file or 
directory
----------------
??:? @trusted bool std.file.cenforce!(bool).cenforce(bool, const(char)[], 
const(char)*, immutable(char)[], ulong) [0x476c66]
??:? @trusted void std.file.renameImpl(const(char)[], const(char)[], 
const(char)*, const(char)*) [0x475a26]
??:? @safe void std.file.rename!(immutable(char)[], immutable(char)
[]).rename(immutable(char)[], immutable(char)[]) [0x470344]
??:? void test.foo() [0x470242]
??:? _Dmain [0x47020c]

which _does_ have the module name on the function that main calls. So, the
lack of module name must be a quirk of _Dmain - probably tied to the fact
that there's only supposed to be one. But the line numbers are still
missing, which they really shouldn't be. I know that that's been a problem
in the past on *nix systems, but I'd thought that it had been fixed. So, I
don't know what the problem is. Regardless, I think that it should
definitely be considered a bug if the line numbers don't show up.

But in spite of the lack of line numbers, what I have here is way better
than what the OP sees. So, he's doing something differently, but I don't
know what. But based on what I'm seeing, it should be possible for the OP to
get a much better stack trace right now. It's just a question of figuring
out what he's doing differently that causes his stack traces to show up with
just addresses.

- Jonathan M Davis




More information about the Digitalmars-d mailing list