Created
November 3, 2021 09:36
-
-
Save guibou/5fe0f5d195b4def4b10262b41d6f371f to your computer and use it in GitHub Desktop.
Test of GHC debugger with GHC 9.2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ghci> :l ~/TestDebug.hs | |
[1 of 1] Compiling Main ( /home/guillaume/TestDebug.hs, interpreted ) | |
Ok, one module loaded. | |
ghci> -- Let's add a breakpoint in go | |
ghci> :break fact.go | |
Breakpoint 0 activated at /home/guillaume/TestDebug.hs:8:16-23 | |
Breakpoint 1 activated at /home/guillaume/TestDebug.hs:(9,17)-(11,26) | |
ghci> :trace fact 10 | |
Stopped in Main.fact.go, /home/guillaume/TestDebug.hs:(9,17)-(11,26) | |
_result :: IO Int = _ | |
acc :: Int = 1 | |
n :: Int = 10 | |
[/home/guillaume/TestDebug.hs:(9,17)-(11,26)] ghci> :set stop :list | |
[/home/guillaume/TestDebug.hs:(9,17)-(11,26)] ghci> -- I've just set :list each time I stop at a breakpoint, that's convenient. | |
[/home/guillaume/TestDebug.hs:(9,17)-(11,26)] ghci> :continue | |
Yada | |
Stopped in Main.fact.go, /home/guillaume/TestDebug.hs:(9,17)-(11,26) | |
_result :: IO Int = _ | |
acc :: Int = 10 | |
n :: Int = 9 | |
8 go acc 0 = pure acc | |
9 go !acc n = do | |
10 putStrLn "Yada" | |
11 go (acc * n) (n - 1) | |
12 | |
[/home/guillaume/TestDebug.hs:(9,17)-(11,26)] ghci> :continue | |
Yada | |
Stopped in Main.fact.go, /home/guillaume/TestDebug.hs:(9,17)-(11,26) | |
_result :: IO Int = _ | |
acc :: Int = 90 | |
n :: Int = 8 | |
8 go acc 0 = pure acc | |
9 go !acc n = do | |
10 putStrLn "Yada" | |
11 go (acc * n) (n - 1) | |
12 | |
[/home/guillaume/TestDebug.hs:(9,17)-(11,26)] ghci> -- we can inspect values | |
[/home/guillaume/TestDebug.hs:(9,17)-(11,26)] ghci> n | |
8 | |
[/home/guillaume/TestDebug.hs:(9,17)-(11,26)] ghci> acc | |
90 | |
[/home/guillaume/TestDebug.hs:(9,17)-(11,26)] ghci> :step | |
Stopped in Main.fact.go, /home/guillaume/TestDebug.hs:10:7-21 | |
_result :: IO () = _ | |
9 go !acc n = do | |
10 putStrLn "Yada" | |
11 go (acc * n) (n - 1) | |
[/home/guillaume/TestDebug.hs:10:7-21] ghci> :step | |
Yada | |
Stopped in Main.fact.go, /home/guillaume/TestDebug.hs:11:7-26 | |
_result :: IO Int = _ | |
acc :: Int = 90 | |
n :: Int = 8 | |
10 putStrLn "Yada" | |
11 go (acc * n) (n - 1) | |
12 | |
[/home/guillaume/TestDebug.hs:11:7-26] ghci> :step | |
Stopped in Main.fact.go, /home/guillaume/TestDebug.hs:11:21-25 | |
_result :: Int = _ | |
n :: Int = 8 | |
10 putStrLn "Yada" | |
11 go (acc * n) (n - 1) | |
12 | |
[/home/guillaume/TestDebug.hs:11:21-25] ghci> -- Here we saw sub expression evaluation | |
[/home/guillaume/TestDebug.hs:11:21-25] ghci> :force _result | |
_result = 7 | |
[/home/guillaume/TestDebug.hs:11:21-25] ghci> :step | |
Stopped in Main.fact.go, /home/guillaume/TestDebug.hs:11:11-17 | |
_result :: Int = _ | |
acc :: Int = 90 | |
n :: Int = 8 | |
10 putStrLn "Yada" | |
11 go (acc * n) (n - 1) | |
12 | |
[/home/guillaume/TestDebug.hs:11:11-17] ghci> :step | |
Stopped in Main.fact.go, /home/guillaume/TestDebug.hs:(9,17)-(11,26) | |
_result :: IO Int = _ | |
acc :: Int = 720 | |
n :: Int = 7 | |
8 go acc 0 = pure acc | |
9 go !acc n = do | |
10 putStrLn "Yada" | |
11 go (acc * n) (n - 1) | |
12 | |
[/home/guillaume/TestDebug.hs:(9,17)-(11,26)] ghci> :step | |
Stopped in Main.fact.go, /home/guillaume/TestDebug.hs:10:7-21 | |
_result :: IO () = _ | |
9 go !acc n = do | |
10 putStrLn "Yada" | |
11 go (acc * n) (n - 1) | |
[/home/guillaume/TestDebug.hs:10:7-21] ghci> :step | |
Yada | |
Stopped in Main.fact.go, /home/guillaume/TestDebug.hs:11:7-26 | |
_result :: IO Int = _ | |
acc :: Int = 720 | |
n :: Int = 7 | |
10 putStrLn "Yada" | |
11 go (acc * n) (n - 1) | |
12 | |
[/home/guillaume/TestDebug.hs:11:7-26] ghci> -- we can also skip N times | |
[/home/guillaume/TestDebug.hs:11:7-26] ghci> :continue 4 | |
Stopped in Main.fact.go, /home/guillaume/TestDebug.hs:(9,17)-(11,26) | |
_result :: IO Int = _ | |
acc :: Int = 5040 | |
n :: Int = 6 | |
8 go acc 0 = pure acc | |
9 go !acc n = do | |
10 putStrLn "Yada" | |
11 go (acc * n) (n - 1) | |
12 | |
[/home/guillaume/TestDebug.hs:(9,17)-(11,26)] ghci> :continue 20 | |
Yada | |
Yada | |
Yada | |
Yada | |
Yada | |
Stopped in Main.fact.go, /home/guillaume/TestDebug.hs:11:7-26 | |
_result :: IO Int = _ | |
acc :: Int = 1814400 | |
n :: Int = 2 | |
10 putStrLn "Yada" | |
11 go (acc * n) (n - 1) | |
12 | |
[/home/guillaume/TestDebug.hs:11:7-26] ghci> -- We can inspect history | |
[/home/guillaume/TestDebug.hs:11:7-26] ghci> :history | |
-1 : fact:go (/home/guillaume/TestDebug.hs:(9,17)-(11,26)) | |
-2 : fact:go (/home/guillaume/TestDebug.hs:11:7-26) | |
-3 : fact:go (/home/guillaume/TestDebug.hs:10:7-21) | |
-4 : fact:go (/home/guillaume/TestDebug.hs:(9,17)-(11,26)) | |
-5 : fact:go (/home/guillaume/TestDebug.hs:11:11-17) | |
-6 : fact:go (/home/guillaume/TestDebug.hs:11:21-25) | |
-7 : fact:go (/home/guillaume/TestDebug.hs:11:7-26) | |
-8 : fact:go (/home/guillaume/TestDebug.hs:10:7-21) | |
-9 : fact:go (/home/guillaume/TestDebug.hs:(9,17)-(11,26)) | |
-10 : fact:go (/home/guillaume/TestDebug.hs:(9,17)-(11,26)) | |
-11 : fact:go (/home/guillaume/TestDebug.hs:(9,17)-(11,26)) | |
-12 : fact (/home/guillaume/TestDebug.hs:6:8-11) | |
<end of history> | |
[/home/guillaume/TestDebug.hs:11:7-26] ghci> -- and we can even have a look back in history | |
[/home/guillaume/TestDebug.hs:11:7-26] ghci> :back | |
Logged breakpoint at /home/guillaume/TestDebug.hs:(9,17)-(11,26) | |
_result :: IO Int | |
acc :: Int | |
n :: Int | |
8 go acc 0 = pure acc | |
9 go !acc n = do | |
10 putStrLn "Yada" | |
11 go (acc * n) (n - 1) | |
12 | |
[-1: /home/guillaume/TestDebug.hs:(9,17)-(11,26)] ghci> :back | |
Logged breakpoint at /home/guillaume/TestDebug.hs:11:7-26 | |
_result :: IO Int | |
acc :: Int | |
n :: Int | |
10 putStrLn "Yada" | |
11 go (acc * n) (n - 1) | |
12 | |
[-2: /home/guillaume/TestDebug.hs:11:7-26] ghci> :back | |
Logged breakpoint at /home/guillaume/TestDebug.hs:10:7-21 | |
_result :: IO () | |
9 go !acc n = do | |
10 putStrLn "Yada" | |
11 go (acc * n) (n - 1) | |
[-3: /home/guillaume/TestDebug.hs:10:7-21] ghci> :back | |
Logged breakpoint at /home/guillaume/TestDebug.hs:(9,17)-(11,26) | |
_result :: IO Int | |
acc :: Int | |
n :: Int | |
8 go acc 0 = pure acc | |
9 go !acc n = do | |
10 putStrLn "Yada" | |
11 go (acc * n) (n - 1) | |
12 | |
[-4: /home/guillaume/TestDebug.hs:(9,17)-(11,26)] ghci> :back | |
Logged breakpoint at /home/guillaume/TestDebug.hs:11:11-17 | |
_result :: Int | |
acc :: Int | |
n :: Int | |
10 putStrLn "Yada" | |
11 go (acc * n) (n - 1) | |
12 | |
[-5: /home/guillaume/TestDebug.hs:11:11-17] ghci> :back | |
Warning: _result has been evaluated, some bindings have been lost | |
Logged breakpoint at /home/guillaume/TestDebug.hs:11:21-25 | |
_result :: t | |
10 putStrLn "Yada" | |
11 go (acc * n) (n - 1) | |
12 | |
[-6: /home/guillaume/TestDebug.hs:11:21-25] ghci> :back | |
Logged breakpoint at /home/guillaume/TestDebug.hs:11:7-26 | |
_result :: IO Int | |
acc :: Int | |
n :: Int | |
10 putStrLn "Yada" | |
11 go (acc * n) (n - 1) | |
12 | |
[-7: /home/guillaume/TestDebug.hs:11:7-26] ghci> :back | |
Logged breakpoint at /home/guillaume/TestDebug.hs:10:7-21 | |
_result :: IO () | |
9 go !acc n = do | |
10 putStrLn "Yada" | |
11 go (acc * n) (n - 1) | |
[-8: /home/guillaume/TestDebug.hs:10:7-21] ghci> :step | |
Stopped in Main.fact.go, /home/guillaume/TestDebug.hs:11:21-25 | |
_result :: Int = _ | |
n :: Int = 2 | |
10 putStrLn "Yada" | |
11 go (acc * n) (n - 1) | |
12 | |
[/home/guillaume/TestDebug.hs:11:21-25] ghci> :history | |
-1 : fact:go (/home/guillaume/TestDebug.hs:11:7-26) | |
-2 : fact:go (/home/guillaume/TestDebug.hs:(9,17)-(11,26)) | |
-3 : fact:go (/home/guillaume/TestDebug.hs:11:7-26) | |
-4 : fact:go (/home/guillaume/TestDebug.hs:10:7-21) | |
-5 : fact:go (/home/guillaume/TestDebug.hs:(9,17)-(11,26)) | |
-6 : fact:go (/home/guillaume/TestDebug.hs:11:11-17) | |
-7 : fact:go (/home/guillaume/TestDebug.hs:11:21-25) | |
-8 : fact:go (/home/guillaume/TestDebug.hs:11:7-26) | |
-9 : fact:go (/home/guillaume/TestDebug.hs:10:7-21) | |
-10 : fact:go (/home/guillaume/TestDebug.hs:(9,17)-(11,26)) | |
-11 : fact:go (/home/guillaume/TestDebug.hs:(9,17)-(11,26)) | |
-12 : fact:go (/home/guillaume/TestDebug.hs:(9,17)-(11,26)) | |
-13 : fact (/home/guillaume/TestDebug.hs:6:8-11) | |
<end of history> | |
[/home/guillaume/TestDebug.hs:11:21-25] ghci> :forward | |
already at the beginning of the history | |
[/home/guillaume/TestDebug.hs:11:21-25] ghci> :contiue | |
unknown command ':contiue' | |
use :? for help. | |
[/home/guillaume/TestDebug.hs:11:21-25] ghci> :continue | |
Yada | |
Stopped in Main.fact.go, /home/guillaume/TestDebug.hs:11:7-26 | |
_result :: IO Int = _ | |
acc :: Int = 3628800 | |
n :: Int = 1 | |
10 putStrLn "Yada" | |
11 go (acc * n) (n - 1) | |
12 | |
[/home/guillaume/TestDebug.hs:11:7-26] ghci> :continue | |
Stopped in Main.fact.go, /home/guillaume/TestDebug.hs:8:16-23 | |
_result :: IO t = _ | |
acc :: t = _ | |
7 where | |
8 go acc 0 = pure acc | |
9 go !acc n = do | |
[/home/guillaume/TestDebug.hs:8:16-23] ghci> :history | |
-1 : fact:go (/home/guillaume/TestDebug.hs:11:7-26) | |
-2 : fact:go (/home/guillaume/TestDebug.hs:11:21-25) | |
-3 : fact:go (/home/guillaume/TestDebug.hs:11:7-26) | |
-4 : fact:go (/home/guillaume/TestDebug.hs:(9,17)-(11,26)) | |
-5 : fact:go (/home/guillaume/TestDebug.hs:11:7-26) | |
-6 : fact:go (/home/guillaume/TestDebug.hs:10:7-21) | |
-7 : fact:go (/home/guillaume/TestDebug.hs:(9,17)-(11,26)) | |
-8 : fact:go (/home/guillaume/TestDebug.hs:11:11-17) | |
-9 : fact:go (/home/guillaume/TestDebug.hs:11:21-25) | |
-10 : fact:go (/home/guillaume/TestDebug.hs:11:7-26) | |
-11 : fact:go (/home/guillaume/TestDebug.hs:10:7-21) | |
-12 : fact:go (/home/guillaume/TestDebug.hs:(9,17)-(11,26)) | |
-13 : fact:go (/home/guillaume/TestDebug.hs:(9,17)-(11,26)) | |
-14 : fact:go (/home/guillaume/TestDebug.hs:(9,17)-(11,26)) | |
-15 : fact (/home/guillaume/TestDebug.hs:6:8-11) | |
<end of history> | |
[/home/guillaume/TestDebug.hs:8:16-23] ghci> :back 15 | |
Logged breakpoint at /home/guillaume/TestDebug.hs:6:8-11 | |
_result :: Int -> IO Int | |
5 fact :: Int -> IO Int | |
6 fact = go 1 | |
7 where | |
[-15: /home/guillaume/TestDebug.hs:6:8-11] ghci> :force _result | |
_result = _ | |
[-15: /home/guillaume/TestDebug.hs:6:8-11] ghci> -- haha, that's fun | |
[-15: /home/guillaume/TestDebug.hs:6:8-11] ghci> :continue | |
3628800 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE TypeApplications #-} | |
{-# LANGUAGE BangPatterns #-} | |
import Control.Arrow | |
fact :: Int -> IO Int | |
fact = go 1 | |
where | |
go acc 0 = pure acc | |
go !acc n = do | |
putStrLn "Yada" | |
go (acc * n) (n - 1) | |
main = do | |
mapM_ (\n -> print =<< fact n) [0..100] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment