-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dump: Add a command to print out the
Data.Macaw.Memory.Memory
- Loading branch information
1 parent
19d9e9e
commit 7e16485
Showing
13 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
{-# LANGUAGE ImportQualifiedPost #-} | ||
{-# LANGUAGE ScopedTypeVariables #-} | ||
{-# LANGUAGE TypeApplications #-} | ||
{-# LANGUAGE FlexibleContexts #-} | ||
|
||
module Data.Macaw.Dump.Memory | ||
( MemoryConfig(..) | ||
, memoryConfig | ||
, memory | ||
) where | ||
|
||
import Data.ElfEdit qualified as EE | ||
import Data.Macaw.Architecture.Info qualified as MAI | ||
import Data.Macaw.BinaryLoader qualified as Loader | ||
import Data.Macaw.CFG.Core qualified as MC | ||
import Data.Macaw.Dump.CLIUtils qualified as MDCU | ||
import Data.Macaw.Memory.LoadCommon qualified as LC | ||
import Data.Macaw.Memory qualified as MM | ||
import Options.Applicative qualified as Opt | ||
|
||
data MemoryConfig | ||
= MemoryConfig | ||
{ memBinPath :: FilePath | ||
} | ||
|
||
memoryConfig :: Opt.Parser MemoryConfig | ||
memoryConfig = | ||
MemoryConfig | ||
<$> MDCU.binOpt | ||
|
||
-- Currently, we do not apply any offsets to addresses in the loaded binary. We | ||
-- will need to reconsider this if we want to support shared libraries. | ||
loadOptions :: LC.LoadOptions | ||
loadOptions = | ||
LC.LoadOptions | ||
{ LC.loadOffset = Nothing | ||
} | ||
|
||
memory :: | ||
forall arch. | ||
( MM.MemWidth (MC.ArchAddrWidth arch) | ||
, Loader.BinaryLoader arch (EE.ElfHeaderInfo (MC.ArchAddrWidth arch)) | ||
) => | ||
MAI.ArchitectureInfo arch -> | ||
MemoryConfig -> | ||
IO () | ||
memory archInfo cfg = do | ||
ehi <- MDCU.loadElf archInfo (memBinPath cfg) | ||
loaded <- Loader.loadBinary @arch loadOptions ehi | ||
let mem = Loader.memoryImage loaded | ||
print mem |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters