@@ -14,6 +14,20 @@ import GHC.Debugger.Runtime.Term.Key
1414import GHC.Debugger.Runtime.Term.Cache
1515import GHC.Debugger.Monad
1616
17+ import GHC.Core.TyCon
18+ import GHC.Core.Type
19+ import GHC.Types.Name
20+ import GHC.Core.Class
21+ import GHC.Core.InstEnv
22+ import Debug.Trace
23+ import qualified GHC.Linker.Loader as Loader
24+ import GHC.Driver.Env
25+ import GHC.Types.Var
26+ import GHC.Driver.Config
27+ import GHCi.Message
28+ import GHC.Runtime.Interpreter
29+ import GHC.Utils.Outputable
30+
1731-- | Obtain the runtime 'Term' from a 'TermKey'.
1832--
1933-- The 'TermKey' will be looked up in the 'TermCache' to avoid recomputing the
@@ -73,4 +87,30 @@ isBoringTy :: Type -> Bool
7387isBoringTy t = isDoubleTy t || isFloatTy t || isIntTy t || isWordTy t || isStringTy t
7488 || isIntegerTy t || isNaturalTy t || isCharTy t
7589
90+ onDebugInstance :: Term -> Type -> Debugger Bool
91+ onDebugInstance term t = do
92+ hsc_env <- getSession
93+ instances <- getInstancesForType t
94+
95+ case filter ((== " Debug" ) . occNameString . occName . tyConName . classTyCon . is_cls) instances of
96+ (c: _) -> do
97+ let methods = (classOpItems . is_cls) c
98+ traceM (" Found Debug instance with methods: " ++ (show . map (occNameString . occName . fst )) methods ++ " " )
99+ case filter ((== " debugDisplayTree" ) . occNameString . occName . fst ) methods of
100+ (m: _) -> do
101+ let dfun = is_dfun c
102+ traceM $ " Dictionary function: " ++ showSDocUnsafe (ppr dfun) ++ " :: " ++ showSDocUnsafe (ppr (varType dfun))
103+
104+ let method_id = fst m :: Id
105+ traceM $ " debugDisplayTree method: " ++ showSDocUnsafe (ppr method_id) ++ " :: " ++ showSDocUnsafe (ppr (varType method_id))
106+
107+ (method_hv, _, _) <- liftIO $ Loader. loadName (hscInterp hsc_env) hsc_env (GHC.Types.Var. varName method_id)
108+ (dfun_hv, _, _) <- liftIO $ Loader. loadName (hscInterp hsc_env) hsc_env (GHC.Types.Var. varName dfun)
109+
110+ -- this call fails
111+ ev <- liftIO $ evalStmt (hscInterp hsc_env) (initEvalOpts (hsc_dflags hsc_env) EvalStepNone ) (EvalApp (EvalApp (EvalThis method_hv) (EvalThis dfun_hv)) (EvalThis (val term)))
76112
113+ return True
114+ [] -> return False
115+ return False
116+ _ -> return False
0 commit comments