Re: [ooc-compiler] How to track down a segmentation fault?
Brought to you by:
mva
|
From: Stewart G. <sgr...@us...> - 2009-08-07 02:44:05
|
Hi Frank,
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?
The best way to get some error context is to use gdb. Start your program
under the debugger. When it segfaults look at the backtrace to see the
error context. Unfortunately, the listing will only give you the source
context in the generated C code, but you can often figure out what's
happening from there.
Interface modules are unlikely to cause segfaults as they contain no
generated code. However all bets are off if you've got an error in the
declaration of an external procedure. Incorrect procedure calls may
cause stack frames to be trashed which could get quite nasty.
Hope this helps.
Cheers,
Stewart
Frank Hrebabetzky wrote:
> The following are just a few lines of a larger program:
>
> ------------------------------------------------
> state.MoveList (moves);
> (**) Out.String("move list calculated ");
> (**) IF moves.first=NIL THEN Out.String ("(empty)")
> (**) ELSE Out.String ("(not empty)")
> (**) END; Out.Ln;
> nm:= 0;
> (* grow tree *)
> (**) Out.String("moves.first is ");
> (**) IF moves.first IS Game.MoveItem THEN Out.String("MoveItem")
> (**) ELSE Out.String("NOT MoveItem")
> (**) END; Out.Ln;
> -------------------------------------------------
>
> '(**)' mark the lines included for debugging. When executed, this part
> produces the console output:
>
> -------------------------------------------------
> move list calculated (not empty)
> moves.first is Segmentation fault
> -------------------------------------------------
>
> How do you debug such a thing?
>
> Some additional informations:
> - In other modules of the same program I use a lot of GTK procedures. In
> the corresponding Interface Module I might have some errors. (Could
> these cause the seg fault?)
> - I use Ubuntu 8.04 with its repository version of OOC on a PC with a 32
> bit AMD processor.
>
|