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 |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 20 | #include "lldb/lldb-private-forward.h" |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 21 | #include "GDBRemoteCommunication.h" |
| 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 | |
| 30 | class GDBRemoteCommunicationServer : public GDBRemoteCommunication |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 31 | { |
| 32 | public: |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 33 | using PortMap = std::map<uint16_t, lldb::pid_t>; |
| 34 | using PacketHandler = std::function<PacketResult(StringExtractorGDBRemote &packet, |
Tamas Berghammer | db264a6 | 2015-03-31 09:52:22 +0000 | [diff] [blame] | 35 | Error &error, |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 36 | bool &interrupt, |
| 37 | bool &quit)>; |
Greg Clayton | 29b8fc4 | 2013-11-21 01:44:58 +0000 | [diff] [blame] | 38 | |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 39 | GDBRemoteCommunicationServer(const char *comm_name, |
| 40 | const char *listener_name); |
Todd Fiala | b8b49ec | 2014-01-28 00:34:23 +0000 | [diff] [blame] | 41 | |
Eugene Zelenko | edb35d9 | 2015-10-24 01:08:35 +0000 | [diff] [blame^] | 42 | ~GDBRemoteCommunicationServer() override; |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 43 | |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 44 | void RegisterPacketHandler(StringExtractorGDBRemote::ServerPacketType packet_type, |
| 45 | PacketHandler handler); |
| 46 | |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 47 | PacketResult |
Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 48 | GetPacketAndSendResponse (uint32_t timeout_usec, |
Tamas Berghammer | db264a6 | 2015-03-31 09:52:22 +0000 | [diff] [blame] | 49 | Error &error, |
Greg Clayton | d314e81 | 2011-03-23 00:09:55 +0000 | [diff] [blame] | 50 | bool &interrupt, |
| 51 | bool &quit); |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 52 | |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 53 | // After connecting, do a little handshake with the client to make sure |
| 54 | // we are at least communicating |
| 55 | bool |
Pavel Labath | 77dc956 | 2015-07-13 10:44:55 +0000 | [diff] [blame] | 56 | HandshakeWithClient (); |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 57 | |
| 58 | protected: |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 59 | std::map<StringExtractorGDBRemote::ServerPacketType, PacketHandler> m_packet_handlers; |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 60 | bool m_exit_now; // use in asynchronous handling to indicate process should exit. |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 61 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 62 | PacketResult |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 63 | SendUnimplementedResponse (const char *packet); |
| 64 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 65 | PacketResult |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 66 | SendErrorResponse (uint8_t error); |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 67 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 68 | PacketResult |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 69 | SendIllFormedResponse (const StringExtractorGDBRemote &packet, const char *error_message); |
| 70 | |
| 71 | PacketResult |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 72 | SendOKResponse (); |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 73 | |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 74 | private: |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 75 | DISALLOW_COPY_AND_ASSIGN (GDBRemoteCommunicationServer); |
| 76 | }; |
| 77 | |
Tamas Berghammer | db264a6 | 2015-03-31 09:52:22 +0000 | [diff] [blame] | 78 | } // namespace process_gdb_remote |
| 79 | } // namespace lldb_private |
| 80 | |
Eugene Zelenko | edb35d9 | 2015-10-24 01:08:35 +0000 | [diff] [blame^] | 81 | #endif // liblldb_GDBRemoteCommunicationServer_h_ |