Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Continue debugging in GHC after interrupt

I have a nonterminating expression in Haskell. I want to debug and inspect the reason why it is not terminating. A technique I learned is to use the following in GHCi:

:set -fbreak-on-exception
:trace nonterminating_expression
^C
:hist 50

So I can see the instructions that are running in the infinite computation. The problem is that I would like to continue the computation with :step, ignoring the interrupt. Can I do that?

Any other solutions for debugging nonterminating computations? (History larger than 50 records or other practices to help the task.)

like image 728
Boldizsár Németh Avatar asked Aug 29 '13 07:08

Boldizsár Németh


1 Answers

One thing I've done in the past is use unsafePerformIO to break whenever I press a key:

Let's say t is your original expression, insert x in the expression:

import System.IO
import System.IO.Unsafe

t  i = do print i;    t  (i+1)
t2 i = do print i; x; t2 (i+1)

x = do r <- hReady stdin
       if r then do a<-hGetChar stdin
                    print a -- break on this line
            else print "" 

Then at the ghci prompt:

*Main> :break 9
*Main> t2 0

Press a keyboard key

*Main> :cont

resumes where you left off.

like image 172
ja. Avatar answered Nov 16 '22 06:11

ja.