www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - SIGSEGV in invariant._d_invariant(Object)

reply Keywan Ghadami <keywan.ghadami googlemail.com> writes:
Hi  all,

how to fix an SIGSEGV in invariant._d_invariant(Object)?

Maybe i should give some context:

I am learning D and started hacking the 
dlangide(https://github.com/buggins/dlangide), and normally 
finding the cause of an segmentation fault isn't that hard. But 
this time it is somehow different because gdb prints something 
about a function "_d_invariant" and not directly giving the stack 
trace.

I guess the segmentation fault happens somewhere in the druntime 
(https://github.com/D-Programming-Language/druntime/blob/master/src/rt/invariant.d).

I am wondering if am searching i the right direction. Should i 
try to debug the runtime somehow or better search in the 
application code to find the reason?


This is the output from gdb crashdump:

Using host libthread_db library 
"/lib/x86_64-linux-gnu/libthread_db.so.1".
Core was generated by `bin/dlangide'.
Program terminated with signal SIGSEGV, Segmentation fault.

[Current thread is 1 (Thread 0x7fd86bf965c0 (LWP 3665))]
(gdb) up

dlangui.widgets.lists.StringListAdapter.itemCount() const (
     this=0x7fd85bc03d00) at 
../.dub/packages/dlangui-0.7.32/src/dlangui/widgets/lists.d:306
306	     property override int itemCount() const {
(gdb) up

dlangui.widgets.lists.ListWidget.itemCount() (this=0x7fd85c3af400)
     at 
../.dub/packages/dlangui-0.7.32/src/dlangui/widgets/lists.d:513
513	            return _adapter.itemCount;
Jan 06 2016
parent reply Adam D. Ruppe <destructionator gmail.com> writes:
On Wednesday, 6 January 2016 at 21:50:23 UTC, Keywan Ghadami 
wrote:
 how to fix an SIGSEGV in invariant._d_invariant(Object)?
That means you are calling a method on a null object. Your object might be at the bottom of the stack trace listing. Check your code for a declared class that you forgot to use `new` on, that's usually the cause with new users (in D, you must explicitly new all classes you create.)
Jan 06 2016
parent Keywan Ghadami <keywan.ghadami googlemail.com> writes:
On Wednesday, 6 January 2016 at 21:58:51 UTC, Adam D. Ruppe wrote:
 On Wednesday, 6 January 2016 at 21:50:23 UTC, Keywan Ghadami 
 wrote:
 how to fix an SIGSEGV in invariant._d_invariant(Object)?
That means you are calling a method on a null object. Your object might be at the bottom of the stack trace listing. Check your code for a declared class that you forgot to use `new` on, that's usually the cause with new users (in D, you must explicitly new all classes you create.)
Hi thank you, i am glad to read that i can focus on the applicatin code, and that stacktrace. If i read that stack trace correctly the segfault happens while accessing a struct within the method of a class instance. This instance is the object "_adapter" that can not be null please see the following code from line 512. property int itemCount() { if (_adapter !is null) return _adapter.itemCount; return 0; } could it be that this instance was deallocated from anonther thread, or can it really be be that the object was never created. if so than i do not understand why i do not get a SIGSEGV for the initial method call.
Jan 06 2016