Greg Clayton | 269f91e | 2011-07-15 18:02:58 +0000 | [diff] [blame^] | 1 | //===-- CommunicationKDP.h --------------------------------------*- C++ -*-===// |
Greg Clayton | 363be3f | 2011-07-15 03:27:12 +0000 | [diff] [blame] | 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_CommunicationKDP_h_ |
| 11 | #define liblldb_CommunicationKDP_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" |
| 21 | #include "lldb/Core/Communication.h" |
| 22 | #include "lldb/Core/Listener.h" |
| 23 | #include "lldb/Host/Mutex.h" |
| 24 | #include "lldb/Host/Predicate.h" |
| 25 | #include "lldb/Host/TimeValue.h" |
| 26 | |
| 27 | class StringExtractor; |
| 28 | |
| 29 | class CommunicationKDP : public lldb_private::Communication |
| 30 | { |
| 31 | public: |
| 32 | enum |
| 33 | { |
| 34 | eBroadcastBitRunPacketSent = kLoUserBroadcastBit |
| 35 | }; |
Greg Clayton | 1e5b021 | 2011-07-15 16:31:38 +0000 | [diff] [blame] | 36 | |
| 37 | const static uint32_t kMaxPacketSize = 1200; |
| 38 | const static uint32_t kMaxDataSize = 1024; |
| 39 | |
| 40 | typedef enum |
| 41 | { |
| 42 | eRequestTypeConnect = 0u, |
| 43 | eRequestTypeDisconnect, |
| 44 | eRequestTypeHostInfo, |
| 45 | eRequestTypeVersion, |
| 46 | eRequestTypeMaxBytes, |
| 47 | eRequestTypeReadMemory, |
| 48 | eRequestTypeWriteMemory, |
| 49 | eRequestTypeReadRegisters, |
| 50 | eRequestTypeWriteRegisters, |
| 51 | eRequestTypeLoad, |
| 52 | eRequestTypeImagePath, |
| 53 | eRequestTypeSuspend, |
| 54 | eRequestTypeResume, |
| 55 | eRequestTypeException, |
| 56 | eRequestTypeTermination, |
| 57 | eRequestTypeBreakpointSet, |
| 58 | eRequestTypeBreakpointRemove, |
| 59 | eRequestTypeRegions, |
| 60 | eRequestTypeReattach, |
| 61 | eRequestTypeHostReboot, |
| 62 | eRequestTypeReadMemory64, |
| 63 | eRequestTypeWriteMemory64, |
| 64 | eRequestTypeBreakpointSet64, |
| 65 | eRequestTypeBreakpointRemove64, |
| 66 | eRequestTypeKernelVersion |
| 67 | } RequestType; |
| 68 | |
| 69 | typedef enum |
| 70 | { |
| 71 | eErrorSuccess = 0, |
| 72 | eErrorAlreadyConnected, |
| 73 | eErrorPacketToBig, |
| 74 | eErrorInvalidRegisterFlavor, |
| 75 | eErrorUnimplemented |
| 76 | } ErrorType; |
| 77 | |
| 78 | typedef enum |
| 79 | { |
| 80 | ePacketTypeRequest = 0u, |
| 81 | ePacketTypeReply = 1u |
| 82 | } PacketType; |
Greg Clayton | 363be3f | 2011-07-15 03:27:12 +0000 | [diff] [blame] | 83 | //------------------------------------------------------------------ |
| 84 | // Constructors and Destructors |
| 85 | //------------------------------------------------------------------ |
| 86 | CommunicationKDP (const char *comm_name); |
| 87 | |
| 88 | virtual |
| 89 | ~CommunicationKDP(); |
| 90 | |
Greg Clayton | 1e5b021 | 2011-07-15 16:31:38 +0000 | [diff] [blame] | 91 | bool |
| 92 | SendRequestPacket (const lldb_private::StreamString &request_packet); |
Greg Clayton | 363be3f | 2011-07-15 03:27:12 +0000 | [diff] [blame] | 93 | |
| 94 | // Wait for a packet within 'nsec' seconds |
| 95 | size_t |
| 96 | WaitForPacketWithTimeoutMicroSeconds (StringExtractor &response, |
| 97 | uint32_t usec); |
| 98 | |
Greg Clayton | 363be3f | 2011-07-15 03:27:12 +0000 | [diff] [blame] | 99 | bool |
| 100 | GetSequenceMutex(lldb_private::Mutex::Locker& locker); |
| 101 | |
| 102 | bool |
| 103 | CheckForPacket (const uint8_t *src, |
| 104 | size_t src_len, |
| 105 | StringExtractor &packet); |
| 106 | bool |
| 107 | IsRunning() const |
| 108 | { |
| 109 | return m_public_is_running.GetValue(); |
| 110 | } |
| 111 | |
Greg Clayton | 363be3f | 2011-07-15 03:27:12 +0000 | [diff] [blame] | 112 | //------------------------------------------------------------------ |
| 113 | // Set the global packet timeout. |
| 114 | // |
| 115 | // For clients, this is the timeout that gets used when sending |
| 116 | // packets and waiting for responses. For servers, this might not |
| 117 | // get used, and if it doesn't this should be moved to the |
| 118 | // CommunicationKDPClient. |
| 119 | //------------------------------------------------------------------ |
| 120 | uint32_t |
| 121 | SetPacketTimeout (uint32_t packet_timeout) |
| 122 | { |
| 123 | const uint32_t old_packet_timeout = m_packet_timeout; |
| 124 | m_packet_timeout = packet_timeout; |
| 125 | return old_packet_timeout; |
| 126 | } |
| 127 | |
| 128 | uint32_t |
| 129 | GetPacketTimeoutInMicroSeconds () const |
| 130 | { |
| 131 | return m_packet_timeout * lldb_private::TimeValue::MicroSecPerSec; |
| 132 | } |
| 133 | //------------------------------------------------------------------ |
| 134 | // Start a debugserver instance on the current host using the |
| 135 | // supplied connection URL. |
| 136 | //------------------------------------------------------------------ |
| 137 | lldb_private::Error |
| 138 | StartDebugserverProcess (const char *connect_url, |
| 139 | const char *unix_socket_name, |
| 140 | lldb_private::ProcessLaunchInfo &launch_info); |
| 141 | |
| 142 | |
Greg Clayton | 1e5b021 | 2011-07-15 16:31:38 +0000 | [diff] [blame] | 143 | ErrorType |
| 144 | Connect (uint16_t reply_port, |
| 145 | uint16_t exc_port, |
| 146 | const char *greeting); |
| 147 | |
| 148 | ErrorType |
| 149 | Disconnect (); |
| 150 | |
Greg Clayton | 363be3f | 2011-07-15 03:27:12 +0000 | [diff] [blame] | 151 | protected: |
| 152 | typedef std::list<std::string> packet_collection; |
| 153 | |
Greg Clayton | 1e5b021 | 2011-07-15 16:31:38 +0000 | [diff] [blame] | 154 | bool |
| 155 | SendRequestPacketNoLock (const lldb_private::StreamString &request_packet); |
Greg Clayton | 363be3f | 2011-07-15 03:27:12 +0000 | [diff] [blame] | 156 | |
| 157 | size_t |
| 158 | WaitForPacketWithTimeoutMicroSecondsNoLock (StringExtractor &response, |
| 159 | uint32_t timeout_usec); |
| 160 | |
| 161 | bool |
| 162 | WaitForNotRunningPrivate (const lldb_private::TimeValue *timeout_ptr); |
| 163 | |
Greg Clayton | 1e5b021 | 2011-07-15 16:31:38 +0000 | [diff] [blame] | 164 | void |
| 165 | MakeRequestPacketHeader (RequestType request_type, |
| 166 | lldb_private::StreamString &request_packet); |
| 167 | |
Greg Clayton | 363be3f | 2011-07-15 03:27:12 +0000 | [diff] [blame] | 168 | //------------------------------------------------------------------ |
| 169 | // Classes that inherit from CommunicationKDP can see and modify these |
| 170 | //------------------------------------------------------------------ |
| 171 | uint32_t m_packet_timeout; |
| 172 | lldb_private::Mutex m_sequence_mutex; // Restrict access to sending/receiving packets to a single thread at a time |
| 173 | lldb_private::Predicate<bool> m_public_is_running; |
| 174 | lldb_private::Predicate<bool> m_private_is_running; |
Greg Clayton | 1e5b021 | 2011-07-15 16:31:38 +0000 | [diff] [blame] | 175 | uint32_t m_session_key; |
| 176 | uint8_t m_request_sequence_id; |
| 177 | uint8_t m_exception_sequence_id; |
Greg Clayton | 363be3f | 2011-07-15 03:27:12 +0000 | [diff] [blame] | 178 | private: |
| 179 | //------------------------------------------------------------------ |
| 180 | // For CommunicationKDP only |
| 181 | //------------------------------------------------------------------ |
| 182 | DISALLOW_COPY_AND_ASSIGN (CommunicationKDP); |
| 183 | }; |
| 184 | |
| 185 | #endif // liblldb_CommunicationKDP_h_ |