{-# LANGUAGE CPP #-}
module Data.Memory.Debug.Wrapper where
import System.Process
import Foreign
import Data.Word
import Data.Int
import Data.Binary (Binary(..))
import Data.Memory.Debug
class Binary a => Wrapper a where
load
:: Pid
-> Ptr Word8
-> IO a
store
:: Pid
-> Ptr Word8
-> a
-> IO ()
change :: Pid -> Ptr Word8 -> (a -> a) -> IO ()
change pid ptr f = load pid ptr >>= \v -> store pid ptr (f v)
#define WRAPPER(TYPE) \
instance Wrapper TYPE where {\
load pid ptr = \
let len = sizeOf (undefined :: TYPE)\
in do { res <- processVMReadV pid ptr len ;\
return (decode res) };\
store pid ptr v = \
let len = sizeOf (undefined :: TYPE) \
in processVMWriteV pid ptr len (encode v)}
WRAPPER(Int)
WRAPPER(Char)
WRAPPER(Bool)
WRAPPER(Int8)
WRAPPER(Int16)
WRAPPER(Int32)
WRAPPER(Int64)
WRAPPER(Word8)
WRAPPER(Word16)
WRAPPER(Word32)
WRAPPER(Word64)