blob: 63567bb9b5dee771d93788f821ca6242b8418f21 [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
Jonas Devliegherecdc514e2020-02-17 15:57:45 -08009#ifndef LLDB_SOURCE_PLUGINS_PROCESS_GDB_REMOTE_GDBREMOTECOMMUNICATIONSERVER_H
10#define LLDB_SOURCE_PLUGINS_PROCESS_GDB_REMOTE_GDBREMOTECOMMUNICATIONSERVER_H
Greg Clayton576d8832011-03-22 04:00:09 +000011
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
Antonio Afonso57e2da42019-06-10 20:59:58 +000018#include "llvm/Support/Errc.h"
19#include "llvm/Support/Error.h"
20
Greg Clayton32e0a752011-03-30 18:16:51 +000021class StringExtractorGDBRemote;
Greg Clayton576d8832011-03-22 04:00:09 +000022
Tamas Berghammerdb264a62015-03-31 09:52:22 +000023namespace lldb_private {
24namespace process_gdb_remote {
25
26class ProcessGDBRemote;
27
Kate Stoneb9c1b512016-09-06 20:57:50 +000028class GDBRemoteCommunicationServer : public GDBRemoteCommunication {
Greg Clayton576d8832011-03-22 04:00:09 +000029public:
Kate Stoneb9c1b512016-09-06 20:57:50 +000030 using PortMap = std::map<uint16_t, lldb::pid_t>;
31 using PacketHandler =
Zachary Turner97206d52017-05-12 04:51:55 +000032 std::function<PacketResult(StringExtractorGDBRemote &packet,
33 Status &error, bool &interrupt, bool &quit)>;
Greg Clayton29b8fc42013-11-21 01:44:58 +000034
Kate Stoneb9c1b512016-09-06 20:57:50 +000035 GDBRemoteCommunicationServer(const char *comm_name,
36 const char *listener_name);
Todd Fialab8b49ec2014-01-28 00:34:23 +000037
Kate Stoneb9c1b512016-09-06 20:57:50 +000038 ~GDBRemoteCommunicationServer() override;
Greg Clayton576d8832011-03-22 04:00:09 +000039
Kate Stoneb9c1b512016-09-06 20:57:50 +000040 void
41 RegisterPacketHandler(StringExtractorGDBRemote::ServerPacketType packet_type,
42 PacketHandler handler);
Tamas Berghammere13c2732015-02-11 10:29:30 +000043
Pavel Labath1eff73c2016-11-24 10:54:49 +000044 PacketResult GetPacketAndSendResponse(Timeout<std::micro> timeout,
Zachary Turner97206d52017-05-12 04:51:55 +000045 Status &error, bool &interrupt,
Pavel Labath1eff73c2016-11-24 10:54:49 +000046 bool &quit);
Greg Clayton576d8832011-03-22 04:00:09 +000047
Kate Stoneb9c1b512016-09-06 20:57:50 +000048 // After connecting, do a little handshake with the client to make sure
49 // we are at least communicating
50 bool HandshakeWithClient();
Greg Clayton576d8832011-03-22 04:00:09 +000051
52protected:
Kate Stoneb9c1b512016-09-06 20:57:50 +000053 std::map<StringExtractorGDBRemote::ServerPacketType, PacketHandler>
54 m_packet_handlers;
55 bool m_exit_now; // use in asynchronous handling to indicate process should
56 // exit.
Greg Clayton576d8832011-03-22 04:00:09 +000057
Pavel Labatha70512a2018-04-11 13:30:54 +000058 bool m_send_error_strings = false; // If the client enables this then
59 // we will send error strings as well.
Ravitheja Addepallydab1d5f2017-07-12 11:15:34 +000060
61 PacketResult Handle_QErrorStringEnable(StringExtractorGDBRemote &packet);
62
63 PacketResult SendErrorResponse(const Status &error);
64
Antonio Afonso57e2da42019-06-10 20:59:58 +000065 PacketResult SendErrorResponse(llvm::Error 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:
Konrad Kleineeaebcbc2020-06-02 12:19:55 -040077 GDBRemoteCommunicationServer(const GDBRemoteCommunicationServer &) = delete;
78 const GDBRemoteCommunicationServer &
79 operator=(const GDBRemoteCommunicationServer &) = delete;
Greg Clayton576d8832011-03-22 04:00:09 +000080};
81
Tamas Berghammerdb264a62015-03-31 09:52:22 +000082} // namespace process_gdb_remote
83} // namespace lldb_private
84
Jonas Devliegherecdc514e2020-02-17 15:57:45 -080085#endif // LLDB_SOURCE_PLUGINS_PROCESS_GDB_REMOTE_GDBREMOTECOMMUNICATIONSERVER_H