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" 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 #include "Utility/StringExtractorGDBRemote.h" 28 29 class ProcessGDBRemote; 30 31 class GDBRemoteCommunication : public lldb_private::Communication 32 { 33 public: 34 enum 35 { 36 eBroadcastBitRunPacketSent = kLoUserBroadcastBit 37 }; 38 //------------------------------------------------------------------ 39 // Constructors and Destructors 40 //------------------------------------------------------------------ 41 GDBRemoteCommunication(const char *comm_name, 42 const char *listener_name, 43 bool is_platform); 44 45 virtual 46 ~GDBRemoteCommunication(); 47 48 size_t 49 SendPacket (const char *payload); 50 51 size_t 52 SendPacket (const char *payload, 53 size_t payload_length); 54 55 size_t 56 SendPacket (lldb_private::StreamString &response); 57 58 // Wait for a packet within 'nsec' seconds 59 size_t 60 WaitForPacketWithTimeoutMicroSeconds (StringExtractorGDBRemote &response, 61 uint32_t usec); 62 63 char 64 GetAck (); 65 66 size_t 67 SendAck (); 68 69 size_t 70 SendNack (); 71 72 char 73 CalculcateChecksum (const char *payload, 74 size_t payload_length); 75 76 bool 77 GetSequenceMutex(lldb_private::Mutex::Locker& locker); 78 79 bool 80 CheckForPacket (const uint8_t *src, 81 size_t src_len, 82 StringExtractorGDBRemote &packet); 83 bool 84 IsRunning() const 85 { 86 return m_public_is_running.GetValue(); 87 } 88 89 bool 90 GetSendAcks () 91 { 92 return m_send_acks; 93 } 94 95 //------------------------------------------------------------------ 96 // Client and server must implement these pure virtual functions 97 //------------------------------------------------------------------ 98 virtual bool 99 GetThreadSuffixSupported () = 0; 100 101 //------------------------------------------------------------------ 102 // Set the global packet timeout. 103 // 104 // For clients, this is the timeout that gets used when sending 105 // packets and waiting for responses. For servers, this might not 106 // get used, and if it doesn't this should be moved to the 107 // GDBRemoteCommunicationClient. 108 //------------------------------------------------------------------ 109 uint32_t 110 SetPacketTimeout (uint32_t packet_timeout) 111 { 112 const uint32_t old_packet_timeout = m_packet_timeout; 113 m_packet_timeout = packet_timeout; 114 return old_packet_timeout; 115 } 116 117 uint32_t 118 GetPacketTimeoutInMicroSeconds () const 119 { 120 return m_packet_timeout * lldb_private::TimeValue::MicroSecPerSec; 121 } 122 //------------------------------------------------------------------ 123 // Start a debugserver instance on the current host using the 124 // supplied connection URL. 125 //------------------------------------------------------------------ 126 lldb_private::Error 127 StartDebugserverProcess (const char *connect_url, 128 const char *unix_socket_name, 129 lldb_private::ProcessLaunchInfo &launch_info); 130 131 132 protected: 133 typedef std::list<std::string> packet_collection; 134 135 size_t 136 SendPacketNoLock (const char *payload, 137 size_t payload_length); 138 139 size_t 140 WaitForPacketWithTimeoutMicroSecondsNoLock (StringExtractorGDBRemote &response, 141 uint32_t timeout_usec); 142 143 bool 144 WaitForNotRunningPrivate (const lldb_private::TimeValue *timeout_ptr); 145 146 //------------------------------------------------------------------ 147 // Classes that inherit from GDBRemoteCommunication can see and modify these 148 //------------------------------------------------------------------ 149 uint32_t m_packet_timeout; 150 lldb_private::Mutex m_sequence_mutex; // Restrict access to sending/receiving packets to a single thread at a time 151 lldb_private::Predicate<bool> m_public_is_running; 152 lldb_private::Predicate<bool> m_private_is_running; 153 bool m_send_acks; 154 bool m_is_platform; // Set to true if this class represents a platform, 155 // false if this class represents a debug session for 156 // a single process 157 158 159 160 161 private: 162 //------------------------------------------------------------------ 163 // For GDBRemoteCommunication only 164 //------------------------------------------------------------------ 165 DISALLOW_COPY_AND_ASSIGN (GDBRemoteCommunication); 166 }; 167 168 #endif // liblldb_GDBRemoteCommunication_h_ 169