Skip to content

Commit

Permalink
dump: Implementation for PPC
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Oct 9, 2024
1 parent 05b5a28 commit 76e4999
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 1 deletion.
2 changes: 1 addition & 1 deletion macaw-dump/src/Data/Macaw/Dump.hs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ loadELF loadOpts ehi = do
Left err -> X.throwIO (ELFResolutionError err)
Right (warnings, mem, _mentry, nameAddrList) -> do
F.forM_ warnings $ \w -> do
IO.hPutStrLn IO.stderr w
IO.hPutStrLn IO.stderr ("WARN: " ++ w)
return (mem, nameAddrList)

-- | Run discovery on the provided symbols, or all if none are provided
Expand Down
17 changes: 17 additions & 0 deletions macaw-ppc-symbolic/macaw-ppc-symbolic.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,23 @@ library
default-language: Haskell2010
ghc-options: -Wall -Wcompat

executable macaw-ppc-dump
hs-source-dirs: tools
main-is: Dump.hs
default-language: Haskell2010
ghc-options: -Wall -Wcompat
build-depends:
base,
bytestring,
containers,
elf-edit,
macaw-base,
macaw-dump,
macaw-loader,
macaw-ppc,
macaw-ppc-symbolic,
macaw-symbolic

test-suite macaw-ppc-symbolic-tests
type: exitcode-stdio-1.0
default-language: Haskell2010
Expand Down
51 changes: 51 additions & 0 deletions macaw-ppc-symbolic/tools/Dump.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{-# LANGUAGE GADTs #-}
{-# LANGUAGE ImportQualifiedPost #-}
{-# LANGUAGE TypeApplications #-}

module Main (main) where

import Data.ByteString qualified as BS
import Data.ElfEdit qualified as EE
import Data.Macaw.BinaryLoader qualified as MBL
import Data.Macaw.Dump.CLI qualified as MDC
import Data.Macaw.Dump qualified as MD
import Data.Macaw.Memory.ElfLoader qualified as MM
import Data.Macaw.PPC qualified as PPC
import Data.Macaw.PPC.Symbolic ()
import Data.Macaw.Symbolic qualified as MS
import Data.Proxy (Proxy(..))
import Data.Set qualified as Set
import System.Exit qualified as Exit
import System.IO qualified as IO

die :: String -> IO a
die msg = do
IO.hPutStrLn IO.stderr msg
Exit.exitFailure

main :: IO ()
main = do
cli <- MDC.parseCli
let exePath = MDC.cliBinPath cli
bytes <- BS.readFile exePath
case EE.decodeElfHeaderInfo bytes of
Left (_, msg) -> die ("Error parsing ELF header from file '" ++ exePath ++ "': " ++ msg)
Right (EE.SomeElf ehi) -> do
let symbs = Set.fromList (MDC.cliSymbols cli)
case EE.headerClass (EE.header ehi) of
EE.ELFCLASS32 -> do
discState <- MD.runDiscovery ehi PPC.ppc32_linux_info symbs
archVals <-
case MS.archVals (Proxy @PPC.PPC32) Nothing of
Just archVals -> pure archVals
Nothing -> error "impossible"
MD.displayCfgs exePath discState archVals (MDC.cliPrintCrucible cli)
EE.ELFCLASS64 -> do
loadedBinary <- MBL.loadBinary MM.defaultLoadOptions ehi
let archInfo = PPC.ppc64_linux_info loadedBinary
discState <- MD.runDiscovery ehi archInfo symbs
archVals <-
case MS.archVals (Proxy @PPC.PPC64) Nothing of
Just archVals -> pure archVals
Nothing -> error "impossible"
MD.displayCfgs exePath discState archVals (MDC.cliPrintCrucible cli)

0 comments on commit 76e4999

Please sign in to comment.