single-stepping and infinite recursion
dbueno at gmail.com
Mon Nov 26 10:06:29 EST 2007
In the past few days I'd been wondering about how to detect infinite
loops myself, so thanks for this advice, pepe! I've put pepe's advice
on the Wiki under Debugging: http://haskell.org/haskellwiki/Debugging
Please feel free to flesh it out or add more advice as necessary.
On Nov 21, 2007 6:20 AM, pepe <mnislaih at gmail.com> wrote:
> Hi Wolfgang,
> you are right, this behaviour is a bit surprising. What you want to
> observe can be obtained with, for example:
> loop c = putChar c >> loop c
> where loop is not a CAF anymore since it takes an argument.
> In the definition that you gave, main is a CAF and gets evaluated only
> the first time. The subsequent times it is entered do not trigger any
> further evaluation: the IO action is already evaluated and the only
> thing left to do is execute it. This does not trigger a breakpoint
> since no evaluation proper is done.
> For more information about CAFs see
> That page remarks that CAFs are an optimization which does not alter
> referential transparency. Unfortunately their special behaviour is
> highlighted by the ghci debugger.
> If you want to find the reason for an infinite loop:
> 1. enable the flag -fbreak-on-error
> 2. run your expression with :trace (eg :trace loop 'a')
> 3. hit Ctrl-C while your program is stuck in the loop to have the
> debugger break in the loop.
> 4: use :history and :back to find out where the loop is located and why.
> On 20/11/2007, at 16:09, Wolfgang Jeltsch wrote:
> > Hello,
> > please consider the following program:
> > main = putChar 'A' >> main
> > I load this into GHCi, enter :step main, followed by :step and a
> > second :step.
> > Although I would expect to get the As in the output step by step,
> > GHCi now
> > hangs inside the infinite loop. Is this intentional? To me, this
> > seems
> > rather weird. I wanted to use GHCi's debugger to find the reason
> > for an
> > infinite recursion but from my experience it looks as if this might
> > not be
> > possible. :-(
> > Best wishes,
> > Wolfgang
> > _______________________________________________
> > Glasgow-haskell-users mailing list
> > Glasgow-haskell-users at haskell.org
> > http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
> Glasgow-haskell-users mailing list
> Glasgow-haskell-users at haskell.org
More information about the Glasgow-haskell-users