blob: 082fb0d8542431590fa0fb910636eda432ded6b3 [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
Tamas Berghammercb527a72015-02-11 12:52:55 +000013#include <functional>
14#include <map>
15
Greg Clayton576d8832011-03-22 04:00:09 +000016#include "GDBRemoteCommunication.h"
Kate Stoneb9c1b512016-09-06 20:57:50 +000017#include "lldb/lldb-private-forward.h"
Greg Clayton576d8832011-03-22 04:00:09 +000018
Greg Clayton32e0a752011-03-30 18:16:51 +000019class StringExtractorGDBRemote;
Greg Clayton576d8832011-03-22 04:00:09 +000020
Tamas Berghammerdb264a62015-03-31 09:52:22 +000021namespace lldb_private {
22namespace process_gdb_remote {
23
24class ProcessGDBRemote;
25
Kate Stoneb9c1b512016-09-06 20:57:50 +000026class GDBRemoteCommunicationServer : public GDBRemoteCommunication {
Greg Clayton576d8832011-03-22 04:00:09 +000027public:
Kate Stoneb9c1b512016-09-06 20:57:50 +000028 using PortMap = std::map<uint16_t, lldb::pid_t>;
29 using PacketHandler =
Zachary Turner97206d52017-05-12 04:51:55 +000030 std::function<PacketResult(StringExtractorGDBRemote &packet,
31 Status &error, bool &interrupt, bool &quit)>;
Greg Clayton29b8fc42013-11-21 01:44:58 +000032
Kate Stoneb9c1b512016-09-06 20:57:50 +000033 GDBRemoteCommunicationServer(const char *comm_name,
34 const char *listener_name);
Todd Fialab8b49ec2014-01-28 00:34:23 +000035
Kate Stoneb9c1b512016-09-06 20:57:50 +000036 ~GDBRemoteCommunicationServer() override;
Greg Clayton576d8832011-03-22 04:00:09 +000037
Kate Stoneb9c1b512016-09-06 20:57:50 +000038 void
39 RegisterPacketHandler(StringExtractorGDBRemote::ServerPacketType packet_type,
40 PacketHandler handler);
Tamas Berghammere13c2732015-02-11 10:29:30 +000041
Pavel Labath1eff73c2016-11-24 10:54:49 +000042 PacketResult GetPacketAndSendResponse(Timeout<std::micro> timeout,
Zachary Turner97206d52017-05-12 04:51:55 +000043 Status &error, bool &interrupt,
Pavel Labath1eff73c2016-11-24 10:54:49 +000044 bool &quit);
Greg Clayton576d8832011-03-22 04:00:09 +000045
Kate Stoneb9c1b512016-09-06 20:57:50 +000046 // After connecting, do a little handshake with the client to make sure
47 // we are at least communicating
48 bool HandshakeWithClient();
Greg Clayton576d8832011-03-22 04:00:09 +000049
50protected:
Kate Stoneb9c1b512016-09-06 20:57:50 +000051 std::map<StringExtractorGDBRemote::ServerPacketType, PacketHandler>
52 m_packet_handlers;
53 bool m_exit_now; // use in asynchronous handling to indicate process should
54 // exit.
Greg Clayton576d8832011-03-22 04:00:09 +000055
Pavel Labatha70512a2018-04-11 13:30:54 +000056 bool m_send_error_strings = false; // If the client enables this then
57 // we will send error strings as well.
Ravitheja Addepallydab1d5f2017-07-12 11:15:34 +000058
59 PacketResult Handle_QErrorStringEnable(StringExtractorGDBRemote &packet);
60
61 PacketResult SendErrorResponse(const Status &error);
62
Kate Stoneb9c1b512016-09-06 20:57:50 +000063 PacketResult SendUnimplementedResponse(const char *packet);
Greg Clayton32e0a752011-03-30 18:16:51 +000064
Kate Stoneb9c1b512016-09-06 20:57:50 +000065 PacketResult SendErrorResponse(uint8_t error);
Greg Clayton576d8832011-03-22 04:00:09 +000066
Kate Stoneb9c1b512016-09-06 20:57:50 +000067 PacketResult SendIllFormedResponse(const StringExtractorGDBRemote &packet,
68 const char *error_message);
Todd Fialaaf245d12014-06-30 21:05:18 +000069
Kate Stoneb9c1b512016-09-06 20:57:50 +000070 PacketResult SendOKResponse();
Greg Clayton576d8832011-03-22 04:00:09 +000071
Greg Clayton576d8832011-03-22 04:00:09 +000072private:
Kate Stoneb9c1b512016-09-06 20:57:50 +000073 DISALLOW_COPY_AND_ASSIGN(GDBRemoteCommunicationServer);
Greg Clayton576d8832011-03-22 04:00:09 +000074};
75
Tamas Berghammerdb264a62015-03-31 09:52:22 +000076} // namespace process_gdb_remote
77} // namespace lldb_private
78
Eugene Zelenkoedb35d92015-10-24 01:08:35 +000079#endif // liblldb_GDBRemoteCommunicationServer_h_