Thread overview
Mysterious segfault
Jul 10, 2004
Ben Hinkle
Jul 10, 2004
teqDruid
Jul 10, 2004
Ben Hinkle
Jul 10, 2004
teqDruid
Jul 10, 2004
Ben Hinkle
Jul 11, 2004
teqDruid
Jul 11, 2004
Ben Hinkle
Jul 11, 2004
teqDruid
writfnln bug (was Re: Mysterious segfault)
Jul 11, 2004
Ben Hinkle
July 10, 2004
In what cases would a program segfault whenever trying to access a method of a class?  I'm aware of that behavior if the reference to the class is null, but other than that, I'm not sure why it would occur.

This feels like a stupid error, but I'm not seeing it.

I'm using DMD 0.95 in Linux

The offending class can be found here: http://www.neuralnexus.com/projects/nnStore/file/trunk/src/com/neuralnexus/libnnstore/diskIO.d and sample code to access it here: http://www.neuralnexus.com/projects/nnStore/file/trunk/src/com/neuralnexus/libnnstore/createdb.d

I'd appriciate any advice here... I'm pretty stumped.

Thanks
John
July 10, 2004
teqDruid (formerly DemmeGod) wrote:

> In what cases would a program segfault whenever trying to access a method of a class?  I'm aware of that behavior if the reference to the class is null, but other than that, I'm not sure why it would occur.
> 
> This feels like a stupid error, but I'm not seeing it.
> 
> I'm using DMD 0.95 in Linux
> 
> The offending class can be found here:
>
http://www.neuralnexus.com/projects/nnStore/file/trunk/src/com/neuralnexus/libnnstore/diskIO.d
> and sample code to access it here:
>
http://www.neuralnexus.com/projects/nnStore/file/trunk/src/com/neuralnexus/libnnstore/createdb.d
> 
> I'd appriciate any advice here... I'm pretty stumped.
> 
> Thanks
> John

can you run it in gdb and see where it seg-v's?
July 10, 2004
The output from the sample class I've linked to is:

$ ./createdb
Starting creation...
Database opened
2

So it doesn't even run the debug output that's the first line of the function it's calling.

gdb says:
-----------------
(gdb) run
Starting program: /home/teqdruid/workspace/nnStore/createdb
Starting creation...
Database opened
2

Program received signal SIGSEGV, Segmentation fault.
0x0804c987 in _D3com11neuralnexus10libnnstore6diskIO14nnDiskDatabase10createNodeFC3com11neuralnexus10libnnstore6nnNode8nnNodeIDZC3com11neuralnexus10libnnstore11nnStoreNode11nnStoreNode ()
(gdb) bt
#0  0x0804c987 in _D3com11neuralnexus10libnnstore6diskIO14nnDiskDatabase10createNodeFC3com11neuralnexus10libnnstore6nnNode8nnNodeIDZC3com11neuralnexus10libnnstore11nnStoreNode11nnStoreNode ()
#1  0x0804a8dc in _Dmain ()
#2  0x0804a8dc in _Dmain ()
Previous frame identical to this frame (corrupt stack?)
(gdb)
------------------------
I'm not sure what other information in gdb is useful, since I'm not too familiar with the tool.

Thanks
John

On Sat, 10 Jul 2004 09:12:04 -0400, Ben Hinkle
wrote:

> teqDruid (formerly DemmeGod) wrote:
> 
>> In what cases would a program segfault whenever trying to access a method of a class?  I'm aware of that behavior if the reference to the class is null, but other than that, I'm not sure why it would occur.
>> 
>> This feels like a stupid error, but I'm not seeing it.
>> 
>> I'm using DMD 0.95 in Linux
>> 
>> The offending class can be found here:
>>
> http://www.neuralnexus.com/projects/nnStore/file/trunk/src/com/neuralnexus/libnnstore/diskIO.d
>> and sample code to access it here:
>>
> http://www.neuralnexus.com/projects/nnStore/file/trunk/src/com/neuralnexus/libnnstore/createdb.d
>> 
>> I'd appriciate any advice here... I'm pretty stumped.
>> 
>> Thanks
>> John
> 
> can you run it in gdb and see where it seg-v's?

July 10, 2004
teqDruid wrote:

> The output from the sample class I've linked to is:
> 
> $ ./createdb
> Starting creation...
> Database opened
> 2
> 
> So it doesn't even run the debug output that's the first line of the function it's calling.
> 
> gdb says:
> -----------------
> (gdb) run
> Starting program: /home/teqdruid/workspace/nnStore/createdb
> Starting creation...
> Database opened
> 2
> 
> Program received signal SIGSEGV, Segmentation fault.
> 0x0804c987 in
>
_D3com11neuralnexus10libnnstore6diskIO14nnDiskDatabase10createNodeFC3com11neuralnexus10libnnstore6nnNode8nnNodeIDZC3com11neuralnexus10libnnstore11nnStoreNode11nnStoreNode
> () (gdb) bt
> #0  0x0804c987 in
>
#_D3com11neuralnexus10libnnstore6diskIO14nnDiskDatabase10createNodeFC3com11neuralnexus10libnnstore6nnNode8nnNodeIDZC3com11neuralnexus10libnnstore11nnStoreNode11nnStoreNode
> #()
> #1  0x0804a8dc in _Dmain ()
> #2  0x0804a8dc in _Dmain ()
> Previous frame identical to this frame (corrupt stack?)
> (gdb)
> ------------------------
> I'm not sure what other information in gdb is useful, since I'm not too familiar with the tool.
> 
> Thanks
> John
> 
> On Sat, 10 Jul 2004 09:12:04 -0400, Ben Hinkle
> wrote:
> 
>> teqDruid (formerly DemmeGod) wrote:
>> 
>>> In what cases would a program segfault whenever trying to access a method of a class?  I'm aware of that behavior if the reference to the class is null, but other than that, I'm not sure why it would occur.
>>> 
>>> This feels like a stupid error, but I'm not seeing it.
>>> 
>>> I'm using DMD 0.95 in Linux
>>> 
>>> The offending class can be found here:
>>>
>>
http://www.neuralnexus.com/projects/nnStore/file/trunk/src/com/neuralnexus/libnnstore/diskIO.d
>>> and sample code to access it here:
>>>
>>
http://www.neuralnexus.com/projects/nnStore/file/trunk/src/com/neuralnexus/libnnstore/createdb.d
>>> 
>>> I'd appriciate any advice here... I'm pretty stumped.
>>> 
>>> Thanks
>>> John
>> 
>> can you run it in gdb and see where it seg-v's?

crazy idea: I notice you are importing both std.stream and std.stdio - could it be the wrong stdout is being used? Does it do the same thing with printf instead of writef?
July 10, 2004
I added these two lines:
alias std.stdio.writef writef;
alias std.stdio.writefln writefln;

To no avail.

On Sat, 10 Jul 2004 16:40:36 -0400, Ben Hinkle wrote:

> teqDruid wrote:
> 
>> The output from the sample class I've linked to is:
>> 
>> $ ./createdb
>> Starting creation...
>> Database opened
>> 2
>> 
>> So it doesn't even run the debug output that's the first line of the function it's calling.
>> 
>> gdb says:
>> -----------------
>> (gdb) run
>> Starting program: /home/teqdruid/workspace/nnStore/createdb Starting
>> creation...
>> Database opened
>> 2
>> 
>> Program received signal SIGSEGV, Segmentation fault. 0x0804c987 in
>>
> _D3com11neuralnexus10libnnstore6diskIO14nnDiskDatabase10createNodeFC3com11neuralnexus10libnnstore6nnNode8nnNodeIDZC3com11neuralnexus10libnnstore11nnStoreNode11nnStoreNode
>> () (gdb) bt
>> #0  0x0804c987 in
>>
> #_D3com11neuralnexus10libnnstore6diskIO14nnDiskDatabase10createNodeFC3com11neuralnexus10libnnstore6nnNode8nnNodeIDZC3com11neuralnexus10libnnstore11nnStoreNode11nnStoreNode
>> #()
>> #1  0x0804a8dc in _Dmain ()
>> #2  0x0804a8dc in _Dmain ()
>> Previous frame identical to this frame (corrupt stack?) (gdb)
>> ------------------------
>> I'm not sure what other information in gdb is useful, since I'm not too familiar with the tool.
>> 
>> Thanks
>> John
>> 
>> On Sat, 10 Jul 2004 09:12:04 -0400, Ben Hinkle wrote:
>> 
>>> teqDruid (formerly DemmeGod) wrote:
>>> 
>>>> In what cases would a program segfault whenever trying to access a method of a class?  I'm aware of that behavior if the reference to the class is null, but other than that, I'm not sure why it would occur.
>>>> 
>>>> This feels like a stupid error, but I'm not seeing it.
>>>> 
>>>> I'm using DMD 0.95 in Linux
>>>> 
>>>> The offending class can be found here:
>>>>
>>>>
> http://www.neuralnexus.com/projects/nnStore/file/trunk/src/com/neuralnexus/libnnstore/diskIO.d
>>>> and sample code to access it here:
>>>>
>>>>
> http://www.neuralnexus.com/projects/nnStore/file/trunk/src/com/neuralnexus/libnnstore/createdb.d
>>>> 
>>>> I'd appriciate any advice here... I'm pretty stumped.
>>>> 
>>>> Thanks
>>>> John
>>> 
>>> can you run it in gdb and see where it seg-v's?
> 
> crazy idea: I notice you are importing both std.stream and std.stdio - could it be the wrong stdout is being used? Does it do the same thing with printf instead of writef?

July 10, 2004
teqDruid wrote:

> I added these two lines:
> alias std.stdio.writef writef;
> alias std.stdio.writefln writefln;
> 
> To no avail.

I meant try replacing writef with printf. The stack looks like it is in the right function but since that first writefln didn't print anything it must have messed up at the writefln somehow. It isn't a problem of flushing buffers since the newline in writefln would have flushed stdout if the writefln worked.

> On Sat, 10 Jul 2004 16:40:36 -0400, Ben Hinkle wrote:
> 
>> teqDruid wrote:
>> 
>>> The output from the sample class I've linked to is:
>>> 
>>> $ ./createdb
>>> Starting creation...
>>> Database opened
>>> 2
>>> 
>>> So it doesn't even run the debug output that's the first line of the function it's calling.
>>> 
>>> gdb says:
>>> -----------------
>>> (gdb) run
>>> Starting program: /home/teqdruid/workspace/nnStore/createdb Starting
>>> creation...
>>> Database opened
>>> 2
>>> 
>>> Program received signal SIGSEGV, Segmentation fault. 0x0804c987 in
>>>
>>
_D3com11neuralnexus10libnnstore6diskIO14nnDiskDatabase10createNodeFC3com11neuralnexus10libnnstore6nnNode8nnNodeIDZC3com11neuralnexus10libnnstore11nnStoreNode11nnStoreNode
>>> () (gdb) bt
>>> #0  0x0804c987 in
>>>
>>
#_D3com11neuralnexus10libnnstore6diskIO14nnDiskDatabase10createNodeFC3com11neuralnexus10libnnstore6nnNode8nnNodeIDZC3com11neuralnexus10libnnstore11nnStoreNode11nnStoreNode
>>> #()
>>> #1  0x0804a8dc in _Dmain ()
>>> #2  0x0804a8dc in _Dmain ()
>>> Previous frame identical to this frame (corrupt stack?) (gdb)
>>> ------------------------
>>> I'm not sure what other information in gdb is useful, since I'm not too familiar with the tool.
>>> 
>>> Thanks
>>> John
>>> 
>>> On Sat, 10 Jul 2004 09:12:04 -0400, Ben Hinkle wrote:
>>> 
>>>> teqDruid (formerly DemmeGod) wrote:
>>>> 
>>>>> In what cases would a program segfault whenever trying to access a method of a class?  I'm aware of that behavior if the reference to the class is null, but other than that, I'm not sure why it would occur.
>>>>> 
>>>>> This feels like a stupid error, but I'm not seeing it.
>>>>> 
>>>>> I'm using DMD 0.95 in Linux
>>>>> 
>>>>> The offending class can be found here:
>>>>>
>>>>>
>>
http://www.neuralnexus.com/projects/nnStore/file/trunk/src/com/neuralnexus/libnnstore/diskIO.d
>>>>> and sample code to access it here:
>>>>>
>>>>>
>>
http://www.neuralnexus.com/projects/nnStore/file/trunk/src/com/neuralnexus/libnnstore/createdb.d
>>>>> 
>>>>> I'd appriciate any advice here... I'm pretty stumped.
>>>>> 
>>>>> Thanks
>>>>> John
>>>> 
>>>> can you run it in gdb and see where it seg-v's?
>> 
>> crazy idea: I notice you are importing both std.stream and std.stdio - could it be the wrong stdout is being used? Does it do the same thing with printf instead of writef?

July 11, 2004
That did the trick.  So how should I use writef?

Thanks for the help
John

On Sat, 10 Jul 2004 18:58:50 -0400, Ben Hinkle wrote:

> teqDruid wrote:
> 
>> I added these two lines:
>> alias std.stdio.writef writef;
>> alias std.stdio.writefln writefln;
>> 
>> To no avail.
> 
> I meant try replacing writef with printf. The stack looks like it is in the right function but since that first writefln didn't print anything it must have messed up at the writefln somehow. It isn't a problem of flushing buffers since the newline in writefln would have flushed stdout if the writefln worked.
> 
July 11, 2004
teqDruid wrote:

> That did the trick.  So how should I use writef?

I tried to reproduce the seg-v with a simpler example to see where the bug
is exactly but could get it seg-v. How did you compile those files? From
what I understand your code should have worked fine.

> Thanks for the help

np - if there's a bug with writef it would be nice to narrow it down to report to Walter.

> John
>
> On Sat, 10 Jul 2004 18:58:50 -0400, Ben Hinkle wrote:
> 
>> teqDruid wrote:
>> 
>>> I added these two lines:
>>> alias std.stdio.writef writef;
>>> alias std.stdio.writefln writefln;
>>> 
>>> To no avail.
>> 
>> I meant try replacing writef with printf. The stack looks like it is in the right function but since that first writefln didn't print anything it must have messed up at the writefln somehow. It isn't a problem of flushing buffers since the newline in writefln would have flushed stdout if the writefln worked.
>>

July 11, 2004
dmd -Ibuild -Idui/src -unittest	-g -debug -d

If you've got a copy of Subversion and Scons:
$svn co http://svn.neuralnexus.com/nnStore nnStore
$cd nnStore
$scons createdb
or
#scons test

John
On Sat, 10 Jul 2004 21:55:34 -0400, Ben Hinkle wrote:

> teqDruid wrote:
> 
>> That did the trick.  So how should I use writef?
> 
> I tried to reproduce the seg-v with a simpler example to see where the bug
> is exactly but could get it seg-v. How did you compile those files? From
> what I understand your code should have worked fine.
> 
>> Thanks for the help
> 
> np - if there's a bug with writef it would be nice to narrow it down to report to Walter.
> 
>> John
>>
>> On Sat, 10 Jul 2004 18:58:50 -0400, Ben Hinkle wrote:
>> 
>>> teqDruid wrote:
>>> 
>>>> I added these two lines:
>>>> alias std.stdio.writef writef;
>>>> alias std.stdio.writefln writefln;
>>>> 
>>>> To no avail.
>>> 
>>> I meant try replacing writef with printf. The stack looks like it is in the right function but since that first writefln didn't print anything it must have messed up at the writefln somehow. It isn't a problem of flushing buffers since the newline in writefln would have flushed stdout if the writefln worked.
>>>
>>>

July 11, 2004
ok, I found some simple reproduction steps (on Linux):

file1.d:
import std.stdio;
void foo() { writefln("foo"); }

file2.d:
import file1;
import std.stdio;
int main() {
  writefln("before foo");
  foo();
  return 0;
}

dmd file1.d file2.d
run file1

Both the writefln's are needed. If either are removed it works fine.


Ben Hinkle wrote:

> teqDruid wrote:
> 
>> That did the trick.  So how should I use writef?
> 
> I tried to reproduce the seg-v with a simpler example to see where the bug
> is exactly but could get it seg-v. How did you compile those files? From
> what I understand your code should have worked fine.
> 
>> Thanks for the help
> 
> np - if there's a bug with writef it would be nice to narrow it down to report to Walter.
> 
>> John
>>
>> On Sat, 10 Jul 2004 18:58:50 -0400, Ben Hinkle wrote:
>> 
>>> teqDruid wrote:
>>> 
>>>> I added these two lines:
>>>> alias std.stdio.writef writef;
>>>> alias std.stdio.writefln writefln;
>>>> 
>>>> To no avail.
>>> 
>>> I meant try replacing writef with printf. The stack looks like it is in the right function but since that first writefln didn't print anything it must have messed up at the writefln somehow. It isn't a problem of flushing buffers since the newline in writefln would have flushed stdout if the writefln worked.
>>>