From: Bernhard Urban Date: Sat, 25 Aug 2012 19:06:03 +0000 (+0200) Subject: debug: remove #ifdef's and use dumb logger X-Git-Url: http://wien.tomnetworks.com/gitweb/?p=mate.git;a=commitdiff_plain;h=dc7082de1fff3158da5682d683502128b5f6cc0b debug: remove #ifdef's and use dumb logger advantage: - Haskell code, i.e. tools like hlint or ghc-mod don't have problems with processing the source files with CPP - no (ugly?) old school CPP stuff disadvantage: - it's not really a printf thingy (maybe we'll be able to use it soon) --- diff --git a/.gitignore b/.gitignore index d48b83d..b382dfe 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ mate mate.static mate.dbg mate.prof +mate.log tags *.swp *_stub.c diff --git a/HACKING b/HACKING index c70e194..c1d34d9 100644 --- a/HACKING +++ b/HACKING @@ -6,14 +6,10 @@ for testing a release build against OpenJDK output, use $ make tests/Fib.test -for testing with a debug build, use -$ DBGFLAGS='-DDBG_JIT -DDBG_BB' make tests/Fib.dbg +for testing with a debug build, use edit Mate/Debug.hs and set +`mateDEBUG = True' and build again. Output is in `mate.log' -`make clean' is needed if you change $DBGFLAGS. -for all available flags, see `debug.h'. - - -for debugging with gdb, modify Mate/MethodPool.hs and make a debug build with at -least -DDBG_JIT enabled, then use +for debugging with gdb, modify Mate/MethodPool.hs and enable Debugging in +Mate/Debug.hs, then use $ make tests/Fib.gdb and follow the instructions in the source file. diff --git a/Makefile b/Makefile index 837c67c..1b02428 100644 --- a/Makefile +++ b/Makefile @@ -68,24 +68,11 @@ mate.static: Mate.hs ffi/trap.c $(HS_FILES) $(HS_BOOT) ffi/native.o $(CLASS_FILE @mkdir -p $(B_STATIC) $(GHCCALL) $(B_STATIC) -static -%.dbg: %.class mate.dbg - ./mate.dbg $(basename $<) - -%.gdb: %.class mate.dbg - gdb -x .gdbcmds -q --args mate.dbg $(basename $<) +RTS -V0 --install-signal-handlers=no - -ifeq (${DBGFLAGS},) -DEBUGFLAGS = -DDBG_JIT -DDBG_MP -else -DEBUGFLAGS = ${DBGFLAGS} -endif -mate.dbg: Mate.hs ffi/trap.c $(HS_FILES) $(HS_BOOT) ffi/native.o $(CLASS_FILES) - @mkdir -p $(B_DEBUG)/{ffi,Mate,} - gcc -Wall $(DEBUGFLAGS) -O0 -c ffi/trap.c -o $(B_DEBUG)/ffi/trap.o - ghc --make $(DEBUGFLAGS) $(GHC_OPT) Mate.hs $(B_DEBUG)/ffi/trap.o -o $@ $(GHC_LD) -outputdir $(B_DEBUG) +%.gdb: %.class mate + gdb -x .gdbcmds -q --args mate $(basename $<) +RTS -V0 --install-signal-handlers=no clean: - rm -rf $(BUILD) mate mate.static mate.dbg ffi/native.o \ + rm -rf $(BUILD) mate mate.static ffi/native.o \ tests/*.class Mate/*_stub.* \ jmate/lang/*.class jmate/io/*.class java/io/*.class \ java/lang/{Integer,Character,String,System}.class \ @@ -101,13 +88,7 @@ tags: mate.static ghc -I. -fforce-recomp -fobject-code $(PACKAGES) Mate.hs -outputdir $(B_STATIC) -e :ctags $(GHC_CPP) hlint: - @# hlint isn't able to evaluate CPP comments correctly *sigh* - @cp debug.h debug_tmp.h - @# so we remove them "by hand", for hlint - @gcc -E -x c -fpreprocessed -dD -E debug_tmp.h | grep -v 'debug_tmp.h' > debug.h - @# ignore error code from hlint - -hlint Mate.hs Mate/ - @mv debug_tmp.h debug.h + hlint Mate.hs Mate/ scratch: mate $(wildcard jmate/lang/*.java) scratch/GCTest.java javac $(wildcard jmate/lang/*.java) diff --git a/Mate.hs b/Mate.hs index 96edb96..a191048 100644 --- a/Mate.hs +++ b/Mate.hs @@ -1,6 +1,4 @@ -{-# LANGUAGE CPP #-} {-# LANGUAGE OverloadedStrings #-} -#include "debug.h" module Main where import System.Environment @@ -10,9 +8,6 @@ import Data.List.Split import qualified Data.ByteString.Lazy as B import Control.Monad -#ifdef DEBUG -import Text.Printf -#endif import JVM.ClassFile import Java.JAR @@ -21,6 +16,7 @@ import Mate.MethodPool import Mate.Types import Mate.ClassPool import Mate.NativeMachine +import Mate.Debug import Mate.GC.Boehm @@ -65,6 +61,7 @@ parseArgs _ _ = parseArgs ["-"] False executeMain :: B.ByteString -> Class Direct -> IO () executeMain bclspath cls = do initGC --required on some platforms. [todo bernhard: maybe this should be moved somewhere else - maybe at a global place where vm initialization takes place + let methods = classMethods cls; methods :: [Method Direct] case find (\x -> methodName x == "main") methods of Just m -> do @@ -72,8 +69,6 @@ executeMain bclspath cls = do rawmethod <- parseMethod cls "main" $ methodSignature m entry <- compileBB rawmethod mi addMethodRef entry mi [bclspath] -#ifdef DEBUG - printf "executing `main' now:\n" -#endif + printfInfo "executing `main' now:\n" executeFuncPtr entry Nothing -> error "main not found" diff --git a/Mate/BasicBlocks.hs b/Mate/BasicBlocks.hs index 955f4f5..04a2c3b 100644 --- a/Mate/BasicBlocks.hs +++ b/Mate/BasicBlocks.hs @@ -1,15 +1,11 @@ -{-# LANGUAGE CPP #-} {-# LANGUAGE OverloadedStrings #-} -#include "debug.h" module Mate.BasicBlocks( BlockID, BasicBlock, BBEnd, MapBB, Method, -#ifdef DBG_BB printMapBB, -#endif parseMethod, testCFG -- added by hs to perform benches from outside )where @@ -29,49 +25,40 @@ import Mate.Types import Mate.Debug import Mate.Utilities -#ifdef DEBUG -import Text.Printf -#endif - -- for immediate representation to determine BBs type Offset = (Int, Maybe BBEnd) -- (offset in bytecode, offset to jump target) type OffIns = (Offset, Instruction) -#ifdef DBG_BB printMapBB :: MapBB -> IO () printMapBB hmap = do - putStr "BlockIDs: " + printfBb "BlockIDs: " let keys = M.keys hmap - mapM_ (putStr . (flip (++)) ", " . show) keys - putStrLn "\n\nBasicBlocks:" + mapM_ (printfBb. (flip (++)) ", " . show) keys + printfBb "\n\nBasicBlocks:" printMapBB' keys hmap where printMapBB' :: [BlockID] -> MapBB -> IO () printMapBB' [] _ = return () printMapBB' (i:is) hmap' = case M.lookup i hmap' of Just bb -> do - putStrLn $ "Block " ++ (show i) - mapM_ putStrLn (map ((++) "\t" . show) $ code bb) - case successor bb of - Return -> putStrLn "" - FallThrough t1 -> putStrLn $ "Sucessor: " ++ (show t1) ++ "\n" - OneTarget t1 -> putStrLn $ "Sucessor: " ++ (show t1) ++ "\n" - TwoTarget t1 t2 -> putStrLn $ "Sucessor: " ++ (show t1) ++ ", " ++ (show t2) ++ "\n" + printfBb $ "Block " ++ (show i) + mapM_ printfBb (map ((++) "\t" . show) $ code bb) + printfBb $ case successor bb of + Return -> "" + FallThrough t1 -> "Sucessor: " ++ (show t1) ++ "\n" + OneTarget t1 -> "Sucessor: " ++ (show t1) ++ "\n" + TwoTarget t1 t2 -> "Sucessor: " ++ (show t1) ++ ", " ++ (show t2) ++ "\n" printMapBB' is hmap Nothing -> error $ "BlockID " ++ show i ++ " not found." -#endif -#if 0 -#ifdef DBG_BB +{- testInstance :: String -> B.ByteString -> MethodSignature -> IO () testInstance cf method sig = do cls <- parseClassFile cf hmap <- parseMethod cls method sig printMapBB hmap -#endif -#ifdef DBG_BB test_main :: IO () test_main = do test_01 @@ -84,8 +71,7 @@ test_01 = testInstance "./tests/Fib.class" "fib" test_02 = testInstance "./tests/While.class" "f" test_03 = testInstance "./tests/While.class" "g" test_04 = testInstance "./tests/Fac.class" "fac" -#endif -#endif +-} parseMethod :: Class Direct -> B.ByteString -> MethodSignature -> IO RawMethod @@ -107,19 +93,17 @@ parseMethod cls methodname sig = do let argscount = methodGetArgsCount nametype + (if isStatic then 0 else 1) let msig = methodSignature method - printfBb "BB: analysing \"%s\"\n" $ toString (methodname `B.append` ": " `B.append` encode msig) -#ifdef DBG_BB + printfBb $ printf "BB: analysing \"%s\"\n" $ toString (methodname `B.append` ": " `B.append` encode msig) printMapBB mapbb -#endif -- small example how to get information about -- exceptions of a method -- TODO: remove ;-) let (Just m) = lookupMethodSig methodname sig cls case attrByName m "Code" of Nothing -> - printfBb "exception: no handler for this method\n" + printfBb $ printf "exception: no handler for this method\n" Just exceptionstream -> - printfBb "exception: \"%s\"\n" (show $ codeExceptions $ decodeMethod exceptionstream) + printfBb $ printf "exception: \"%s\"\n" (show $ codeExceptions $ decodeMethod exceptionstream) return $ RawMethod mapbb locals stacks argscount codelen diff --git a/Mate/ClassPool.hs b/Mate/ClassPool.hs index dde77e7..849f1a1 100644 --- a/Mate/ClassPool.hs +++ b/Mate/ClassPool.hs @@ -1,6 +1,4 @@ -{-# LANGUAGE CPP #-} {-# LANGUAGE OverloadedStrings #-} -#include "debug.h" module Mate.ClassPool ( getClassInfo, classLoaded, @@ -24,12 +22,7 @@ import qualified Data.ByteString.Lazy as B import Data.String.Utils import Control.Monad -#ifdef DEBUG -import Text.Printf -#endif -#ifdef DBG_CLASS -import JVM.Dump -#endif +-- import JVM.Dump import Foreign.Ptr import Foreign.C.Types @@ -126,9 +119,8 @@ readClass path = do Just cm -> return cm Nothing -> do cfile <- readClassFile $ toString path -#ifdef DBG_CLASS - dumpClass cfile -#endif + -- TODO(bernhard): hDumpClass + -- dumpClass cfile -- load all interfaces, which are implemented by this class sequence_ [ loadInterface i | i <- interfaces cfile ] superclass <- if path /= "java/lang/Object" @@ -149,15 +141,23 @@ readClass path = do let wn_iftable = fromIntegral $ ptrToIntPtr iftable :: NativeWord -- store interface-table at offset 0 in method-table pokeElemOff (intPtrToPtr $ fromIntegral mbase) 0 wn_iftable -#ifdef DBG_CLASS - let strpath = toString path - hexDumpMap ("staticmap @ " ++ strpath) staticmap - hexDumpMap ("fieldmap @ " ++ strpath) fieldmap - hexDumpMap ("methodmap @ " ++ strpath) methodmap - hexDumpMap ("interfacemap @ " ++ strpath) immap -#endif - printfCp "mbase: 0x%08x\n" mbase - printfCp "iftable: 0x%08x\n" wn_iftable + let hexDumpMap :: Integral v => String -> M.Map B.ByteString v -> IO () + hexDumpMap header mmap = do + let printValue :: B.ByteString -> IO () + printValue key = printfCp $ printf "\t%-70s: 0x%08x\n" (toString key) val + where val = fromIntegral (mmap M.! key) :: NativeWord + printfCp $ printf "%s\n" header + mapM_ printValue (M.keys mmap) + if mateDEBUG + then do + let strpath = toString path + hexDumpMap ("staticmap @ " ++ strpath) staticmap + hexDumpMap ("fieldmap @ " ++ strpath) fieldmap + hexDumpMap ("methodmap @ " ++ strpath) methodmap + hexDumpMap ("interfacemap @ " ++ strpath) immap + printfCp $ printf "mbase: 0x%08x\n" mbase + printfCp $ printf "iftable: 0x%08x\n" wn_iftable + else return () virtual_map <- getVirtualMap setVirtualMap $ M.insert mbase path virtual_map @@ -174,7 +174,7 @@ loadInterface path = do case M.lookup path imap of Just _ -> return () Nothing -> do - printfCp "interface: loading \"%s\"\n" $ toString path + printfCp $ printf "interface: loading \"%s\"\n" $ toString path cfile <- readClassFile $ toString path -- load "superinterfaces" first sequence_ [ loadInterface i | i <- interfaces cfile ] @@ -267,9 +267,9 @@ loadAndInitClass path = do let mi = MethodInfo "" path (methodSignature m) entry <- compileBB rawmethod mi addMethodRef entry mi [path] - printfCp "executing static initializer from %s now\n" (toString path) + printfCp $ printf "executing static initializer from %s now\n" (toString path) executeFuncPtr entry - printfCp "static initializer from %s done\n" (toString path) + printfCp $ printf "static initializer from %s done\n" (toString path) Nothing -> return () class_map' <- getClassMap @@ -286,13 +286,13 @@ readClassFile path' = readIORef classPaths >>= rcf rcf [] = error $ "readClassFile: Class \"" ++ show path ++ "\" not found." rcf (Directory pre:xs) = do let cf = pre ++ path ++ ".class" - printfCp "rcf: searching @ %s for %s\n" (show pre) (show path) + printfCp $ printf "rcf: searching @ %s for %s\n" (show pre) (show path) b <- doesFileExist cf if b then parseClassFile cf else rcf xs rcf (JAR p:xs) = do - printfCp "rcf: searching %s in JAR\n" (show path) + printfCp $ printf "rcf: searching %s in JAR\n" (show path) entry <- getEntry p path case entry of Just (LoadedJAR _ cls) -> return cls diff --git a/Mate/Debug.hs b/Mate/Debug.hs index dc8954e..7acd3cd 100644 --- a/Mate/Debug.hs +++ b/Mate/Debug.hs @@ -1,48 +1,45 @@ -{-# LANGUAGE CPP #-} {-# LANGUAGE OverloadedStrings #-} -#include "debug.h" -module Mate.Debug where - -{- we cannot use `PrintfType' from Text.Printf, as it isn't exported. - - so we implement a `VarArgsFake' here. - - http://www.haskell.org/haskellwiki/Varargs -} -class VarArgsFake t where - varFake :: [String] -> t - -instance VarArgsFake (IO a) where - varFake _ = return undefined - -instance (Show a, VarArgsFake r) => VarArgsFake (a -> r) where - varFake _ _ = varFake [] - --- note: with -O2 GHC is able to completely optimize away such a `printfFake' call -printfFake :: String -> (VarArgsFake t) => t -printfFake _ = varFake [] - - --- see counterpart at `debug.h' -#ifndef DBG_JIT -printfJit :: String -> (VarArgsFake t) => t -printfJit = printfFake -#endif - -#ifndef DBG_BB -printfBb :: String -> (VarArgsFake t) => t -printfBb = printfFake -#endif - -#ifndef DBG_MP -printfMp :: String -> (VarArgsFake t) => t -printfMp = printfFake -#endif - -#ifndef DBG_CP -printfCp :: String -> (VarArgsFake t) => t -printfCp = printfFake -#endif - -#ifndef DBG_STR -printfStr :: String -> (VarArgsFake t) => t -printfStr = printfFake -#endif +module Mate.Debug + ( printfJit + , printfBb + , printfMp + , printfCp + , printfStr + , printfInfo + , mateDEBUG + , printf -- TODO: delete me + ) where + +import Text.Printf +import System.IO +import System.IO.Unsafe + + +{-# NOINLINE logHandle #-} +-- TODO(bernhard): use MVar if threaded +logHandle :: Handle +logHandle = unsafePerformIO $ openFile "mate.log" WriteMode + +{-# INLINE mateDEBUG #-} +mateDEBUG :: Bool +mateDEBUG = False + +{-# INLINE printString #-} +printString :: String -> String -> IO () +printString prefix str = if mateDEBUG + then hPutStr logHandle . (++) prefix $ str + else return () + + +printfJit, printfBb, printfMp, printfCp, printfStr, printfInfo :: String -> IO () +{- +-- TODO(bernhard): +-- http://stackoverflow.com/questions/12123082/function-composition-with-text-printf-printf +-} +printfJit = printString "Jit: " +printfBb = printString "Bb: " +printfMp = printString "Mp: " +printfCp = printString "Cp: " +printfStr = printString "Str: " +printfInfo = printString "Info: " diff --git a/Mate/GarbageAlloc.hs b/Mate/GarbageAlloc.hs index aa2ed3f..617e571 100644 --- a/Mate/GarbageAlloc.hs +++ b/Mate/GarbageAlloc.hs @@ -1,6 +1,4 @@ {-# LANGUAGE ForeignFunctionInterface #-} -{-# LANGUAGE CPP #-} -#include "debug.h" module Mate.GarbageAlloc( mallocClassData, mallocStringGC, @@ -16,9 +14,6 @@ import Foreign.C import Mate.GC.Boehm -#ifdef DBG_STR -import Text.Printf -#endif import Mate.Debug -- unified place for allocating Memory @@ -26,32 +21,32 @@ import Mate.Debug mallocClassData :: Int -> IO (Ptr a) mallocClassData size = do - printfStr "mallocClassData: %d\n" size + printfStr $ printf "mallocClassData: %d\n" size mem <- mallocBytes size addRootGC mem (plusPtr mem size) return mem mallocStringGC :: Int -> IO (Ptr a) mallocStringGC size = do - printfStr "mallocString: %d\n" size + printfStr $ printf "mallocString: %d\n" size mallocBytesGC size foreign export ccall mallocObjectGC :: Int -> IO CPtrdiff mallocObjectGC :: Int -> IO CPtrdiff mallocObjectGC size = do ptr <- mallocBytesGC size - printfStr "mallocObject: %d\n" size + printfStr $ printf "mallocObject: %d\n" size return $ fromIntegral $ ptrToIntPtr ptr mallocObjectUnmanaged :: Int -> IO CPtrdiff mallocObjectUnmanaged size = do ptr <- mallocBytes size - printfStr "mallocObjectUnmanged: %d\n" size + printfStr $ printf "mallocObjectUnmanged: %d\n" size return $ fromIntegral $ ptrToIntPtr ptr mallocStringUnmanaged :: Int -> IO (Ptr a) mallocStringUnmanaged size = do - printfStr "mallocStringUnamaged: %d\n" size + printfStr $ printf "mallocStringUnamaged: %d\n" size mallocBytes size diff --git a/Mate/MethodPool.hs b/Mate/MethodPool.hs index 79b63e3..223f509 100644 --- a/Mate/MethodPool.hs +++ b/Mate/MethodPool.hs @@ -1,7 +1,5 @@ -{-# LANGUAGE CPP #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ForeignFunctionInterface #-} -#include "debug.h" module Mate.MethodPool where import Data.Binary @@ -18,13 +16,7 @@ import Foreign.C.String import JVM.ClassFile import Harpy -#ifdef DBG_JIT import Harpy.X86Disassembler -#endif - -#ifdef DEBUG -import Text.Printf -#endif import Mate.BasicBlocks import Mate.Types @@ -67,7 +59,7 @@ getMethodEntry signal_from methodtable = do entryaddr <- case M.lookup mi' mmap of Nothing -> do cls <- getClassFile cm - printfMp "getMethodEntry(from 0x%08x): no method \"%s\" found. compile it\n" w32_from (show mi') + printfMp $ printf "getMethodEntry(from 0x%08x): no method \"%s\" found. compile it\n" w32_from (show mi') mm <- lookupMethodRecursive method sig [] cls case mm of Just (mm', clsnames, cls') -> do @@ -91,7 +83,7 @@ getMethodEntry signal_from methodtable = do parenth = replace "(" "_" $ replace ")" "_" $ toString $ encode sig sym2 = replace ";" "_" $ replace "/" "_" parenth symbol = sym1 ++ "__" ++ smethod ++ "__" ++ sym2 - printfMp "native-call: symbol: %s\n" symbol + printfMp $ printf "native-call: symbol: %s\n" symbol nf <- loadNativeFunction symbol setMethodMap $ M.insert mi' nf mmap return nf @@ -165,12 +157,12 @@ compileBB rawmethod methodinfo = do let ((entry, _, _, new_tmap), _) = right setTrapMap $ tmap `M.union` new_tmap -- prefers elements in tmap - printfJit "generated code of \"%s\" from \"%s\":\n" (toString $ methName methodinfo) (toString $ methClassName methodinfo) - printfJit "\tstacksize: 0x%04x, locals: 0x%04x\n" (rawStackSize rawmethod) (rawLocals rawmethod) -#ifdef DBG_JIT - mapM_ (printfJit "%s\n" . showAtt) (snd right) -#endif - printfJit "\n\n" + printfJit $ printf "generated code of \"%s\" from \"%s\":\n" (toString $ methName methodinfo) (toString $ methClassName methodinfo) + printfJit $ printf "\tstacksize: 0x%04x, locals: 0x%04x\n" (rawStackSize rawmethod) (rawLocals rawmethod) + if mateDEBUG + then mapM_ (printfJit . printf "%s\n" . showAtt) (snd right) + else return () + printfJit $ printf "\n\n" -- UNCOMMENT NEXT LINES FOR GDB FUN -- if (toString $ methName methodinfo) == "thejavamethodIwant2debug" -- then putStrLn "press CTRL+C now for setting a breakpoint. then `c' and ENTER for continue" >> getLine diff --git a/Mate/NativeMachine.hs b/Mate/NativeMachine.hs index 1474741..2587d93 100644 --- a/Mate/NativeMachine.hs +++ b/Mate/NativeMachine.hs @@ -11,7 +11,10 @@ module Mate.NativeMachine( import Mate.X86CodeGen import Mate.X86TrapHandling import Mate.NativeSizes - #else -#error "no other arch supported yet :/" + +-- HACK, for ghc-mod ... +import Mate.X86CodeGen +import Mate.X86TrapHandling +import Mate.NativeSizes #endif diff --git a/Mate/NativeSizes.hs b/Mate/NativeSizes.hs index 0ba6128..5e8795b 100644 --- a/Mate/NativeSizes.hs +++ b/Mate/NativeSizes.hs @@ -8,5 +8,10 @@ ptrSize, longSize :: NativeWord ptrSize = 4 longSize = 8 +type NativeWord = Word32 +#else +-- HACK, for ghc-mod ... +ptrSize = undefined +longSize = undefined type NativeWord = Word32 #endif diff --git a/Mate/RegisterAllocation.hs b/Mate/RegisterAllocation.hs index 249840a..8c4e040 100644 --- a/Mate/RegisterAllocation.hs +++ b/Mate/RegisterAllocation.hs @@ -1,9 +1,5 @@ -{-# LANGUAGE CPP #-} module Mate.RegisterAllocation where - -#include "debug.h" - import Data.List import Data.Maybe diff --git a/Mate/Strings.hs b/Mate/Strings.hs index 2f7504a..bb2bc89 100644 --- a/Mate/Strings.hs +++ b/Mate/Strings.hs @@ -1,6 +1,4 @@ -{-# LANGUAGE CPP #-} {-# LANGUAGE OverloadedStrings #-} -#include "debug.h" module Mate.Strings ( getUniqueStringAddr ) where @@ -9,9 +7,6 @@ import Data.Word import qualified Data.Map as M import qualified Data.ByteString.Lazy as B import qualified Data.ByteString.Internal as BI -#ifdef DEBUG -import Text.Printf -#endif import JVM.ClassFile @@ -56,7 +51,7 @@ allocateJavaString str = do -} -- build object layout fsize <- getObjectSize "java/lang/String" - printfStr "string: fsize: %d (should be 4 * 5)\n" fsize + printfStr $ printf "string: fsize: %d (should be 4 * 5)\n" fsize tblptr <- mallocObjectUnmanaged $ fromIntegral fsize let ptr = intPtrToPtr (fromIntegral tblptr) :: Ptr CPtrdiff mtbl <- getMethodTable "java/lang/String" @@ -69,7 +64,7 @@ allocateJavaString str = do BI.memset newstr 0 (fromIntegral $ strlen + 5) arr <- newArray ((map fromIntegral $ B.unpack str) :: [Word8]) copyBytes (plusPtr newstr 4) arr strlen - printfStr "new str ptr: (%s)@%d\n" (toString str) strlen + printfStr $ printf "new str ptr: (%s)@%d\n" (toString str) strlen let newstr_length = castPtr newstr :: Ptr CPtrdiff poke newstr_length $ fromIntegral strlen diff --git a/Mate/Utilities.hs b/Mate/Utilities.hs index 8f234e5..43e264c 100644 --- a/Mate/Utilities.hs +++ b/Mate/Utilities.hs @@ -1,4 +1,3 @@ -{-# LANGUAGE CPP #-} {-# LANGUAGE OverloadedStrings #-} module Mate.Utilities where @@ -14,10 +13,6 @@ import JVM.ClassFile import Mate.Types import Mate.NativeSizes -#ifdef DEBUG -import Text.Printf -#endif - buildMethodID :: Class Direct -> Word16 -> MethodInfo buildMethodID cls idx = MethodInfo (ntName nt) rc (ntSignature nt) where @@ -76,15 +71,3 @@ methodIsStatic = S.member ACC_STATIC . methodAccessFlags lookupMethodSig :: B.ByteString -> MethodSignature -> Class Direct -> Maybe (Method Direct) lookupMethodSig name sig cls = find (\x -> methodName x == name && methodSignature x == sig) $ classMethods cls - -hexDumpMap :: Integral v => String -> M.Map B.ByteString v -> IO () -#ifdef DEBUG -hexDumpMap header mmap = do - let printValue :: B.ByteString -> IO () - printValue key = printf "\t%-70s: 0x%08x\n" (toString key) val - where val = fromIntegral (mmap M.! key) :: NativeWord - printf "%s\n" header - mapM_ printValue (M.keys mmap) -#else -hexDumpMap _ _ = return () -#endif diff --git a/Mate/X86CodeGen.hs b/Mate/X86CodeGen.hs index 2f0f6e4..1a04579 100644 --- a/Mate/X86CodeGen.hs +++ b/Mate/X86CodeGen.hs @@ -1,7 +1,5 @@ -{-# LANGUAGE CPP #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ForeignFunctionInterface #-} -#include "debug.h" module Mate.X86CodeGen where import Prelude hiding (and, div) @@ -30,9 +28,6 @@ import Mate.Types import Mate.Utilities import Mate.ClassPool import Mate.Strings -#ifdef DEBUG -import Text.Printf -#endif foreign import ccall "&mallocObjectGC" diff --git a/Mate/X86TrapHandling.hs b/Mate/X86TrapHandling.hs index 1a571a3..520e177 100644 --- a/Mate/X86TrapHandling.hs +++ b/Mate/X86TrapHandling.hs @@ -1,7 +1,5 @@ -{-# LANGUAGE CPP #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ForeignFunctionInterface #-} -#include "debug.h" module Mate.X86TrapHandling ( mateHandler, register_signal @@ -22,9 +20,6 @@ import {-# SOURCE #-} Mate.MethodPool import Mate.ClassPool import Mate.X86CodeGen -#ifdef DBG_JIT -import Text.Printf -#endif import Mate.Debug import Harpy.X86Disassembler @@ -57,7 +52,7 @@ patchWithHarpy patcher reip = do let entry = Just (intPtrToPtr (fromIntegral reip), fixme) let cgconfig = defaultCodeGenConfig { customCodeBuffer = entry } (_, Right right) <- runCodeGenWithConfig (withDisasm $ patcher reip) () () cgconfig - mapM_ (printfJit "patched: %s\n" . showAtt) $ snd right + mapM_ (printfJit . printf "patched: %s\n" . showAtt) $ snd right return reip withDisasm :: CodeGen e s CPtrdiff -> CodeGen e s (CPtrdiff, [Instruction]) diff --git a/debug.h b/debug.h deleted file mode 100644 index 4277648..0000000 --- a/debug.h +++ /dev/null @@ -1,88 +0,0 @@ -/* DBG_JIT .... see generated code and CodeGen information - * DBG_BB ..... BasicBlock information - * DBG_MP ..... MethodPool.hs - * DBG_CP ..... ClassPool.hs - * DBG_STR .... Strings.hs - * // no printf* defined - * DBG_TRAP ... show information @ trap.c - * DBG_CLASS .. dump classfile - */ - -/* ooops defines */ -#ifdef BG_ALL -#define DBG_ALL -#endif - -#ifdef BG_JIT -#define DBG_JIT -#endif - -#ifdef BG_BB -#define DBG_BB -#endif - -#ifdef BG_MP -#define DBG_MP -#endif - -#ifdef BG_CP -#define DBG_CP -#endif - -#ifdef BG_STR -#define DBG_STR -#endif - -#ifdef BG_TRAP -#define DBG_TRAP -#endif - -#ifdef BG_CLASS -#define DBG_CLASS -#endif - -/* if one constant from above is defined, we want to import - * libraries like Text.Printf - * needed for gettting proper `-Wall' output on a release build */ - -#if defined(DBG_ALL) || defined(DBG_JIT) || defined(DBG_BB) || defined(DBG_MP) || defined(DBG_CP) || defined(DBG_STR) -#define DEBUG -#endif - -#if defined(DBG_ALL) -#define DBG_JIT -#define DBG_BB -#define DBG_MP -#define DBG_CP -#define DBG_STR -#define DBG_TRAP -#if 0 -#define DBG_CLASS -#endif -#endif - -/* it would be awesome if we could just write - * > printfFake = printf - * here, but the type can't be infered, since `PrintfType' - * isn't visible (at least this is my explanation :/). - * if I'm wrong, move this to `Mate/Debug.hs' - */ -#ifdef DBG_JIT -#define printfJit printf -#endif - -#ifdef DBG_BB -#define printfBb printf -#endif - -#ifdef DBG_MP -#define printfMp printf -#endif - -#ifdef DBG_CP -#define printfCp printf -#endif - -#ifdef DBG_STR -#define printfStr printf -#endif diff --git a/ffi/trap.c b/ffi/trap.c index 4e526f2..c550658 100644 --- a/ffi/trap.c +++ b/ffi/trap.c @@ -2,8 +2,6 @@ #include #include -#include "../debug.h" - /* TODO(bernhard): use {u,}int* types */ #define __USE_GNU