blob: bd87521fe6e7525e73d69259915b2276053c34a6 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- GDBRemoteCommunication.cpp ------------------------------*- 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
Chris Lattner30fdc8d2010-06-08 16:52:24 +000010#include "GDBRemoteCommunication.h"
11
12// C Includes
Johnny Chena5663552011-05-13 20:07:25 +000013#include <limits.h>
Stephen Wilsona78867b2011-03-25 18:16:28 +000014#include <string.h>
Greg Clayton91a9b2472013-12-04 19:19:12 +000015#include <sys/stat.h>
Stephen Wilsona78867b2011-03-25 18:16:28 +000016
Chris Lattner30fdc8d2010-06-08 16:52:24 +000017// C++ Includes
18// Other libraries and framework includes
Chris Lattner30fdc8d2010-06-08 16:52:24 +000019#include "lldb/Core/Log.h"
Greg Claytonb30c50c2015-05-29 00:01:55 +000020#include "lldb/Core/RegularExpression.h"
Greg Claytonc1422c12012-04-09 22:46:21 +000021#include "lldb/Core/StreamFile.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000022#include "lldb/Core/StreamString.h"
Zachary Turner93a66fc2014-10-06 21:22:36 +000023#include "lldb/Host/ConnectionFileDescriptor.h"
Greg Clayton8b82f082011-04-12 05:54:46 +000024#include "lldb/Host/FileSpec.h"
25#include "lldb/Host/Host.h"
Zachary Turner42ff0ad2014-08-21 17:29:12 +000026#include "lldb/Host/HostInfo.h"
Oleksiy Vyalovd5f8b6a2015-01-13 23:19:40 +000027#include "lldb/Host/Pipe.h"
Zachary Turner98688922014-08-06 18:16:26 +000028#include "lldb/Host/Socket.h"
Vince Harron5275aaa2015-01-15 20:08:35 +000029#include "lldb/Host/StringConvert.h"
Zachary Turner39de3112014-09-09 20:54:56 +000030#include "lldb/Host/ThreadLauncher.h"
Greg Clayton6988abc2015-10-19 20:44:01 +000031#include "lldb/Target/Platform.h"
Greg Clayton8b82f082011-04-12 05:54:46 +000032#include "lldb/Target/Process.h"
Oleksiy Vyalov4536c452015-02-05 16:29:12 +000033#include "llvm/ADT/SmallString.h"
Pavel Labath1eb0d422016-08-08 12:54:36 +000034#include "llvm/Support/ScopedPrinter.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000035
36// Project includes
Chris Lattner30fdc8d2010-06-08 16:52:24 +000037#include "ProcessGDBRemoteLog.h"
38
Todd Fiala015d8182014-07-22 23:41:36 +000039#if defined(__APPLE__)
Kate Stoneb9c1b512016-09-06 20:57:50 +000040#define DEBUGSERVER_BASENAME "debugserver"
Todd Fiala015d8182014-07-22 23:41:36 +000041#else
Kate Stoneb9c1b512016-09-06 20:57:50 +000042#define DEBUGSERVER_BASENAME "lldb-server"
Todd Fiala015d8182014-07-22 23:41:36 +000043#endif
Greg Clayton8b82f082011-04-12 05:54:46 +000044
Kate Stoneb9c1b512016-09-06 20:57:50 +000045#if defined(HAVE_LIBCOMPRESSION)
Jason Molenda91ffe0a2015-06-18 21:46:06 +000046#include <compression.h>
47#endif
48
Kate Stoneb9c1b512016-09-06 20:57:50 +000049#if defined(HAVE_LIBZ)
Jason Molenda91ffe0a2015-06-18 21:46:06 +000050#include <zlib.h>
51#endif
52
Chris Lattner30fdc8d2010-06-08 16:52:24 +000053using namespace lldb;
54using namespace lldb_private;
Tamas Berghammerdb264a62015-03-31 09:52:22 +000055using namespace lldb_private::process_gdb_remote;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000056
Kate Stoneb9c1b512016-09-06 20:57:50 +000057GDBRemoteCommunication::History::History(uint32_t size)
58 : m_packets(), m_curr_idx(0), m_total_packet_count(0),
59 m_dumped_to_log(false) {
60 m_packets.resize(size);
Greg Claytonc1422c12012-04-09 22:46:21 +000061}
62
Kate Stoneb9c1b512016-09-06 20:57:50 +000063GDBRemoteCommunication::History::~History() {}
64
65void GDBRemoteCommunication::History::AddPacket(char packet_char,
66 PacketType type,
67 uint32_t bytes_transmitted) {
68 const size_t size = m_packets.size();
69 if (size > 0) {
70 const uint32_t idx = GetNextIndex();
71 m_packets[idx].packet.assign(1, packet_char);
72 m_packets[idx].type = type;
73 m_packets[idx].bytes_transmitted = bytes_transmitted;
74 m_packets[idx].packet_idx = m_total_packet_count;
75 m_packets[idx].tid = Host::GetCurrentThreadID();
76 }
Greg Claytonc1422c12012-04-09 22:46:21 +000077}
78
Kate Stoneb9c1b512016-09-06 20:57:50 +000079void GDBRemoteCommunication::History::AddPacket(const std::string &src,
80 uint32_t src_len,
81 PacketType type,
82 uint32_t bytes_transmitted) {
83 const size_t size = m_packets.size();
84 if (size > 0) {
85 const uint32_t idx = GetNextIndex();
86 m_packets[idx].packet.assign(src, 0, src_len);
87 m_packets[idx].type = type;
88 m_packets[idx].bytes_transmitted = bytes_transmitted;
89 m_packets[idx].packet_idx = m_total_packet_count;
90 m_packets[idx].tid = Host::GetCurrentThreadID();
91 }
Greg Claytond451c1a2012-04-13 21:24:18 +000092}
93
Kate Stoneb9c1b512016-09-06 20:57:50 +000094void GDBRemoteCommunication::History::Dump(Stream &strm) const {
95 const uint32_t size = GetNumPacketsInHistory();
96 const uint32_t first_idx = GetFirstSavedPacketIndex();
97 const uint32_t stop_idx = m_curr_idx + size;
98 for (uint32_t i = first_idx; i < stop_idx; ++i) {
99 const uint32_t idx = NormalizeIndex(i);
100 const Entry &entry = m_packets[idx];
101 if (entry.type == ePacketTypeInvalid || entry.packet.empty())
102 break;
103 strm.Printf("history[%u] tid=0x%4.4" PRIx64 " <%4u> %s packet: %s\n",
104 entry.packet_idx, entry.tid, entry.bytes_transmitted,
105 (entry.type == ePacketTypeSend) ? "send" : "read",
106 entry.packet.c_str());
107 }
Greg Claytond451c1a2012-04-13 21:24:18 +0000108}
109
Kate Stoneb9c1b512016-09-06 20:57:50 +0000110void GDBRemoteCommunication::History::Dump(Log *log) const {
111 if (log && !m_dumped_to_log) {
112 m_dumped_to_log = true;
113 const uint32_t size = GetNumPacketsInHistory();
114 const uint32_t first_idx = GetFirstSavedPacketIndex();
Greg Claytonc1422c12012-04-09 22:46:21 +0000115 const uint32_t stop_idx = m_curr_idx + size;
Kate Stoneb9c1b512016-09-06 20:57:50 +0000116 for (uint32_t i = first_idx; i < stop_idx; ++i) {
117 const uint32_t idx = NormalizeIndex(i);
118 const Entry &entry = m_packets[idx];
119 if (entry.type == ePacketTypeInvalid || entry.packet.empty())
120 break;
121 log->Printf("history[%u] tid=0x%4.4" PRIx64 " <%4u> %s packet: %s",
122 entry.packet_idx, entry.tid, entry.bytes_transmitted,
123 (entry.type == ePacketTypeSend) ? "send" : "read",
124 entry.packet.c_str());
Greg Claytonc1422c12012-04-09 22:46:21 +0000125 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000126 }
Greg Claytonc1422c12012-04-09 22:46:21 +0000127}
128
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000129//----------------------------------------------------------------------
130// GDBRemoteCommunication constructor
131//----------------------------------------------------------------------
Kate Stoneb9c1b512016-09-06 20:57:50 +0000132GDBRemoteCommunication::GDBRemoteCommunication(const char *comm_name,
133 const char *listener_name)
Saleem Abdulrasool2d6a9ec2016-07-28 17:32:20 +0000134 : Communication(comm_name),
Daniel Maleae0f8f572013-08-26 23:57:52 +0000135#ifdef LLDB_CONFIGURATION_DEBUG
Saleem Abdulrasool2d6a9ec2016-07-28 17:32:20 +0000136 m_packet_timeout(1000),
Daniel Maleae0f8f572013-08-26 23:57:52 +0000137#else
Saleem Abdulrasool2d6a9ec2016-07-28 17:32:20 +0000138 m_packet_timeout(1),
Daniel Maleae0f8f572013-08-26 23:57:52 +0000139#endif
Kate Stoneb9c1b512016-09-06 20:57:50 +0000140 m_echo_number(0), m_supports_qEcho(eLazyBoolCalculate), m_history(512),
141 m_send_acks(true), m_compression_type(CompressionType::None),
142 m_listen_url() {
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000143}
144
145//----------------------------------------------------------------------
146// Destructor
147//----------------------------------------------------------------------
Kate Stoneb9c1b512016-09-06 20:57:50 +0000148GDBRemoteCommunication::~GDBRemoteCommunication() {
149 if (IsConnected()) {
150 Disconnect();
151 }
Ewan Crawfordfab40d32015-06-16 15:50:18 +0000152
Kate Stoneb9c1b512016-09-06 20:57:50 +0000153 // Stop the communications read thread which is used to parse all
154 // incoming packets. This function will block until the read
155 // thread returns.
156 if (m_read_thread_enabled)
157 StopReadThread();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000158}
159
Kate Stoneb9c1b512016-09-06 20:57:50 +0000160char GDBRemoteCommunication::CalculcateChecksum(llvm::StringRef payload) {
161 int checksum = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000162
Kate Stoneb9c1b512016-09-06 20:57:50 +0000163 for (char c : payload)
164 checksum += c;
Ed Mastea6b4c772013-08-20 14:12:58 +0000165
Kate Stoneb9c1b512016-09-06 20:57:50 +0000166 return checksum & 255;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000167}
168
Kate Stoneb9c1b512016-09-06 20:57:50 +0000169size_t GDBRemoteCommunication::SendAck() {
170 Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PACKETS));
171 ConnectionStatus status = eConnectionStatusSuccess;
172 char ch = '+';
173 const size_t bytes_written = Write(&ch, 1, status, NULL);
174 if (log)
175 log->Printf("<%4" PRIu64 "> send packet: %c", (uint64_t)bytes_written, ch);
176 m_history.AddPacket(ch, History::ePacketTypeSend, bytes_written);
177 return bytes_written;
178}
179
180size_t GDBRemoteCommunication::SendNack() {
181 Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PACKETS));
182 ConnectionStatus status = eConnectionStatusSuccess;
183 char ch = '-';
184 const size_t bytes_written = Write(&ch, 1, status, NULL);
185 if (log)
186 log->Printf("<%4" PRIu64 "> send packet: %c", (uint64_t)bytes_written, ch);
187 m_history.AddPacket(ch, History::ePacketTypeSend, bytes_written);
188 return bytes_written;
189}
190
191GDBRemoteCommunication::PacketResult
192GDBRemoteCommunication::SendPacketNoLock(llvm::StringRef payload) {
193 if (IsConnected()) {
194 StreamString packet(0, 4, eByteOrderBig);
195
196 packet.PutChar('$');
197 packet.Write(payload.data(), payload.size());
198 packet.PutChar('#');
199 packet.PutHex8(CalculcateChecksum(payload));
200
201 Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PACKETS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000202 ConnectionStatus status = eConnectionStatusSuccess;
Zachary Turnerc1564272016-11-16 21:15:24 +0000203 // TODO: Don't shimmy through a std::string, just use StringRef.
204 std::string packet_str = packet.GetString();
205 const char *packet_data = packet_str.c_str();
Kate Stoneb9c1b512016-09-06 20:57:50 +0000206 const size_t packet_length = packet.GetSize();
207 size_t bytes_written = Write(packet_data, packet_length, status, NULL);
208 if (log) {
209 size_t binary_start_offset = 0;
210 if (strncmp(packet_data, "$vFile:pwrite:", strlen("$vFile:pwrite:")) ==
211 0) {
212 const char *first_comma = strchr(packet_data, ',');
213 if (first_comma) {
214 const char *second_comma = strchr(first_comma + 1, ',');
215 if (second_comma)
216 binary_start_offset = second_comma - packet_data + 1;
Greg Claytonc1422c12012-04-09 22:46:21 +0000217 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000218 }
Greg Claytonc1422c12012-04-09 22:46:21 +0000219
Kate Stoneb9c1b512016-09-06 20:57:50 +0000220 // If logging was just enabled and we have history, then dump out what
221 // we have to the log so we get the historical context. The Dump() call
222 // that
223 // logs all of the packet will set a boolean so that we don't dump this
224 // more
225 // than once
226 if (!m_history.DidDumpToLog())
227 m_history.Dump(log);
Greg Claytonc1422c12012-04-09 22:46:21 +0000228
Kate Stoneb9c1b512016-09-06 20:57:50 +0000229 if (binary_start_offset) {
230 StreamString strm;
231 // Print non binary data header
232 strm.Printf("<%4" PRIu64 "> send packet: %.*s", (uint64_t)bytes_written,
233 (int)binary_start_offset, packet_data);
234 const uint8_t *p;
235 // Print binary data exactly as sent
236 for (p = (const uint8_t *)packet_data + binary_start_offset; *p != '#';
237 ++p)
238 strm.Printf("\\x%2.2x", *p);
239 // Print the checksum
240 strm.Printf("%*s", (int)3, p);
Zachary Turnerc1564272016-11-16 21:15:24 +0000241 log->PutString(strm.GetString());
Kate Stoneb9c1b512016-09-06 20:57:50 +0000242 } else
243 log->Printf("<%4" PRIu64 "> send packet: %.*s", (uint64_t)bytes_written,
244 (int)packet_length, packet_data);
Greg Claytonf5e56de2010-09-14 23:36:40 +0000245 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000246
Kate Stoneb9c1b512016-09-06 20:57:50 +0000247 m_history.AddPacket(packet.GetString(), packet_length,
248 History::ePacketTypeSend, bytes_written);
249
250 if (bytes_written == packet_length) {
251 if (GetSendAcks())
252 return GetAck();
253 else
254 return PacketResult::Success;
255 } else {
256 if (log)
257 log->Printf("error: failed to send packet: %.*s", (int)packet_length,
258 packet_data);
Greg Clayton3dedae12013-12-06 21:45:27 +0000259 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000260 }
261 return PacketResult::ErrorSendFailed;
262}
263
264GDBRemoteCommunication::PacketResult GDBRemoteCommunication::GetAck() {
265 StringExtractorGDBRemote packet;
Pavel Labath1eff73c2016-11-24 10:54:49 +0000266 PacketResult result = ReadPacket(packet, GetPacketTimeout(), false);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000267 if (result == PacketResult::Success) {
268 if (packet.GetResponseType() ==
269 StringExtractorGDBRemote::ResponseType::eAck)
270 return PacketResult::Success;
271 else
272 return PacketResult::ErrorSendAck;
273 }
274 return result;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000275}
276
Greg Clayton3dedae12013-12-06 21:45:27 +0000277GDBRemoteCommunication::PacketResult
Kate Stoneb9c1b512016-09-06 20:57:50 +0000278GDBRemoteCommunication::ReadPacket(StringExtractorGDBRemote &response,
Pavel Labath1eff73c2016-11-24 10:54:49 +0000279 Timeout<std::micro> timeout,
Kate Stoneb9c1b512016-09-06 20:57:50 +0000280 bool sync_on_timeout) {
281 if (m_read_thread_enabled)
Pavel Labath1eff73c2016-11-24 10:54:49 +0000282 return PopPacketFromQueue(response, timeout);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000283 else
Pavel Labath1eff73c2016-11-24 10:54:49 +0000284 return WaitForPacketNoLock(response, timeout, sync_on_timeout);
Ewan Crawfordfab40d32015-06-16 15:50:18 +0000285}
286
Ewan Crawfordfab40d32015-06-16 15:50:18 +0000287// This function is called when a packet is requested.
288// A whole packet is popped from the packet queue and returned to the caller.
289// Packets are placed into this queue from the communication read thread.
290// See GDBRemoteCommunication::AppendBytesToCache.
291GDBRemoteCommunication::PacketResult
Kate Stoneb9c1b512016-09-06 20:57:50 +0000292GDBRemoteCommunication::PopPacketFromQueue(StringExtractorGDBRemote &response,
Pavel Labath1eff73c2016-11-24 10:54:49 +0000293 Timeout<std::micro> timeout) {
294 auto pred = [&] { return !m_packet_queue.empty() && IsConnected(); };
295 // lock down the packet queue
296 std::unique_lock<std::mutex> lock(m_packet_queue_mutex);
Ewan Crawfordfab40d32015-06-16 15:50:18 +0000297
Pavel Labath1eff73c2016-11-24 10:54:49 +0000298 if (!timeout)
299 m_condition_queue_not_empty.wait(lock, pred);
300 else {
301 if (!m_condition_queue_not_empty.wait_for(lock, *timeout, pred))
302 return PacketResult::ErrorReplyTimeout;
Kate Stoneb9c1b512016-09-06 20:57:50 +0000303 if (!IsConnected())
304 return PacketResult::ErrorDisconnected;
Kate Stoneb9c1b512016-09-06 20:57:50 +0000305 }
306
Pavel Labath1eff73c2016-11-24 10:54:49 +0000307 // get the front element of the queue
308 response = m_packet_queue.front();
309
310 // remove the front element
311 m_packet_queue.pop();
312
313 // we got a packet
314 return PacketResult::Success;
Kate Stoneb9c1b512016-09-06 20:57:50 +0000315}
Ewan Crawfordfab40d32015-06-16 15:50:18 +0000316
317GDBRemoteCommunication::PacketResult
Pavel Labath1eff73c2016-11-24 10:54:49 +0000318GDBRemoteCommunication::WaitForPacketNoLock(StringExtractorGDBRemote &packet,
319 Timeout<std::micro> timeout,
320 bool sync_on_timeout) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000321 uint8_t buffer[8192];
322 Error error;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000323
Kate Stoneb9c1b512016-09-06 20:57:50 +0000324 Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PACKETS |
325 GDBR_LOG_VERBOSE));
Greg Clayton644247c2011-07-07 01:59:51 +0000326
Kate Stoneb9c1b512016-09-06 20:57:50 +0000327 // Check for a packet from our cache first without trying any reading...
328 if (CheckForPacket(NULL, 0, packet) != PacketType::Invalid)
329 return PacketResult::Success;
330
331 bool timed_out = false;
332 bool disconnected = false;
333 while (IsConnected() && !timed_out) {
334 lldb::ConnectionStatus status = eConnectionStatusNoConnection;
Pavel Labathc4063ee2016-11-25 11:58:44 +0000335 size_t bytes_read = Read(buffer, sizeof(buffer), timeout, status, &error);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000336
337 if (log)
Pavel Labath1eff73c2016-11-24 10:54:49 +0000338 log->Printf("%s: Read (buffer, (sizeof(buffer), timeout = %ld us, "
Kate Stoneb9c1b512016-09-06 20:57:50 +0000339 "status = %s, error = %s) => bytes_read = %" PRIu64,
Pavel Labath1eff73c2016-11-24 10:54:49 +0000340 LLVM_PRETTY_FUNCTION, long(timeout ? timeout->count() : -1),
Kate Stoneb9c1b512016-09-06 20:57:50 +0000341 Communication::ConnectionStatusAsCString(status),
342 error.AsCString(), (uint64_t)bytes_read);
343
344 if (bytes_read > 0) {
345 if (CheckForPacket(buffer, bytes_read, packet) != PacketType::Invalid)
Greg Clayton3dedae12013-12-06 21:45:27 +0000346 return PacketResult::Success;
Kate Stoneb9c1b512016-09-06 20:57:50 +0000347 } else {
348 switch (status) {
349 case eConnectionStatusTimedOut:
350 case eConnectionStatusInterrupted:
351 if (sync_on_timeout) {
352 //------------------------------------------------------------------
353 /// Sync the remote GDB server and make sure we get a response that
354 /// corresponds to what we send.
355 ///
356 /// Sends a "qEcho" packet and makes sure it gets the exact packet
357 /// echoed back. If the qEcho packet isn't supported, we send a qC
358 /// packet and make sure we get a valid thread ID back. We use the
359 /// "qC" packet since its response if very unique: is responds with
360 /// "QC%x" where %x is the thread ID of the current thread. This
361 /// makes the response unique enough from other packet responses to
362 /// ensure we are back on track.
363 ///
364 /// This packet is needed after we time out sending a packet so we
365 /// can ensure that we are getting the response for the packet we
366 /// are sending. There are no sequence IDs in the GDB remote
367 /// protocol (there used to be, but they are not supported anymore)
368 /// so if you timeout sending packet "abc", you might then send
369 /// packet "cde" and get the response for the previous "abc" packet.
370 /// Many responses are "OK" or "" (unsupported) or "EXX" (error) so
371 /// many responses for packets can look like responses for other
372 /// packets. So if we timeout, we need to ensure that we can get
373 /// back on track. If we can't get back on track, we must
374 /// disconnect.
375 //------------------------------------------------------------------
376 bool sync_success = false;
377 bool got_actual_response = false;
378 // We timed out, we need to sync back up with the
379 char echo_packet[32];
380 int echo_packet_len = 0;
381 RegularExpression response_regex;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000382
Kate Stoneb9c1b512016-09-06 20:57:50 +0000383 if (m_supports_qEcho == eLazyBoolYes) {
384 echo_packet_len = ::snprintf(echo_packet, sizeof(echo_packet),
385 "qEcho:%u", ++m_echo_number);
386 std::string regex_str = "^";
387 regex_str += echo_packet;
388 regex_str += "$";
Zachary Turner95eae422016-09-21 16:01:28 +0000389 response_regex.Compile(regex_str);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000390 } else {
391 echo_packet_len =
392 ::snprintf(echo_packet, sizeof(echo_packet), "qC");
Zachary Turner95eae422016-09-21 16:01:28 +0000393 response_regex.Compile(llvm::StringRef("^QC[0-9A-Fa-f]+$"));
Kate Stoneb9c1b512016-09-06 20:57:50 +0000394 }
Greg Clayton644247c2011-07-07 01:59:51 +0000395
Kate Stoneb9c1b512016-09-06 20:57:50 +0000396 PacketResult echo_packet_result =
397 SendPacketNoLock(llvm::StringRef(echo_packet, echo_packet_len));
398 if (echo_packet_result == PacketResult::Success) {
399 const uint32_t max_retries = 3;
400 uint32_t successful_responses = 0;
401 for (uint32_t i = 0; i < max_retries; ++i) {
402 StringExtractorGDBRemote echo_response;
Pavel Labath1eff73c2016-11-24 10:54:49 +0000403 echo_packet_result =
404 WaitForPacketNoLock(echo_response, timeout, false);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000405 if (echo_packet_result == PacketResult::Success) {
406 ++successful_responses;
Zachary Turner95eae422016-09-21 16:01:28 +0000407 if (response_regex.Execute(echo_response.GetStringRef())) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000408 sync_success = true;
409 break;
410 } else if (successful_responses == 1) {
411 // We got something else back as the first successful
412 // response, it probably is
413 // the response to the packet we actually wanted, so copy it
414 // over if this
415 // is the first success and continue to try to get the qEcho
416 // response
417 packet = echo_response;
418 got_actual_response = true;
Greg Claytonb30c50c2015-05-29 00:01:55 +0000419 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000420 } else if (echo_packet_result == PacketResult::ErrorReplyTimeout)
421 continue; // Packet timed out, continue waiting for a response
422 else
423 break; // Something else went wrong getting the packet back, we
424 // failed and are done trying
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000425 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000426 }
427
428 // We weren't able to sync back up with the server, we must abort
429 // otherwise
430 // all responses might not be from the right packets...
431 if (sync_success) {
432 // We timed out, but were able to recover
433 if (got_actual_response) {
434 // We initially timed out, but we did get a response that came in
435 // before the successful
436 // reply to our qEcho packet, so lets say everything is fine...
437 return PacketResult::Success;
438 }
439 } else {
440 disconnected = true;
441 Disconnect();
442 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000443 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000444 timed_out = true;
445 break;
446 case eConnectionStatusSuccess:
447 // printf ("status = success but error = %s\n",
448 // error.AsCString("<invalid>"));
449 break;
450
451 case eConnectionStatusEndOfFile:
452 case eConnectionStatusNoConnection:
453 case eConnectionStatusLostConnection:
454 case eConnectionStatusError:
455 disconnected = true;
456 Disconnect();
457 break;
458 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000459 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000460 }
461 packet.Clear();
462 if (disconnected)
463 return PacketResult::ErrorDisconnected;
464 if (timed_out)
465 return PacketResult::ErrorReplyTimeout;
466 else
467 return PacketResult::ErrorReplyFailed;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000468}
469
Kate Stoneb9c1b512016-09-06 20:57:50 +0000470bool GDBRemoteCommunication::DecompressPacket() {
471 Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PACKETS));
Jason Molenda91ffe0a2015-06-18 21:46:06 +0000472
Kate Stoneb9c1b512016-09-06 20:57:50 +0000473 if (!CompressionIsEnabled())
Jason Molenda91ffe0a2015-06-18 21:46:06 +0000474 return true;
Kate Stoneb9c1b512016-09-06 20:57:50 +0000475
476 size_t pkt_size = m_bytes.size();
477
478 // Smallest possible compressed packet is $N#00 - an uncompressed empty reply,
479 // most commonly indicating
480 // an unsupported packet. Anything less than 5 characters, it's definitely
481 // not a compressed packet.
482 if (pkt_size < 5)
483 return true;
484
485 if (m_bytes[0] != '$' && m_bytes[0] != '%')
486 return true;
487 if (m_bytes[1] != 'C' && m_bytes[1] != 'N')
488 return true;
489
490 size_t hash_mark_idx = m_bytes.find('#');
491 if (hash_mark_idx == std::string::npos)
492 return true;
493 if (hash_mark_idx + 2 >= m_bytes.size())
494 return true;
495
496 if (!::isxdigit(m_bytes[hash_mark_idx + 1]) ||
497 !::isxdigit(m_bytes[hash_mark_idx + 2]))
498 return true;
499
500 size_t content_length =
501 pkt_size -
502 5; // not counting '$', 'C' | 'N', '#', & the two hex checksum chars
503 size_t content_start = 2; // The first character of the
504 // compressed/not-compressed text of the packet
505 size_t checksum_idx =
506 hash_mark_idx +
507 1; // The first character of the two hex checksum characters
508
509 // Normally size_of_first_packet == m_bytes.size() but m_bytes may contain
510 // multiple packets.
511 // size_of_first_packet is the size of the initial packet which we'll replace
512 // with the decompressed
513 // version of, leaving the rest of m_bytes unmodified.
514 size_t size_of_first_packet = hash_mark_idx + 3;
515
516 // Compressed packets ("$C") start with a base10 number which is the size of
517 // the uncompressed payload,
518 // then a : and then the compressed data. e.g. $C1024:<binary>#00
519 // Update content_start and content_length to only include the <binary> part
520 // of the packet.
521
522 uint64_t decompressed_bufsize = ULONG_MAX;
523 if (m_bytes[1] == 'C') {
524 size_t i = content_start;
525 while (i < hash_mark_idx && isdigit(m_bytes[i]))
526 i++;
527 if (i < hash_mark_idx && m_bytes[i] == ':') {
528 i++;
529 content_start = i;
530 content_length = hash_mark_idx - content_start;
531 std::string bufsize_str(m_bytes.data() + 2, i - 2 - 1);
532 errno = 0;
533 decompressed_bufsize = ::strtoul(bufsize_str.c_str(), NULL, 10);
534 if (errno != 0 || decompressed_bufsize == ULONG_MAX) {
535 m_bytes.erase(0, size_of_first_packet);
536 return false;
537 }
538 }
539 }
540
541 if (GetSendAcks()) {
542 char packet_checksum_cstr[3];
543 packet_checksum_cstr[0] = m_bytes[checksum_idx];
544 packet_checksum_cstr[1] = m_bytes[checksum_idx + 1];
545 packet_checksum_cstr[2] = '\0';
546 long packet_checksum = strtol(packet_checksum_cstr, NULL, 16);
547
548 long actual_checksum = CalculcateChecksum(
549 llvm::StringRef(m_bytes).substr(1, hash_mark_idx - 1));
550 bool success = packet_checksum == actual_checksum;
551 if (!success) {
552 if (log)
553 log->Printf(
554 "error: checksum mismatch: %.*s expected 0x%2.2x, got 0x%2.2x",
555 (int)(pkt_size), m_bytes.c_str(), (uint8_t)packet_checksum,
556 (uint8_t)actual_checksum);
557 }
558 // Send the ack or nack if needed
559 if (!success) {
560 SendNack();
561 m_bytes.erase(0, size_of_first_packet);
562 return false;
563 } else {
564 SendAck();
565 }
566 }
567
568 if (m_bytes[1] == 'N') {
569 // This packet was not compressed -- delete the 'N' character at the
570 // start and the packet may be processed as-is.
571 m_bytes.erase(1, 1);
572 return true;
573 }
574
575 // Reverse the gdb-remote binary escaping that was done to the compressed text
576 // to
577 // guard characters like '$', '#', '}', etc.
578 std::vector<uint8_t> unescaped_content;
579 unescaped_content.reserve(content_length);
580 size_t i = content_start;
581 while (i < hash_mark_idx) {
582 if (m_bytes[i] == '}') {
583 i++;
584 unescaped_content.push_back(m_bytes[i] ^ 0x20);
585 } else {
586 unescaped_content.push_back(m_bytes[i]);
587 }
588 i++;
589 }
590
591 uint8_t *decompressed_buffer = nullptr;
592 size_t decompressed_bytes = 0;
593
594 if (decompressed_bufsize != ULONG_MAX) {
595 decompressed_buffer = (uint8_t *)malloc(decompressed_bufsize + 1);
596 if (decompressed_buffer == nullptr) {
597 m_bytes.erase(0, size_of_first_packet);
598 return false;
599 }
600 }
601
602#if defined(HAVE_LIBCOMPRESSION)
603 // libcompression is weak linked so check that compression_decode_buffer() is
604 // available
605 if (compression_decode_buffer != NULL &&
606 (m_compression_type == CompressionType::ZlibDeflate ||
607 m_compression_type == CompressionType::LZFSE ||
608 m_compression_type == CompressionType::LZ4)) {
609 compression_algorithm compression_type;
610 if (m_compression_type == CompressionType::ZlibDeflate)
611 compression_type = COMPRESSION_ZLIB;
612 else if (m_compression_type == CompressionType::LZFSE)
613 compression_type = COMPRESSION_LZFSE;
614 else if (m_compression_type == CompressionType::LZ4)
615 compression_type = COMPRESSION_LZ4_RAW;
616 else if (m_compression_type == CompressionType::LZMA)
617 compression_type = COMPRESSION_LZMA;
618
619 // If we have the expected size of the decompressed payload, we can allocate
620 // the right-sized buffer and do it. If we don't have that information,
621 // we'll
622 // need to try decoding into a big buffer and if the buffer wasn't big
623 // enough,
624 // increase it and try again.
625
626 if (decompressed_bufsize != ULONG_MAX && decompressed_buffer != nullptr) {
627 decompressed_bytes = compression_decode_buffer(
628 decompressed_buffer, decompressed_bufsize + 10,
629 (uint8_t *)unescaped_content.data(), unescaped_content.size(), NULL,
630 compression_type);
631 }
632 }
633#endif
634
635#if defined(HAVE_LIBZ)
636 if (decompressed_bytes == 0 && decompressed_bufsize != ULONG_MAX &&
637 decompressed_buffer != nullptr &&
638 m_compression_type == CompressionType::ZlibDeflate) {
639 z_stream stream;
640 memset(&stream, 0, sizeof(z_stream));
641 stream.next_in = (Bytef *)unescaped_content.data();
642 stream.avail_in = (uInt)unescaped_content.size();
643 stream.total_in = 0;
644 stream.next_out = (Bytef *)decompressed_buffer;
645 stream.avail_out = decompressed_bufsize;
646 stream.total_out = 0;
647 stream.zalloc = Z_NULL;
648 stream.zfree = Z_NULL;
649 stream.opaque = Z_NULL;
650
651 if (inflateInit2(&stream, -15) == Z_OK) {
652 int status = inflate(&stream, Z_NO_FLUSH);
653 inflateEnd(&stream);
654 if (status == Z_STREAM_END) {
655 decompressed_bytes = stream.total_out;
656 }
657 }
658 }
659#endif
660
661 if (decompressed_bytes == 0 || decompressed_buffer == nullptr) {
662 if (decompressed_buffer)
663 free(decompressed_buffer);
664 m_bytes.erase(0, size_of_first_packet);
665 return false;
666 }
667
668 std::string new_packet;
669 new_packet.reserve(decompressed_bytes + 6);
670 new_packet.push_back(m_bytes[0]);
671 new_packet.append((const char *)decompressed_buffer, decompressed_bytes);
672 new_packet.push_back('#');
673 if (GetSendAcks()) {
674 uint8_t decompressed_checksum = CalculcateChecksum(
675 llvm::StringRef((const char *)decompressed_buffer, decompressed_bytes));
676 char decompressed_checksum_str[3];
677 snprintf(decompressed_checksum_str, 3, "%02x", decompressed_checksum);
678 new_packet.append(decompressed_checksum_str);
679 } else {
680 new_packet.push_back('0');
681 new_packet.push_back('0');
682 }
683
684 m_bytes.replace(0, size_of_first_packet, new_packet.data(),
685 new_packet.size());
686
687 free(decompressed_buffer);
688 return true;
Jason Molenda91ffe0a2015-06-18 21:46:06 +0000689}
690
Ewan Crawford9aa2da002015-05-27 14:12:34 +0000691GDBRemoteCommunication::PacketType
Kate Stoneb9c1b512016-09-06 20:57:50 +0000692GDBRemoteCommunication::CheckForPacket(const uint8_t *src, size_t src_len,
693 StringExtractorGDBRemote &packet) {
694 // Put the packet data into the buffer in a thread safe fashion
695 std::lock_guard<std::recursive_mutex> guard(m_bytes_mutex);
Saleem Abdulrasool16ff8602016-05-18 01:59:10 +0000696
Kate Stoneb9c1b512016-09-06 20:57:50 +0000697 Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PACKETS));
Greg Clayton197bacf2011-07-02 21:07:54 +0000698
Kate Stoneb9c1b512016-09-06 20:57:50 +0000699 if (src && src_len > 0) {
700 if (log && log->GetVerbose()) {
701 StreamString s;
702 log->Printf("GDBRemoteCommunication::%s adding %u bytes: %.*s",
703 __FUNCTION__, (uint32_t)src_len, (uint32_t)src_len, src);
704 }
705 m_bytes.append((const char *)src, src_len);
706 }
707
708 bool isNotifyPacket = false;
709
710 // Parse up the packets into gdb remote packets
711 if (!m_bytes.empty()) {
712 // end_idx must be one past the last valid packet byte. Start
713 // it off with an invalid value that is the same as the current
714 // index.
715 size_t content_start = 0;
716 size_t content_length = 0;
717 size_t total_length = 0;
718 size_t checksum_idx = std::string::npos;
719
720 // Size of packet before it is decompressed, for logging purposes
721 size_t original_packet_size = m_bytes.size();
722 if (CompressionIsEnabled()) {
723 if (DecompressPacket() == false) {
724 packet.Clear();
725 return GDBRemoteCommunication::PacketType::Standard;
726 }
Greg Clayton197bacf2011-07-02 21:07:54 +0000727 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000728
Kate Stoneb9c1b512016-09-06 20:57:50 +0000729 switch (m_bytes[0]) {
730 case '+': // Look for ack
731 case '-': // Look for cancel
732 case '\x03': // ^C to halt target
733 content_length = total_length = 1; // The command is one byte long...
734 break;
Ewan Crawford9aa2da002015-05-27 14:12:34 +0000735
Kate Stoneb9c1b512016-09-06 20:57:50 +0000736 case '%': // Async notify packet
737 isNotifyPacket = true;
738 LLVM_FALLTHROUGH;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000739
Kate Stoneb9c1b512016-09-06 20:57:50 +0000740 case '$':
741 // Look for a standard gdb packet?
742 {
743 size_t hash_pos = m_bytes.find('#');
744 if (hash_pos != std::string::npos) {
745 if (hash_pos + 2 < m_bytes.size()) {
746 checksum_idx = hash_pos + 1;
747 // Skip the dollar sign
748 content_start = 1;
749 // Don't include the # in the content or the $ in the content length
750 content_length = hash_pos - 1;
751
752 total_length =
753 hash_pos + 3; // Skip the # and the two hex checksum bytes
754 } else {
755 // Checksum bytes aren't all here yet
756 content_length = std::string::npos;
757 }
Jason Molenda91ffe0a2015-06-18 21:46:06 +0000758 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000759 }
760 break;
Jason Molenda91ffe0a2015-06-18 21:46:06 +0000761
Kate Stoneb9c1b512016-09-06 20:57:50 +0000762 default: {
763 // We have an unexpected byte and we need to flush all bad
764 // data that is in m_bytes, so we need to find the first
765 // byte that is a '+' (ACK), '-' (NACK), \x03 (CTRL+C interrupt),
766 // or '$' character (start of packet header) or of course,
767 // the end of the data in m_bytes...
768 const size_t bytes_len = m_bytes.size();
769 bool done = false;
770 uint32_t idx;
771 for (idx = 1; !done && idx < bytes_len; ++idx) {
772 switch (m_bytes[idx]) {
773 case '+':
774 case '-':
775 case '\x03':
776 case '%':
777 case '$':
778 done = true;
779 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000780
Kate Stoneb9c1b512016-09-06 20:57:50 +0000781 default:
782 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000783 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000784 }
785 if (log)
786 log->Printf("GDBRemoteCommunication::%s tossing %u junk bytes: '%.*s'",
787 __FUNCTION__, idx - 1, idx - 1, m_bytes.c_str());
788 m_bytes.erase(0, idx - 1);
789 } break;
790 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000791
Kate Stoneb9c1b512016-09-06 20:57:50 +0000792 if (content_length == std::string::npos) {
793 packet.Clear();
794 return GDBRemoteCommunication::PacketType::Invalid;
795 } else if (total_length > 0) {
796
797 // We have a valid packet...
798 assert(content_length <= m_bytes.size());
799 assert(total_length <= m_bytes.size());
800 assert(content_length <= total_length);
801 size_t content_end = content_start + content_length;
802
803 bool success = true;
804 std::string &packet_str = packet.GetStringRef();
805 if (log) {
806 // If logging was just enabled and we have history, then dump out what
807 // we have to the log so we get the historical context. The Dump() call
808 // that
809 // logs all of the packet will set a boolean so that we don't dump this
810 // more
811 // than once
812 if (!m_history.DidDumpToLog())
813 m_history.Dump(log);
814
815 bool binary = false;
816 // Only detect binary for packets that start with a '$' and have a '#CC'
817 // checksum
818 if (m_bytes[0] == '$' && total_length > 4) {
819 for (size_t i = 0; !binary && i < total_length; ++i) {
820 if (isprint(m_bytes[i]) == 0 && isspace(m_bytes[i]) == 0) {
821 binary = true;
822 }
823 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000824 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000825 if (binary) {
826 StreamString strm;
827 // Packet header...
828 if (CompressionIsEnabled())
829 strm.Printf("<%4" PRIu64 ":%" PRIu64 "> read packet: %c",
830 (uint64_t)original_packet_size, (uint64_t)total_length,
831 m_bytes[0]);
832 else
833 strm.Printf("<%4" PRIu64 "> read packet: %c",
834 (uint64_t)total_length, m_bytes[0]);
835 for (size_t i = content_start; i < content_end; ++i) {
836 // Remove binary escaped bytes when displaying the packet...
837 const char ch = m_bytes[i];
838 if (ch == 0x7d) {
839 // 0x7d is the escape character. The next character is to
840 // be XOR'd with 0x20.
841 const char escapee = m_bytes[++i] ^ 0x20;
842 strm.Printf("%2.2x", escapee);
843 } else {
844 strm.Printf("%2.2x", (uint8_t)ch);
Greg Claytonc1422c12012-04-09 22:46:21 +0000845 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000846 }
847 // Packet footer...
848 strm.Printf("%c%c%c", m_bytes[total_length - 3],
849 m_bytes[total_length - 2], m_bytes[total_length - 1]);
Zachary Turnerc1564272016-11-16 21:15:24 +0000850 log->PutString(strm.GetString());
Kate Stoneb9c1b512016-09-06 20:57:50 +0000851 } else {
852 if (CompressionIsEnabled())
853 log->Printf("<%4" PRIu64 ":%" PRIu64 "> read packet: %.*s",
854 (uint64_t)original_packet_size, (uint64_t)total_length,
855 (int)(total_length), m_bytes.c_str());
856 else
857 log->Printf("<%4" PRIu64 "> read packet: %.*s",
858 (uint64_t)total_length, (int)(total_length),
859 m_bytes.c_str());
860 }
861 }
Greg Claytonc1422c12012-04-09 22:46:21 +0000862
Malcolm Parsons771ef6d2016-11-02 20:34:10 +0000863 m_history.AddPacket(m_bytes, total_length, History::ePacketTypeRecv,
864 total_length);
Greg Claytonc1422c12012-04-09 22:46:21 +0000865
Kate Stoneb9c1b512016-09-06 20:57:50 +0000866 // Clear packet_str in case there is some existing data in it.
867 packet_str.clear();
868 // Copy the packet from m_bytes to packet_str expanding the
869 // run-length encoding in the process.
870 // Reserve enough byte for the most common case (no RLE used)
871 packet_str.reserve(m_bytes.length());
872 for (std::string::const_iterator c = m_bytes.begin() + content_start;
873 c != m_bytes.begin() + content_end; ++c) {
874 if (*c == '*') {
875 // '*' indicates RLE. Next character will give us the
876 // repeat count and previous character is what is to be
877 // repeated.
878 char char_to_repeat = packet_str.back();
879 // Number of time the previous character is repeated
880 int repeat_count = *++c + 3 - ' ';
881 // We have the char_to_repeat and repeat_count. Now push
882 // it in the packet.
883 for (int i = 0; i < repeat_count; ++i)
884 packet_str.push_back(char_to_repeat);
885 } else if (*c == 0x7d) {
886 // 0x7d is the escape character. The next character is to
887 // be XOR'd with 0x20.
888 char escapee = *++c ^ 0x20;
889 packet_str.push_back(escapee);
890 } else {
891 packet_str.push_back(*c);
892 }
893 }
894
895 if (m_bytes[0] == '$' || m_bytes[0] == '%') {
896 assert(checksum_idx < m_bytes.size());
897 if (::isxdigit(m_bytes[checksum_idx + 0]) ||
898 ::isxdigit(m_bytes[checksum_idx + 1])) {
899 if (GetSendAcks()) {
900 const char *packet_checksum_cstr = &m_bytes[checksum_idx];
901 char packet_checksum = strtol(packet_checksum_cstr, NULL, 16);
902 char actual_checksum = CalculcateChecksum(packet_str);
903 success = packet_checksum == actual_checksum;
904 if (!success) {
905 if (log)
906 log->Printf("error: checksum mismatch: %.*s expected 0x%2.2x, "
907 "got 0x%2.2x",
908 (int)(total_length), m_bytes.c_str(),
909 (uint8_t)packet_checksum, (uint8_t)actual_checksum);
Hafiz Abid Qadeerda96ef22013-08-28 10:31:52 +0000910 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000911 // Send the ack or nack if needed
912 if (!success)
913 SendNack();
Ewan Crawford9aa2da002015-05-27 14:12:34 +0000914 else
Kate Stoneb9c1b512016-09-06 20:57:50 +0000915 SendAck();
916 }
917 } else {
918 success = false;
919 if (log)
920 log->Printf("error: invalid checksum in packet: '%s'\n",
921 m_bytes.c_str());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000922 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000923 }
924
925 m_bytes.erase(0, total_length);
926 packet.SetFilePos(0);
927
928 if (isNotifyPacket)
929 return GDBRemoteCommunication::PacketType::Notify;
930 else
931 return GDBRemoteCommunication::PacketType::Standard;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000932 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000933 }
934 packet.Clear();
935 return GDBRemoteCommunication::PacketType::Invalid;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000936}
937
Kate Stoneb9c1b512016-09-06 20:57:50 +0000938Error GDBRemoteCommunication::StartListenThread(const char *hostname,
939 uint16_t port) {
940 Error error;
941 if (m_listen_thread.IsJoinable()) {
942 error.SetErrorString("listen thread already running");
943 } else {
944 char listen_url[512];
945 if (hostname && hostname[0])
946 snprintf(listen_url, sizeof(listen_url), "listen://%s:%i", hostname,
947 port);
Greg Clayton00fe87b2013-12-05 22:58:22 +0000948 else
Kate Stoneb9c1b512016-09-06 20:57:50 +0000949 snprintf(listen_url, sizeof(listen_url), "listen://%i", port);
950 m_listen_url = listen_url;
951 SetConnection(new ConnectionFileDescriptor());
952 m_listen_thread = ThreadLauncher::LaunchThread(
953 listen_url, GDBRemoteCommunication::ListenThread, this, &error);
954 }
955 return error;
Greg Clayton00fe87b2013-12-05 22:58:22 +0000956}
957
Kate Stoneb9c1b512016-09-06 20:57:50 +0000958bool GDBRemoteCommunication::JoinListenThread() {
959 if (m_listen_thread.IsJoinable())
960 m_listen_thread.Join(nullptr);
961 return true;
Greg Clayton00fe87b2013-12-05 22:58:22 +0000962}
963
964lldb::thread_result_t
Kate Stoneb9c1b512016-09-06 20:57:50 +0000965GDBRemoteCommunication::ListenThread(lldb::thread_arg_t arg) {
966 GDBRemoteCommunication *comm = (GDBRemoteCommunication *)arg;
967 Error error;
968 ConnectionFileDescriptor *connection =
969 (ConnectionFileDescriptor *)comm->GetConnection();
970
971 if (connection) {
972 // Do the listen on another thread so we can continue on...
973 if (connection->Connect(comm->m_listen_url.c_str(), &error) !=
974 eConnectionStatusSuccess)
975 comm->SetConnection(NULL);
976 }
977 return NULL;
Greg Clayton00fe87b2013-12-05 22:58:22 +0000978}
979
Kate Stoneb9c1b512016-09-06 20:57:50 +0000980Error GDBRemoteCommunication::StartDebugserverProcess(
981 const char *url, Platform *platform, ProcessLaunchInfo &launch_info,
982 uint16_t *port, const Args *inferior_args, int pass_comm_fd) {
983 Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS));
984 if (log)
985 log->Printf("GDBRemoteCommunication::%s(url=%s, port=%" PRIu16 ")",
986 __FUNCTION__, url ? url : "<empty>",
987 port ? *port : uint16_t(0));
988
989 Error error;
990 // If we locate debugserver, keep that located version around
991 static FileSpec g_debugserver_file_spec;
992
993 char debugserver_path[PATH_MAX];
994 FileSpec &debugserver_file_spec = launch_info.GetExecutableFile();
995
996 // Always check to see if we have an environment override for the path
997 // to the debugserver to use and use it if we do.
998 const char *env_debugserver_path = getenv("LLDB_DEBUGSERVER_PATH");
999 if (env_debugserver_path) {
1000 debugserver_file_spec.SetFile(env_debugserver_path, false);
Todd Fiala015d8182014-07-22 23:41:36 +00001001 if (log)
Kate Stoneb9c1b512016-09-06 20:57:50 +00001002 log->Printf("GDBRemoteCommunication::%s() gdb-remote stub exe path set "
1003 "from environment variable: %s",
1004 __FUNCTION__, env_debugserver_path);
1005 } else
1006 debugserver_file_spec = g_debugserver_file_spec;
1007 bool debugserver_exists = debugserver_file_spec.Exists();
1008 if (!debugserver_exists) {
1009 // The debugserver binary is in the LLDB.framework/Resources
1010 // directory.
1011 if (HostInfo::GetLLDBPath(ePathTypeSupportExecutableDir,
1012 debugserver_file_spec)) {
1013 debugserver_file_spec.AppendPathComponent(DEBUGSERVER_BASENAME);
1014 debugserver_exists = debugserver_file_spec.Exists();
1015 if (debugserver_exists) {
Todd Fiala015d8182014-07-22 23:41:36 +00001016 if (log)
Kate Stoneb9c1b512016-09-06 20:57:50 +00001017 log->Printf(
1018 "GDBRemoteCommunication::%s() found gdb-remote stub exe '%s'",
1019 __FUNCTION__, debugserver_file_spec.GetPath().c_str());
Todd Fiala015d8182014-07-22 23:41:36 +00001020
Kate Stoneb9c1b512016-09-06 20:57:50 +00001021 g_debugserver_file_spec = debugserver_file_spec;
1022 } else {
1023 debugserver_file_spec =
1024 platform->LocateExecutable(DEBUGSERVER_BASENAME);
1025 if (debugserver_file_spec) {
1026 // Platform::LocateExecutable() wouldn't return a path if it doesn't
1027 // exist
1028 debugserver_exists = true;
1029 } else {
1030 if (log)
1031 log->Printf("GDBRemoteCommunication::%s() could not find "
1032 "gdb-remote stub exe '%s'",
1033 __FUNCTION__, debugserver_file_spec.GetPath().c_str());
Greg Clayton8b82f082011-04-12 05:54:46 +00001034 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00001035 // Don't cache the platform specific GDB server binary as it could
1036 // change
1037 // from platform to platform
1038 g_debugserver_file_spec.Clear();
1039 }
Greg Clayton8b82f082011-04-12 05:54:46 +00001040 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00001041 }
Greg Clayton8b82f082011-04-12 05:54:46 +00001042
Kate Stoneb9c1b512016-09-06 20:57:50 +00001043 if (debugserver_exists) {
1044 debugserver_file_spec.GetPath(debugserver_path, sizeof(debugserver_path));
Tamas Berghammerc2c3d712015-02-18 15:39:41 +00001045
Kate Stoneb9c1b512016-09-06 20:57:50 +00001046 Args &debugserver_args = launch_info.GetArguments();
1047 debugserver_args.Clear();
1048 char arg_cstr[PATH_MAX];
1049
1050 // Start args with "debugserver /file/path -r --"
Zachary Turnerecbb0bb2016-09-19 17:54:06 +00001051 debugserver_args.AppendArgument(llvm::StringRef(debugserver_path));
Greg Clayton00fe87b2013-12-05 22:58:22 +00001052
Tamas Berghammerc2c3d712015-02-18 15:39:41 +00001053#if !defined(__APPLE__)
Kate Stoneb9c1b512016-09-06 20:57:50 +00001054 // First argument to lldb-server must be mode in which to run.
Zachary Turnerecbb0bb2016-09-19 17:54:06 +00001055 debugserver_args.AppendArgument(llvm::StringRef("gdbserver"));
Tamas Berghammerc2c3d712015-02-18 15:39:41 +00001056#endif
1057
Kate Stoneb9c1b512016-09-06 20:57:50 +00001058 // If a url is supplied then use it
1059 if (url)
Zachary Turnerecbb0bb2016-09-19 17:54:06 +00001060 debugserver_args.AppendArgument(llvm::StringRef(url));
Greg Claytonfda4fab2014-01-10 22:24:11 +00001061
Kate Stoneb9c1b512016-09-06 20:57:50 +00001062 if (pass_comm_fd >= 0) {
1063 StreamString fd_arg;
1064 fd_arg.Printf("--fd=%i", pass_comm_fd);
Zachary Turnerecbb0bb2016-09-19 17:54:06 +00001065 debugserver_args.AppendArgument(fd_arg.GetString());
Kate Stoneb9c1b512016-09-06 20:57:50 +00001066 // Send "pass_comm_fd" down to the inferior so it can use it to
1067 // communicate back with this process
1068 launch_info.AppendDuplicateFileAction(pass_comm_fd, pass_comm_fd);
1069 }
Greg Claytonc6c420f2016-08-12 16:46:18 +00001070
Kate Stoneb9c1b512016-09-06 20:57:50 +00001071 // use native registers, not the GDB registers
Zachary Turnerecbb0bb2016-09-19 17:54:06 +00001072 debugserver_args.AppendArgument(llvm::StringRef("--native-regs"));
Oleksiy Vyalovf8ce61c2015-01-28 17:36:59 +00001073
Kate Stoneb9c1b512016-09-06 20:57:50 +00001074 if (launch_info.GetLaunchInSeparateProcessGroup()) {
Zachary Turnerecbb0bb2016-09-19 17:54:06 +00001075 debugserver_args.AppendArgument(llvm::StringRef("--setsid"));
Kate Stoneb9c1b512016-09-06 20:57:50 +00001076 }
Greg Clayton91a9b2472013-12-04 19:19:12 +00001077
Kate Stoneb9c1b512016-09-06 20:57:50 +00001078 llvm::SmallString<PATH_MAX> named_pipe_path;
1079 // socket_pipe is used by debug server to communicate back either
1080 // TCP port or domain socket name which it listens on.
1081 // The second purpose of the pipe to serve as a synchronization point -
1082 // once data is written to the pipe, debug server is up and running.
1083 Pipe socket_pipe;
Greg Clayton00fe87b2013-12-05 22:58:22 +00001084
Kate Stoneb9c1b512016-09-06 20:57:50 +00001085 // port is null when debug server should listen on domain socket -
1086 // we're not interested in port value but rather waiting for debug server
1087 // to become available.
1088 if (pass_comm_fd == -1 &&
1089 ((port != nullptr && *port == 0) || port == nullptr)) {
1090 if (url) {
1091// Create a temporary file to get the stdout/stderr and redirect the
1092// output of the command into this file. We will later read this file
1093// if all goes well and fill the data into "command_output_ptr"
Chaoren Lin46951b52015-07-30 17:48:44 +00001094#if defined(__APPLE__)
Kate Stoneb9c1b512016-09-06 20:57:50 +00001095 // Binding to port zero, we need to figure out what port it ends up
1096 // using using a named pipe...
1097 error = socket_pipe.CreateWithUniqueName("debugserver-named-pipe",
1098 false, named_pipe_path);
1099 if (error.Fail()) {
1100 if (log)
1101 log->Printf("GDBRemoteCommunication::%s() "
1102 "named pipe creation failed: %s",
1103 __FUNCTION__, error.AsCString());
1104 return error;
1105 }
Sean Callanan1355f472016-09-19 22:06:12 +00001106 debugserver_args.AppendArgument(llvm::StringRef("--named-pipe"));
Zachary Turner9a4e3012016-09-21 16:01:43 +00001107 debugserver_args.AppendArgument(named_pipe_path);
Chaoren Lin46951b52015-07-30 17:48:44 +00001108#else
Kate Stoneb9c1b512016-09-06 20:57:50 +00001109 // Binding to port zero, we need to figure out what port it ends up
1110 // using using an unnamed pipe...
1111 error = socket_pipe.CreateNew(true);
1112 if (error.Fail()) {
1113 if (log)
1114 log->Printf("GDBRemoteCommunication::%s() "
1115 "unnamed pipe creation failed: %s",
1116 __FUNCTION__, error.AsCString());
1117 return error;
1118 }
1119 int write_fd = socket_pipe.GetWriteFileDescriptor();
Zachary Turnerecbb0bb2016-09-19 17:54:06 +00001120 debugserver_args.AppendArgument(llvm::StringRef("--pipe"));
1121 debugserver_args.AppendArgument(llvm::to_string(write_fd));
Kate Stoneb9c1b512016-09-06 20:57:50 +00001122 launch_info.AppendCloseFileAction(socket_pipe.GetReadFileDescriptor());
Chaoren Lin46951b52015-07-30 17:48:44 +00001123#endif
Kate Stoneb9c1b512016-09-06 20:57:50 +00001124 } else {
1125 // No host and port given, so lets listen on our end and make the
1126 // debugserver
1127 // connect to us..
1128 error = StartListenThread("127.0.0.1", 0);
1129 if (error.Fail()) {
1130 if (log)
1131 log->Printf("GDBRemoteCommunication::%s() unable to start listen "
1132 "thread: %s",
1133 __FUNCTION__, error.AsCString());
1134 return error;
Greg Clayton00fe87b2013-12-05 22:58:22 +00001135 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00001136
1137 ConnectionFileDescriptor *connection =
1138 (ConnectionFileDescriptor *)GetConnection();
1139 // Wait for 10 seconds to resolve the bound port
1140 uint16_t port_ = connection->GetListeningPort(10);
1141 if (port_ > 0) {
1142 char port_cstr[32];
1143 snprintf(port_cstr, sizeof(port_cstr), "127.0.0.1:%i", port_);
1144 // Send the host and port down that debugserver and specify an option
1145 // so that it connects back to the port we are listening to in this
1146 // process
Zachary Turnerecbb0bb2016-09-19 17:54:06 +00001147 debugserver_args.AppendArgument(llvm::StringRef("--reverse-connect"));
1148 debugserver_args.AppendArgument(llvm::StringRef(port_cstr));
Kate Stoneb9c1b512016-09-06 20:57:50 +00001149 if (port)
1150 *port = port_;
1151 } else {
1152 error.SetErrorString("failed to bind to port 0 on 127.0.0.1");
1153 if (log)
1154 log->Printf("GDBRemoteCommunication::%s() failed: %s", __FUNCTION__,
1155 error.AsCString());
1156 return error;
Greg Clayton8b82f082011-04-12 05:54:46 +00001157 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00001158 }
1159 }
1160
1161 const char *env_debugserver_log_file = getenv("LLDB_DEBUGSERVER_LOG_FILE");
1162 if (env_debugserver_log_file) {
1163 ::snprintf(arg_cstr, sizeof(arg_cstr), "--log-file=%s",
1164 env_debugserver_log_file);
Zachary Turnerecbb0bb2016-09-19 17:54:06 +00001165 debugserver_args.AppendArgument(llvm::StringRef(arg_cstr));
Kate Stoneb9c1b512016-09-06 20:57:50 +00001166 }
1167
Vince Harron9753dd92015-05-10 15:22:09 +00001168#if defined(__APPLE__)
Kate Stoneb9c1b512016-09-06 20:57:50 +00001169 const char *env_debugserver_log_flags =
1170 getenv("LLDB_DEBUGSERVER_LOG_FLAGS");
1171 if (env_debugserver_log_flags) {
1172 ::snprintf(arg_cstr, sizeof(arg_cstr), "--log-flags=%s",
1173 env_debugserver_log_flags);
Sean Callanan1355f472016-09-19 22:06:12 +00001174 debugserver_args.AppendArgument(llvm::StringRef(arg_cstr));
Kate Stoneb9c1b512016-09-06 20:57:50 +00001175 }
Vince Harron9753dd92015-05-10 15:22:09 +00001176#else
Kate Stoneb9c1b512016-09-06 20:57:50 +00001177 const char *env_debugserver_log_channels =
1178 getenv("LLDB_SERVER_LOG_CHANNELS");
1179 if (env_debugserver_log_channels) {
1180 ::snprintf(arg_cstr, sizeof(arg_cstr), "--log-channels=%s",
1181 env_debugserver_log_channels);
Zachary Turnerecbb0bb2016-09-19 17:54:06 +00001182 debugserver_args.AppendArgument(llvm::StringRef(arg_cstr));
Kate Stoneb9c1b512016-09-06 20:57:50 +00001183 }
Vince Harron9753dd92015-05-10 15:22:09 +00001184#endif
Todd Fiala34ba4262014-08-29 17:10:31 +00001185
Kate Stoneb9c1b512016-09-06 20:57:50 +00001186 // Add additional args, starting with LLDB_DEBUGSERVER_EXTRA_ARG_1 until an
1187 // env var doesn't come back.
1188 uint32_t env_var_index = 1;
1189 bool has_env_var;
1190 do {
1191 char env_var_name[64];
1192 snprintf(env_var_name, sizeof(env_var_name),
1193 "LLDB_DEBUGSERVER_EXTRA_ARG_%" PRIu32, env_var_index++);
1194 const char *extra_arg = getenv(env_var_name);
1195 has_env_var = extra_arg != nullptr;
Todd Fiala34ba4262014-08-29 17:10:31 +00001196
Kate Stoneb9c1b512016-09-06 20:57:50 +00001197 if (has_env_var) {
Zachary Turnerecbb0bb2016-09-19 17:54:06 +00001198 debugserver_args.AppendArgument(llvm::StringRef(extra_arg));
Todd Fiala7aa4d972016-05-31 18:32:20 +00001199 if (log)
Kate Stoneb9c1b512016-09-06 20:57:50 +00001200 log->Printf("GDBRemoteCommunication::%s adding env var %s contents "
1201 "to stub command line (%s)",
1202 __FUNCTION__, env_var_name, extra_arg);
1203 }
1204 } while (has_env_var);
1205
1206 if (inferior_args && inferior_args->GetArgumentCount() > 0) {
Zachary Turnerecbb0bb2016-09-19 17:54:06 +00001207 debugserver_args.AppendArgument(llvm::StringRef("--"));
Kate Stoneb9c1b512016-09-06 20:57:50 +00001208 debugserver_args.AppendArguments(*inferior_args);
1209 }
1210
1211 // Copy the current environment to the gdbserver/debugserver instance
1212 StringList env;
1213 if (Host::GetEnvironment(env)) {
1214 for (size_t i = 0; i < env.GetSize(); ++i)
Zachary Turnerecbb0bb2016-09-19 17:54:06 +00001215 launch_info.GetEnvironmentEntries().AppendArgument(env[i]);
Kate Stoneb9c1b512016-09-06 20:57:50 +00001216 }
1217
1218 // Close STDIN, STDOUT and STDERR.
1219 launch_info.AppendCloseFileAction(STDIN_FILENO);
1220 launch_info.AppendCloseFileAction(STDOUT_FILENO);
1221 launch_info.AppendCloseFileAction(STDERR_FILENO);
1222
1223 // Redirect STDIN, STDOUT and STDERR to "/dev/null".
1224 launch_info.AppendSuppressFileAction(STDIN_FILENO, true, false);
1225 launch_info.AppendSuppressFileAction(STDOUT_FILENO, false, true);
1226 launch_info.AppendSuppressFileAction(STDERR_FILENO, false, true);
1227
1228 if (log) {
1229 StreamString string_stream;
1230 Platform *const platform = nullptr;
1231 launch_info.Dump(string_stream, platform);
1232 log->Printf("launch info for gdb-remote stub:\n%s",
Zachary Turnerc1564272016-11-16 21:15:24 +00001233 string_stream.GetData());
Kate Stoneb9c1b512016-09-06 20:57:50 +00001234 }
1235 error = Host::LaunchProcess(launch_info);
1236
1237 if (error.Success() &&
1238 (launch_info.GetProcessID() != LLDB_INVALID_PROCESS_ID) &&
1239 pass_comm_fd == -1) {
1240 if (named_pipe_path.size() > 0) {
1241 error = socket_pipe.OpenAsReader(named_pipe_path, false);
1242 if (error.Fail())
1243 if (log)
1244 log->Printf("GDBRemoteCommunication::%s() "
1245 "failed to open named pipe %s for reading: %s",
1246 __FUNCTION__, named_pipe_path.c_str(),
1247 error.AsCString());
1248 }
1249
1250 if (socket_pipe.CanWrite())
1251 socket_pipe.CloseWriteFileDescriptor();
1252 if (socket_pipe.CanRead()) {
1253 char port_cstr[PATH_MAX] = {0};
1254 port_cstr[0] = '\0';
1255 size_t num_bytes = sizeof(port_cstr);
1256 // Read port from pipe with 10 second timeout.
1257 error = socket_pipe.ReadWithTimeout(
1258 port_cstr, num_bytes, std::chrono::seconds{10}, num_bytes);
1259 if (error.Success() && (port != nullptr)) {
1260 assert(num_bytes > 0 && port_cstr[num_bytes - 1] == '\0');
1261 *port = StringConvert::ToUInt32(port_cstr, 0);
1262 if (log)
1263 log->Printf("GDBRemoteCommunication::%s() "
1264 "debugserver listens %u port",
1265 __FUNCTION__, *port);
1266 } else {
1267 if (log)
1268 log->Printf("GDBRemoteCommunication::%s() "
1269 "failed to read a port value from pipe %s: %s",
1270 __FUNCTION__, named_pipe_path.c_str(),
1271 error.AsCString());
Todd Fiala7aa4d972016-05-31 18:32:20 +00001272 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00001273 socket_pipe.Close();
1274 }
Chaoren Lin368c9f62015-04-27 23:20:30 +00001275
Kate Stoneb9c1b512016-09-06 20:57:50 +00001276 if (named_pipe_path.size() > 0) {
1277 const auto err = socket_pipe.Delete(named_pipe_path);
1278 if (err.Fail()) {
1279 if (log)
1280 log->Printf(
1281 "GDBRemoteCommunication::%s failed to delete pipe %s: %s",
1282 __FUNCTION__, named_pipe_path.c_str(), err.AsCString());
Greg Clayton00fe87b2013-12-05 22:58:22 +00001283 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00001284 }
1285
1286 // Make sure we actually connect with the debugserver...
1287 JoinListenThread();
Greg Clayton8b82f082011-04-12 05:54:46 +00001288 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00001289 } else {
1290 error.SetErrorStringWithFormat("unable to locate " DEBUGSERVER_BASENAME);
1291 }
Vince Harron8b335672015-05-12 01:10:56 +00001292
Kate Stoneb9c1b512016-09-06 20:57:50 +00001293 if (error.Fail()) {
1294 if (log)
1295 log->Printf("GDBRemoteCommunication::%s() failed: %s", __FUNCTION__,
1296 error.AsCString());
1297 }
Vince Harron8b335672015-05-12 01:10:56 +00001298
Kate Stoneb9c1b512016-09-06 20:57:50 +00001299 return error;
Greg Clayton8b82f082011-04-12 05:54:46 +00001300}
1301
Kate Stoneb9c1b512016-09-06 20:57:50 +00001302void GDBRemoteCommunication::DumpHistory(Stream &strm) { m_history.Dump(strm); }
1303
1304GDBRemoteCommunication::ScopedTimeout::ScopedTimeout(
Pavel Labath3aa04912016-10-31 17:19:42 +00001305 GDBRemoteCommunication &gdb_comm, std::chrono::seconds timeout)
Kate Stoneb9c1b512016-09-06 20:57:50 +00001306 : m_gdb_comm(gdb_comm) {
1307 m_saved_timeout = m_gdb_comm.SetPacketTimeout(timeout);
Greg Claytonc1422c12012-04-09 22:46:21 +00001308}
Tamas Berghammer912800c2015-02-24 10:23:39 +00001309
Kate Stoneb9c1b512016-09-06 20:57:50 +00001310GDBRemoteCommunication::ScopedTimeout::~ScopedTimeout() {
1311 m_gdb_comm.SetPacketTimeout(m_saved_timeout);
Tamas Berghammer912800c2015-02-24 10:23:39 +00001312}
1313
Kate Stoneb9c1b512016-09-06 20:57:50 +00001314// This function is called via the Communications class read thread when bytes
1315// become available
1316// for this connection. This function will consume all incoming bytes and try to
1317// parse whole
1318// packets as they become available. Full packets are placed in a queue, so that
1319// all packet
1320// requests can simply pop from this queue. Async notification packets will be
1321// dispatched
Ewan Crawfordfab40d32015-06-16 15:50:18 +00001322// immediately to the ProcessGDBRemote Async thread via an event.
Kate Stoneb9c1b512016-09-06 20:57:50 +00001323void GDBRemoteCommunication::AppendBytesToCache(const uint8_t *bytes,
1324 size_t len, bool broadcast,
1325 lldb::ConnectionStatus status) {
1326 StringExtractorGDBRemote packet;
Ewan Crawfordfab40d32015-06-16 15:50:18 +00001327
Kate Stoneb9c1b512016-09-06 20:57:50 +00001328 while (true) {
1329 PacketType type = CheckForPacket(bytes, len, packet);
Ewan Crawfordfab40d32015-06-16 15:50:18 +00001330
Kate Stoneb9c1b512016-09-06 20:57:50 +00001331 // scrub the data so we do not pass it back to CheckForPacket
1332 // on future passes of the loop
1333 bytes = nullptr;
1334 len = 0;
Ewan Crawfordfab40d32015-06-16 15:50:18 +00001335
Kate Stoneb9c1b512016-09-06 20:57:50 +00001336 // we may have received no packet so lets bail out
1337 if (type == PacketType::Invalid)
1338 break;
Ewan Crawfordfab40d32015-06-16 15:50:18 +00001339
Kate Stoneb9c1b512016-09-06 20:57:50 +00001340 if (type == PacketType::Standard) {
1341 // scope for the mutex
1342 {
1343 // lock down the packet queue
1344 std::lock_guard<std::mutex> guard(m_packet_queue_mutex);
1345 // push a new packet into the queue
1346 m_packet_queue.push(packet);
1347 // Signal condition variable that we have a packet
1348 m_condition_queue_not_empty.notify_one();
1349 }
Ewan Crawfordfab40d32015-06-16 15:50:18 +00001350 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00001351
1352 if (type == PacketType::Notify) {
1353 // put this packet into an event
1354 const char *pdata = packet.GetStringRef().c_str();
1355
1356 // as the communication class, we are a broadcaster and the
1357 // async thread is tuned to listen to us
1358 BroadcastEvent(eBroadcastBitGdbReadThreadGotNotify,
1359 new EventDataBytes(pdata));
1360 }
1361 }
Ewan Crawfordfab40d32015-06-16 15:50:18 +00001362}