@@ -52,10 +52,12 @@ import System.Process
5252import System.Environment
5353import System.FilePath
5454import System.Directory
55+ import Text.Printf
5556
5657data Debuggee = Debuggee { debuggeeHdl :: Handle
5758 , debuggeeInfoTblEnv :: MVar (HM. HashMap InfoTablePtr RawInfoTable )
5859 , debuggeeDwarf :: Maybe Dwarf
60+ , debuggeeFilename :: FilePath
5961 }
6062
6163
@@ -77,24 +79,25 @@ withDebuggee exeName action = do
7779 withCreateProcess cp $ \ _ _ _ _ -> do
7880 dwarf <- getDwarfInfo exeName
7981 -- Now connect to the socket the debuggeeProcess just started
80- withDebuggeeSocket sockName (Just dwarf) action
82+ withDebuggeeSocket exeName sockName (Just dwarf) action
8183
8284
8385-- | Open a debuggee's socket directly
84- withDebuggeeSocket :: FilePath -- ^ debuggee's socket location
86+ withDebuggeeSocket :: FilePath -- ^ executable name of the debuggee
87+ -> FilePath -- ^ debuggee's socket location
8588 -> Maybe Dwarf
8689 -> (Debuggee -> IO a )
8790 -> IO a
88- withDebuggeeSocket sockName mdwarf action = do
91+ withDebuggeeSocket exeName sockName mdwarf action = do
8992 s <- socket AF_UNIX Stream defaultProtocol
9093 connect s (SockAddrUnix sockName)
9194 hdl <- socketToHandle s ReadWriteMode
9295 infoTableEnv <- newMVar mempty
93- action (Debuggee hdl infoTableEnv mdwarf)
96+ action (Debuggee hdl infoTableEnv mdwarf exeName )
9497
9598-- | Send a request to a 'Debuggee' paused with 'pauseDebuggee'.
9699request :: Debuggee -> Request resp -> IO resp
97- request ( Debuggee hdl _ _) req = doRequest hdl req
100+ request d req = doRequest (debuggeeHdl d) req
98101
99102lookupInfoTable :: Debuggee -> RawClosure -> IO (RawInfoTable , RawClosure )
100103lookupInfoTable d rc = do
@@ -155,15 +158,17 @@ lookupDwarfLine w Nothing (d, nd) = do
155158 else Nothing
156159lookupDwarfLine _ (Just r) _ = Just r
157160
158- showFileSnippet :: ([FilePath ], Int , Int ) -> IO ()
159- showFileSnippet (fps, l, c) = go fps
161+ showFileSnippet :: Debuggee -> ([FilePath ], Int , Int ) -> IO ()
162+ showFileSnippet d (fps, l, c) = go fps
160163 where
161164 go [] = putStrLn (" No files could be found: " ++ show fps)
162165 go (fp: fps) = do
163166 exists <- doesFileExist fp
167+ -- get file modtime
164168 if not exists
165169 then go fps
166170 else do
171+ fp `warnIfNewer` (debuggeeFilename d)
167172 src <- zip [1 .. ] . lines <$> readFile fp
168173 let ctx = take 10 (drop (max (l - 5 ) 0 ) src)
169174 putStrLn (fp <> " :" <> show l <> " :" <> show c)
@@ -211,6 +216,15 @@ fullStackTraversal d sc = do
211216 print ds
212217 MkFix2 <$> traverse (fullTraversal d) ds
213218
214-
215-
216-
219+ -- | Print a warning if source file (first argument) is newer than the binary (second argument)
220+ warnIfNewer :: FilePath -> FilePath -> IO ()
221+ warnIfNewer fpSrc fpBin = do
222+ modTimeSource <- getModificationTime fpSrc
223+ modTimeBinary <- getModificationTime fpBin
224+ if modTimeSource > modTimeBinary
225+ then
226+ hPutStrLn stderr $
227+ printf " Warning: %s is newer than %s. Code snippets might be wrong!"
228+ fpSrc fpBin
229+ else
230+ return ()
0 commit comments