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