Re: [ooc-compiler] How to track down a segmentation fault?
Brought to you by:
mva
|
From: Frank H. <hr...@te...> - 2009-08-20 00:40:35
|
On Fri, 07 Aug 2009 10:08:05 +0800
Stewart Greenhill <sgr...@us...> wrote:
Hi Stewart,
> The most common cause of segmentation errors is uninitialised
> pointers. NIL pointers are checked but the run-time system, but
> dereference checks can't differentiate between random garbage on the
> heap and a valid pointer.
>
> Is is possible that "moves.first" has not been initialised?
That was indeed the problem. I relied on Oberon to initialize all
pointers to NULL, but this is not the case if the variable is local to
a procedure as in my appended example. It wouldn't make sense anyway to
initialize a local variable at the first call, when it can have an
arbitrary value on all further calls. But: Is that documented anywhere?
> The best way to get some error context is to use gdb.
I got lost in the C-translations of structures, pointers and their
extensions, so I fell back on the traditional Oberon debugger: MODULE
Out :->
Now for my example which reproduces the problem:
------------------------------------------------
MODULE test;
IMPORT Out;
TYPE
Item = POINTER TO ItemD;
ItemD = RECORD next: Item END;
Header= RECORD first, last: Item END;
PROCEDURE Foo;
VAR list: Header;
BEGIN
IF list.first=NIL THEN Out.String("list.first is NIL")
ELSE Out.String("list.first is NOT NIL")
END;
Out.Ln;
END Foo;
BEGIN
Foo;
END test.
-----------------------------------------------------------
The output is 'list.first is NOT NIL'.
Thanks for the hints.
--
Frank Hrebabetzky +55 / 48 / 3235 1106
Florianopolis, Brazil
|