blob: 0c583e62d76bb01b4d1e4551bc574f7a0fc8e6ea [file] [log] [blame]
Greg Clayton576d8832011-03-22 04:00:09 +00001//===-- GDBRemoteCommunicationServer.h --------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef liblldb_GDBRemoteCommunicationServer_h_
11#define liblldb_GDBRemoteCommunicationServer_h_
12
13// C Includes
14// C++ Includes
Tamas Berghammercb527a72015-02-11 12:52:55 +000015#include <functional>
16#include <map>
17
Greg Clayton576d8832011-03-22 04:00:09 +000018// Other libraries and framework includes
19// Project includes
20#include "GDBRemoteCommunication.h"
Kate Stoneb9c1b512016-09-06 20:57:50 +000021#include "lldb/lldb-private-forward.h"
Greg Clayton576d8832011-03-22 04:00:09 +000022
Greg Clayton32e0a752011-03-30 18:16:51 +000023class StringExtractorGDBRemote;
Greg Clayton576d8832011-03-22 04:00:09 +000024
Tamas Berghammerdb264a62015-03-31 09:52:22 +000025namespace lldb_private {
26namespace process_gdb_remote {
27
28class ProcessGDBRemote;
29
Kate Stoneb9c1b512016-09-06 20:57:50 +000030class GDBRemoteCommunicationServer : public GDBRemoteCommunication {
Greg Clayton576d8832011-03-22 04:00:09 +000031public:
Kate Stoneb9c1b512016-09-06 20:57:50 +000032 using PortMap = std::map<uint16_t, lldb::pid_t>;
33 using PacketHandler =
34 std::function<PacketResult(StringExtractorGDBRemote &packet, Error &error,
35 bool &interrupt, bool &quit)>;
Greg Clayton29b8fc42013-11-21 01:44:58 +000036
Kate Stoneb9c1b512016-09-06 20:57:50 +000037 GDBRemoteCommunicationServer(const char *comm_name,
38 const char *listener_name);
Todd Fialab8b49ec2014-01-28 00:34:23 +000039
Kate Stoneb9c1b512016-09-06 20:57:50 +000040 ~GDBRemoteCommunicationServer() override;
Greg Clayton576d8832011-03-22 04:00:09 +000041
Kate Stoneb9c1b512016-09-06 20:57:50 +000042 void
43 RegisterPacketHandler(StringExtractorGDBRemote::ServerPacketType packet_type,
44 PacketHandler handler);
Tamas Berghammere13c2732015-02-11 10:29:30 +000045
Pavel Labath1eff73c2016-11-24 10:54:49 +000046 PacketResult GetPacketAndSendResponse(Timeout<std::micro> timeout,
47 Error &error, bool &interrupt,
48 bool &quit);
Greg Clayton576d8832011-03-22 04:00:09 +000049
Kate Stoneb9c1b512016-09-06 20:57:50 +000050 // After connecting, do a little handshake with the client to make sure
51 // we are at least communicating
52 bool HandshakeWithClient();
Greg Clayton576d8832011-03-22 04:00:09 +000053
54protected:
Kate Stoneb9c1b512016-09-06 20:57:50 +000055 std::map<StringExtractorGDBRemote::ServerPacketType, PacketHandler>
56 m_packet_handlers;
57 bool m_exit_now; // use in asynchronous handling to indicate process should
58 // exit.
Greg Clayton576d8832011-03-22 04:00:09 +000059
Kate Stoneb9c1b512016-09-06 20:57:50 +000060 PacketResult SendUnimplementedResponse(const char *packet);
Greg Clayton32e0a752011-03-30 18:16:51 +000061
Kate Stoneb9c1b512016-09-06 20:57:50 +000062 PacketResult SendErrorResponse(uint8_t error);
Greg Clayton576d8832011-03-22 04:00:09 +000063
Kate Stoneb9c1b512016-09-06 20:57:50 +000064 PacketResult SendIllFormedResponse(const StringExtractorGDBRemote &packet,
65 const char *error_message);
Todd Fialaaf245d12014-06-30 21:05:18 +000066
Kate Stoneb9c1b512016-09-06 20:57:50 +000067 PacketResult SendOKResponse();
Greg Clayton576d8832011-03-22 04:00:09 +000068
Greg Clayton576d8832011-03-22 04:00:09 +000069private:
Kate Stoneb9c1b512016-09-06 20:57:50 +000070 DISALLOW_COPY_AND_ASSIGN(GDBRemoteCommunicationServer);
Greg Clayton576d8832011-03-22 04:00:09 +000071};
72
Tamas Berghammerdb264a62015-03-31 09:52:22 +000073} // namespace process_gdb_remote
74} // namespace lldb_private
75
Eugene Zelenkoedb35d92015-10-24 01:08:35 +000076#endif // liblldb_GDBRemoteCommunicationServer_h_