Johannes Waldmann | 22 Jun 13:04 2013
Picon

how to debug stack overflow?

What is the recommended method 
to find the exact reason for a stack overflow
(when running a Haskell program compiled with ghc)?

When I compile with -prof -auto-all, and run with +RTS -xc,
I see a very short call stack, which can't be right. 
But that's probably because I am calling some library method 
that was compiled without -auto-all so it's invisible in the trace?

I can avoid the overflow by +RTS -K1G  or something
but I want to investigate because it might indicate
some inefficiency in the code (evaluations happening
at the wrong time).

- J.W.
Aleksey Uymanov | 22 Jun 14:37 2013
Picon

Re: how to debug stack overflow?

On Sat, 22 Jun 2013 11:04:21 +0000 (UTC)
Johannes Waldmann <waldmann <at> imn.htwk-leipzig.de> wrote:

> What is the recommended method 

Try to use heap profiling. There is very high probability that the
problem is because of space leak.

--

-- 
Aleksey Uymanov <s9gf4ult <at> gmail.com>
Johannes Waldmann | 22 Jun 16:36 2013
Picon

Re: how to debug stack overflow?

Aleksey Uymanov <s9gf4ult <at> gmail.com> writes:

> Try to use heap profiling. There is very high probability that the
> problem is because of space leak.

Really? Would it help in the standard example:

main = print $ foldr (+) 0 [1 .. 100000000::Int]

this leaks space (that is, cannot run in small space)
only because it leaks closures, right?
but how I'm going to recognize them in the heap profile?

When I run the above with +RTS -K1G -M1G -h -p
I do indeed get heap overflow (instead of stack overflow)
but the heap profile shows an allocation of 30k bytes only.

- J.W.

Gmane