disasm: also label bad instructions
authorBernhard Urban <lewurm@gmail.com>
Thu, 2 Aug 2012 18:48:33 +0000 (20:48 +0200)
committerBernhard Urban <lewurm@gmail.com>
Thu, 2 Aug 2012 18:48:33 +0000 (20:48 +0200)
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.<init>.()
returns Void: [0a2f501a]
0a2f501a  ff ff                         (invalid opcode, byte=255)
0a2f501c  90                            nop

Harpy/CodeGenMonad.hs

index 0c0a281defe70b2814bd9bb3510053f79aacedd9..46d930db2dafb2e53b4a3738702fd9dbb7a3fb4e 100644 (file)
@@ -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