LLDB  mainline
GDBRemoteCommunicationServer.h
Go to the documentation of this file.
1 //===-- GDBRemoteCommunicationServer.h --------------------------*- C++ -*-===//
2 //
3 // 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
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLDB_SOURCE_PLUGINS_PROCESS_GDB_REMOTE_GDBREMOTECOMMUNICATIONSERVER_H
10 #define LLDB_SOURCE_PLUGINS_PROCESS_GDB_REMOTE_GDBREMOTECOMMUNICATIONSERVER_H
11 
12 #include <functional>
13 #include <map>
14 
15 #include "GDBRemoteCommunication.h"
17 
18 #include "llvm/Support/Errc.h"
19 #include "llvm/Support/Error.h"
20 
22 
23 namespace lldb_private {
24 namespace process_gdb_remote {
25 
26 class ProcessGDBRemote;
27 
29 public:
30  using PortMap = std::map<uint16_t, lldb::pid_t>;
31  using PacketHandler =
32  std::function<PacketResult(StringExtractorGDBRemote &packet,
33  Status &error, bool &interrupt, bool &quit)>;
34 
35  GDBRemoteCommunicationServer(const char *comm_name,
36  const char *listener_name);
37 
39 
40  void
42  PacketHandler handler);
43 
45  Status &error, bool &interrupt,
46  bool &quit);
47 
48  // After connecting, do a little handshake with the client to make sure
49  // we are at least communicating
50  bool HandshakeWithClient();
51 
52 protected:
53  std::map<StringExtractorGDBRemote::ServerPacketType, PacketHandler>
55  bool m_exit_now; // use in asynchronous handling to indicate process should
56  // exit.
57 
58  bool m_send_error_strings = false; // If the client enables this then
59  // we will send error strings as well.
60 
62 
64 
66 
67  PacketResult SendUnimplementedResponse(const char *packet);
68 
70 
72  const char *error_message);
73 
75 
76 private:
79  operator=(const GDBRemoteCommunicationServer &) = delete;
80 };
81 
83  : public llvm::ErrorInfo<PacketUnimplementedError, llvm::StringError> {
84 public:
85  static char ID;
86  using llvm::ErrorInfo<PacketUnimplementedError,
87  llvm::StringError>::ErrorInfo; // inherit constructors
88  PacketUnimplementedError(const llvm::Twine &S)
89  : ErrorInfo(S, llvm::errc::not_supported) {}
90 
91  PacketUnimplementedError() : ErrorInfo(llvm::errc::not_supported) {}
92 };
93 
94 } // namespace process_gdb_remote
95 } // namespace lldb_private
96 
97 #endif // LLDB_SOURCE_PLUGINS_PROCESS_GDB_REMOTE_GDBREMOTECOMMUNICATIONSERVER_H
A class that represents a running process on the host machine.
Definition: Debugger.h:49
GDBRemoteCommunicationServer(const char *comm_name, const char *listener_name)
llvm::Error Error
std::map< StringExtractorGDBRemote::ServerPacketType, PacketHandler > m_packet_handlers
PacketResult SendIllFormedResponse(const StringExtractorGDBRemote &packet, const char *error_message)
static llvm::raw_ostream & error(Stream &strm)
void RegisterPacketHandler(StringExtractorGDBRemote::ServerPacketType packet_type, PacketHandler handler)
const GDBRemoteCommunicationServer & operator=(const GDBRemoteCommunicationServer &)=delete
PacketResult Handle_QErrorStringEnable(StringExtractorGDBRemote &packet)
PacketResult GetPacketAndSendResponse(Timeout< std::micro > timeout, Status &error, bool &interrupt, bool &quit)
std::function< PacketResult(StringExtractorGDBRemote &packet, Status &error, bool &interrupt, bool &quit)> PacketHandler
An error handling class.
Definition: Status.h:44