Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- GDBRemoteCommunication.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_GDBRemoteCommunication_h_ |
| 11 | #define liblldb_GDBRemoteCommunication_h_ |
| 12 | |
| 13 | // C Includes |
| 14 | // C++ Includes |
| 15 | #include <list> |
| 16 | #include <string> |
| 17 | |
| 18 | // Other libraries and framework includes |
| 19 | // Project includes |
| 20 | #include "lldb/lldb-private.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 21 | #include "lldb/Core/Communication.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 22 | #include "lldb/Core/Listener.h" |
| 23 | #include "lldb/Host/Mutex.h" |
| 24 | #include "lldb/Host/Predicate.h" |
| 25 | |
Greg Clayton | 54e7afa | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 26 | #include "Utility/StringExtractorGDBRemote.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 27 | |
| 28 | class ProcessGDBRemote; |
| 29 | |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 30 | class GDBRemoteCommunication : public lldb_private::Communication |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 31 | { |
| 32 | public: |
Greg Clayton | b749a26 | 2010-12-03 06:02:24 +0000 | [diff] [blame] | 33 | enum |
| 34 | { |
| 35 | eBroadcastBitRunPacketSent = kLoUserBroadcastBit |
| 36 | }; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 37 | //------------------------------------------------------------------ |
| 38 | // Constructors and Destructors |
| 39 | //------------------------------------------------------------------ |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 40 | GDBRemoteCommunication(const char *comm_name, const char *listener_name); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 41 | |
| 42 | virtual |
| 43 | ~GDBRemoteCommunication(); |
| 44 | |
| 45 | size_t |
| 46 | SendPacket (const char *payload); |
| 47 | |
| 48 | size_t |
| 49 | SendPacket (const char *payload, |
| 50 | size_t payload_length); |
| 51 | |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame^] | 52 | size_t |
| 53 | SendPacket (lldb_private::StreamString &response); |
| 54 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 55 | // Wait for a packet within 'nsec' seconds |
| 56 | size_t |
| 57 | WaitForPacket (StringExtractorGDBRemote &response, |
Greg Clayton | c97bfdb | 2011-03-10 02:26:48 +0000 | [diff] [blame] | 58 | uint32_t sec); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 59 | |
| 60 | // Wait for a packet with an absolute timeout time. If 'timeout' is NULL |
| 61 | // wait indefinitely. |
| 62 | size_t |
| 63 | WaitForPacket (StringExtractorGDBRemote &response, |
Greg Clayton | 72e1c78 | 2011-01-22 23:43:18 +0000 | [diff] [blame] | 64 | const lldb_private::TimeValue* timeout); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 65 | |
| 66 | char |
Greg Clayton | c97bfdb | 2011-03-10 02:26:48 +0000 | [diff] [blame] | 67 | GetAck (); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 68 | |
| 69 | size_t |
Greg Clayton | a4881d0 | 2011-01-22 07:12:45 +0000 | [diff] [blame] | 70 | SendAck (); |
| 71 | |
| 72 | size_t |
| 73 | SendNack (); |
| 74 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 75 | char |
| 76 | CalculcateChecksum (const char *payload, |
| 77 | size_t payload_length); |
| 78 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 79 | bool |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 80 | GetSequenceMutex(lldb_private::Mutex::Locker& locker); |
| 81 | |
| 82 | //------------------------------------------------------------------ |
| 83 | // Communication overrides |
| 84 | //------------------------------------------------------------------ |
| 85 | virtual void |
Caroline Tice | c4f55fe | 2010-11-19 20:47:54 +0000 | [diff] [blame] | 86 | AppendBytesToCache (const uint8_t *src, size_t src_len, bool broadcast, lldb::ConnectionStatus status); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 87 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 88 | bool |
| 89 | IsRunning() const |
| 90 | { |
Greg Clayton | cecf348 | 2011-01-20 07:53:45 +0000 | [diff] [blame] | 91 | return m_public_is_running.GetValue(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 92 | } |
Greg Clayton | 72e1c78 | 2011-01-22 23:43:18 +0000 | [diff] [blame] | 93 | |
Greg Clayton | 58e26e0 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 94 | bool |
| 95 | GetSendAcks () |
| 96 | { |
| 97 | return m_send_acks; |
| 98 | } |
| 99 | |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 100 | //------------------------------------------------------------------ |
| 101 | // Client and server must implement these pure virtual functions |
| 102 | //------------------------------------------------------------------ |
| 103 | virtual bool |
| 104 | GetThreadSuffixSupported () = 0; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 105 | |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 106 | //------------------------------------------------------------------ |
| 107 | // Set the global packet timeout. |
| 108 | // |
| 109 | // For clients, this is the timeout that gets used when sending |
| 110 | // packets and waiting for responses. For servers, this might not |
| 111 | // get used, and if it doesn't this should be moved to the |
| 112 | // GDBRemoteCommunicationClient. |
| 113 | //------------------------------------------------------------------ |
Greg Clayton | c97bfdb | 2011-03-10 02:26:48 +0000 | [diff] [blame] | 114 | uint32_t |
| 115 | SetPacketTimeout (uint32_t packet_timeout) |
| 116 | { |
| 117 | const uint32_t old_packet_timeout = m_packet_timeout; |
| 118 | m_packet_timeout = packet_timeout; |
| 119 | return old_packet_timeout; |
| 120 | } |
Greg Clayton | c1f4587 | 2011-02-12 06:28:37 +0000 | [diff] [blame] | 121 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 122 | protected: |
| 123 | typedef std::list<std::string> packet_collection; |
| 124 | |
| 125 | size_t |
| 126 | SendPacketNoLock (const char *payload, |
| 127 | size_t payload_length); |
| 128 | |
| 129 | size_t |
| 130 | WaitForPacketNoLock (StringExtractorGDBRemote &response, |
Greg Clayton | 72e1c78 | 2011-01-22 23:43:18 +0000 | [diff] [blame] | 131 | const lldb_private::TimeValue* timeout_ptr); |
| 132 | |
| 133 | bool |
| 134 | WaitForNotRunningPrivate (const lldb_private::TimeValue *timeout_ptr); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 135 | |
| 136 | //------------------------------------------------------------------ |
| 137 | // Classes that inherit from GDBRemoteCommunication can see and modify these |
| 138 | //------------------------------------------------------------------ |
Greg Clayton | c97bfdb | 2011-03-10 02:26:48 +0000 | [diff] [blame] | 139 | uint32_t m_packet_timeout; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 140 | lldb_private::Listener m_rx_packet_listener; |
| 141 | lldb_private::Mutex m_sequence_mutex; // Restrict access to sending/receiving packets to a single thread at a time |
Greg Clayton | cecf348 | 2011-01-20 07:53:45 +0000 | [diff] [blame] | 142 | lldb_private::Predicate<bool> m_public_is_running; |
| 143 | lldb_private::Predicate<bool> m_private_is_running; |
Greg Clayton | 58e26e0 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 144 | bool m_send_acks; |
| 145 | |
| 146 | |
| 147 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 148 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 149 | private: |
| 150 | //------------------------------------------------------------------ |
| 151 | // For GDBRemoteCommunication only |
| 152 | //------------------------------------------------------------------ |
| 153 | DISALLOW_COPY_AND_ASSIGN (GDBRemoteCommunication); |
| 154 | }; |
| 155 | |
| 156 | #endif // liblldb_GDBRemoteCommunication_h_ |