ghci debugger :trace command does not always extend trace history

Simon Marlow marlowsd at gmail.com
Tue Jan 6 09:10:30 EST 2009


Peter Hercek wrote:
> Hi,
> 
> I expected ":trace expr" to always add data to the trace history but it 
> does not do so for CAFs (which are not reduced yet).
> My point is that the command ":trace z" did not add anything to the 
> trace history and I cannot check why value z is 2, because value of y is 
> not in the trace history. Is this the expected behavior? If it is, how 
> can I make ghci to extend the trace history when "forcing" variables?
> 
> Peter.
> 
> Here is the example:
> 
> status:0 peter at metod [765] ~/tmp
> % cat a.hs
> test :: Int -> Int
> test x =
>   let y = x+1 in
>   let z = y+1 in
>   z
> status:0 peter at metod [766] ~/tmp
> % ghci a.hs
> GHCi, version 6.8.2: http://www.haskell.org/ghc/  :? for help
> Loading package base ... linking ... done.
> [1 of 1] Compiling Main             ( a.hs, interpreted )
> Ok, modules loaded: Main.
> *Main> :break Main 5
> Breakpoint 0 activated at a.hs:5:2
> *Main> :trace test 0
> Stopped at a.hs:5:2
> _result :: Int = _
> z :: Int = _
> 4    let z = y+1 in
> 5    z
> 6
> [a.hs:5:2] *Main> :back
> Logged breakpoint at a.hs:(2,0)-(5,2)
> _result :: Int
> 1  test :: Int -> Int
> 2  test x =
> 3    let y = x+1 in
> 4    let z = y+1 in
> 5    z
> 6
> [-1: a.hs:(2,0)-(5,2)] *Main> :back
> no more logged breakpoints

ok so far - y and z have not been evaluated.

> [-1: a.hs:(2,0)-(5,2)] *Main> :forward
> Stopped at a.hs:5:2
> _result :: Int
> z :: Int
> 4    let z = y+1 in
> 5    z
> 6
> [a.hs:5:2] *Main> :trace z
> 2

this evaluates z.

> [a.hs:5:2] *Main> :back
> Logged breakpoint at a.hs:(2,0)-(5,2)
> _result :: Int
> 1  test :: Int -> Int
> 2  test x =
> 3    let y = x+1 in
> 4    let z = y+1 in
> 5    z
> 6

You are going back in the original context, but I presume you were 
expecting to go back in the evaluation of z.  You can only go back in the 
context of the current evaluation, however.

Try this:

*Main> :break 3
Breakpoint 4 activated at trace.hs:3:10-12
*Main> :trace test 0
Stopped at trace.hs:3:10-12
_result :: Int = _
x :: Int = 90
2  test x =
3    let y = x+1 in
4    let z = y+1 in
[trace.hs:3:10-12] *Main> :history
-1  : test (trace.hs:4:10-12)
-2  : test (trace.hs:5:2)
-3  : test (trace.hs:(2,0)-(5,2))
<end of history>
[trace.hs:3:10-12] *Main> :back
Logged breakpoint at trace.hs:4:10-12
_result :: Int
y :: Int
3    let y = x+1 in
4    let z = y+1 in
5    z
[-1: trace.hs:4:10-12] *Main> :back
Logged breakpoint at trace.hs:5:2
_result :: Int
z :: Int
4    let z = y+1 in
5    z
6

Cheers,
	Simon



More information about the Glasgow-haskell-users mailing list