X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=docs%2Fusers_guide%2Fghci.xml;h=7f3fd32ce9cc4a74d89b9c0cfaa521bd90eea5b0;hb=985916e235d53246d5a00b91349803f563377904;hp=94d352b9f7b1ea006e533274bee6cb7bfe49e6d3;hpb=c3e1f7be52fbe5d13a7ee733b99ef6e73762e5ab;p=ghc-hetmet.git diff --git a/docs/users_guide/ghci.xml b/docs/users_guide/ghci.xml index 94d352b..7f3fd32 100644 --- a/docs/users_guide/ghci.xml +++ b/docs/users_guide/ghci.xml @@ -18,7 +18,7 @@ FFIGHCi support Foreign Function InterfaceGHCi support - + Introduction to GHCi Let's start with an example GHCi session. You can fire up @@ -106,7 +106,7 @@ Prelude> enter, GHCi will attempt to evaluate it. - + Loading source files Suppose we have the following Haskell source code, which we @@ -363,7 +363,7 @@ Ok, modules loaded: A, B, C, D. - + Interactive evaluation at the prompt When you type an expression at the prompt, GHCi immediately @@ -906,7 +906,7 @@ $ ghci -lm - :breakpoint list|add|del|stop|step ... + :breakpoint list|add|continue|del|stop|step ... :breakpoint @@ -963,6 +963,15 @@ $ ghci -lm + :continue + :continue + + Shortcut to :breakpoint continue + + + + + :def name expr :def @@ -1551,12 +1560,12 @@ Prelude> :set -fno-glasgow-exts Using the debugger - The debugger allows the insertion of breakpoints at specific locations in the source code. These locations are goberned by event sites, and not by line as in traditional debuggers such as gdb. + The debugger allows the insertion of breakpoints at specific locations in the source code. These locations are governed by event sites, and not by line as in traditional debuggers such as gdb. Once a breakpointed event is hit, the debugger stops the execution and you can examine the local variables in scope in the context of the event, as well as evaluate arbitrary Haskell expressions in a special interactive prompt. - When you are done you issue the :quit + When you are done you issue the :continue command to leave the breakpoint and let the execution go on. Note that not all the GHCi commands are supported in a breakpoint. @@ -1614,7 +1623,7 @@ Local bindings in scope: qsort2.hs:2:15-46> What is happening here is that GHCi has interrupted the evaluation of - qsort at the breakpoint set in line 2, as the prompt indicates. + qsort at the breakpoint set in line 2, as the prompt indicates. At this point you can freely explore the contents of the bindings in scope, but with two catches. First, take into account that due to the lazy nature of Haskell, some of @@ -1622,9 +1631,9 @@ qsort2.hs:2:15-46> trigger a computation. Second: look at the types of the things in scope. GHCi has left its types parameterised by a variable! - Look at the type of qsort, which is + Look at the type of qsort, which is polymorphic on the type of its argument. It does not - tell us really what the types of x and xs can be. + tell us really what the types of x and xs can be. In general, polymorphic programs deal with polymorphic values, and this means that some of the bindings available in a breakpoint site will be parametrically typed. @@ -1635,12 +1644,13 @@ qsort2.hs:2:15-46> This is useful because you cannot just type x in the prompt and expect GHCi to return you its value. Perhaps you know for sure that - x is of type Int, which is an instance of - Show, but GHCi does not have this information. - :print however is fine, because it does not need to know the + x is of type Int, which is an instance of + Show, but GHCi does not have this information. + :print however is fine, because it does not need to know the type to do its work. - Let's go on with the debugging session of the qsort + Let's go on with the debugging session of the qsort example: +A short debugging session qsort2.hs:2:15-46> x This is an untyped, unevaluated computation. You can use seq to @@ -1658,28 +1668,28 @@ x - 10 qsort2.hs:2:15-46> :t x x :: Int - + GHCi reminds us that this value is untyped, and instructs us to force its evaluation - This line forces the evaluation of x + This line forces the evaluation of x Even though x has been evaluated, we cannot simply use its name to see its value! This is a bit counterintuitive, but currently in GHCi the type of a binding - cannot be a type variable a. - Thus, the binding x gets assigned the concrete type Unknown. + cannot be a type variable a. + Thus, the binding x gets assigned the concrete type Unknown. - We can explore x using the :print - command, which does find out that x is of type Int and prints + We can explore x using the :print + command, which does find out that x is of type Int and prints its value accordingly. - :print also updates the type of x with - the most concrete type information available. + :print also updates the type of x with + the most concrete type information available. The example shows the standard way to proceeed with polymorphic values in a breakpoint. @@ -1705,6 +1715,26 @@ x :: Int at line line in module, if any. + + + + :breakpoint continue + + + When at a breakpoint, continue execution up to the next breakpoint + or end of evaluation. + + + + + + :continue + + + Shortcut for :breakpoint continue + + + :breakpoint list @@ -1754,7 +1784,7 @@ x :: Int - are only available + Implicit parameters (see ) are only available at the scope of a breakpoint if there is a explicit type signature. @@ -1767,7 +1797,44 @@ x :: Int - + Tips + + * Use PRAGMAs to fine tune which modules are loaded under debugging mode + + {-# OPTIONS_GHC -fdebugging #-} + + + * Repeated use of seq and + :print may be necessary to observe unevaluated + untyped bindings + see + + + * GHC.Exts.unsafeCoerce can help if you are positive about the type of a binding + +type MyLongType a = [Maybe [Maybe a]] + +main:Main> :m +GHC.Exts +main:Main> main +Local bindings in scope: + x :: a +Main.hs:15> let x' = unsafeCoerce x :: MyLongType Bool +Main.hs:15> x' +[Just [Just False, Just True]] + + Note that a wrong coercion will likely result in your debugging session being interrupted by a segmentation fault + + + * The undocumented (and unsupported) :force command + + equivalent to :print with automatic + seq forcing, + may prove useful to replace sequences of seq and + :print in some situations. + + + + The <filename>.ghci</filename> file .ghcifile @@ -1908,7 +1975,7 @@ x :: Int I can't use Control-C to interrupt computations in GHCi on Windows. - See . + See