1 //===-- GDBRemoteCommunication.h --------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_GDBRemoteCommunication_h_
11 #define liblldb_GDBRemoteCommunication_h_
18 // Other libraries and framework includes
20 #include "lldb/lldb-public.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"
27 #include "Utility/StringExtractorGDBRemote.h"
29 class ProcessGDBRemote;
31 class GDBRemoteCommunication : public lldb_private::Communication
36 eBroadcastBitRunPacketSent = kLoUserBroadcastBit
38 //------------------------------------------------------------------
39 // Constructors and Destructors
40 //------------------------------------------------------------------
41 GDBRemoteCommunication(const char *comm_name,
42 const char *listener_name,
46 ~GDBRemoteCommunication();
58 CalculcateChecksum (const char *payload,
59 size_t payload_length);
62 GetSequenceMutex (lldb_private::Mutex::Locker& locker, const char *failure_message = NULL);
65 CheckForPacket (const uint8_t *src,
67 StringExtractorGDBRemote &packet);
71 return m_public_is_running.GetValue();
80 //------------------------------------------------------------------
81 // Client and server must implement these pure virtual functions
82 //------------------------------------------------------------------
84 GetThreadSuffixSupported () = 0;
86 //------------------------------------------------------------------
87 // Set the global packet timeout.
89 // For clients, this is the timeout that gets used when sending
90 // packets and waiting for responses. For servers, this might not
91 // get used, and if it doesn't this should be moved to the
92 // GDBRemoteCommunicationClient.
93 //------------------------------------------------------------------
95 SetPacketTimeout (uint32_t packet_timeout)
97 const uint32_t old_packet_timeout = m_packet_timeout;
98 m_packet_timeout = packet_timeout;
99 return old_packet_timeout;
103 GetPacketTimeoutInMicroSeconds () const
105 return m_packet_timeout * lldb_private::TimeValue::MicroSecPerSec;
107 //------------------------------------------------------------------
108 // Start a debugserver instance on the current host using the
109 // supplied connection URL.
110 //------------------------------------------------------------------
112 StartDebugserverProcess (const char *connect_url,
113 const char *unix_socket_name,
114 lldb_private::ProcessLaunchInfo &launch_info);
117 DumpHistory(lldb_private::Stream &strm);
126 ePacketTypeInvalid = 0,
135 type (ePacketTypeInvalid),
136 bytes_transmitted (0),
138 tid (LLDB_INVALID_THREAD_ID)
146 type = ePacketTypeInvalid;
147 bytes_transmitted = 0;
149 tid = LLDB_INVALID_THREAD_ID;
153 uint32_t bytes_transmitted;
158 History (uint32_t size);
162 // For single char packets for ack, nack and /x03
164 AddPacket (char packet_char,
166 uint32_t bytes_transmitted);
168 AddPacket (const std::string &src,
171 uint32_t bytes_transmitted);
174 Dump (lldb_private::Stream &strm) const;
177 Dump (lldb_private::Log *log) const;
180 DidDumpToLog () const
182 return m_dumped_to_log;
187 GetFirstSavedPacketIndex () const
189 if (m_total_packet_count < m_packets.size())
192 return m_curr_idx + 1;
196 GetNumPacketsInHistory () const
198 if (m_total_packet_count < m_packets.size())
199 return m_total_packet_count;
201 return (uint32_t)m_packets.size();
207 ++m_total_packet_count;
208 const uint32_t idx = m_curr_idx;
209 m_curr_idx = NormalizeIndex(idx + 1);
214 NormalizeIndex (uint32_t i) const
216 return i % m_packets.size();
220 std::vector<Entry> m_packets;
222 uint32_t m_total_packet_count;
223 mutable bool m_dumped_to_log;
227 SendPacket (const char *payload,
228 size_t payload_length);
231 SendPacketNoLock (const char *payload,
232 size_t payload_length);
235 WaitForPacketWithTimeoutMicroSecondsNoLock (StringExtractorGDBRemote &response,
236 uint32_t timeout_usec);
239 WaitForNotRunningPrivate (const lldb_private::TimeValue *timeout_ptr);
241 //------------------------------------------------------------------
242 // Classes that inherit from GDBRemoteCommunication can see and modify these
243 //------------------------------------------------------------------
244 uint32_t m_packet_timeout;
245 #ifdef LLDB_CONFIGURATION_DEBUG
246 lldb_private::TrackingMutex m_sequence_mutex;
248 lldb_private::Mutex m_sequence_mutex; // Restrict access to sending/receiving packets to a single thread at a time
250 lldb_private::Predicate<bool> m_public_is_running;
251 lldb_private::Predicate<bool> m_private_is_running;
254 bool m_is_platform; // Set to true if this class represents a platform,
255 // false if this class represents a debug session for
262 //------------------------------------------------------------------
263 // For GDBRemoteCommunication only
264 //------------------------------------------------------------------
265 DISALLOW_COPY_AND_ASSIGN (GDBRemoteCommunication);
268 #endif // liblldb_GDBRemoteCommunication_h_