GaloisInc / macaw

Open source binary analysis tools.
BSD 3-Clause "New" or "Revised" License
208 stars 21 forks source link

macaw-dump: A CLI for printing internal data structures #446

Closed langston-barrett closed 1 week ago

langston-barrett commented 1 month ago

A simple library and tiny wrappers for different architectures, intended for debugging purposes. The only current capability is to run code discovery on a set of symbols in a binary (or all of them if none are specified), and pretty-print the resulting Macaw or Crucible CFGs.

Needs:

langston-barrett commented 1 month ago

Not sure what this error from specifically GHC 9.4 is all about:

tools/Dump.hs:35:24: error:
Error:     • Could not deduce (macaw-base-0.3.15.6:Data.Macaw.CFG.AssignRhs.RegAddrWidth
                          (macaw-base-0.3.15.6:Data.Macaw.CFG.AssignRhs.ArchReg
                             semmc-aarch[32](https://github.com/GaloisInc/macaw/actions/runs/11258785738/job/31306208454?pr=446#step:20:33)-0.1.0.0:SemMC.Architecture.AArch32.AArch32)
                        ~ 32)
        arising from a use of ‘MD.runDiscovery’
RyanGlScott commented 1 month ago

Sigh. This is https://gitlab.haskell.org/ghc/ghc/-/issues/16234. The good news is that this is fixed in GHC 9.6 or later, but the bad news is that we'll have to live with the bug until we drop GHC 9.4 support. Happily, it is straightforward to work around the bug:

diff --git a/macaw-aarch32-symbolic/tools/Dump.hs b/macaw-aarch32-symbolic/tools/Dump.hs
index a11a6ca5..09b0bf03 100644
--- a/macaw-aarch32-symbolic/tools/Dump.hs
+++ b/macaw-aarch32-symbolic/tools/Dump.hs
@@ -3,6 +3,15 @@

 module Main (main) where

+-- Sometimes, GHC 9.4 is unable to find instances of RegAddrWidth that are
+-- available by way of transitive module imports. The only reliable way of
+-- preventing this issue that I've found is to import the defining module for
+-- the instances (Data.Macaw.ARM.ARMReg) directly. See
+-- https://gitlab.haskell.org/ghc/ghc/-/issues/16234 for the upstream GHC issue.
+--
+-- This issue does not affect GHC 9.6 or later, so when we drop support for GHC
+-- 9.4, we can remove the redundant import below.
+import Data.Macaw.ARM.ARMReg ()
 import Data.Macaw.AArch32.Symbolic ()
 import Data.Macaw.ARM qualified as MA
 import Data.Macaw.Dump qualified as MD
langston-barrett commented 1 month ago

@RyanGlScott Can you take a quick look and see if you like this functionality, and if so, I'll add the other architectures?