GDBRemoteCommunicationReplayServer.h revision 360784
1//===-- GDBRemoteCommunicationReplayServer.h --------------------*- C++ -*-===// 2// 3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4// See https://llvm.org/LICENSE.txt for license information. 5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6// 7//===----------------------------------------------------------------------===// 8 9#ifndef liblldb_GDBRemoteCommunicationReplayServer_h_ 10#define liblldb_GDBRemoteCommunicationReplayServer_h_ 11 12// Other libraries and framework includes 13#include "GDBRemoteCommunication.h" 14#include "GDBRemoteCommunicationHistory.h" 15 16// Project includes 17#include "lldb/Host/HostThread.h" 18#include "lldb/Utility/Broadcaster.h" 19#include "lldb/lldb-private-forward.h" 20#include "llvm/Support/Error.h" 21 22// C Includes 23// C++ Includes 24#include <functional> 25#include <map> 26#include <thread> 27 28class StringExtractorGDBRemote; 29 30namespace lldb_private { 31namespace process_gdb_remote { 32 33class ProcessGDBRemote; 34 35/// Dummy GDB server that replays packets from the GDB Remote Communication 36/// history. This is used to replay GDB packets. 37class GDBRemoteCommunicationReplayServer : public GDBRemoteCommunication { 38public: 39 GDBRemoteCommunicationReplayServer(); 40 41 ~GDBRemoteCommunicationReplayServer() override; 42 43 PacketResult GetPacketAndSendResponse(Timeout<std::micro> timeout, 44 Status &error, bool &interrupt, 45 bool &quit); 46 47 bool HandshakeWithClient() { return GetAck() == PacketResult::Success; } 48 49 llvm::Error LoadReplayHistory(const FileSpec &path); 50 51 bool StartAsyncThread(); 52 void StopAsyncThread(); 53 54protected: 55 enum { 56 eBroadcastBitAsyncContinue = (1 << 0), 57 eBroadcastBitAsyncThreadShouldExit = (1 << 1), 58 }; 59 60 static void ReceivePacket(GDBRemoteCommunicationReplayServer &server, 61 bool &done); 62 static lldb::thread_result_t AsyncThread(void *arg); 63 64 /// Replay history with the oldest packet at the end. 65 std::vector<GDBRemotePacket> m_packet_history; 66 67 /// Server thread. 68 Broadcaster m_async_broadcaster; 69 lldb::ListenerSP m_async_listener_sp; 70 HostThread m_async_thread; 71 std::recursive_mutex m_async_thread_state_mutex; 72 73 bool m_skip_acks; 74 75private: 76 DISALLOW_COPY_AND_ASSIGN(GDBRemoteCommunicationReplayServer); 77}; 78 79} // namespace process_gdb_remote 80} // namespace lldb_private 81 82#endif // liblldb_GDBRemoteCommunicationReplayServer_h_ 83