blob: 1d512bf1de59578696d6ae0900d7ee823e891f53 [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
Todd Fialaaf245d12014-06-30 21:05:18 +000020#include "lldb/lldb-private-forward.h"
Greg Clayton576d8832011-03-22 04:00:09 +000021#include "GDBRemoteCommunication.h"
22
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
30class GDBRemoteCommunicationServer : public GDBRemoteCommunication
Greg Clayton576d8832011-03-22 04:00:09 +000031{
32public:
Tamas Berghammere13c2732015-02-11 10:29:30 +000033 using PortMap = std::map<uint16_t, lldb::pid_t>;
34 using PacketHandler = std::function<PacketResult(StringExtractorGDBRemote &packet,
Tamas Berghammerdb264a62015-03-31 09:52:22 +000035 Error &error,
Tamas Berghammere13c2732015-02-11 10:29:30 +000036 bool &interrupt,
37 bool &quit)>;
Greg Clayton29b8fc42013-11-21 01:44:58 +000038
Tamas Berghammere13c2732015-02-11 10:29:30 +000039 GDBRemoteCommunicationServer(const char *comm_name,
40 const char *listener_name);
Todd Fialab8b49ec2014-01-28 00:34:23 +000041
Eugene Zelenkoedb35d92015-10-24 01:08:35 +000042 ~GDBRemoteCommunicationServer() override;
Greg Clayton576d8832011-03-22 04:00:09 +000043
Tamas Berghammere13c2732015-02-11 10:29:30 +000044 void RegisterPacketHandler(StringExtractorGDBRemote::ServerPacketType packet_type,
45 PacketHandler handler);
46
Todd Fialaaf245d12014-06-30 21:05:18 +000047 PacketResult
Greg Clayton73bf5db2011-06-17 01:22:15 +000048 GetPacketAndSendResponse (uint32_t timeout_usec,
Tamas Berghammerdb264a62015-03-31 09:52:22 +000049 Error &error,
Greg Claytond314e812011-03-23 00:09:55 +000050 bool &interrupt,
51 bool &quit);
Greg Clayton576d8832011-03-22 04:00:09 +000052
Greg Clayton1cb64962011-03-24 04:28:38 +000053 // After connecting, do a little handshake with the client to make sure
54 // we are at least communicating
55 bool
Pavel Labath77dc9562015-07-13 10:44:55 +000056 HandshakeWithClient ();
Greg Clayton576d8832011-03-22 04:00:09 +000057
58protected:
Tamas Berghammere13c2732015-02-11 10:29:30 +000059 std::map<StringExtractorGDBRemote::ServerPacketType, PacketHandler> m_packet_handlers;
Todd Fialaaf245d12014-06-30 21:05:18 +000060 bool m_exit_now; // use in asynchronous handling to indicate process should exit.
Greg Clayton576d8832011-03-22 04:00:09 +000061
Greg Clayton3dedae12013-12-06 21:45:27 +000062 PacketResult
Greg Clayton32e0a752011-03-30 18:16:51 +000063 SendUnimplementedResponse (const char *packet);
64
Greg Clayton3dedae12013-12-06 21:45:27 +000065 PacketResult
Greg Clayton32e0a752011-03-30 18:16:51 +000066 SendErrorResponse (uint8_t error);
Greg Clayton576d8832011-03-22 04:00:09 +000067
Greg Clayton3dedae12013-12-06 21:45:27 +000068 PacketResult
Todd Fialaaf245d12014-06-30 21:05:18 +000069 SendIllFormedResponse (const StringExtractorGDBRemote &packet, const char *error_message);
70
71 PacketResult
Greg Clayton1cb64962011-03-24 04:28:38 +000072 SendOKResponse ();
Greg Clayton576d8832011-03-22 04:00:09 +000073
Greg Clayton576d8832011-03-22 04:00:09 +000074private:
Greg Clayton576d8832011-03-22 04:00:09 +000075 DISALLOW_COPY_AND_ASSIGN (GDBRemoteCommunicationServer);
76};
77
Tamas Berghammerdb264a62015-03-31 09:52:22 +000078} // namespace process_gdb_remote
79} // namespace lldb_private
80
Eugene Zelenkoedb35d92015-10-24 01:08:35 +000081#endif // liblldb_GDBRemoteCommunicationServer_h_