validateHistoryWorker' :: Worker -> [HistoryEntry] -> IO Bool
validateHistoryWorker' worker desired_hist =
    let validateHistory [] [] = True
        validateHistory [ResponseDataAncillary 19 [0]] _ = True
        validateHistory ((ResponseDataAncillary 19 [0x1236, tid, acc]):o) o's@((HistoryRun tid' acc'):o')
            | (ThreadId $ toInteger tid) == tid' =
                case (Finite $ AccessNr $ toInteger acc) `compare` acc' of
                  LT -> validateHistory o o's
                  EQ -> validateHistory o o'
                  GT -> Debug.Trace.trace ("history validation failed because worker was at " ++ (show acc) ++ " and we only wanted " ++ (show acc') ++ ", rest " ++ (show o')) False
        validateHistory ((ResponseDataAncillary 19 [0x1244, tid, reg, val]):o)
                        ((HistorySetRegister tid' reg' val'):o')
            | (ThreadId $ toInteger tid) == tid' && (parseRegister reg) == reg' && val == val' = validateHistory o o'
        validateHistory ((ResponseDataAncillary 19 [0x1245, addr, size, prot]):o)
                        ((HistoryAllocMemory addr' size' prot'):o')
            | addr == addr' && size == size' && prot == prot' = validateHistory o o'
        validateHistory ((ResponseDataAncillary 19 [0x1246, addr, size]):o)
                        ((HistorySetMemory addr' bytes):o')
            | addr == addr' && size == (fromIntegral $ length bytes) = validateHistory o o'
        validateHistory ((ResponseDataAncillary 19 [0x1247, addr, size, prot]):o)
                        ((HistorySetMemoryProtection addr' size' prot'):o')
            | addr == addr' && size == size' && prot == prot' = validateHistory o o'
        validateHistory ((ResponseDataAncillary 19 [0x1248, tid, tsc]):o)
                        ((HistorySetTsc (ThreadId tid') tsc'):o')
            | toInteger tid == tid' && tsc == tsc' = validateHistory o o'
        validateHistory o ((HistoryAdvanceLog _):o')
            = validateHistory o o'
        validateHistory ((ResponseDataAncillary 19 [0x124c, t]):o)
                        ((HistoryRunSyscall (ThreadId t')):o')
            | t == (fromIntegral t') = validateHistory o o'
        validateHistory o o' = Debug.Trace.trace ("history validation failed: " ++ (show o) ++ " vs " ++ (show o')) False
    in do (ResponsePacket _ params) <- sendWorkerCommand worker getHistoryPacket
          let r = validateHistory params desired_hist
          when (not r) $ putStrLn $ "validation of " ++ (show desired_hist) ++ " against " ++ (show params) ++ " in " ++ (show worker) ++ " failed"
          return r
validateHistoryWorker' :: Worker -> [HistoryEntry] -> IO Bool
validateHistoryWorker' worker desired_hist =
    let validateHistory [] [] = True
        validateHistory [ResponseDataAncillary 19 [0]] _ = True
        validateHistory ((ResponseDataAncillary 19 [0x1236, tid, acc]):o) o's@((HistoryRun tid' acc'):o')
            | (ThreadId $ toInteger tid) == tid' =
                case (Finite $ AccessNr $ toInteger acc) `compare` acc' of
                  LT -> validateHistory o o's
                  EQ -> validateHistory o o'
                  GT -> Debug.Trace.trace ("history validation failed because worker was at " ++ (show acc) ++ " and we only wanted " ++ (show acc') ++ ", rest " ++ (show o')) False
        validateHistory ((ResponseDataAncillary 19 [0x1244, tid, reg, val]):o)
                        ((HistorySetRegister tid' reg' val'):o')
            | (ThreadId $ toInteger tid) == tid' && (parseRegister reg) == reg' && val == val' = validateHistory o o'
        validateHistory ((ResponseDataAncillary 19 [0x1245, addr, size, prot]):o)
                        ((HistoryAllocMemory addr' size' prot'):o')
            | addr == addr' && size == size' && prot == prot' = validateHistory o o'
        validateHistory ((ResponseDataAncillary 19 [0x1246, addr, size]):o)
                        ((HistorySetMemory addr' bytes):o')
            | addr == addr' && size == (fromIntegral $ length bytes) = validateHistory o o'
        validateHistory ((ResponseDataAncillary 19 [0x1247, addr, size, prot]):o)
                        ((HistorySetMemoryProtection addr' size' prot'):o')
            | addr == addr' && size == size' && prot == prot' = validateHistory o o'
        validateHistory ((ResponseDataAncillary 19 [0x1248, tid, tsc]):o)
                        ((HistorySetTsc (ThreadId tid') tsc'):o')
            | toInteger tid == tid' && tsc == tsc' = validateHistory o o'
        validateHistory o ((HistoryAdvanceLog _):o')
            = validateHistory o o'
        validateHistory ((ResponseDataAncillary 19 [0x124c, t]):o)
                        ((HistoryRunSyscall (ThreadId t')):o')
            | t == (fromIntegral t') = validateHistory o o'
        validateHistory o o' = Debug.Trace.trace ("history validation failed: " ++ (show o) ++ " vs " ++ (show o')) False
    in do (ResponsePacket _ params) <- sendWorkerCommand worker getHistoryPacket
          let r = validateHistory params desired_hist
          when (not r) $ putStrLn $ "validation of " ++ (show desired_hist) ++ " against " ++ (show params) ++ " in " ++ (show worker) ++ " failed"
          return r
validateHistoryWorker' worker desired_hist =
    let validateHistory [] [] = True
        validateHistory [ResponseDataAncillary 19 [0]] _ = True
        validateHistory ((ResponseDataAncillary 19 [0x1236, tid, acc]):o) o's@((HistoryRun tid' acc'):o')
            | (ThreadId $ toInteger tid) == tid' =
                case (Finite $ AccessNr $ toInteger acc) `compare` acc' of
                  LT -> validateHistory o o's
                  EQ -> validateHistory o o'
                  GT -> Debug.Trace.trace ("history validation failed because worker was at " ++ (show acc) ++ " and we only wanted " ++ (show acc') ++ ", rest " ++ (show o')) False
        validateHistory ((ResponseDataAncillary 19 [0x1244, tid, reg, val]):o)
                        ((HistorySetRegister tid' reg' val'):o')
            | (ThreadId $ toInteger tid) == tid' && (parseRegister reg) == reg' && val == val' = validateHistory o o'
        validateHistory ((ResponseDataAncillary 19 [0x1245, addr, size, prot]):o)
                        ((HistoryAllocMemory addr' size' prot'):o')
            | addr == addr' && size == size' && prot == prot' = validateHistory o o'
        validateHistory ((ResponseDataAncillary 19 [0x1246, addr, size]):o)
                        ((HistorySetMemory addr' bytes):o')
            | addr == addr' && size == (fromIntegral $ length bytes) = validateHistory o o'
        validateHistory ((ResponseDataAncillary 19 [0x1247, addr, size, prot]):o)
                        ((HistorySetMemoryProtection addr' size' prot'):o')
            | addr == addr' && size == size' && prot == prot' = validateHistory o o'
        validateHistory ((ResponseDataAncillary 19 [0x1248, tid, tsc]):o)
                        ((HistorySetTsc (ThreadId tid') tsc'):o')
            | toInteger tid == tid' && tsc == tsc' = validateHistory o o'
        validateHistory o ((HistoryAdvanceLog _):o')
            = validateHistory o o'
        validateHistory ((ResponseDataAncillary 19 [0x124c, t]):o)
                        ((HistoryRunSyscall (ThreadId t')):o')
            | t == (fromIntegral t') = validateHistory o o'
        validateHistory o o' = Debug.Trace.trace ("history validation failed: " ++ (show o) ++ " vs " ++ (show o')) False
    in do (ResponsePacket _ params) <- sendWorkerCommand worker getHistoryPacket
          let r = validateHistory params desired_hist
          when (not r) $ putStrLn $ "validation of " ++ (show desired_hist) ++ " against " ++ (show params) ++ " in " ++ (show worker) ++ " failed"
          return r