Handle breakpoint jumps while splicing TH functions in ghci
[ghc-hetmet.git] / compiler / main / Breakpoints.hs
1 -----------------------------------------------------------------------------\r
2 --\r
3 -- GHC API breakpoints. This module includes the main API (BkptHandler) and\r
4 -- utility code for implementing a client to this API used in GHCi \r
5 --\r
6 -- Pepe Iborra (supported by Google SoC) 2006\r
7 --\r
8 -----------------------------------------------------------------------------\r
9 \r
10 module Breakpoints where\r
11 \r
12 #ifdef GHCI\r
13 import {-#SOURCE#-} ByteCodeLink ( HValue ) \r
14 #endif\r
15 \r
16 import {-#SOURCE#-} HscTypes     ( Session )\r
17 import Name\r
18 import Var                       ( Id )\r
19 import PrelNames\r
20 \r
21 import GHC.Exts                  ( unsafeCoerce# )\r
22 \r
23 data BkptHandler a = BkptHandler {\r
24      handleBreakpoint  :: forall b. Session -> [(Id,HValue)] -> BkptLocation a ->  String -> b -> IO b\r
25    , isAutoBkptEnabled :: Session -> BkptLocation a -> IO Bool\r
26    }\r
27 \r
28 nullBkptHandler = BkptHandler {\r
29     isAutoBkptEnabled = \ _ _     -> return False,\r
30     handleBreakpoint  = \_ _ _ _ b -> putStrLn "null Bkpt Handler" >> return b\r
31                               }\r
32 \r
33 type BkptLocation a = (a, SiteNumber)\r
34 type SiteNumber   = Int\r
35 \r
36 type SiteMap      = [(SiteNumber, Coord)]\r
37 type Coord        = (Int, Int)\r
38 \r
39 noDbgSites :: SiteMap\r
40 noDbgSites = []\r
41 \r
42 -- | Returns the 'identity' jumps\r
43 --   Used to deal with spliced code, where we don't want breakpoints\r
44 #ifdef GHCI\r
45 lookupBogusBreakpointVal :: Name -> Maybe HValue\r
46 lookupBogusBreakpointVal name \r
47   | name == breakpointJumpName     = Just$ unsafeCoerce# (\_ _ _ _ a->a)\r
48   | name == breakpointAutoJumpName = Just$ unsafeCoerce# (\_ _ _ _ a->a)\r
49   | name == breakpointCondJumpName = Just$ unsafeCoerce# (\_ _ _ _ _ a->a)\r
50   | otherwise = Nothing\r
51 #else \r
52 lookupBogusBreakpointVal _ = Nothing\r
53 #endif //GHCI\r