summaryrefslogtreecommitdiff
path: root/compiler/main/Breakpoints.hs
blob: fccf1a83c7c84c08f2027f0f85e475b3bf1de813 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
-----------------------------------------------------------------------------
--
-- GHC API breakpoints. This module includes the main API (BkptHandler) and
-- utility code for implementing a client to this API used in GHCi 
--
-- Pepe Iborra (supported by Google SoC) 2006
--
-----------------------------------------------------------------------------

module Breakpoints where

#ifdef GHCI
import {-#SOURCE#-} ByteCodeLink ( HValue ) 
#endif

import {-#SOURCE#-} HscTypes     ( Session )
import Name
import Var                       ( Id )
import PrelNames

import GHC.Exts

#ifdef GHCI
data BkptHandler a = BkptHandler {
     handleBreakpoint  :: forall b. Session -> [(Id,HValue)] -> BkptLocation a ->  String -> b -> IO b
   , isAutoBkptEnabled :: Session -> BkptLocation a -> IO Bool
   }

nullBkptHandler = BkptHandler {
    isAutoBkptEnabled = \ _ _     -> return False,
    handleBreakpoint  = \_ _ _ _ b -> putStrLn "null Bkpt Handler" >> return b
                              }
#endif

type BkptLocation a = (a, SiteNumber)
type SiteNumber   = Int

type SiteMap      = [(SiteNumber, Coord)]
type Coord        = (Int, Int)

noDbgSites :: SiteMap
noDbgSites = []

-- | Returns the 'identity' jumps
--   Used to deal with spliced code, where we don't want breakpoints
#ifdef GHCI
lookupBogusBreakpointVal :: Name -> Maybe HValue
lookupBogusBreakpointVal name 
  | name == breakpointJumpName     = Just$ unsafeCoerce# (\_ _ _ _ a->a)
  | name == breakpointAutoJumpName = Just$ unsafeCoerce# (\_ _ _ _ a->a)
  | name == breakpointCondJumpName = Just$ unsafeCoerce# (\_ _ _ _ _ a->a)
  | otherwise = Nothing
#else 
lookupBogusBreakpointVal _ = Nothing
#endif /* GHCI */