@@ -39,6 +39,7 @@ import qualified Data.Conduit.List as CL
3939import qualified Data.Conduit.Text as CT
4040import Data.Either (partitionEithers )
4141import Data.IORef
42+ import Data.List (isPrefixOf )
4243import Data.Map (Map )
4344import qualified Data.Map as Map
4445import Data.Maybe (catMaybes , listToMaybe )
@@ -254,12 +255,10 @@ addHaddock (InstalledCache ref) =
254255-- | Add debugging symbol information to the stream of @DumpPackage@s
255256addSymbols :: MonadIO m
256257 => InstalledCache
257- -> CompilerVersion
258258 -> Conduit (DumpPackage a b c ) m (DumpPackage a b Bool )
259- addSymbols (InstalledCache ref) ver =
259+ addSymbols (InstalledCache ref) =
260260 CL. mapM go
261261 where
262- ver' = versionString . getGhcVersion $ ver
263262 go dp = do
264263 InstalledCacheInner m <- liftIO $ readIORef ref
265264 let gid = dpGhcPkgId dp
@@ -268,22 +267,25 @@ addSymbols (InstalledCache ref) ver =
268267 Nothing | null (dpLibraries dp) -> return True
269268 Nothing -> do
270269 let lib = T. unpack . head $ dpLibraries dp
271- liftM or . mapM (\ dir -> liftIO $ hasDebuggingSymbols ver' dir lib) $ dpLibDirs dp
270+ liftM or . mapM (\ dir -> liftIO $ hasDebuggingSymbols dir lib) $ dpLibDirs dp
272271 return dp { dpSymbols = s }
273272
274- hasDebuggingSymbols :: String -- ^ target compiler
275- -> FilePath -- ^ library directory
273+ hasDebuggingSymbols :: FilePath -- ^ library directory
276274 -> String -- ^ name of library
277275 -> IO Bool
278- hasDebuggingSymbols ver dir lib = case OS. buildOS of
279- OS. OSX -> liftM (and . fmap ((/= ' 0' ) . head ) . Prelude. take 30 . lines ) $
280- readProcess " dwarfdump" [concat [dir, " /lib" , lib, " -ghc" , ver, " .a" ]] " "
281- OS. Linux -> liftM ((== " Contents" ) . head . words . (!! 2 ) . lines ) $
282- readProcess " readelf" [" --debug-dump=info" , " --dwarf-depth=1" , concat [dir, " /lib" , lib, " -ghc" , ver, " .a" ]] " "
283- OS. FreeBSD -> liftM ((== " Contents" ) . head . words . (!! 2 ) . lines ) $
284- readProcess " readelf" [" --debug-dump=info" , " --dwarf-depth=1" , concat [dir, " /lib" , lib, " -ghc" , ver, " .a" ]] " "
285- OS. Windows -> return False -- No support, so it can't be there.
286- _ -> return False
276+ hasDebuggingSymbols dir lib = do
277+ let path = concat [dir, " /lib" , lib, " .a" ]
278+ exists <- doesFileExist path
279+ if not exists then return False
280+ else case OS. buildOS of
281+ OS. OSX -> liftM (any (isPrefixOf " 0x" ) . lines ) $
282+ readProcess " dwarfdump" [path] " "
283+ OS. Linux -> liftM (any (isPrefixOf " Contents" ) . lines ) $
284+ readProcess " readelf" [" --debug-dump=info" , " --dwarf-depth=1" , path] " "
285+ OS. FreeBSD -> liftM (any (isPrefixOf " Contents" ) . lines ) $
286+ readProcess " readelf" [" --debug-dump=info" , " --dwarf-depth=1" , path] " "
287+ OS. Windows -> return False -- No support, so it can't be there.
288+ _ -> return False
287289
288290
289291-- | Dump information for a single package
0 commit comments