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 | b72d0f0 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 40 | GDBRemoteCommunication(const char *comm_name, |
| 41 | const char *listener_name, |
| 42 | bool is_platform); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 43 | |
| 44 | virtual |
| 45 | ~GDBRemoteCommunication(); |
| 46 | |
| 47 | size_t |
| 48 | SendPacket (const char *payload); |
| 49 | |
| 50 | size_t |
| 51 | SendPacket (const char *payload, |
| 52 | size_t payload_length); |
| 53 | |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 54 | size_t |
| 55 | SendPacket (lldb_private::StreamString &response); |
| 56 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 57 | // Wait for a packet within 'nsec' seconds |
| 58 | size_t |
Greg Clayton | 63afdb0 | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 59 | WaitForPacketWithTimeoutMicroSeconds (StringExtractorGDBRemote &response, |
| 60 | uint32_t usec); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 61 | |
| 62 | char |
Greg Clayton | c97bfdb | 2011-03-10 02:26:48 +0000 | [diff] [blame] | 63 | GetAck (); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 64 | |
| 65 | size_t |
Greg Clayton | a4881d0 | 2011-01-22 07:12:45 +0000 | [diff] [blame] | 66 | SendAck (); |
| 67 | |
| 68 | size_t |
| 69 | SendNack (); |
| 70 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 71 | char |
| 72 | CalculcateChecksum (const char *payload, |
| 73 | size_t payload_length); |
| 74 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 75 | bool |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 76 | GetSequenceMutex(lldb_private::Mutex::Locker& locker); |
| 77 | |
Greg Clayton | 63afdb0 | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 78 | bool |
| 79 | CheckForPacket (const uint8_t *src, |
| 80 | size_t src_len, |
| 81 | StringExtractorGDBRemote &packet); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 82 | bool |
| 83 | IsRunning() const |
| 84 | { |
Greg Clayton | cecf348 | 2011-01-20 07:53:45 +0000 | [diff] [blame] | 85 | return m_public_is_running.GetValue(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 86 | } |
Greg Clayton | 72e1c78 | 2011-01-22 23:43:18 +0000 | [diff] [blame] | 87 | |
Greg Clayton | 58e26e0 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 88 | bool |
| 89 | GetSendAcks () |
| 90 | { |
| 91 | return m_send_acks; |
| 92 | } |
| 93 | |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 94 | //------------------------------------------------------------------ |
| 95 | // Client and server must implement these pure virtual functions |
| 96 | //------------------------------------------------------------------ |
| 97 | virtual bool |
| 98 | GetThreadSuffixSupported () = 0; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 99 | |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 100 | //------------------------------------------------------------------ |
| 101 | // Set the global packet timeout. |
| 102 | // |
| 103 | // For clients, this is the timeout that gets used when sending |
| 104 | // packets and waiting for responses. For servers, this might not |
| 105 | // get used, and if it doesn't this should be moved to the |
| 106 | // GDBRemoteCommunicationClient. |
| 107 | //------------------------------------------------------------------ |
Greg Clayton | c97bfdb | 2011-03-10 02:26:48 +0000 | [diff] [blame] | 108 | uint32_t |
| 109 | SetPacketTimeout (uint32_t packet_timeout) |
| 110 | { |
| 111 | const uint32_t old_packet_timeout = m_packet_timeout; |
| 112 | m_packet_timeout = packet_timeout; |
| 113 | return old_packet_timeout; |
| 114 | } |
Greg Clayton | c1f4587 | 2011-02-12 06:28:37 +0000 | [diff] [blame] | 115 | |
Greg Clayton | 63afdb0 | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 116 | uint32_t |
| 117 | GetPacketTimeoutInMicroSeconds () const |
| 118 | { |
| 119 | return m_packet_timeout * USEC_PER_SEC; |
| 120 | } |
Greg Clayton | b72d0f0 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 121 | //------------------------------------------------------------------ |
| 122 | // Start a debugserver instance on the current host using the |
| 123 | // supplied connection URL. |
| 124 | //------------------------------------------------------------------ |
| 125 | lldb_private::Error |
| 126 | StartDebugserverProcess (const char *connect_url, |
| 127 | const char *unix_socket_name, |
| 128 | lldb_private::ProcessLaunchInfo &launch_info); |
| 129 | |
Greg Clayton | 63afdb0 | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 130 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 131 | protected: |
| 132 | typedef std::list<std::string> packet_collection; |
| 133 | |
| 134 | size_t |
| 135 | SendPacketNoLock (const char *payload, |
| 136 | size_t payload_length); |
| 137 | |
| 138 | size_t |
Greg Clayton | 63afdb0 | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 139 | WaitForPacketWithTimeoutMicroSecondsNoLock (StringExtractorGDBRemote &response, |
| 140 | uint32_t timeout_usec); |
Greg Clayton | 72e1c78 | 2011-01-22 23:43:18 +0000 | [diff] [blame] | 141 | |
| 142 | bool |
| 143 | WaitForNotRunningPrivate (const lldb_private::TimeValue *timeout_ptr); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 144 | |
| 145 | //------------------------------------------------------------------ |
| 146 | // Classes that inherit from GDBRemoteCommunication can see and modify these |
| 147 | //------------------------------------------------------------------ |
Greg Clayton | c97bfdb | 2011-03-10 02:26:48 +0000 | [diff] [blame] | 148 | uint32_t m_packet_timeout; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 149 | 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] | 150 | lldb_private::Predicate<bool> m_public_is_running; |
| 151 | lldb_private::Predicate<bool> m_private_is_running; |
Greg Clayton | 58e26e0 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 152 | bool m_send_acks; |
Greg Clayton | b72d0f0 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 153 | bool m_is_platform; // Set to true if this class represents a platform, |
| 154 | // false if this class represents a debug session for |
| 155 | // a single process |
Greg Clayton | 58e26e0 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 156 | |
| 157 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 158 | |
Greg Clayton | b72d0f0 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 159 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 160 | private: |
| 161 | //------------------------------------------------------------------ |
| 162 | // For GDBRemoteCommunication only |
| 163 | //------------------------------------------------------------------ |
| 164 | DISALLOW_COPY_AND_ASSIGN (GDBRemoteCommunication); |
| 165 | }; |
| 166 | |
| 167 | #endif // liblldb_GDBRemoteCommunication_h_ |