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
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.
participants (2)
-
Aleksey Uymanov
-
Johannes Waldmann