Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 1 | //===-- 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 | |
| 13 | // C Includes |
| 14 | // C++ Includes |
Tamas Berghammer | cb527a7 | 2015-02-11 12:52:55 +0000 | [diff] [blame] | 15 | #include <functional> |
| 16 | #include <map> |
| 17 | |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 18 | // Other libraries and framework includes |
| 19 | // Project includes |
| 20 | #include "GDBRemoteCommunication.h" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 21 | #include "lldb/lldb-private-forward.h" |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 22 | |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 23 | class StringExtractorGDBRemote; |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 24 | |
Tamas Berghammer | db264a6 | 2015-03-31 09:52:22 +0000 | [diff] [blame] | 25 | namespace lldb_private { |
| 26 | namespace process_gdb_remote { |
| 27 | |
| 28 | class ProcessGDBRemote; |
| 29 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 30 | class GDBRemoteCommunicationServer : public GDBRemoteCommunication { |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 31 | public: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 32 | using PortMap = std::map<uint16_t, lldb::pid_t>; |
| 33 | using PacketHandler = |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 34 | std::function<PacketResult(StringExtractorGDBRemote &packet, |
| 35 | Status &error, bool &interrupt, bool &quit)>; |
Greg Clayton | 29b8fc4 | 2013-11-21 01:44:58 +0000 | [diff] [blame] | 36 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 37 | GDBRemoteCommunicationServer(const char *comm_name, |
| 38 | const char *listener_name); |
Todd Fiala | b8b49ec | 2014-01-28 00:34:23 +0000 | [diff] [blame] | 39 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 40 | ~GDBRemoteCommunicationServer() override; |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 41 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 42 | void |
| 43 | RegisterPacketHandler(StringExtractorGDBRemote::ServerPacketType packet_type, |
| 44 | PacketHandler handler); |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 45 | |
Pavel Labath | 1eff73c | 2016-11-24 10:54:49 +0000 | [diff] [blame] | 46 | PacketResult GetPacketAndSendResponse(Timeout<std::micro> timeout, |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 47 | Status &error, bool &interrupt, |
Pavel Labath | 1eff73c | 2016-11-24 10:54:49 +0000 | [diff] [blame] | 48 | bool &quit); |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 49 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 50 | // After connecting, do a little handshake with the client to make sure |
| 51 | // we are at least communicating |
| 52 | bool HandshakeWithClient(); |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 53 | |
| 54 | protected: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 55 | std::map<StringExtractorGDBRemote::ServerPacketType, PacketHandler> |
| 56 | m_packet_handlers; |
| 57 | bool m_exit_now; // use in asynchronous handling to indicate process should |
| 58 | // exit. |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 59 | |
Pavel Labath | a70512a | 2018-04-11 13:30:54 +0000 | [diff] [blame] | 60 | bool m_send_error_strings = false; // If the client enables this then |
| 61 | // we will send error strings as well. |
Ravitheja Addepally | dab1d5f | 2017-07-12 11:15:34 +0000 | [diff] [blame] | 62 | |
| 63 | PacketResult Handle_QErrorStringEnable(StringExtractorGDBRemote &packet); |
| 64 | |
| 65 | PacketResult SendErrorResponse(const Status &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: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 77 | DISALLOW_COPY_AND_ASSIGN(GDBRemoteCommunicationServer); |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 78 | }; |
| 79 | |
Tamas Berghammer | db264a6 | 2015-03-31 09:52:22 +0000 | [diff] [blame] | 80 | } // namespace process_gdb_remote |
| 81 | } // namespace lldb_private |
| 82 | |
Eugene Zelenko | edb35d9 | 2015-10-24 01:08:35 +0000 | [diff] [blame] | 83 | #endif // liblldb_GDBRemoteCommunicationServer_h_ |