blob: 880caacd64149fa214143fcfb42bca86ade05603 [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 =
Zachary Turner97206d52017-05-12 04:51:55 +000034 std::function<PacketResult(StringExtractorGDBRemote &packet,
35 Status &error, 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,
Zachary Turner97206d52017-05-12 04:51:55 +000047 Status &error, bool &interrupt,
Pavel Labath1eff73c2016-11-24 10:54:49 +000048 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
Pavel Labatha70512a2018-04-11 13:30:54 +000060 bool m_send_error_strings = false; // If the client enables this then
61 // we will send error strings as well.
Ravitheja Addepallydab1d5f2017-07-12 11:15:34 +000062
63 PacketResult Handle_QErrorStringEnable(StringExtractorGDBRemote &packet);
64
65 PacketResult SendErrorResponse(const Status &error);
66
Kate Stoneb9c1b512016-09-06 20:57:50 +000067 PacketResult SendUnimplementedResponse(const char *packet);
Greg Clayton32e0a752011-03-30 18:16:51 +000068
Kate Stoneb9c1b512016-09-06 20:57:50 +000069 PacketResult SendErrorResponse(uint8_t error);
Greg Clayton576d8832011-03-22 04:00:09 +000070
Kate Stoneb9c1b512016-09-06 20:57:50 +000071 PacketResult SendIllFormedResponse(const StringExtractorGDBRemote &packet,
72 const char *error_message);
Todd Fialaaf245d12014-06-30 21:05:18 +000073
Kate Stoneb9c1b512016-09-06 20:57:50 +000074 PacketResult SendOKResponse();
Greg Clayton576d8832011-03-22 04:00:09 +000075
Greg Clayton576d8832011-03-22 04:00:09 +000076private:
Kate Stoneb9c1b512016-09-06 20:57:50 +000077 DISALLOW_COPY_AND_ASSIGN(GDBRemoteCommunicationServer);
Greg Clayton576d8832011-03-22 04:00:09 +000078};
79
Tamas Berghammerdb264a62015-03-31 09:52:22 +000080} // namespace process_gdb_remote
81} // namespace lldb_private
82
Eugene Zelenkoedb35d92015-10-24 01:08:35 +000083#endif // liblldb_GDBRemoteCommunicationServer_h_