Jonas Devlieghere | 9e046f0 | 2018-11-13 19:18:16 +0000 | [diff] [blame] | 1 | //===-- GDBRemoteCommunicationReplayServer.h --------------------*- C++ -*-===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 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 |
Jonas Devlieghere | 9e046f0 | 2018-11-13 19:18:16 +0000 | [diff] [blame] | 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 |
Jonas Devlieghere | 9e046f0 | 2018-11-13 19:18:16 +0000 | [diff] [blame] | 17 | #include "lldb/Host/HostThread.h" |
Pavel Labath | 181b823 | 2018-12-14 15:59:49 +0000 | [diff] [blame] | 18 | #include "lldb/Utility/Broadcaster.h" |
Jonas Devlieghere | 9e046f0 | 2018-11-13 19:18:16 +0000 | [diff] [blame] | 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 | |
| 28 | class StringExtractorGDBRemote; |
| 29 | |
| 30 | namespace lldb_private { |
| 31 | namespace process_gdb_remote { |
| 32 | |
| 33 | class ProcessGDBRemote; |
| 34 | |
| 35 | /// Dummy GDB server that replays packets from the GDB Remote Communication |
| 36 | /// history. This is used to replay GDB packets. |
| 37 | class GDBRemoteCommunicationReplayServer : public GDBRemoteCommunication { |
| 38 | public: |
| 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 | |
| 54 | protected: |
| 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<GDBRemoteCommunicationHistory::Entry> 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 | |
| 75 | private: |
| 76 | DISALLOW_COPY_AND_ASSIGN(GDBRemoteCommunicationReplayServer); |
| 77 | }; |
| 78 | |
| 79 | } // namespace process_gdb_remote |
| 80 | } // namespace lldb_private |
| 81 | |
| 82 | #endif // liblldb_GDBRemoteCommunicationReplayServer_h_ |