@@ -45,12 +45,6 @@ reportStateSync = do
4545 msg <- getThreadReport
4646 liftIO $ putMVar dbgSyncResponse msg
4747
48- reportStateAsync :: M ()
49- reportStateAsync = do
50- DebuggerChan {.. } <- gets ssDebuggerChan
51- msg <- getThreadReport
52- liftIO $ Unagi. writeChan dbgAsyncEventIn msg
53-
5448getThreadReport :: M DebugOutput
5549getThreadReport = do
5650 tid <- gets ssCurrentThreadId
@@ -120,40 +114,46 @@ showRetainerTree i = do
120114 tree <- getRetainerTree i
121115 liftIO $ putStrLn $ drawTree tree
122116
117+ wrapWithDbgOut :: ([String ] -> M () ) -> [String ] -> M ()
118+ wrapWithDbgOut cmdM args = do
119+ cmdM args
120+ DebuggerChan {.. } <- gets ssDebuggerChan
121+ liftIO $ putMVar dbgSyncResponse DbgOut
122+
123123dbgCommands :: [([String ], String , [String ] -> M () )]
124124dbgCommands =
125125 [ ( [" gc" ]
126126 , " run sync. garbage collector"
127- , \ _ -> do
127+ , wrapWithDbgOut $ \ _ -> do
128128 curClosureAddr <- gets ssCurrentClosureAddr
129129 GC. runGCSync [HeapPtr curClosureAddr]
130130 )
131131 , ( [" cleardb" ]
132132 , " clear retainer db"
133- , \ _ -> clearRetanerDb
133+ , wrapWithDbgOut $ \ _ -> clearRetanerDb
134134 )
135135
136136 , ( [" loaddb" ]
137137 , " load retainer db"
138- , \ _ -> loadRetainerDb2
138+ , wrapWithDbgOut $ \ _ -> loadRetainerDb2
139139 )
140140
141141 , ( [" ?" ]
142142 , " show debuggers' all internal commands"
143- , \ _ -> printHelp
143+ , wrapWithDbgOut $ \ _ -> printHelp
144144 )
145145
146146 , ( [" report" ]
147147 , " report some internal data"
148- , \ _ -> do
148+ , wrapWithDbgOut $ \ _ -> do
149149 heapStart <- gets ssHeapStartAddress
150150 liftIO $ do
151151 putStrLn $ " heap start address: " ++ show heapStart
152152 )
153153
154154 , ( [" query" , " ??" ]
155155 , " queries a given list of NAME_PATTERNs in static global env as substring"
156- , \ patterns -> do
156+ , wrapWithDbgOut $ \ patterns -> do
157157 env <- gets ssStaticGlobalEnv
158158 let filterPattern pat resultList = [n | n <- resultList, List. isInfixOf pat n]
159159 matches = foldr filterPattern (map show $ Map. keys env) patterns
@@ -162,14 +162,14 @@ dbgCommands =
162162
163163 , ( [" ?b" ]
164164 , " list breakpoints"
165- , \ _ -> do
165+ , wrapWithDbgOut $ \ _ -> do
166166 bks <- Map. toList <$> gets ssBreakpoints
167167 liftIO $ putStrLn $ unlines [printf " %-40s %d [fuel]" (BS8. unpack name) fuel | (name, fuel) <- bks]
168168 )
169169
170170 , ( [" ?r" ]
171171 , " [START] [END] list a given region or all regions if the arguments are omitted"
172- , \ case
172+ , wrapWithDbgOut $ \ case
173173 [] -> do
174174 regions <- Map. keys <$> gets ssRegions
175175 liftIO $ putStrLn $ unlines $ map show regions
@@ -180,31 +180,31 @@ dbgCommands =
180180
181181 , ( [" ?r-dump" ]
182182 , " [START] [END] dump all heap object from the given region"
183- , \ case
183+ , wrapWithDbgOut $ \ case
184184 [start] -> showRegion True start start
185185 [start, end] -> showRegion True start end
186186 _ -> pure ()
187187 )
188188
189189 , ( [" +r" ]
190190 , " add region: +r START_CLOSURE_NAME [END_CLOSURE_NAME] ; if only the start is provided then it will be the end marker also"
191- , \ case
191+ , wrapWithDbgOut $ \ case
192192 [start] -> addRegion start start
193193 [start, end] -> addRegion start end
194194 _ -> pure ()
195195 )
196196
197197 , ( [" -r" ]
198198 , " del region: -r START_CLOSURE_NAME [END_CLOSURE_NAME] ; if only the start is provided then it will be the end marker also"
199- , \ case
199+ , wrapWithDbgOut $ \ case
200200 [start] -> delRegion start start
201201 [start, end] -> delRegion start end
202202 _ -> pure ()
203203 )
204204
205205 , ( [" peek-range" , " pr" ]
206206 , " ADDR_START ADDR_END [COUNT] - list all heap objects in the given heap address region, optionally show only the first (COUNT) elements"
207- , \ case
207+ , wrapWithDbgOut $ \ case
208208 [start, end]
209209 | Just s <- Text. readMaybe start
210210 , Just e <- Text. readMaybe end
@@ -223,7 +223,7 @@ dbgCommands =
223223
224224 , ( [" count-range" , " cr" ]
225225 , " ADDR_START ADDR_END - count heap objects in the given heap address region"
226- , \ case
226+ , wrapWithDbgOut $ \ case
227227 [start, end]
228228 | Just s <- Text. readMaybe start
229229 , Just e <- Text. readMaybe end
@@ -235,7 +235,7 @@ dbgCommands =
235235
236236 , ( [" retainer" , " ret" ]
237237 , " ADDR - show the retainer objects (heap objects that refer to the queried object"
238- , \ case
238+ , wrapWithDbgOut $ \ case
239239 [addrS]
240240 | Just addr <- Text. readMaybe addrS
241241 -> showRetainer addr
@@ -244,7 +244,7 @@ dbgCommands =
244244
245245 , ( [" ret-tree" , " rt" ]
246246 , " ADDR - show the retainer tree of an object"
247- , \ case
247+ , wrapWithDbgOut $ \ case
248248 [addrS]
249249 | Just addr <- Text. readMaybe addrS
250250 -> showRetainerTree addr
@@ -253,7 +253,7 @@ dbgCommands =
253253
254254 , ( [" trace-origin" , " to" ]
255255 , " ADDR - traces back heap object origin until the first dead object"
256- , \ case
256+ , wrapWithDbgOut $ \ case
257257 [addrS]
258258 | Just addr <- Text. readMaybe addrS
259259 -> showOriginTrace addr
@@ -262,14 +262,14 @@ dbgCommands =
262262
263263 , ( [" ?e" ]
264264 , " list all trace events and heap address state"
265- , \ _-> do
265+ , wrapWithDbgOut $ \ _-> do
266266 events <- gets ssTraceEvents
267267 forM_ (reverse events) $ \ (msg, AddressState {.. }) -> liftIO $ printf " %-10d %s\n " asNextHeapAddr (show msg)
268268 )
269269
270270 , ( [" ?e-dump" ]
271271 , " list all trace events and the whole address state"
272- , \ _-> do
272+ , wrapWithDbgOut $ \ _-> do
273273 events <- gets ssTraceEvents
274274 forM_ (reverse events) $ \ (msg, a) -> liftIO $ do
275275 print msg
@@ -278,14 +278,14 @@ dbgCommands =
278278
279279 , ( [" ?m" ]
280280 , " list all trace markers and heap address state"
281- , \ _-> do
281+ , wrapWithDbgOut $ \ _-> do
282282 markers <- gets ssTraceMarkers
283283 forM_ (reverse markers) $ \ (msg, AddressState {.. }) -> liftIO $ printf " %-10d %s\n " asNextHeapAddr (show msg)
284284 )
285285
286286 , ( [" ?m-dump" ]
287287 , " list all trace markers and the whole address state"
288- , \ _-> do
288+ , wrapWithDbgOut $ \ _-> do
289289 markers <- gets ssTraceMarkers
290290 forM_ (reverse markers) $ \ (msg, a) -> liftIO $ do
291291 print msg
@@ -294,7 +294,7 @@ dbgCommands =
294294
295295 , ( [" save-state" ]
296296 , " DIR_NAME - save stg state as datalog facts to the given directory"
297- , \ case
297+ , wrapWithDbgOut $ \ case
298298 [dirName] -> do
299299 s <- get
300300 liftIO $ do
@@ -305,7 +305,7 @@ dbgCommands =
305305
306306 , ( [" fuel" ]
307307 , " STEP-COUNT - make multiple steps ; 'fuel -' - turn off step count check"
308- , \ case
308+ , wrapWithDbgOut $ \ case
309309 [" -" ]
310310 -> modify' $ \ s@ StgState {.. } -> s {ssDebugFuel = Nothing }
311311 [countS]
0 commit comments