[mercury-users] Stack overflow, because I don't use unique modes?

Ondrej Bojar oboj7042 at ss1000.ms.mff.cuni.cz
Mon Feb 11 20:35:12 AEDT 2002


On Mon, 11 Feb 2002, Fergus Henderson wrote:

> On 10-Feb-2002, Ondrej Bojar <oboj7042 at ss1000.ms.mff.cuni.cz> wrote:
> > I want Mercury to walk over very big files and get some statistics about
> > the files. I walk line by line, perform (not too simple, but
> > from the outside deterministic) calculation and accumulate the
> > statistics. The problem is that the stack overflows after parsing more
> > than about 50000 lines of input (and succeeds if the input is shorter).
> ...
> > I'm afraid the thing is I do not use di and uo modes for the stats
> > accumulator.
>
> That won't have any effect on stack overflow.
>
> Because of some limitations in Mercury's current mode system,
> unique modes should in general only be used for io__states.
>
> The stack overflow problem is likely to be that you have a main loop
> with a recursive procedure that is not tail recursive.

I guess mmc must *know* which predicate is tail recursive and which is
not. Is there a way to get this information from mmc?

> So, probably the best way to debug the problem is get a C stack trace,
> which you can do by building with
>
> 	GRADEFLAGS = --high-level-code
> 	MGNUCFLAGS = --c-debug --no-c-optimize
> 	MLFLAGS = --c-debug
>
> in your Mmakefile, and then running your program with gdb,
> and using gdb's `backtrace' command.

I tried this and got:
(gdb) run < clip.in
Starting program: /a/ohh/bojar/diplomka/ax/src/teststack0 < clip.in
.(0)..........(1000)..........(2000)..........(3000)..........(4000)..........(5000)..........(6000)..........(7000)..........(8000)..........(9000)..........(10000)..........(11000)..........(12000)..........(13000)..........(14000)..........(15000)..........(16000)..........(17000)..........(18000)..........(19000)..........(20000)..........(21000)..........(22000)..........(23000)..........(24000)..........(25000)..........(26000)..........(27000)..........(28000)..........(29000)..........(30000)..........(31000)..........(32000)..........(33000)..........(34000)..........(35000)..........(36000)..........(37000)..........(38000)..........(39000)..........(40000)..........(41000)..........(42000)..........(43000)..........(44000)..........(45000)..........(46000)..........(47000)..........(48000)..........(49000)..........(50000)..........(51000)...
Program received signal SIGSEGV, Segmentation fault.
0x082194f5 in _entry_mercury__io__read_char_code_4_0 () at io.c:48157
48157   io.c: No such file or directory.
        in io.c
(gdb) backtrace
#0  0x082194f5 in _entry_mercury__io__read_char_code_4_0 () at io.c:48157
#1  0x083b32d5 in MR_call_engine (entry_point=0x83bbd70,
    catch_exceptions=0 '\000') at mercury_engine.c:341
#2  0x083bbca0 in mercury_runtime_main () at mercury_wrapper.c:1135
#3  0x08048a13 in mercury_call_main () at teststack0_init.c:1156
#4  0x08048a4c in mercury_main (argc=1, argv=0xbfffef14)
    at teststack0_init.c:1170
#5  0x08048a6c in main (argc=1, argv=0xbfffef14) at teststack0_init.c:1180
#6  0x083db212 in __libc_start_main (main=0x8048a58 <main>, argc=1,
    ubp_av=0xbfffef14, init=0x80480b4 <_init>, fini=0x842d4e0 <_fini>,
    rtld_fini=0, stack_end=0xbfffef0c) at
../sysdeps/generic/libc-start.c:129
(gdb)

It's somewhere inside Mercury standard library... The most strange thing
is that when I tried to create a minimal example, without my own
libraries, but with the same main -- just count the input lines -- it
works. But if I compile the same with my libraries, it crashes. So the bug
is somewhere deeper...

I do not know, what is the best way to post the code. It's a lot of files
with two different Mmakefiles, and lot of files is not needed...

Thanks for help, Andrew.

--------------------------------------------------------------------------
mercury-users mailing list
post:  mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the users mailing list