Jump to page: 1 2 3
Thread overview
Segmentation fault in DMD - how to debug?
Sep 28, 2022
Andrey Zherikov
Sep 28, 2022
Nicholas Wilson
Sep 28, 2022
Andrey Zherikov
Sep 29, 2022
Paul Backus
Sep 29, 2022
max haughton
Sep 29, 2022
Andrey Zherikov
Sep 29, 2022
Andrey Zherikov
Sep 29, 2022
Andrey Zherikov
Oct 02, 2022
Walter Bright
Oct 04, 2022
Walter Bright
Oct 04, 2022
Walter Bright
Oct 04, 2022
Walter Bright
Oct 04, 2022
Dennis
Oct 04, 2022
ryuukk_
Oct 04, 2022
Andrey Zherikov
Oct 04, 2022
ryuukk_
Oct 04, 2022
Walter Bright
Oct 06, 2022
Walter Bright
Oct 07, 2022
Andrey Zherikov
Oct 07, 2022
Andrey Zherikov
Oct 07, 2022
Walter Bright
Oct 08, 2022
Andrey Zherikov
Oct 08, 2022
Walter Bright
Oct 02, 2022
Walter Bright
Sep 29, 2022
Ali Çehreli
September 28, 2022

I'm refactoring my library by mostly moving functions between modules and I get DMD crashes pretty often. The latest example:

(No debugging symbols found in /usr/bin/dmd)
(gdb) r  -c -of.dub/build/argparse-test-library-unittest-linux.posix-x86_64-dmd_v2.100.0-85E634C9744FC817BD0D2766A2B6CFD9/argparse-test-library.o -debug -g -unittest -w -version=Have_argparse -Isource/ .dub/code/argparse-test-library-unittest-linux.posix-x86_64-dmd_v2.100.0-662575AE9496601C3D84B10DCD65DAFE_dub_test_root.d source/argparse/ansi.d source/argparse/internal/arguments.d source/argparse/internal/completer.d source/argparse/internal/help.d source/argparse/internal/lazystring.d source/argparse/internal/package.d source/argparse/internal/parser.d source/argparse/internal/subcommands.d source/argparse/internal/utils.d source/argparse/package.d -vcolumns
Starting program: /usr/bin/dmd -c -of.dub/build/argparse-test-library-unittest-linux.posix-x86_64-dmd_v2.100.0-85E634C9744FC817BD0D2766A2B6CFD9/argparse-test-library.o -debug -g -unittest -w -version=Have_argparse -Isource/ .dub/code/argparse-test-library-unittest-linux.posix-x86_64-dmd_v2.100.0-662575AE9496601C3D84B10DCD65DAFE_dub_test_root.d source/argparse/ansi.d source/argparse/internal/arguments.d source/argparse/internal/completer.d source/argparse/internal/help.d source/argparse/internal/lazystring.d source/argparse/internal/package.d source/argparse/internal/parser.d source/argparse/internal/subcommands.d source/argparse/internal/utils.d source/argparse/package.d -vcolumns
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

Program received signal SIGSEGV, Segmentation fault.
0x0000555555822ee6 in getTypePointerBitmap::PointerBitmapVisitor::visit(TypeStruct*) ()

(gdb) where
#0  0x0000555555822ee6 in getTypePointerBitmap::PointerBitmapVisitor::visit(TypeStruct*) ()
#1  0x0000555555822bc9 in dmd.traits.getTypePointerBitmap(dmd.globals.Loc, dmd.mtype.Type, dmd.root.array.Array!(ulong).Array*) ()
#2  0x000055555581d832 in dmd.traits.semanticTraits(dmd.expression.TraitsExp, dmd.dscope.Scope*) ()
#3  0x00005555557d4ded in ExpressionSemanticVisitor::visit(TraitsExp*) ()
#4  0x00005555558499af in dmd.initsem.inferType(dmd.init.Initializer, dmd.dscope.Scope*) ()
#5  0x000055555582b965 in DsymbolSemanticVisitor::visit(VarDeclaration*) ()
#6  0x00005555556f06ad in dmd.dsymbolsem.templateInstanceSemantic(dmd.dtemplate.TemplateInstance, dmd.dscope.Scope*, dmd.root.array.Array!(dmd.expression.Expression).(gdb)
#7  0x00005555556c7ee4 in Semantic3Visitor::visit(AggregateDeclaration*) ()
#8  0x00005555556c83fc in Semantic3Visitor::visit(TemplateInstance*) ()
#9  0x00005555558e317e in dmd.mars.tryMain(ulong, const(char)**, ref dmd.globals.Param) ()
#10 0x00005555558f27d1 in D main ()

How do you debug and fix these things?

September 28, 2022

On Wednesday, 28 September 2022 at 22:48:47 UTC, Andrey Zherikov wrote:

>

I'm refactoring my library by mostly moving functions between modules and I get DMD crashes pretty often. The latest example:

Program received signal SIGSEGV, Segmentation fault.
0x0000555555822ee6 in getTypePointerBitmap::PointerBitmapVisitor::visit(TypeStruct*) ()

(gdb) where
#0  0x0000555555822ee6 in getTypePointerBitmap::PointerBitmapVisitor::visit(TypeStruct*) ()
#1  0x0000555555822bc9 in dmd.traits.getTypePointerBitmap(dmd.globals.Loc, dmd.mtype.Type, dmd.root.array.Array!(ulong).Array*) ()

How do you debug and fix these things?

This seems to stem from use of __traits(getPointerBitmap, T), with a T that is not handled properly. If you can get a reduced test case that will make things much easier. dustmite (which should come with dmd, is useful for automatic reduction, otherwise if you have few uses of __traits(getPointerBitmap, T), it might be easier to synthesise an example that crashes the compiler.

September 28, 2022

On Wednesday, 28 September 2022 at 23:07:34 UTC, Nicholas Wilson wrote:

>

This seems to stem from use of __traits(getPointerBitmap, T), with a T that is not handled properly. If you can get a reduced test case that will make things much easier. dustmite (which should come with dmd, is useful for automatic reduction, otherwise if you have few uses of __traits(getPointerBitmap, T), it might be easier to synthesise an example that crashes the compiler.

I don't use getPointerBitmap in my code:

$ grep -r --include=*.d getPointerBitmap
$
September 29, 2022

On Wednesday, 28 September 2022 at 23:15:42 UTC, Andrey Zherikov wrote:

>

On Wednesday, 28 September 2022 at 23:07:34 UTC, Nicholas Wilson wrote:

>

This seems to stem from use of __traits(getPointerBitmap, T), with a T that is not handled properly. If you can get a reduced test case that will make things much easier. dustmite (which should come with dmd, is useful for automatic reduction, otherwise if you have few uses of __traits(getPointerBitmap, T), it might be easier to synthesise an example that crashes the compiler.

I don't use getPointerBitmap in my code:

$ grep -r --include=*.d getPointerBitmap
$

It's used in druntime, by RTInfo:

https://github.com/dlang/druntime/blob/v2.100.2/src/object.d#L3695-L3702

September 29, 2022

I actually see that DMD is very unstable.
Here are three consequtive calls of dub test --coverage -v --build-mode singleFile without any change in source files:

Failed:

C:\D\dmd2\windows\bin\..\..\src\phobos\std\sumtype.d-mixin-2084(2084,7): Error: unterminated string constant starting at C:\D\dmd2\windows\bin\..\..\src\phobos\std\sumtype.d-mixin-2084(2084,14)
C:\D\dmd2\windows\bin\..\..\src\phobos\std\sumtype.d-mixin-2084(2084,14): Error: no identifier for declarator `handler`
C:\D\dmd2\windows\bin\..\..\src\phobos\std\sumtype.d-mixin-2084(2084,14): Error: semicolon expected to close `alias` declaration
C:\D\dmd2\windows\bin\..\..\src\phobos\std\sumtype.d(2096,32): Error: incomplete mixin expression `handler`(args[`].get!(SumTypes[`].Types[`])(), )`
C:\D\dmd2\windows\bin\..\..\src\phobos\std\sumtype.d(2096,32): Error: incomplete mixin expression `handler`(args[`].get!(SumTypes[`].Types[1])(), )`
C:\D\dmd2\windows\bin\..\..\src\phobos\std\sumtype.d(2096,32): Error: incomplete mixin expression `handler`(args[`].get!(SumTypes[`].Types[2])(), )`
C:\D\dmd2\windows\bin\..\..\src\phobos\std\sumtype.d(2096,32): Error: incomplete mixin expression `handler`(args[`].get!(SumTypes[`].Types[3])(), )`
C:\D\dmd2\windows\bin\..\..\src\phobos\std\sumtype.d(2096,32): Error: incomplete mixin expression `handler`(args[`].get!(SumTypes[`].Types[4])(), )`
C:\D\dmd2\windows\bin\..\..\src\phobos\std\sumtype.d(1662,52): Error: template instance `argparse.internal.parser.Parser.parse!(false, Init).parse.matchImpl!(SumType!(Unknown, EndOfArgs, Positional, NamedShort, NamedLong))` error instantiating
source\argparse\internal\parser.d(234,19):        instantiated from here: `match!(SumType!(Unknown, EndOfArgs, Positional, NamedShort, NamedLong))`
source\argparse\internal\subcommands.d(138,47):        instantiated from here: `parse!(false, Init)`
source\argparse\internal\subcommands.d(103,17):        instantiated from here: `ParsingSubCommandArgument!(Config('=', '\xff', '-', "--", false, false, true, StylingMode.autodetect, null, Style(TextStyle([cast(ubyte)1u]), TextStyle([cast(ubyte)1u]), TextStyle([cast(ubyte)1u, cast(ubyte)4u]), TextStyle([cast(ubyte)93u]), TextStyle([cast(ubyte)3u]), TextStyle([cast(ubyte)93u])), null), Init, CommandInfo(["init"], LazyString(SumType(Storage(null, ), cast(ubyte)0u)), LazyString(SumType(Storage("Print initialization script for shell completion.", ), cast(ubyte)0u)), LazyString(SumType(Storage("Print initialization script.", ), cast(ubyte)0u)), LazyString(SumType(Storage(null, ), cast(ubyte)0u))), Complete!(T), "cmd", false)`
source\argparse\internal\package.d(402,32):        ... (4 instantiations, -v to show) ...
source\argparse\package.d(999,46):        instantiated from here: `callParser!(Config('=', '\xff', '-', "--", false, false, true, StylingMode.autodetect, null, Style(TextStyle([cast(ubyte)1u]), TextStyle([cast(ubyte)1u]), TextStyle([cast(ubyte)1u, cast(ubyte)4u]), TextStyle([cast(ubyte)93u]), TextStyle([cast(ubyte)3u]), TextStyle([cast(ubyte)93u])), null), false, Complete!(T))`
source\argparse\package.d(794,12):        instantiated from here: `CLI!(Config('=', '\xff', '-', "--", false, false, true, StylingMode.autodetect, null, Style(TextStyle([cast(ubyte)1u]), TextStyle([cast(ubyte)1u]), TextStyle([cast(ubyte)1u, cast(ubyte)4u]), TextStyle([cast(ubyte)93u]), TextStyle([cast(ubyte)3u]), TextStyle([cast(ubyte)93u])), null), T)`
C:\D\dmd2\windows\bin\..\..\src\phobos\std\sumtype.d-mixin-2084(2084,7): Error: unterminated string constant starting at C:\D\dmd2\windows\bin\..\..\src\phobos\std\sumtype.d-mixin-2084(2084,14)
C:\D\dmd2\windows\bin\..\..\src\phobos\std\sumtype.d-mixin-2084(2084,14): Error: no identifier for declarator `handler`
C:\D\dmd2\windows\bin\..\..\src\phobos\std\sumtype.d-mixin-2084(2084,14): Error: semicolon expected to close `alias` declaration
C:\D\dmd2\windows\bin\..\..\src\phobos\std\sumtype.d(2096,32): Error: incomplete mixin expression `handler`(args[`].get!(SumTypes[`].Types[`])(), )`
C:\D\dmd2\windows\bin\..\..\src\phobos\std\sumtype.d(2096,32): Error: incomplete mixin expression `handler`(args[`].get!(SumTypes[`].Types[1])(), )`
C:\D\dmd2\windows\bin\..\..\src\phobos\std\sumtype.d(2096,32): Error: incomplete mixin expression `handler`(args[`].get!(SumTypes[`].Types[2])(), )`
C:\D\dmd2\windows\bin\..\..\src\phobos\std\sumtype.d(2096,32): Error: incomplete mixin expression `handler`(args[`].get!(SumTypes[`].Types[3])(), )`
C:\D\dmd2\windows\bin\..\..\src\phobos\std\sumtype.d(2096,32): Error: incomplete mixin expression `handler`(args[`].get!(SumTypes[`].Types[4])(), )`
C:\D\dmd2\windows\bin\..\..\src\phobos\std\sumtype.d(1662,52): Error: template instance `argparse.internal.parser.Parser.parse!(true, Init).parse.matchImpl!(SumType!(Unknown, EndOfArgs, Positional, NamedShort, NamedLong))` error instantiating
source\argparse\internal\parser.d(234,19):        instantiated from here: `match!(SumType!(Unknown, EndOfArgs, Positional, NamedShort, NamedLong))`
source\argparse\internal\subcommands.d(138,47):        instantiated from here: `parse!(true, Init)`
source\argparse\internal\subcommands.d(104,17):        instantiated from here: `ParsingSubCommandArgument!(Config('=', '\xff', '-', "--", false, false, true, StylingMode.autodetect, null, Style(TextStyle([cast(ubyte)1u]), TextStyle([cast(ubyte)1u]), TextStyle([cast(ubyte)1u, cast(ubyte)4u]), TextStyle([cast(ubyte)93u]), TextStyle([cast(ubyte)3u]), TextStyle([cast(ubyte)93u])), null), Init, CommandInfo(["init"], LazyString(SumType(Storage(null, ), cast(ubyte)0u)), LazyString(SumType(Storage("Print initialization script for shell completion.", ), cast(ubyte)0u)), LazyString(SumType(Storage("Print initialization script.", ), cast(ubyte)0u)), LazyString(SumType(Storage(null, ), cast(ubyte)0u))), Complete!(T), "cmd", true)`
source\argparse\internal\package.d(402,32):        ... (4 instantiations, -v to show) ...
source\argparse\package.d(999,46):        instantiated from here: `callParser!(Config('=', '\xff', '-', "--", false, false, true, StylingMode.autodetect, null, Style(TextStyle([cast(ubyte)1u]), TextStyle([cast(ubyte)1u]), TextStyle([cast(ubyte)1u, cast(ubyte)4u]), TextStyle([cast(ubyte)93u]), TextStyle([cast(ubyte)3u]), TextStyle([cast(ubyte)93u])), null), false, Complete!(T))`
source\argparse\package.d(794,12):        instantiated from here: `CLI!(Config('=', '\xff', '-', "--", false, false, true, StylingMode.autodetect, null, Style(TextStyle([cast(ubyte)1u]), TextStyle([cast(ubyte)1u]), TextStyle([cast(ubyte)1u, cast(ubyte)4u]), TextStyle([cast(ubyte)93u]), TextStyle([cast(ubyte)3u]), TextStyle([cast(ubyte)93u])), null), T)`
C:\D\dmd2\windows\bin\..\..\src\phobos\std\sumtype.d-mixin-2084(2084,7): Error: unterminated string constant starting at C:\D\dmd2\windows\bin\..\..\src\phobos\std\sumtype.d-mixin-2084(2084,14)
C:\D\dmd2\windows\bin\..\..\src\phobos\std\sumtype.d-mixin-2084(2084,14): Error: no identifier for declarator `handler`
C:\D\dmd2\windows\bin\dmd.exe failed with exit code 1.

Failed:

C:\D\dmd2\windows\bin\dmd.exe failed with exit code -1073741819.

Succeeded:

Linking...
LINK : .dub\build\argparse-test-library-unittest-cov-windows-x86_64-dmd_v2.100.2-dirty-54DD8361E221F5FB88F9291F67344057\argparse-test-library.exe not found or not built by the last incremental link; performing full link
Running argparse-test-library.exe
September 29, 2022

On Thursday, 29 September 2022 at 00:07:41 UTC, Paul Backus wrote:

>

On Wednesday, 28 September 2022 at 23:15:42 UTC, Andrey Zherikov wrote:

>

On Wednesday, 28 September 2022 at 23:07:34 UTC, Nicholas Wilson wrote:

>

This seems to stem from use of __traits(getPointerBitmap, T), with a T that is not handled properly. If you can get a reduced test case that will make things much easier. dustmite (which should come with dmd, is useful for automatic reduction, otherwise if you have few uses of __traits(getPointerBitmap, T), it might be easier to synthesise an example that crashes the compiler.

I don't use getPointerBitmap in my code:

$ grep -r --include=*.d getPointerBitmap
$

It's used in druntime, by RTInfo:

https://github.com/dlang/druntime/blob/v2.100.2/src/object.d#L3695-L3702

getPointerBitmap needs to be completely rewritten.

Currently it uses the visitor pattern and doesn't cache anything so a N element static array gets walked N times which is very very very slow even ignoring that each one has the same result.

September 29, 2022

On Thursday, 29 September 2022 at 00:48:03 UTC, Andrey Zherikov wrote:

>

I actually see that DMD is very unstable.

The same code fails to build on Ubuntu:

Starting program: /usr/bin/dmd -debug -cov -g -unittest -w -version=Have_argparse -Isource/ source/argparse/package.d -c -of.dub/build/argparse-test-library-unittest-cov-linux.posix-x86_64-dmd_v2.100.0-2270E3354D7B3AAE3038EDF467033FBF/package_bcdb8bae.o -vcolumns
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

Program received signal SIGILL, Illegal instruction.
0x00005555556b67c0 in ParseTimeVisitor<ASTCodegen>::visit(Expression*) ()

(gdb) where
#0  0x00005555556b67c0 in ParseTimeVisitor<ASTCodegen>::visit(Expression*) ()
#1  0x000055555587361a in S2irVisitor::visit(CompoundStatement*) ()
#2  0x0000555555869fea in S2irVisitor::visit(ScopeStatement*) ()
#3  0x000055555586c396 in S2irVisitor::visit(IfStatement*) ()
#4  0x000055555586c528 in S2irVisitor::visit(IfStatement*) ()
#5  0x000055555587361a in S2irVisitor::visit(CompoundStatement*) ()
#6  0x0000555555869fea in S2irVisitor::visit(ScopeStatement*) ()
#7  0x000055555586b477 in S2irVisitor::visit(ForStatement*) ()
#8  0x000055555587361a in S2irVisitor::visit(CompoundStatement*) ()
#9  0x000055555587361a in S2irVisitor::visit(CompoundStatement*) ()
#10 0x00005555558679da in FuncDeclaration_toObjFile(FuncDeclaration*, bool) ()
#11 0x000055555584e0b1 in toObjFile::ToObjFile::visit(TemplateInstance*) ()
#12 0x00005555558ce23e in genObjFile(Module*, bool) ()
#13 0x00005555558e584e in dmd.mars.tryMain(ulong, const(char)**, ref dmd.globals.Param) ()
#14 0x00005555558f27d1 in D main ()
September 28, 2022
On 9/28/22 17:48, Andrey Zherikov wrote:
> without any change in source files:
>
> Failed:
[...]
> Failed:
[...]
> Succeeded:

I see progress. :o)

Ali


September 28, 2022

On 9/28/22 9:01 PM, Andrey Zherikov wrote:

>

On Thursday, 29 September 2022 at 00:48:03 UTC, Andrey Zherikov wrote:

>

I actually see that DMD is very unstable.

This seems like it might be an out of memory problem. When the compiler runs out of memory, any of a number of things might happen, including segfaults.

-Steve

September 29, 2022

On Thursday, 29 September 2022 at 03:19:08 UTC, Steven Schveighoffer wrote:

>

On 9/28/22 9:01 PM, Andrey Zherikov wrote:

>

On Thursday, 29 September 2022 at 00:48:03 UTC, Andrey Zherikov wrote:

>

I actually see that DMD is very unstable.

This seems like it might be an out of memory problem. When the compiler runs out of memory, any of a number of things might happen, including segfaults.

-Steve

Why doesn't it fail with "out of memory exception"? I remember it did in previous versions (I use 2.100.2 now).

« First   ‹ Prev
1 2 3