blob: 148545f4103c51e2ed6aeece85cf89356580a58c [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
23class ProcessGDBRemote;
Greg Clayton32e0a752011-03-30 18:16:51 +000024class StringExtractorGDBRemote;
Greg Clayton576d8832011-03-22 04:00:09 +000025
Todd Fialaaf245d12014-06-30 21:05:18 +000026class GDBRemoteCommunicationServer :
Tamas Berghammere13c2732015-02-11 10:29:30 +000027 public GDBRemoteCommunication
Greg Clayton576d8832011-03-22 04:00:09 +000028{
29public:
Tamas Berghammere13c2732015-02-11 10:29:30 +000030 using PortMap = std::map<uint16_t, lldb::pid_t>;
31 using PacketHandler = std::function<PacketResult(StringExtractorGDBRemote &packet,
32 lldb_private::Error &error,
33 bool &interrupt,
34 bool &quit)>;
Greg Clayton29b8fc42013-11-21 01:44:58 +000035
Tamas Berghammere13c2732015-02-11 10:29:30 +000036 GDBRemoteCommunicationServer(const char *comm_name,
37 const char *listener_name);
Todd Fialab8b49ec2014-01-28 00:34:23 +000038
Greg Clayton576d8832011-03-22 04:00:09 +000039 virtual
40 ~GDBRemoteCommunicationServer();
41
Tamas Berghammere13c2732015-02-11 10:29:30 +000042 void RegisterPacketHandler(StringExtractorGDBRemote::ServerPacketType packet_type,
43 PacketHandler handler);
44
Todd Fialaaf245d12014-06-30 21:05:18 +000045 PacketResult
Greg Clayton73bf5db2011-06-17 01:22:15 +000046 GetPacketAndSendResponse (uint32_t timeout_usec,
Greg Clayton1cb64962011-03-24 04:28:38 +000047 lldb_private::Error &error,
Greg Claytond314e812011-03-23 00:09:55 +000048 bool &interrupt,
49 bool &quit);
Greg Clayton576d8832011-03-22 04:00:09 +000050
Greg Clayton1cb64962011-03-24 04:28:38 +000051 // After connecting, do a little handshake with the client to make sure
52 // we are at least communicating
53 bool
54 HandshakeWithClient (lldb_private::Error *error_ptr);
Greg Clayton576d8832011-03-22 04:00:09 +000055
56protected:
Tamas Berghammere13c2732015-02-11 10:29:30 +000057 std::map<StringExtractorGDBRemote::ServerPacketType, PacketHandler> m_packet_handlers;
Todd Fialaaf245d12014-06-30 21:05:18 +000058 bool m_exit_now; // use in asynchronous handling to indicate process should exit.
Greg Clayton576d8832011-03-22 04:00:09 +000059
Greg Clayton3dedae12013-12-06 21:45:27 +000060 PacketResult
Greg Clayton32e0a752011-03-30 18:16:51 +000061 SendUnimplementedResponse (const char *packet);
62
Greg Clayton3dedae12013-12-06 21:45:27 +000063 PacketResult
Greg Clayton32e0a752011-03-30 18:16:51 +000064 SendErrorResponse (uint8_t error);
Greg Clayton576d8832011-03-22 04:00:09 +000065
Greg Clayton3dedae12013-12-06 21:45:27 +000066 PacketResult
Todd Fialaaf245d12014-06-30 21:05:18 +000067 SendIllFormedResponse (const StringExtractorGDBRemote &packet, const char *error_message);
68
69 PacketResult
Greg Clayton1cb64962011-03-24 04:28:38 +000070 SendOKResponse ();
Greg Clayton576d8832011-03-22 04:00:09 +000071
Greg Clayton576d8832011-03-22 04:00:09 +000072private:
Greg Clayton576d8832011-03-22 04:00:09 +000073 //------------------------------------------------------------------
74 // For GDBRemoteCommunicationServer only
75 //------------------------------------------------------------------
76 DISALLOW_COPY_AND_ASSIGN (GDBRemoteCommunicationServer);
77};
78
79#endif // liblldb_GDBRemoteCommunicationServer_h_