Skip to content

Commit 021f54a

Browse files
obreitwimpickering
authored andcommitted
Display warning if source is newer than debuggee
1 parent afd53a5 commit 021f54a

File tree

4 files changed

+29
-15
lines changed

4 files changed

+29
-15
lines changed

client/src/GHC/Debug/Client.hs

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,12 @@ import System.Process
5252
import System.Environment
5353
import System.FilePath
5454
import System.Directory
55+
import Text.Printf
5556

5657
data 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'.
9699
request :: Debuggee -> Request resp -> IO resp
97-
request (Debuggee hdl _ _) req = doRequest hdl req
100+
request d req = doRequest (debuggeeHdl d) req
98101

99102
lookupInfoTable :: Debuggee -> RawClosure -> IO (RawInfoTable, RawClosure)
100103
lookupInfoTable d rc = do
@@ -155,15 +158,17 @@ lookupDwarfLine w Nothing (d, nd) = do
155158
else Nothing
156159
lookupDwarfLine _ (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 ()

dyepack-test/dyepack-test.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ executable dyepack-test
2121
-- other-extensions:
2222
build-depends: base ^>=4.12.0.0, dyepack, ghc-debug-stub
2323
-- hs-source-dirs:
24-
ghc-options: -threaded -debug -fwhole-archive-hs-libs -O0
24+
ghc-options: -threaded -debug -fwhole-archive-hs-libs -O0 -g3
2525
default-language: Haskell2010

stub/Test.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ main :: IO ()
2727
main = do
2828
start
2929
let !y = Data.Sequence.fromList [1..5]
30-
let !y = [1..5]
30+
-- let !y = [1..5]
3131
performGC
3232
saveClosures [Box y]
3333
print "start"

test/Test.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ p11 d = do
117117
[c] <- request d (RequestClosures ss)
118118
let itb = getInfoTblPtr c
119119
case lookupDwarf d itb of
120-
Just r -> showFileSnippet r
120+
Just r -> showFileSnippet d r
121121
Nothing -> return ()
122122

123123
p12 d = do
@@ -133,7 +133,7 @@ p12 d = do
133133
forM_ cs $ \c -> do
134134
let itb = getInfoTblPtr c
135135
case lookupDwarf d itb of
136-
Just r -> showFileSnippet r
136+
Just r -> showFileSnippet d r
137137
Nothing -> return ()
138138

139139
print "Following thunk"
@@ -146,7 +146,7 @@ p12 d = do
146146
forM_ cs $ \c -> do
147147
let itb = getInfoTblPtr c
148148
case lookupDwarf d itb of
149-
Just r -> showFileSnippet r
149+
Just r -> showFileSnippet d r
150150
Nothing -> return ()
151151

152152
-- testing stack decoding

0 commit comments

Comments
 (0)