blob: 992c6dffaf547360db5e6f17d47317712d0009b2 [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
Greg Clayton576d8832011-03-22 04:00:09 +000042 virtual
43 ~GDBRemoteCommunicationServer();
44
Tamas Berghammere13c2732015-02-11 10:29:30 +000045 void RegisterPacketHandler(StringExtractorGDBRemote::ServerPacketType packet_type,
46 PacketHandler handler);
47
Todd Fialaaf245d12014-06-30 21:05:18 +000048 PacketResult
Greg Clayton73bf5db2011-06-17 01:22:15 +000049 GetPacketAndSendResponse (uint32_t timeout_usec,
Tamas Berghammerdb264a62015-03-31 09:52:22 +000050 Error &error,
Greg Claytond314e812011-03-23 00:09:55 +000051 bool &interrupt,
52 bool &quit);
Greg Clayton576d8832011-03-22 04:00:09 +000053
Greg Clayton1cb64962011-03-24 04:28:38 +000054 // After connecting, do a little handshake with the client to make sure
55 // we are at least communicating
56 bool
Tamas Berghammerdb264a62015-03-31 09:52:22 +000057 HandshakeWithClient (Error *error_ptr);
Greg Clayton576d8832011-03-22 04:00:09 +000058
59protected:
Tamas Berghammere13c2732015-02-11 10:29:30 +000060 std::map<StringExtractorGDBRemote::ServerPacketType, PacketHandler> m_packet_handlers;
Todd Fialaaf245d12014-06-30 21:05:18 +000061 bool m_exit_now; // use in asynchronous handling to indicate process should exit.
Greg Clayton576d8832011-03-22 04:00:09 +000062
Greg Clayton3dedae12013-12-06 21:45:27 +000063 PacketResult
Greg Clayton32e0a752011-03-30 18:16:51 +000064 SendUnimplementedResponse (const char *packet);
65
Greg Clayton3dedae12013-12-06 21:45:27 +000066 PacketResult
Greg Clayton32e0a752011-03-30 18:16:51 +000067 SendErrorResponse (uint8_t error);
Greg Clayton576d8832011-03-22 04:00:09 +000068
Greg Clayton3dedae12013-12-06 21:45:27 +000069 PacketResult
Todd Fialaaf245d12014-06-30 21:05:18 +000070 SendIllFormedResponse (const StringExtractorGDBRemote &packet, const char *error_message);
71
72 PacketResult
Greg Clayton1cb64962011-03-24 04:28:38 +000073 SendOKResponse ();
Greg Clayton576d8832011-03-22 04:00:09 +000074
Greg Clayton576d8832011-03-22 04:00:09 +000075private:
Greg Clayton576d8832011-03-22 04:00:09 +000076 //------------------------------------------------------------------
77 // For GDBRemoteCommunicationServer only
78 //------------------------------------------------------------------
79 DISALLOW_COPY_AND_ASSIGN (GDBRemoteCommunicationServer);
80};
81
Tamas Berghammerdb264a62015-03-31 09:52:22 +000082} // namespace process_gdb_remote
83} // namespace lldb_private
84
Greg Clayton576d8832011-03-22 04:00:09 +000085#endif // liblldb_GDBRemoteCommunicationServer_h_