summaryrefslogtreecommitdiff
path: root/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationReplayServer.h
blob: 26d65e265463b20f9a267aa64daa1e4f496c0cca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
//===-- GDBRemoteCommunicationReplayServer.h --------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef liblldb_GDBRemoteCommunicationReplayServer_h_
#define liblldb_GDBRemoteCommunicationReplayServer_h_

// Other libraries and framework includes
#include "GDBRemoteCommunication.h"
#include "GDBRemoteCommunicationHistory.h"

// Project includes
#include "lldb/Host/HostThread.h"
#include "lldb/Utility/Broadcaster.h"
#include "lldb/lldb-private-forward.h"
#include "llvm/Support/Error.h"

// C Includes
// C++ Includes
#include <functional>
#include <map>
#include <thread>

class StringExtractorGDBRemote;

namespace lldb_private {
namespace process_gdb_remote {

class ProcessGDBRemote;

/// Dummy GDB server that replays packets from the GDB Remote Communication
/// history. This is used to replay GDB packets.
class GDBRemoteCommunicationReplayServer : public GDBRemoteCommunication {
public:
  GDBRemoteCommunicationReplayServer();

  ~GDBRemoteCommunicationReplayServer() override;

  PacketResult GetPacketAndSendResponse(Timeout<std::micro> timeout,
                                        Status &error, bool &interrupt,
                                        bool &quit);

  bool HandshakeWithClient() { return GetAck() == PacketResult::Success; }

  llvm::Error LoadReplayHistory(const FileSpec &path);

  bool StartAsyncThread();
  void StopAsyncThread();

protected:
  enum {
    eBroadcastBitAsyncContinue = (1 << 0),
    eBroadcastBitAsyncThreadShouldExit = (1 << 1),
  };

  static void ReceivePacket(GDBRemoteCommunicationReplayServer &server,
                            bool &done);
  static lldb::thread_result_t AsyncThread(void *arg);

  /// Replay history with the oldest packet at the end.
  std::vector<GDBRemoteCommunicationHistory::Entry> m_packet_history;

  /// Server thread.
  Broadcaster m_async_broadcaster;
  lldb::ListenerSP m_async_listener_sp;
  HostThread m_async_thread;
  std::recursive_mutex m_async_thread_state_mutex;

  bool m_skip_acks;

private:
  DISALLOW_COPY_AND_ASSIGN(GDBRemoteCommunicationReplayServer);
};

} // namespace process_gdb_remote
} // namespace lldb_private

#endif // liblldb_GDBRemoteCommunicationReplayServer_h_