blob: f2b2d1ef815f23fdeeed79a18cf58e989b510669 [file] [log] [blame]
Greg Clayton576d8832011-03-22 04:00:09 +00001//===-- GDBRemoteCommunicationServer.h --------------------------*- C++ -*-===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Greg Clayton576d8832011-03-22 04:00:09 +00006//
7//===----------------------------------------------------------------------===//
8
9#ifndef liblldb_GDBRemoteCommunicationServer_h_
10#define liblldb_GDBRemoteCommunicationServer_h_
11
Tamas Berghammercb527a72015-02-11 12:52:55 +000012#include <functional>
13#include <map>
14
Greg Clayton576d8832011-03-22 04:00:09 +000015#include "GDBRemoteCommunication.h"
Kate Stoneb9c1b512016-09-06 20:57:50 +000016#include "lldb/lldb-private-forward.h"
Greg Clayton576d8832011-03-22 04:00:09 +000017
Greg Clayton32e0a752011-03-30 18:16:51 +000018class StringExtractorGDBRemote;
Greg Clayton576d8832011-03-22 04:00:09 +000019
Tamas Berghammerdb264a62015-03-31 09:52:22 +000020namespace lldb_private {
21namespace process_gdb_remote {
22
23class ProcessGDBRemote;
24
Kate Stoneb9c1b512016-09-06 20:57:50 +000025class GDBRemoteCommunicationServer : public GDBRemoteCommunication {
Greg Clayton576d8832011-03-22 04:00:09 +000026public:
Kate Stoneb9c1b512016-09-06 20:57:50 +000027 using PortMap = std::map<uint16_t, lldb::pid_t>;
28 using PacketHandler =
Zachary Turner97206d52017-05-12 04:51:55 +000029 std::function<PacketResult(StringExtractorGDBRemote &packet,
30 Status &error, bool &interrupt, bool &quit)>;
Greg Clayton29b8fc42013-11-21 01:44:58 +000031
Kate Stoneb9c1b512016-09-06 20:57:50 +000032 GDBRemoteCommunicationServer(const char *comm_name,
33 const char *listener_name);
Todd Fialab8b49ec2014-01-28 00:34:23 +000034
Kate Stoneb9c1b512016-09-06 20:57:50 +000035 ~GDBRemoteCommunicationServer() override;
Greg Clayton576d8832011-03-22 04:00:09 +000036
Kate Stoneb9c1b512016-09-06 20:57:50 +000037 void
38 RegisterPacketHandler(StringExtractorGDBRemote::ServerPacketType packet_type,
39 PacketHandler handler);
Tamas Berghammere13c2732015-02-11 10:29:30 +000040
Pavel Labath1eff73c2016-11-24 10:54:49 +000041 PacketResult GetPacketAndSendResponse(Timeout<std::micro> timeout,
Zachary Turner97206d52017-05-12 04:51:55 +000042 Status &error, bool &interrupt,
Pavel Labath1eff73c2016-11-24 10:54:49 +000043 bool &quit);
Greg Clayton576d8832011-03-22 04:00:09 +000044
Kate Stoneb9c1b512016-09-06 20:57:50 +000045 // After connecting, do a little handshake with the client to make sure
46 // we are at least communicating
47 bool HandshakeWithClient();
Greg Clayton576d8832011-03-22 04:00:09 +000048
49protected:
Kate Stoneb9c1b512016-09-06 20:57:50 +000050 std::map<StringExtractorGDBRemote::ServerPacketType, PacketHandler>
51 m_packet_handlers;
52 bool m_exit_now; // use in asynchronous handling to indicate process should
53 // exit.
Greg Clayton576d8832011-03-22 04:00:09 +000054
Pavel Labatha70512a2018-04-11 13:30:54 +000055 bool m_send_error_strings = false; // If the client enables this then
56 // we will send error strings as well.
Ravitheja Addepallydab1d5f2017-07-12 11:15:34 +000057
58 PacketResult Handle_QErrorStringEnable(StringExtractorGDBRemote &packet);
59
60 PacketResult SendErrorResponse(const Status &error);
61
Kate Stoneb9c1b512016-09-06 20:57:50 +000062 PacketResult SendUnimplementedResponse(const char *packet);
Greg Clayton32e0a752011-03-30 18:16:51 +000063
Kate Stoneb9c1b512016-09-06 20:57:50 +000064 PacketResult SendErrorResponse(uint8_t error);
Greg Clayton576d8832011-03-22 04:00:09 +000065
Kate Stoneb9c1b512016-09-06 20:57:50 +000066 PacketResult SendIllFormedResponse(const StringExtractorGDBRemote &packet,
67 const char *error_message);
Todd Fialaaf245d12014-06-30 21:05:18 +000068
Kate Stoneb9c1b512016-09-06 20:57:50 +000069 PacketResult SendOKResponse();
Greg Clayton576d8832011-03-22 04:00:09 +000070
Greg Clayton576d8832011-03-22 04:00:09 +000071private:
Kate Stoneb9c1b512016-09-06 20:57:50 +000072 DISALLOW_COPY_AND_ASSIGN(GDBRemoteCommunicationServer);
Greg Clayton576d8832011-03-22 04:00:09 +000073};
74
Tamas Berghammerdb264a62015-03-31 09:52:22 +000075} // namespace process_gdb_remote
76} // namespace lldb_private
77
Eugene Zelenkoedb35d92015-10-24 01:08:35 +000078#endif // liblldb_GDBRemoteCommunicationServer_h_