Reputation: 3943
Say I had the following code in Haskell:
x :: Int
y :: Int
z :: Int
x=y
y=z
z=x
Naturally, referring to any of these variables causes execution to bomb with <<loop>>
if using ghc or spin infinitely if using ghci. I'm working on some code that has high potential for circularity if miscoded - is there any way to debug <<loop>>
- can I examine the stack when it bombs to see the circularity?
Upvotes: 3
Views: 240
Reputation: 18189
I looked at the question @TheInternet linked, and the first answer's advice to use -fbreak-on-exception
-fbreak-on-error
and :trace
is pretty good. However I thought I'd mention two small snags I hit that are specific to this question:
<<loop>>
exceptions, only native compiled GHC does that, and the GHCi debugger cannot trace native compiled code.Fortunately, this can be solved by pressing ^C
to interrupt manually.
:trace
and then ^C
manually instead does give a debugger session, but GHCi hasn't inserted any breakpoints and so there's no context to debug!This was also easy to fix: I just changed the first equation to x = id y
. This is enough to get GHCi to insert breakpoints. I suspect that this problem was due to the OP's code cycle containing only trivial variable equations (to quote the GHC User's Guide: "Single variables are typically not considered to be breakpoint locations (unless the variable is the right-hand-side of a function definition, lambda, or case alternative)"), and that it will not usually happen in "real" code.
Upvotes: 2