From: Bernhard Urban Date: Thu, 2 Aug 2012 18:48:33 +0000 (+0200) Subject: disasm: also label bad instructions X-Git-Url: http://wien.tomnetworks.com/gitweb/?p=harpy.git;a=commitdiff_plain;h=4e512910dd2601fadf48bdc2633473934793717a disasm: also label bad instructions before: 0ad40017 ff 34 24 push dword ptr [esp] 0ad4001a ff ff (invalid opcode, byte=255) 0ad4001c 90 nop after: 0a2f5017 ff 34 24 pushl (%esp) 0a2f501a jvm_insn: INVOKESPECIAL 3: [0a2f501a] 0a2f501a java/lang/NullPointerException..() returns Void: [0a2f501a] 0a2f501a ff ff (invalid opcode, byte=255) 0a2f501c 90 nop --- diff --git a/Harpy/CodeGenMonad.hs b/Harpy/CodeGenMonad.hs index 0c0a281..46d930d 100644 --- a/Harpy/CodeGenMonad.hs +++ b/Harpy/CodeGenMonad.hs @@ -525,9 +525,12 @@ disassemble = do where insertLabels :: [Dis.Instruction] -> CodeGen e s [Dis.Instruction] insertLabels = liftM concat . mapM ins ins :: Dis.Instruction -> CodeGen e s [Dis.Instruction] - ins i@(Dis.BadInstruction{}) = return [i] + ins i@(Dis.BadInstruction _ _ addr _) = insWithLabel i addr ins i@(Dis.PseudoInstruction{}) = return [i] - ins i@(Dis.Instruction{Dis.address = addr}) = + ins i@(Dis.Instruction{Dis.address = addr}) = insWithLabel i addr + + insWithLabel :: Dis.Instruction -> Int -> CodeGen e s [Dis.Instruction] + insWithLabel i addr = do state <- getInternalState let allLabs = Map.toList (definedLabels state) labs = filter (\ (_, (buf, ofs, _)) -> fromIntegral (ptrToWordPtr (buf `plusPtr` ofs)) == addr) allLabs