Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 1 | //===-- GDBRemoteCommunicationServer.h --------------------------*- C++ -*-===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 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 |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
Jonas Devlieghere | cdc514e | 2020-02-17 15:57:45 -0800 | [diff] [blame] | 9 | #ifndef LLDB_SOURCE_PLUGINS_PROCESS_GDB_REMOTE_GDBREMOTECOMMUNICATIONSERVER_H |
| 10 | #define LLDB_SOURCE_PLUGINS_PROCESS_GDB_REMOTE_GDBREMOTECOMMUNICATIONSERVER_H |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 11 | |
Tamas Berghammer | cb527a7 | 2015-02-11 12:52:55 +0000 | [diff] [blame] | 12 | #include <functional> |
| 13 | #include <map> |
| 14 | |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 15 | #include "GDBRemoteCommunication.h" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 16 | #include "lldb/lldb-private-forward.h" |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 17 | |
Antonio Afonso | 57e2da4 | 2019-06-10 20:59:58 +0000 | [diff] [blame] | 18 | #include "llvm/Support/Errc.h" |
| 19 | #include "llvm/Support/Error.h" |
| 20 | |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 21 | class StringExtractorGDBRemote; |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 22 | |
Tamas Berghammer | db264a6 | 2015-03-31 09:52:22 +0000 | [diff] [blame] | 23 | namespace lldb_private { |
| 24 | namespace process_gdb_remote { |
| 25 | |
| 26 | class ProcessGDBRemote; |
| 27 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 28 | class GDBRemoteCommunicationServer : public GDBRemoteCommunication { |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 29 | public: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 30 | using PortMap = std::map<uint16_t, lldb::pid_t>; |
| 31 | using PacketHandler = |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 32 | std::function<PacketResult(StringExtractorGDBRemote &packet, |
| 33 | Status &error, bool &interrupt, bool &quit)>; |
Greg Clayton | 29b8fc4 | 2013-11-21 01:44:58 +0000 | [diff] [blame] | 34 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 35 | GDBRemoteCommunicationServer(const char *comm_name, |
| 36 | const char *listener_name); |
Todd Fiala | b8b49ec | 2014-01-28 00:34:23 +0000 | [diff] [blame] | 37 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 38 | ~GDBRemoteCommunicationServer() override; |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 39 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 40 | void |
| 41 | RegisterPacketHandler(StringExtractorGDBRemote::ServerPacketType packet_type, |
| 42 | PacketHandler handler); |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 43 | |
Pavel Labath | 1eff73c | 2016-11-24 10:54:49 +0000 | [diff] [blame] | 44 | PacketResult GetPacketAndSendResponse(Timeout<std::micro> timeout, |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 45 | Status &error, bool &interrupt, |
Pavel Labath | 1eff73c | 2016-11-24 10:54:49 +0000 | [diff] [blame] | 46 | bool &quit); |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 47 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 48 | // After connecting, do a little handshake with the client to make sure |
| 49 | // we are at least communicating |
| 50 | bool HandshakeWithClient(); |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 51 | |
| 52 | protected: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 53 | 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 Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 57 | |
Pavel Labath | a70512a | 2018-04-11 13:30:54 +0000 | [diff] [blame] | 58 | bool m_send_error_strings = false; // If the client enables this then |
| 59 | // we will send error strings as well. |
Ravitheja Addepally | dab1d5f | 2017-07-12 11:15:34 +0000 | [diff] [blame] | 60 | |
| 61 | PacketResult Handle_QErrorStringEnable(StringExtractorGDBRemote &packet); |
| 62 | |
| 63 | PacketResult SendErrorResponse(const Status &error); |
| 64 | |
Antonio Afonso | 57e2da4 | 2019-06-10 20:59:58 +0000 | [diff] [blame] | 65 | PacketResult SendErrorResponse(llvm::Error error); |
| 66 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 67 | PacketResult SendUnimplementedResponse(const char *packet); |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 68 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 69 | PacketResult SendErrorResponse(uint8_t error); |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 70 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 71 | PacketResult SendIllFormedResponse(const StringExtractorGDBRemote &packet, |
| 72 | const char *error_message); |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 73 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 74 | PacketResult SendOKResponse(); |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 75 | |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 76 | private: |
Konrad Kleine | eaebcbc | 2020-06-02 12:19:55 -0400 | [diff] [blame] | 77 | GDBRemoteCommunicationServer(const GDBRemoteCommunicationServer &) = delete; |
| 78 | const GDBRemoteCommunicationServer & |
| 79 | operator=(const GDBRemoteCommunicationServer &) = delete; |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 80 | }; |
| 81 | |
Tamas Berghammer | db264a6 | 2015-03-31 09:52:22 +0000 | [diff] [blame] | 82 | } // namespace process_gdb_remote |
| 83 | } // namespace lldb_private |
| 84 | |
Jonas Devlieghere | cdc514e | 2020-02-17 15:57:45 -0800 | [diff] [blame] | 85 | #endif // LLDB_SOURCE_PLUGINS_PROCESS_GDB_REMOTE_GDBREMOTECOMMUNICATIONSERVER_H |