blob: d94e0a414f76852ab234ed2a4df9da60c62a5604 [file] [log] [blame]
Greg Clayton576d8832011-03-22 04:00:09 +00001//===-- GDBRemoteCommunicationServer.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
Sylvestre Ledrud28b9932013-09-28 15:23:41 +000010#include <errno.h>
Greg Clayton576d8832011-03-22 04:00:09 +000011
12#include "GDBRemoteCommunicationServer.h"
Daniel Maleae0f8f572013-08-26 23:57:52 +000013#include "lldb/Core/StreamGDBRemote.h"
Greg Clayton576d8832011-03-22 04:00:09 +000014
15// C Includes
16// C++ Includes
17// Other libraries and framework includes
18#include "llvm/ADT/Triple.h"
19#include "lldb/Interpreter/Args.h"
20#include "lldb/Core/ConnectionFileDescriptor.h"
21#include "lldb/Core/Log.h"
22#include "lldb/Core/State.h"
23#include "lldb/Core/StreamString.h"
Enrico Granataf2bbf712011-07-15 02:26:42 +000024#include "lldb/Host/Endian.h"
Daniel Maleae0f8f572013-08-26 23:57:52 +000025#include "lldb/Host/File.h"
Greg Clayton576d8832011-03-22 04:00:09 +000026#include "lldb/Host/Host.h"
27#include "lldb/Host/TimeValue.h"
Greg Clayton8b82f082011-04-12 05:54:46 +000028#include "lldb/Target/Process.h"
Greg Clayton576d8832011-03-22 04:00:09 +000029
30// Project includes
31#include "Utility/StringExtractorGDBRemote.h"
32#include "ProcessGDBRemote.h"
33#include "ProcessGDBRemoteLog.h"
34
35using namespace lldb;
36using namespace lldb_private;
37
38//----------------------------------------------------------------------
39// GDBRemoteCommunicationServer constructor
40//----------------------------------------------------------------------
Greg Clayton8b82f082011-04-12 05:54:46 +000041GDBRemoteCommunicationServer::GDBRemoteCommunicationServer(bool is_platform) :
42 GDBRemoteCommunication ("gdb-remote.server", "gdb-remote.server.rx_packet", is_platform),
43 m_async_thread (LLDB_INVALID_HOST_THREAD),
44 m_process_launch_info (),
45 m_process_launch_error (),
Daniel Maleae0f8f572013-08-26 23:57:52 +000046 m_spawned_pids (),
47 m_spawned_pids_mutex (Mutex::eMutexTypeRecursive),
Greg Clayton8b82f082011-04-12 05:54:46 +000048 m_proc_infos (),
49 m_proc_infos_index (0),
Greg Clayton2b98c562013-11-22 18:53:12 +000050 m_port_map (),
51 m_port_offset(0)
Greg Clayton576d8832011-03-22 04:00:09 +000052{
53}
54
55//----------------------------------------------------------------------
56// Destructor
57//----------------------------------------------------------------------
58GDBRemoteCommunicationServer::~GDBRemoteCommunicationServer()
59{
60}
61
62
63//void *
64//GDBRemoteCommunicationServer::AsyncThread (void *arg)
65//{
66// GDBRemoteCommunicationServer *server = (GDBRemoteCommunicationServer*) arg;
67//
Greg Clayton5160ce52013-03-27 23:08:40 +000068// Log *log;// (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PROCESS));
Greg Clayton576d8832011-03-22 04:00:09 +000069// if (log)
70// log->Printf ("ProcessGDBRemote::%s (arg = %p, pid = %i) thread starting...", __FUNCTION__, arg, process->GetID());
71//
72// StringExtractorGDBRemote packet;
Sylvestre Ledrub027bd22013-09-28 14:35:00 +000073//
Greg Clayton576d8832011-03-22 04:00:09 +000074// while ()
75// {
76// if (packet.
77// }
78//
79// if (log)
80// log->Printf ("ProcessGDBRemote::%s (arg = %p, pid = %i) thread exiting...", __FUNCTION__, arg, process->GetID());
81//
82// process->m_async_thread = LLDB_INVALID_HOST_THREAD;
83// return NULL;
84//}
85//
86bool
Sylvestre Ledrub027bd22013-09-28 14:35:00 +000087GDBRemoteCommunicationServer::GetPacketAndSendResponse (uint32_t timeout_usec,
Greg Clayton1cb64962011-03-24 04:28:38 +000088 Error &error,
Sylvestre Ledrub027bd22013-09-28 14:35:00 +000089 bool &interrupt,
Greg Claytond314e812011-03-23 00:09:55 +000090 bool &quit)
Greg Clayton576d8832011-03-22 04:00:09 +000091{
92 StringExtractorGDBRemote packet;
Greg Clayton37a0a242012-04-11 00:24:49 +000093 if (WaitForPacketWithTimeoutMicroSecondsNoLock (packet, timeout_usec))
Greg Clayton576d8832011-03-22 04:00:09 +000094 {
95 const StringExtractorGDBRemote::ServerPacketType packet_type = packet.GetServerPacketType ();
96 switch (packet_type)
97 {
Greg Clayton8b82f082011-04-12 05:54:46 +000098 case StringExtractorGDBRemote::eServerPacketType_nack:
99 case StringExtractorGDBRemote::eServerPacketType_ack:
100 break;
Greg Clayton576d8832011-03-22 04:00:09 +0000101
Greg Clayton8b82f082011-04-12 05:54:46 +0000102 case StringExtractorGDBRemote::eServerPacketType_invalid:
103 error.SetErrorString("invalid packet");
104 quit = true;
105 break;
Greg Claytond314e812011-03-23 00:09:55 +0000106
Greg Clayton8b82f082011-04-12 05:54:46 +0000107 case StringExtractorGDBRemote::eServerPacketType_interrupt:
108 error.SetErrorString("interrupt received");
109 interrupt = true;
110 break;
Sylvestre Ledrub027bd22013-09-28 14:35:00 +0000111
Greg Clayton8b82f082011-04-12 05:54:46 +0000112 case StringExtractorGDBRemote::eServerPacketType_unimplemented:
113 return SendUnimplementedResponse (packet.GetStringRef().c_str()) > 0;
Greg Clayton576d8832011-03-22 04:00:09 +0000114
Greg Clayton8b82f082011-04-12 05:54:46 +0000115 case StringExtractorGDBRemote::eServerPacketType_A:
116 return Handle_A (packet);
Greg Clayton32e0a752011-03-30 18:16:51 +0000117
Greg Clayton8b82f082011-04-12 05:54:46 +0000118 case StringExtractorGDBRemote::eServerPacketType_qfProcessInfo:
119 return Handle_qfProcessInfo (packet);
Sylvestre Ledrub027bd22013-09-28 14:35:00 +0000120
Greg Clayton8b82f082011-04-12 05:54:46 +0000121 case StringExtractorGDBRemote::eServerPacketType_qsProcessInfo:
122 return Handle_qsProcessInfo (packet);
Sylvestre Ledrub027bd22013-09-28 14:35:00 +0000123
Greg Clayton8b82f082011-04-12 05:54:46 +0000124 case StringExtractorGDBRemote::eServerPacketType_qC:
125 return Handle_qC (packet);
Sylvestre Ledrub027bd22013-09-28 14:35:00 +0000126
Greg Clayton8b82f082011-04-12 05:54:46 +0000127 case StringExtractorGDBRemote::eServerPacketType_qHostInfo:
128 return Handle_qHostInfo (packet);
Sylvestre Ledrub027bd22013-09-28 14:35:00 +0000129
Greg Clayton8b82f082011-04-12 05:54:46 +0000130 case StringExtractorGDBRemote::eServerPacketType_qLaunchGDBServer:
131 return Handle_qLaunchGDBServer (packet);
Sylvestre Ledrub027bd22013-09-28 14:35:00 +0000132
Daniel Maleae0f8f572013-08-26 23:57:52 +0000133 case StringExtractorGDBRemote::eServerPacketType_qKillSpawnedProcess:
134 return Handle_qKillSpawnedProcess (packet);
Sylvestre Ledrub027bd22013-09-28 14:35:00 +0000135
Greg Clayton8b82f082011-04-12 05:54:46 +0000136 case StringExtractorGDBRemote::eServerPacketType_qLaunchSuccess:
137 return Handle_qLaunchSuccess (packet);
Sylvestre Ledrub027bd22013-09-28 14:35:00 +0000138
Greg Clayton8b82f082011-04-12 05:54:46 +0000139 case StringExtractorGDBRemote::eServerPacketType_qGroupName:
140 return Handle_qGroupName (packet);
Greg Clayton32e0a752011-03-30 18:16:51 +0000141
Greg Clayton8b82f082011-04-12 05:54:46 +0000142 case StringExtractorGDBRemote::eServerPacketType_qProcessInfoPID:
143 return Handle_qProcessInfoPID (packet);
Greg Clayton32e0a752011-03-30 18:16:51 +0000144
Greg Clayton8b82f082011-04-12 05:54:46 +0000145 case StringExtractorGDBRemote::eServerPacketType_qSpeedTest:
146 return Handle_qSpeedTest (packet);
Greg Clayton32e0a752011-03-30 18:16:51 +0000147
Greg Clayton8b82f082011-04-12 05:54:46 +0000148 case StringExtractorGDBRemote::eServerPacketType_qUserName:
149 return Handle_qUserName (packet);
Greg Clayton32e0a752011-03-30 18:16:51 +0000150
Greg Claytonfbb76342013-11-20 21:07:01 +0000151 case StringExtractorGDBRemote::eServerPacketType_qGetWorkingDir:
152 return Handle_qGetWorkingDir(packet);
153
Greg Clayton8b82f082011-04-12 05:54:46 +0000154 case StringExtractorGDBRemote::eServerPacketType_QEnvironment:
155 return Handle_QEnvironment (packet);
Sylvestre Ledrub027bd22013-09-28 14:35:00 +0000156
Daniel Maleae0f8f572013-08-26 23:57:52 +0000157 case StringExtractorGDBRemote::eServerPacketType_QLaunchArch:
158 return Handle_QLaunchArch (packet);
Sylvestre Ledrub027bd22013-09-28 14:35:00 +0000159
Greg Clayton8b82f082011-04-12 05:54:46 +0000160 case StringExtractorGDBRemote::eServerPacketType_QSetDisableASLR:
161 return Handle_QSetDisableASLR (packet);
Sylvestre Ledrub027bd22013-09-28 14:35:00 +0000162
Greg Clayton8b82f082011-04-12 05:54:46 +0000163 case StringExtractorGDBRemote::eServerPacketType_QSetSTDIN:
164 return Handle_QSetSTDIN (packet);
Sylvestre Ledrub027bd22013-09-28 14:35:00 +0000165
Greg Clayton8b82f082011-04-12 05:54:46 +0000166 case StringExtractorGDBRemote::eServerPacketType_QSetSTDOUT:
167 return Handle_QSetSTDOUT (packet);
Sylvestre Ledrub027bd22013-09-28 14:35:00 +0000168
Greg Clayton8b82f082011-04-12 05:54:46 +0000169 case StringExtractorGDBRemote::eServerPacketType_QSetSTDERR:
170 return Handle_QSetSTDERR (packet);
Sylvestre Ledrub027bd22013-09-28 14:35:00 +0000171
Greg Clayton8b82f082011-04-12 05:54:46 +0000172 case StringExtractorGDBRemote::eServerPacketType_QSetWorkingDir:
173 return Handle_QSetWorkingDir (packet);
174
175 case StringExtractorGDBRemote::eServerPacketType_QStartNoAckMode:
176 return Handle_QStartNoAckMode (packet);
Sylvestre Ledrub027bd22013-09-28 14:35:00 +0000177
Greg Claytonfbb76342013-11-20 21:07:01 +0000178 case StringExtractorGDBRemote::eServerPacketType_qPlatform_mkdir:
179 return Handle_qPlatform_mkdir (packet);
Sylvestre Ledrub027bd22013-09-28 14:35:00 +0000180
Greg Claytonfbb76342013-11-20 21:07:01 +0000181 case StringExtractorGDBRemote::eServerPacketType_qPlatform_chmod:
182 return Handle_qPlatform_chmod (packet);
Sylvestre Ledrub027bd22013-09-28 14:35:00 +0000183
Greg Claytonfbb76342013-11-20 21:07:01 +0000184 case StringExtractorGDBRemote::eServerPacketType_qPlatform_shell:
185 return Handle_qPlatform_shell (packet);
186
187 case StringExtractorGDBRemote::eServerPacketType_vFile_open:
Daniel Maleae0f8f572013-08-26 23:57:52 +0000188 return Handle_vFile_Open (packet);
Sylvestre Ledrub027bd22013-09-28 14:35:00 +0000189
Greg Claytonfbb76342013-11-20 21:07:01 +0000190 case StringExtractorGDBRemote::eServerPacketType_vFile_close:
Daniel Maleae0f8f572013-08-26 23:57:52 +0000191 return Handle_vFile_Close (packet);
Sylvestre Ledrub027bd22013-09-28 14:35:00 +0000192
Greg Claytonfbb76342013-11-20 21:07:01 +0000193 case StringExtractorGDBRemote::eServerPacketType_vFile_pread:
Daniel Maleae0f8f572013-08-26 23:57:52 +0000194 return Handle_vFile_pRead (packet);
Sylvestre Ledrub027bd22013-09-28 14:35:00 +0000195
Greg Claytonfbb76342013-11-20 21:07:01 +0000196 case StringExtractorGDBRemote::eServerPacketType_vFile_pwrite:
Daniel Maleae0f8f572013-08-26 23:57:52 +0000197 return Handle_vFile_pWrite (packet);
198
Greg Claytonfbb76342013-11-20 21:07:01 +0000199 case StringExtractorGDBRemote::eServerPacketType_vFile_size:
Daniel Maleae0f8f572013-08-26 23:57:52 +0000200 return Handle_vFile_Size (packet);
201
Greg Claytonfbb76342013-11-20 21:07:01 +0000202 case StringExtractorGDBRemote::eServerPacketType_vFile_mode:
Daniel Maleae0f8f572013-08-26 23:57:52 +0000203 return Handle_vFile_Mode (packet);
204
Greg Claytonfbb76342013-11-20 21:07:01 +0000205 case StringExtractorGDBRemote::eServerPacketType_vFile_exists:
Daniel Maleae0f8f572013-08-26 23:57:52 +0000206 return Handle_vFile_Exists (packet);
Sylvestre Ledrub027bd22013-09-28 14:35:00 +0000207
Greg Claytonfbb76342013-11-20 21:07:01 +0000208 case StringExtractorGDBRemote::eServerPacketType_vFile_stat:
Daniel Maleae0f8f572013-08-26 23:57:52 +0000209 return Handle_vFile_Stat (packet);
Sylvestre Ledrub027bd22013-09-28 14:35:00 +0000210
Greg Claytonfbb76342013-11-20 21:07:01 +0000211 case StringExtractorGDBRemote::eServerPacketType_vFile_md5:
Daniel Maleae0f8f572013-08-26 23:57:52 +0000212 return Handle_vFile_MD5 (packet);
Greg Claytonfbb76342013-11-20 21:07:01 +0000213
214 case StringExtractorGDBRemote::eServerPacketType_vFile_symlink:
215 return Handle_vFile_symlink (packet);
216
217 case StringExtractorGDBRemote::eServerPacketType_vFile_unlink:
218 return Handle_vFile_unlink (packet);
Greg Clayton576d8832011-03-22 04:00:09 +0000219 }
220 return true;
221 }
Greg Clayton1cb64962011-03-24 04:28:38 +0000222 else
223 {
224 if (!IsConnected())
225 error.SetErrorString("lost connection");
226 else
227 error.SetErrorString("timeout");
228 }
229
Greg Clayton576d8832011-03-22 04:00:09 +0000230 return false;
231}
232
233size_t
Greg Clayton32e0a752011-03-30 18:16:51 +0000234GDBRemoteCommunicationServer::SendUnimplementedResponse (const char *)
Greg Clayton576d8832011-03-22 04:00:09 +0000235{
Greg Clayton32e0a752011-03-30 18:16:51 +0000236 // TODO: Log the packet we aren't handling...
Greg Clayton37a0a242012-04-11 00:24:49 +0000237 return SendPacketNoLock ("", 0);
Greg Clayton576d8832011-03-22 04:00:09 +0000238}
239
Greg Clayton1cb64962011-03-24 04:28:38 +0000240size_t
Greg Clayton32e0a752011-03-30 18:16:51 +0000241GDBRemoteCommunicationServer::SendErrorResponse (uint8_t err)
242{
243 char packet[16];
244 int packet_len = ::snprintf (packet, sizeof(packet), "E%2.2x", err);
Andy Gibbsa297a972013-06-19 19:04:53 +0000245 assert (packet_len < (int)sizeof(packet));
Greg Clayton37a0a242012-04-11 00:24:49 +0000246 return SendPacketNoLock (packet, packet_len);
Greg Clayton32e0a752011-03-30 18:16:51 +0000247}
248
249
250size_t
Greg Clayton1cb64962011-03-24 04:28:38 +0000251GDBRemoteCommunicationServer::SendOKResponse ()
252{
Greg Clayton37a0a242012-04-11 00:24:49 +0000253 return SendPacketNoLock ("OK", 2);
Greg Clayton1cb64962011-03-24 04:28:38 +0000254}
255
256bool
257GDBRemoteCommunicationServer::HandshakeWithClient(Error *error_ptr)
258{
Greg Clayton73bf5db2011-06-17 01:22:15 +0000259 return GetAck();
Greg Clayton1cb64962011-03-24 04:28:38 +0000260}
Greg Clayton576d8832011-03-22 04:00:09 +0000261
262bool
Greg Clayton32e0a752011-03-30 18:16:51 +0000263GDBRemoteCommunicationServer::Handle_qHostInfo (StringExtractorGDBRemote &packet)
Greg Clayton576d8832011-03-22 04:00:09 +0000264{
265 StreamString response;
Sylvestre Ledrub027bd22013-09-28 14:35:00 +0000266
Greg Clayton576d8832011-03-22 04:00:09 +0000267 // $cputype:16777223;cpusubtype:3;ostype:Darwin;vendor:apple;endian:little;ptrsize:8;#00
268
269 ArchSpec host_arch (Host::GetArchitecture ());
Greg Clayton576d8832011-03-22 04:00:09 +0000270 const llvm::Triple &host_triple = host_arch.GetTriple();
Greg Clayton1cb64962011-03-24 04:28:38 +0000271 response.PutCString("triple:");
272 response.PutCStringAsRawHex8(host_triple.getTriple().c_str());
273 response.Printf (";ptrsize:%u;",host_arch.GetAddressByteSize());
Greg Clayton576d8832011-03-22 04:00:09 +0000274
Greg Clayton1cb64962011-03-24 04:28:38 +0000275 uint32_t cpu = host_arch.GetMachOCPUType();
276 uint32_t sub = host_arch.GetMachOCPUSubType();
277 if (cpu != LLDB_INVALID_CPUTYPE)
278 response.Printf ("cputype:%u;", cpu);
279 if (sub != LLDB_INVALID_CPUTYPE)
280 response.Printf ("cpusubtype:%u;", sub);
Sylvestre Ledrub027bd22013-09-28 14:35:00 +0000281
Enrico Granata1c5431a2012-07-13 23:55:22 +0000282 if (cpu == ArchSpec::kCore_arm_any)
Enrico Granataf04a2192012-07-13 23:18:48 +0000283 response.Printf("watchpoint_exceptions_received:before;"); // On armv7 we use "synchronous" watchpoints which means the exception is delivered before the instruction executes.
284 else
285 response.Printf("watchpoint_exceptions_received:after;");
Sylvestre Ledrub027bd22013-09-28 14:35:00 +0000286
Greg Clayton576d8832011-03-22 04:00:09 +0000287 switch (lldb::endian::InlHostByteOrder())
288 {
289 case eByteOrderBig: response.PutCString ("endian:big;"); break;
290 case eByteOrderLittle: response.PutCString ("endian:little;"); break;
291 case eByteOrderPDP: response.PutCString ("endian:pdp;"); break;
292 default: response.PutCString ("endian:unknown;"); break;
293 }
Sylvestre Ledrub027bd22013-09-28 14:35:00 +0000294
Greg Clayton1cb64962011-03-24 04:28:38 +0000295 uint32_t major = UINT32_MAX;
296 uint32_t minor = UINT32_MAX;
297 uint32_t update = UINT32_MAX;
298 if (Host::GetOSVersion (major, minor, update))
299 {
300 if (major != UINT32_MAX)
301 {
302 response.Printf("os_version:%u", major);
303 if (minor != UINT32_MAX)
304 {
305 response.Printf(".%u", minor);
306 if (update != UINT32_MAX)
307 response.Printf(".%u", update);
308 }
309 response.PutChar(';');
310 }
311 }
312
313 std::string s;
314 if (Host::GetOSBuildString (s))
315 {
316 response.PutCString ("os_build:");
317 response.PutCStringAsRawHex8(s.c_str());
318 response.PutChar(';');
319 }
320 if (Host::GetOSKernelDescription (s))
321 {
322 response.PutCString ("os_kernel:");
323 response.PutCStringAsRawHex8(s.c_str());
324 response.PutChar(';');
325 }
Greg Clayton2b98c562013-11-22 18:53:12 +0000326#if defined(__APPLE__)
327
328#if defined(__arm__)
329 // For iOS devices, we are connected through a USB Mux so we never pretend
330 // to actually have a hostname as far as the remote lldb that is connecting
331 // to this lldb-platform is concerned
332 response.PutCString ("hostname:");
333 response.PutCStringAsRawHex8("localhost");
334 response.PutChar(';');
335#else // #if defined(__arm__)
Greg Clayton1cb64962011-03-24 04:28:38 +0000336 if (Host::GetHostname (s))
337 {
338 response.PutCString ("hostname:");
339 response.PutCStringAsRawHex8(s.c_str());
340 response.PutChar(';');
341 }
Sylvestre Ledrub027bd22013-09-28 14:35:00 +0000342
Greg Clayton2b98c562013-11-22 18:53:12 +0000343#endif // #if defined(__arm__)
344
345#else // #if defined(__APPLE__)
346 if (Host::GetHostname (s))
347 {
348 response.PutCString ("hostname:");
349 response.PutCStringAsRawHex8(s.c_str());
350 response.PutChar(';');
351 }
352#endif // #if defined(__APPLE__)
353
Greg Clayton37a0a242012-04-11 00:24:49 +0000354 return SendPacketNoLock (response.GetData(), response.GetSize()) > 0;
Greg Clayton576d8832011-03-22 04:00:09 +0000355}
Greg Clayton1cb64962011-03-24 04:28:38 +0000356
Greg Clayton32e0a752011-03-30 18:16:51 +0000357static void
Greg Clayton8b82f082011-04-12 05:54:46 +0000358CreateProcessInfoResponse (const ProcessInstanceInfo &proc_info, StreamString &response)
Greg Clayton32e0a752011-03-30 18:16:51 +0000359{
Daniel Malead01b2952012-11-29 21:49:15 +0000360 response.Printf ("pid:%" PRIu64 ";ppid:%" PRIu64 ";uid:%i;gid:%i;euid:%i;egid:%i;",
Greg Clayton32e0a752011-03-30 18:16:51 +0000361 proc_info.GetProcessID(),
362 proc_info.GetParentProcessID(),
Greg Clayton8b82f082011-04-12 05:54:46 +0000363 proc_info.GetUserID(),
364 proc_info.GetGroupID(),
Greg Clayton32e0a752011-03-30 18:16:51 +0000365 proc_info.GetEffectiveUserID(),
366 proc_info.GetEffectiveGroupID());
367 response.PutCString ("name:");
368 response.PutCStringAsRawHex8(proc_info.GetName());
369 response.PutChar(';');
370 const ArchSpec &proc_arch = proc_info.GetArchitecture();
371 if (proc_arch.IsValid())
372 {
373 const llvm::Triple &proc_triple = proc_arch.GetTriple();
374 response.PutCString("triple:");
375 response.PutCStringAsRawHex8(proc_triple.getTriple().c_str());
376 response.PutChar(';');
377 }
378}
Greg Clayton1cb64962011-03-24 04:28:38 +0000379
380bool
Greg Clayton32e0a752011-03-30 18:16:51 +0000381GDBRemoteCommunicationServer::Handle_qProcessInfoPID (StringExtractorGDBRemote &packet)
Greg Clayton1cb64962011-03-24 04:28:38 +0000382{
Greg Clayton32e0a752011-03-30 18:16:51 +0000383 // Packet format: "qProcessInfoPID:%i" where %i is the pid
Greg Clayton8b82f082011-04-12 05:54:46 +0000384 packet.SetFilePos(::strlen ("qProcessInfoPID:"));
Greg Clayton32e0a752011-03-30 18:16:51 +0000385 lldb::pid_t pid = packet.GetU32 (LLDB_INVALID_PROCESS_ID);
386 if (pid != LLDB_INVALID_PROCESS_ID)
387 {
Greg Clayton8b82f082011-04-12 05:54:46 +0000388 ProcessInstanceInfo proc_info;
Greg Clayton32e0a752011-03-30 18:16:51 +0000389 if (Host::GetProcessInfo(pid, proc_info))
390 {
391 StreamString response;
392 CreateProcessInfoResponse (proc_info, response);
Greg Clayton37a0a242012-04-11 00:24:49 +0000393 return SendPacketNoLock (response.GetData(), response.GetSize());
Greg Clayton32e0a752011-03-30 18:16:51 +0000394 }
395 }
396 return SendErrorResponse (1);
397}
398
Sylvestre Ledrub027bd22013-09-28 14:35:00 +0000399bool
Greg Clayton32e0a752011-03-30 18:16:51 +0000400GDBRemoteCommunicationServer::Handle_qfProcessInfo (StringExtractorGDBRemote &packet)
401{
402 m_proc_infos_index = 0;
403 m_proc_infos.Clear();
404
Greg Clayton8b82f082011-04-12 05:54:46 +0000405 ProcessInstanceInfoMatch match_info;
406 packet.SetFilePos(::strlen ("qfProcessInfo"));
Greg Clayton32e0a752011-03-30 18:16:51 +0000407 if (packet.GetChar() == ':')
408 {
Sylvestre Ledrub027bd22013-09-28 14:35:00 +0000409
Greg Clayton32e0a752011-03-30 18:16:51 +0000410 std::string key;
411 std::string value;
412 while (packet.GetNameColonValue(key, value))
413 {
414 bool success = true;
415 if (key.compare("name") == 0)
416 {
417 StringExtractor extractor;
418 extractor.GetStringRef().swap(value);
419 extractor.GetHexByteString (value);
Greg Clayton144f3a92011-11-15 03:53:30 +0000420 match_info.GetProcessInfo().GetExecutableFile().SetFile(value.c_str(), false);
Greg Clayton32e0a752011-03-30 18:16:51 +0000421 }
422 else if (key.compare("name_match") == 0)
423 {
424 if (value.compare("equals") == 0)
425 {
426 match_info.SetNameMatchType (eNameMatchEquals);
427 }
428 else if (value.compare("starts_with") == 0)
429 {
430 match_info.SetNameMatchType (eNameMatchStartsWith);
431 }
432 else if (value.compare("ends_with") == 0)
433 {
434 match_info.SetNameMatchType (eNameMatchEndsWith);
435 }
436 else if (value.compare("contains") == 0)
437 {
438 match_info.SetNameMatchType (eNameMatchContains);
439 }
Sylvestre Ledrub027bd22013-09-28 14:35:00 +0000440 else if (value.compare("regex") == 0)
Greg Clayton32e0a752011-03-30 18:16:51 +0000441 {
442 match_info.SetNameMatchType (eNameMatchRegularExpression);
443 }
Sylvestre Ledrub027bd22013-09-28 14:35:00 +0000444 else
Greg Clayton32e0a752011-03-30 18:16:51 +0000445 {
446 success = false;
447 }
448 }
449 else if (key.compare("pid") == 0)
450 {
451 match_info.GetProcessInfo().SetProcessID (Args::StringToUInt32(value.c_str(), LLDB_INVALID_PROCESS_ID, 0, &success));
452 }
453 else if (key.compare("parent_pid") == 0)
454 {
455 match_info.GetProcessInfo().SetParentProcessID (Args::StringToUInt32(value.c_str(), LLDB_INVALID_PROCESS_ID, 0, &success));
456 }
457 else if (key.compare("uid") == 0)
458 {
Greg Clayton8b82f082011-04-12 05:54:46 +0000459 match_info.GetProcessInfo().SetUserID (Args::StringToUInt32(value.c_str(), UINT32_MAX, 0, &success));
Greg Clayton32e0a752011-03-30 18:16:51 +0000460 }
461 else if (key.compare("gid") == 0)
462 {
Greg Clayton8b82f082011-04-12 05:54:46 +0000463 match_info.GetProcessInfo().SetGroupID (Args::StringToUInt32(value.c_str(), UINT32_MAX, 0, &success));
Greg Clayton32e0a752011-03-30 18:16:51 +0000464 }
465 else if (key.compare("euid") == 0)
466 {
467 match_info.GetProcessInfo().SetEffectiveUserID (Args::StringToUInt32(value.c_str(), UINT32_MAX, 0, &success));
468 }
469 else if (key.compare("egid") == 0)
470 {
471 match_info.GetProcessInfo().SetEffectiveGroupID (Args::StringToUInt32(value.c_str(), UINT32_MAX, 0, &success));
472 }
473 else if (key.compare("all_users") == 0)
474 {
475 match_info.SetMatchAllUsers(Args::StringToBoolean(value.c_str(), false, &success));
476 }
477 else if (key.compare("triple") == 0)
478 {
Greg Claytoneb0103f2011-04-07 22:46:35 +0000479 match_info.GetProcessInfo().GetArchitecture().SetTriple (value.c_str(), NULL);
Greg Clayton32e0a752011-03-30 18:16:51 +0000480 }
481 else
482 {
483 success = false;
484 }
Sylvestre Ledrub027bd22013-09-28 14:35:00 +0000485
Greg Clayton32e0a752011-03-30 18:16:51 +0000486 if (!success)
487 return SendErrorResponse (2);
488 }
489 }
490
491 if (Host::FindProcesses (match_info, m_proc_infos))
492 {
493 // We found something, return the first item by calling the get
494 // subsequent process info packet handler...
495 return Handle_qsProcessInfo (packet);
496 }
497 return SendErrorResponse (3);
498}
499
Sylvestre Ledrub027bd22013-09-28 14:35:00 +0000500bool
Greg Clayton32e0a752011-03-30 18:16:51 +0000501GDBRemoteCommunicationServer::Handle_qsProcessInfo (StringExtractorGDBRemote &packet)
502{
503 if (m_proc_infos_index < m_proc_infos.GetSize())
504 {
505 StreamString response;
506 CreateProcessInfoResponse (m_proc_infos.GetProcessInfoAtIndex(m_proc_infos_index), response);
507 ++m_proc_infos_index;
Greg Clayton37a0a242012-04-11 00:24:49 +0000508 return SendPacketNoLock (response.GetData(), response.GetSize());
Greg Clayton32e0a752011-03-30 18:16:51 +0000509 }
510 return SendErrorResponse (4);
511}
512
Sylvestre Ledrub027bd22013-09-28 14:35:00 +0000513bool
Greg Clayton32e0a752011-03-30 18:16:51 +0000514GDBRemoteCommunicationServer::Handle_qUserName (StringExtractorGDBRemote &packet)
515{
516 // Packet format: "qUserName:%i" where %i is the uid
Greg Clayton8b82f082011-04-12 05:54:46 +0000517 packet.SetFilePos(::strlen ("qUserName:"));
Greg Clayton32e0a752011-03-30 18:16:51 +0000518 uint32_t uid = packet.GetU32 (UINT32_MAX);
519 if (uid != UINT32_MAX)
520 {
521 std::string name;
522 if (Host::GetUserName (uid, name))
523 {
524 StreamString response;
525 response.PutCStringAsRawHex8 (name.c_str());
Greg Clayton37a0a242012-04-11 00:24:49 +0000526 return SendPacketNoLock (response.GetData(), response.GetSize());
Greg Clayton32e0a752011-03-30 18:16:51 +0000527 }
528 }
529 return SendErrorResponse (5);
Sylvestre Ledrub027bd22013-09-28 14:35:00 +0000530
Greg Clayton32e0a752011-03-30 18:16:51 +0000531}
532
Sylvestre Ledrub027bd22013-09-28 14:35:00 +0000533bool
Greg Clayton32e0a752011-03-30 18:16:51 +0000534GDBRemoteCommunicationServer::Handle_qGroupName (StringExtractorGDBRemote &packet)
535{
536 // Packet format: "qGroupName:%i" where %i is the gid
Greg Clayton8b82f082011-04-12 05:54:46 +0000537 packet.SetFilePos(::strlen ("qGroupName:"));
Greg Clayton32e0a752011-03-30 18:16:51 +0000538 uint32_t gid = packet.GetU32 (UINT32_MAX);
539 if (gid != UINT32_MAX)
540 {
541 std::string name;
542 if (Host::GetGroupName (gid, name))
543 {
544 StreamString response;
545 response.PutCStringAsRawHex8 (name.c_str());
Greg Clayton37a0a242012-04-11 00:24:49 +0000546 return SendPacketNoLock (response.GetData(), response.GetSize());
Greg Clayton32e0a752011-03-30 18:16:51 +0000547 }
548 }
549 return SendErrorResponse (6);
550}
551
552bool
Greg Clayton9b1e1cd2011-04-04 18:18:57 +0000553GDBRemoteCommunicationServer::Handle_qSpeedTest (StringExtractorGDBRemote &packet)
554{
Greg Clayton8b82f082011-04-12 05:54:46 +0000555 packet.SetFilePos(::strlen ("qSpeedTest:"));
Greg Clayton9b1e1cd2011-04-04 18:18:57 +0000556
557 std::string key;
558 std::string value;
559 bool success = packet.GetNameColonValue(key, value);
560 if (success && key.compare("response_size") == 0)
561 {
562 uint32_t response_size = Args::StringToUInt32(value.c_str(), 0, 0, &success);
563 if (success)
564 {
565 if (response_size == 0)
566 return SendOKResponse();
567 StreamString response;
568 uint32_t bytes_left = response_size;
569 response.PutCString("data:");
570 while (bytes_left > 0)
571 {
572 if (bytes_left >= 26)
573 {
574 response.PutCString("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
575 bytes_left -= 26;
576 }
577 else
578 {
579 response.Printf ("%*.*s;", bytes_left, bytes_left, "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
580 bytes_left = 0;
581 }
582 }
Greg Clayton37a0a242012-04-11 00:24:49 +0000583 return SendPacketNoLock (response.GetData(), response.GetSize());
Greg Clayton9b1e1cd2011-04-04 18:18:57 +0000584 }
585 }
586 return SendErrorResponse (7);
587}
Greg Clayton8b82f082011-04-12 05:54:46 +0000588
589
590static void *
591AcceptPortFromInferior (void *arg)
592{
593 const char *connect_url = (const char *)arg;
594 ConnectionFileDescriptor file_conn;
595 Error error;
596 if (file_conn.Connect (connect_url, &error) == eConnectionStatusSuccess)
597 {
598 char pid_str[256];
599 ::memset (pid_str, 0, sizeof(pid_str));
600 ConnectionStatus status;
Bill Wendlinged24dcc2012-04-03 07:50:11 +0000601 const size_t pid_str_len = file_conn.Read (pid_str, sizeof(pid_str), 0, status, NULL);
Greg Clayton8b82f082011-04-12 05:54:46 +0000602 if (pid_str_len > 0)
603 {
604 int pid = atoi (pid_str);
605 return (void *)(intptr_t)pid;
606 }
607 }
608 return NULL;
609}
610//
611//static bool
612//WaitForProcessToSIGSTOP (const lldb::pid_t pid, const int timeout_in_seconds)
613//{
614// const int time_delta_usecs = 100000;
615// const int num_retries = timeout_in_seconds/time_delta_usecs;
616// for (int i=0; i<num_retries; i++)
617// {
618// struct proc_bsdinfo bsd_info;
Sylvestre Ledrub027bd22013-09-28 14:35:00 +0000619// int error = ::proc_pidinfo (pid, PROC_PIDTBSDINFO,
620// (uint64_t) 0,
621// &bsd_info,
Greg Clayton8b82f082011-04-12 05:54:46 +0000622// PROC_PIDTBSDINFO_SIZE);
Sylvestre Ledrub027bd22013-09-28 14:35:00 +0000623//
Greg Clayton8b82f082011-04-12 05:54:46 +0000624// switch (error)
625// {
626// case EINVAL:
627// case ENOTSUP:
628// case ESRCH:
629// case EPERM:
630// return false;
Sylvestre Ledrub027bd22013-09-28 14:35:00 +0000631//
Greg Clayton8b82f082011-04-12 05:54:46 +0000632// default:
633// break;
Sylvestre Ledrub027bd22013-09-28 14:35:00 +0000634//
Greg Clayton8b82f082011-04-12 05:54:46 +0000635// case 0:
636// if (bsd_info.pbi_status == SSTOP)
637// return true;
638// }
639// ::usleep (time_delta_usecs);
640// }
641// return false;
642//}
643
644bool
645GDBRemoteCommunicationServer::Handle_A (StringExtractorGDBRemote &packet)
646{
Sylvestre Ledrub027bd22013-09-28 14:35:00 +0000647 // The 'A' packet is the most over designed packet ever here with
648 // redundant argument indexes, redundant argument lengths and needed hex
649 // encoded argument string values. Really all that is needed is a comma
Greg Clayton8b82f082011-04-12 05:54:46 +0000650 // separated hex encoded argument value list, but we will stay true to the
651 // documented version of the 'A' packet here...
652
653 packet.SetFilePos(1); // Skip the 'A'
654 bool success = true;
655 while (success && packet.GetBytesLeft() > 0)
656 {
657 // Decode the decimal argument string length. This length is the
658 // number of hex nibbles in the argument string value.
659 const uint32_t arg_len = packet.GetU32(UINT32_MAX);
660 if (arg_len == UINT32_MAX)
661 success = false;
662 else
663 {
664 // Make sure the argument hex string length is followed by a comma
665 if (packet.GetChar() != ',')
666 success = false;
667 else
668 {
669 // Decode the argument index. We ignore this really becuase
670 // who would really send down the arguments in a random order???
671 const uint32_t arg_idx = packet.GetU32(UINT32_MAX);
672 if (arg_idx == UINT32_MAX)
673 success = false;
674 else
675 {
676 // Make sure the argument index is followed by a comma
677 if (packet.GetChar() != ',')
678 success = false;
679 else
680 {
681 // Decode the argument string value from hex bytes
682 // back into a UTF8 string and make sure the length
683 // matches the one supplied in the packet
684 std::string arg;
685 if (packet.GetHexByteString(arg) != (arg_len / 2))
686 success = false;
687 else
688 {
689 // If there are any bytes lft
690 if (packet.GetBytesLeft())
691 {
692 if (packet.GetChar() != ',')
693 success = false;
694 }
Sylvestre Ledrub027bd22013-09-28 14:35:00 +0000695
Greg Clayton8b82f082011-04-12 05:54:46 +0000696 if (success)
697 {
698 if (arg_idx == 0)
699 m_process_launch_info.GetExecutableFile().SetFile(arg.c_str(), false);
700 m_process_launch_info.GetArguments().AppendArgument(arg.c_str());
701 }
702 }
703 }
704 }
705 }
706 }
707 }
708
709 if (success)
710 {
711 m_process_launch_info.GetFlags().Set (eLaunchFlagDebug);
712 m_process_launch_error = Host::LaunchProcess (m_process_launch_info);
713 if (m_process_launch_info.GetProcessID() != LLDB_INVALID_PROCESS_ID)
714 {
715 return SendOKResponse ();
716 }
717 }
718 return SendErrorResponse (8);
719}
720
721bool
722GDBRemoteCommunicationServer::Handle_qC (StringExtractorGDBRemote &packet)
723{
724 lldb::pid_t pid = m_process_launch_info.GetProcessID();
725 StreamString response;
Daniel Malead01b2952012-11-29 21:49:15 +0000726 response.Printf("QC%" PRIx64, pid);
Greg Clayton8b82f082011-04-12 05:54:46 +0000727 if (m_is_platform)
728 {
Sylvestre Ledrub027bd22013-09-28 14:35:00 +0000729 // If we launch a process and this GDB server is acting as a platform,
730 // then we need to clear the process launch state so we can start
Greg Clayton8b82f082011-04-12 05:54:46 +0000731 // launching another process. In order to launch a process a bunch or
732 // packets need to be sent: environment packets, working directory,
Sylvestre Ledrub027bd22013-09-28 14:35:00 +0000733 // disable ASLR, and many more settings. When we launch a process we
Greg Clayton8b82f082011-04-12 05:54:46 +0000734 // then need to know when to clear this information. Currently we are
735 // selecting the 'qC' packet as that packet which seems to make the most
736 // sense.
737 if (pid != LLDB_INVALID_PROCESS_ID)
738 {
739 m_process_launch_info.Clear();
740 }
741 }
Greg Clayton37a0a242012-04-11 00:24:49 +0000742 return SendPacketNoLock (response.GetData(), response.GetSize());
Greg Clayton8b82f082011-04-12 05:54:46 +0000743}
744
745bool
Daniel Maleae0f8f572013-08-26 23:57:52 +0000746GDBRemoteCommunicationServer::DebugserverProcessReaped (lldb::pid_t pid)
747{
748 Mutex::Locker locker (m_spawned_pids_mutex);
Greg Clayton29b8fc42013-11-21 01:44:58 +0000749 FreePortForProcess(pid);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000750 return m_spawned_pids.erase(pid) > 0;
751}
752bool
753GDBRemoteCommunicationServer::ReapDebugserverProcess (void *callback_baton,
754 lldb::pid_t pid,
755 bool exited,
756 int signal, // Zero for no signal
757 int status) // Exit value of process if signal is zero
758{
759 GDBRemoteCommunicationServer *server = (GDBRemoteCommunicationServer *)callback_baton;
760 server->DebugserverProcessReaped (pid);
761 return true;
762}
763
764bool
Greg Clayton8b82f082011-04-12 05:54:46 +0000765GDBRemoteCommunicationServer::Handle_qLaunchGDBServer (StringExtractorGDBRemote &packet)
766{
Virgile Bellob2f1fb22013-08-23 12:44:05 +0000767#ifdef _WIN32
768 // No unix sockets on windows
769 return false;
770#else
Greg Clayton8b82f082011-04-12 05:54:46 +0000771 // Spawn a local debugserver as a platform so we can then attach or launch
772 // a process...
773
774 if (m_is_platform)
775 {
776 // Sleep and wait a bit for debugserver to start to listen...
777 ConnectionFileDescriptor file_conn;
Greg Clayton8b82f082011-04-12 05:54:46 +0000778 Error error;
Daniel Maleae0f8f572013-08-26 23:57:52 +0000779 std::string hostname;
Sylvestre Ledrufaa63ce2013-09-28 15:57:37 +0000780 // TODO: /tmp/ should not be hardcoded. User might want to override /tmp
781 // with the TMPDIR environnement variable
Greg Clayton29b8fc42013-11-21 01:44:58 +0000782 packet.SetFilePos(::strlen ("qLaunchGDBServer;"));
783 std::string name;
784 std::string value;
785 uint16_t port = UINT16_MAX;
786 while (packet.GetNameColonValue(name, value))
Greg Clayton8b82f082011-04-12 05:54:46 +0000787 {
Greg Clayton29b8fc42013-11-21 01:44:58 +0000788 if (name.compare ("host") == 0)
789 hostname.swap(value);
790 else if (name.compare ("port") == 0)
791 port = Args::StringToUInt32(value.c_str(), 0, 0);
Greg Clayton8b82f082011-04-12 05:54:46 +0000792 }
Greg Clayton29b8fc42013-11-21 01:44:58 +0000793 if (port == UINT16_MAX)
794 port = GetNextAvailablePort();
795
796 // Spawn a new thread to accept the port that gets bound after
797 // binding to port 0 (zero).
Greg Claytonfbb76342013-11-20 21:07:01 +0000798
Greg Clayton29b8fc42013-11-21 01:44:58 +0000799 if (error.Success())
800 {
801 // Spawn a debugserver and try to get the port it listens to.
802 ProcessLaunchInfo debugserver_launch_info;
803 StreamString host_and_port;
804 if (hostname.empty())
805 hostname = "localhost";
806 host_and_port.Printf("%s:%u", hostname.c_str(), port);
807 const char *host_and_port_cstr = host_and_port.GetString().c_str();
808 Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PLATFORM));
809 if (log)
810 log->Printf("Launching debugserver with: %s...\n", host_and_port_cstr);
Sylvestre Ledrub027bd22013-09-28 14:35:00 +0000811
Greg Clayton29b8fc42013-11-21 01:44:58 +0000812 debugserver_launch_info.SetMonitorProcessCallback(ReapDebugserverProcess, this, false);
813
Greg Clayton91a9b2472013-12-04 19:19:12 +0000814 error = GDBRemoteCommunication::StartDebugserverProcess (host_and_port_cstr,
815 debugserver_launch_info,
816 port);
Greg Clayton29b8fc42013-11-21 01:44:58 +0000817
818 lldb::pid_t debugserver_pid = debugserver_launch_info.GetProcessID();
Sylvestre Ledrub027bd22013-09-28 14:35:00 +0000819
Greg Claytonfbb76342013-11-20 21:07:01 +0000820
Greg Clayton29b8fc42013-11-21 01:44:58 +0000821 if (debugserver_pid != LLDB_INVALID_PROCESS_ID)
822 {
823 Mutex::Locker locker (m_spawned_pids_mutex);
824 m_spawned_pids.insert(debugserver_pid);
825 if (port > 0)
826 AssociatePortWithProcess(port, debugserver_pid);
827 }
828 else
829 {
830 if (port > 0)
831 FreePort (port);
832 }
833
834 if (error.Success())
835 {
836 bool success = false;
837
Greg Clayton91a9b2472013-12-04 19:19:12 +0000838 char response[256];
839 const int response_len = ::snprintf (response, sizeof(response), "pid:%" PRIu64 ";port:%u;", debugserver_pid, port + m_port_offset);
840 assert (response_len < sizeof(response));
841 success = SendPacketNoLock (response, response_len) > 0;
Greg Clayton29b8fc42013-11-21 01:44:58 +0000842
843 if (!success)
844 {
845 if (debugserver_pid != LLDB_INVALID_PROCESS_ID)
846 ::kill (debugserver_pid, SIGINT);
847 }
848 return success;
849 }
Greg Clayton8b82f082011-04-12 05:54:46 +0000850 }
851 }
Daniel Maleae0f8f572013-08-26 23:57:52 +0000852 return SendErrorResponse (9);
Virgile Bellob2f1fb22013-08-23 12:44:05 +0000853#endif
Greg Clayton8b82f082011-04-12 05:54:46 +0000854}
855
856bool
Daniel Maleae0f8f572013-08-26 23:57:52 +0000857GDBRemoteCommunicationServer::Handle_qKillSpawnedProcess (StringExtractorGDBRemote &packet)
858{
859 // Spawn a local debugserver as a platform so we can then attach or launch
860 // a process...
Sylvestre Ledrub027bd22013-09-28 14:35:00 +0000861
Daniel Maleae0f8f572013-08-26 23:57:52 +0000862 if (m_is_platform)
863 {
864 packet.SetFilePos(::strlen ("qKillSpawnedProcess:"));
Sylvestre Ledrub027bd22013-09-28 14:35:00 +0000865
Daniel Maleae0f8f572013-08-26 23:57:52 +0000866 lldb::pid_t pid = packet.GetU64(LLDB_INVALID_PROCESS_ID);
867
868 // Scope for locker
869 {
870 Mutex::Locker locker (m_spawned_pids_mutex);
871 if (m_spawned_pids.find(pid) == m_spawned_pids.end())
872 return SendErrorResponse (10);
873 }
Virgile Belloae12a362013-08-27 16:21:49 +0000874 Host::Kill (pid, SIGTERM);
Sylvestre Ledrub027bd22013-09-28 14:35:00 +0000875
Daniel Maleae0f8f572013-08-26 23:57:52 +0000876 for (size_t i=0; i<10; ++i)
877 {
878 // Scope for locker
879 {
880 Mutex::Locker locker (m_spawned_pids_mutex);
881 if (m_spawned_pids.find(pid) == m_spawned_pids.end())
Greg Clayton2b98c562013-11-22 18:53:12 +0000882 return SendOKResponse();
Daniel Maleae0f8f572013-08-26 23:57:52 +0000883 }
884 usleep (10000);
885 }
886
887 // Scope for locker
888 {
889 Mutex::Locker locker (m_spawned_pids_mutex);
890 if (m_spawned_pids.find(pid) == m_spawned_pids.end())
Greg Clayton2b98c562013-11-22 18:53:12 +0000891 return SendOKResponse();
Daniel Maleae0f8f572013-08-26 23:57:52 +0000892 }
Virgile Belloae12a362013-08-27 16:21:49 +0000893 Host::Kill (pid, SIGKILL);
Sylvestre Ledrub027bd22013-09-28 14:35:00 +0000894
Daniel Maleae0f8f572013-08-26 23:57:52 +0000895 for (size_t i=0; i<10; ++i)
896 {
897 // Scope for locker
898 {
899 Mutex::Locker locker (m_spawned_pids_mutex);
900 if (m_spawned_pids.find(pid) == m_spawned_pids.end())
Greg Clayton2b98c562013-11-22 18:53:12 +0000901 return SendOKResponse();
Daniel Maleae0f8f572013-08-26 23:57:52 +0000902 }
903 usleep (10000);
904 }
905 }
Greg Clayton2b98c562013-11-22 18:53:12 +0000906 return SendErrorResponse (11);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000907}
908
909bool
Greg Clayton8b82f082011-04-12 05:54:46 +0000910GDBRemoteCommunicationServer::Handle_qLaunchSuccess (StringExtractorGDBRemote &packet)
911{
912 if (m_process_launch_error.Success())
913 return SendOKResponse();
Sylvestre Ledrub027bd22013-09-28 14:35:00 +0000914 StreamString response;
Greg Clayton8b82f082011-04-12 05:54:46 +0000915 response.PutChar('E');
916 response.PutCString(m_process_launch_error.AsCString("<unknown error>"));
Greg Clayton37a0a242012-04-11 00:24:49 +0000917 return SendPacketNoLock (response.GetData(), response.GetSize());
Greg Clayton8b82f082011-04-12 05:54:46 +0000918}
919
920bool
921GDBRemoteCommunicationServer::Handle_QEnvironment (StringExtractorGDBRemote &packet)
922{
923 packet.SetFilePos(::strlen ("QEnvironment:"));
924 const uint32_t bytes_left = packet.GetBytesLeft();
925 if (bytes_left > 0)
926 {
927 m_process_launch_info.GetEnvironmentEntries ().AppendArgument (packet.Peek());
928 return SendOKResponse ();
929 }
Greg Clayton2b98c562013-11-22 18:53:12 +0000930 return SendErrorResponse (12);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000931}
932
933bool
934GDBRemoteCommunicationServer::Handle_QLaunchArch (StringExtractorGDBRemote &packet)
935{
936 packet.SetFilePos(::strlen ("QLaunchArch:"));
937 const uint32_t bytes_left = packet.GetBytesLeft();
938 if (bytes_left > 0)
939 {
940 const char* arch_triple = packet.Peek();
941 ArchSpec arch_spec(arch_triple,NULL);
942 m_process_launch_info.SetArchitecture(arch_spec);
943 return SendOKResponse();
944 }
Greg Clayton2b98c562013-11-22 18:53:12 +0000945 return SendErrorResponse(13);
Greg Clayton8b82f082011-04-12 05:54:46 +0000946}
947
948bool
949GDBRemoteCommunicationServer::Handle_QSetDisableASLR (StringExtractorGDBRemote &packet)
950{
951 packet.SetFilePos(::strlen ("QSetDisableASLR:"));
952 if (packet.GetU32(0))
953 m_process_launch_info.GetFlags().Set (eLaunchFlagDisableASLR);
954 else
955 m_process_launch_info.GetFlags().Clear (eLaunchFlagDisableASLR);
956 return SendOKResponse ();
957}
958
959bool
960GDBRemoteCommunicationServer::Handle_QSetWorkingDir (StringExtractorGDBRemote &packet)
961{
962 packet.SetFilePos(::strlen ("QSetWorkingDir:"));
963 std::string path;
964 packet.GetHexByteString(path);
Greg Claytonfbb76342013-11-20 21:07:01 +0000965 if (m_is_platform)
966 {
Colin Riley909bb7a2013-11-26 15:10:46 +0000967#ifdef _WIN32
968 // Not implemented on Windows
969 return SendUnimplementedResponse("GDBRemoteCommunicationServer::Handle_QSetWorkingDir unimplemented");
970#else
Greg Claytonfbb76342013-11-20 21:07:01 +0000971 // If this packet is sent to a platform, then change the current working directory
972 if (::chdir(path.c_str()) != 0)
973 return SendErrorResponse(errno);
Colin Riley909bb7a2013-11-26 15:10:46 +0000974#endif
Greg Claytonfbb76342013-11-20 21:07:01 +0000975 }
976 else
977 {
978 m_process_launch_info.SwapWorkingDirectory (path);
979 }
Greg Clayton8b82f082011-04-12 05:54:46 +0000980 return SendOKResponse ();
981}
982
983bool
Greg Claytonfbb76342013-11-20 21:07:01 +0000984GDBRemoteCommunicationServer::Handle_qGetWorkingDir (StringExtractorGDBRemote &packet)
985{
986 StreamString response;
987
988 if (m_is_platform)
989 {
990 // If this packet is sent to a platform, then change the current working directory
991 char cwd[PATH_MAX];
992 if (getcwd(cwd, sizeof(cwd)) == NULL)
993 {
994 return SendErrorResponse(errno);
995 }
996 else
997 {
998 response.PutBytesAsRawHex8(cwd, strlen(cwd));
999 SendPacketNoLock(response.GetData(), response.GetSize());
1000 return true;
1001 }
1002 }
1003 else
1004 {
1005 const char *working_dir = m_process_launch_info.GetWorkingDirectory();
1006 if (working_dir && working_dir[0])
1007 {
1008 response.PutBytesAsRawHex8(working_dir, strlen(working_dir));
1009 SendPacketNoLock(response.GetData(), response.GetSize());
1010 return true;
1011 }
1012 else
1013 {
Greg Clayton2b98c562013-11-22 18:53:12 +00001014 return SendErrorResponse(14);
Greg Claytonfbb76342013-11-20 21:07:01 +00001015 }
1016 }
1017}
1018
1019bool
Greg Clayton8b82f082011-04-12 05:54:46 +00001020GDBRemoteCommunicationServer::Handle_QSetSTDIN (StringExtractorGDBRemote &packet)
1021{
1022 packet.SetFilePos(::strlen ("QSetSTDIN:"));
1023 ProcessLaunchInfo::FileAction file_action;
1024 std::string path;
1025 packet.GetHexByteString(path);
1026 const bool read = false;
1027 const bool write = true;
1028 if (file_action.Open(STDIN_FILENO, path.c_str(), read, write))
1029 {
1030 m_process_launch_info.AppendFileAction(file_action);
1031 return SendOKResponse ();
1032 }
Greg Clayton2b98c562013-11-22 18:53:12 +00001033 return SendErrorResponse (15);
Greg Clayton8b82f082011-04-12 05:54:46 +00001034}
1035
1036bool
1037GDBRemoteCommunicationServer::Handle_QSetSTDOUT (StringExtractorGDBRemote &packet)
1038{
1039 packet.SetFilePos(::strlen ("QSetSTDOUT:"));
1040 ProcessLaunchInfo::FileAction file_action;
1041 std::string path;
1042 packet.GetHexByteString(path);
1043 const bool read = true;
1044 const bool write = false;
1045 if (file_action.Open(STDOUT_FILENO, path.c_str(), read, write))
1046 {
1047 m_process_launch_info.AppendFileAction(file_action);
1048 return SendOKResponse ();
1049 }
Greg Clayton2b98c562013-11-22 18:53:12 +00001050 return SendErrorResponse (16);
Greg Clayton8b82f082011-04-12 05:54:46 +00001051}
1052
1053bool
1054GDBRemoteCommunicationServer::Handle_QSetSTDERR (StringExtractorGDBRemote &packet)
1055{
1056 packet.SetFilePos(::strlen ("QSetSTDERR:"));
1057 ProcessLaunchInfo::FileAction file_action;
1058 std::string path;
1059 packet.GetHexByteString(path);
1060 const bool read = true;
Greg Clayton9845a8d2012-03-06 04:01:04 +00001061 const bool write = false;
Greg Clayton8b82f082011-04-12 05:54:46 +00001062 if (file_action.Open(STDERR_FILENO, path.c_str(), read, write))
1063 {
1064 m_process_launch_info.AppendFileAction(file_action);
1065 return SendOKResponse ();
1066 }
Greg Clayton2b98c562013-11-22 18:53:12 +00001067 return SendErrorResponse (17);
Greg Clayton8b82f082011-04-12 05:54:46 +00001068}
1069
Greg Clayton9b1e1cd2011-04-04 18:18:57 +00001070bool
Greg Clayton32e0a752011-03-30 18:16:51 +00001071GDBRemoteCommunicationServer::Handle_QStartNoAckMode (StringExtractorGDBRemote &packet)
1072{
1073 // Send response first before changing m_send_acks to we ack this packet
Greg Clayton1cb64962011-03-24 04:28:38 +00001074 SendOKResponse ();
1075 m_send_acks = false;
1076 return true;
1077}
Daniel Maleae0f8f572013-08-26 23:57:52 +00001078
1079bool
Greg Claytonfbb76342013-11-20 21:07:01 +00001080GDBRemoteCommunicationServer::Handle_qPlatform_mkdir (StringExtractorGDBRemote &packet)
Daniel Maleae0f8f572013-08-26 23:57:52 +00001081{
Greg Claytonfbb76342013-11-20 21:07:01 +00001082 packet.SetFilePos(::strlen("qPlatform_mkdir:"));
Daniel Maleae0f8f572013-08-26 23:57:52 +00001083 mode_t mode = packet.GetHexMaxU32(false, UINT32_MAX);
Greg Clayton2b98c562013-11-22 18:53:12 +00001084 if (packet.GetChar() == ',')
1085 {
1086 std::string path;
1087 packet.GetHexByteString(path);
1088 Error error = Host::MakeDirectory(path.c_str(),mode);
1089 if (error.Success())
1090 return SendPacketNoLock ("OK", 2);
1091 else
1092 return SendErrorResponse(error.GetError());
1093 }
1094 return SendErrorResponse(20);
Greg Claytonfbb76342013-11-20 21:07:01 +00001095}
1096
1097bool
1098GDBRemoteCommunicationServer::Handle_qPlatform_chmod (StringExtractorGDBRemote &packet)
1099{
1100 packet.SetFilePos(::strlen("qPlatform_chmod:"));
1101
1102 mode_t mode = packet.GetHexMaxU32(false, UINT32_MAX);
Greg Clayton2b98c562013-11-22 18:53:12 +00001103 if (packet.GetChar() == ',')
1104 {
1105 std::string path;
1106 packet.GetHexByteString(path);
1107 Error error = Host::SetFilePermissions (path.c_str(), mode);
1108 if (error.Success())
1109 return SendPacketNoLock ("OK", 2);
1110 else
1111 return SendErrorResponse(error.GetError());
1112 }
1113 return SendErrorResponse(19);
Daniel Maleae0f8f572013-08-26 23:57:52 +00001114}
1115
1116bool
1117GDBRemoteCommunicationServer::Handle_vFile_Open (StringExtractorGDBRemote &packet)
1118{
1119 packet.SetFilePos(::strlen("vFile:open:"));
1120 std::string path;
1121 packet.GetHexByteStringTerminatedBy(path,',');
Greg Clayton2b98c562013-11-22 18:53:12 +00001122 if (!path.empty())
1123 {
1124 if (packet.GetChar() == ',')
1125 {
1126 uint32_t flags = packet.GetHexMaxU32(false, 0);
1127 if (packet.GetChar() == ',')
1128 {
1129 mode_t mode = packet.GetHexMaxU32(false, 0600);
1130 Error error;
1131 int fd = ::open (path.c_str(), flags, mode);
1132 printf ("open('%s', flags=0x%x, mode=%o) fd = %i (%s)\n", path.c_str(), flags, mode, fd, fd == -1 ? strerror(errno) : "<success>");
1133 const int save_errno = fd == -1 ? errno : 0;
1134 StreamString response;
1135 response.PutChar('F');
1136 response.Printf("%i", fd);
1137 if (save_errno)
1138 response.Printf(",%i", save_errno);
1139 return SendPacketNoLock(response.GetData(), response.GetSize());
1140 }
1141 }
1142 }
1143 return SendErrorResponse(18);
Daniel Maleae0f8f572013-08-26 23:57:52 +00001144}
1145
1146bool
1147GDBRemoteCommunicationServer::Handle_vFile_Close (StringExtractorGDBRemote &packet)
1148{
1149 packet.SetFilePos(::strlen("vFile:close:"));
1150 int fd = packet.GetS32(-1);
1151 Error error;
1152 int err = -1;
1153 int save_errno = 0;
1154 if (fd >= 0)
1155 {
1156 err = close(fd);
1157 save_errno = err == -1 ? errno : 0;
1158 }
1159 else
1160 {
1161 save_errno = EINVAL;
1162 }
1163 StreamString response;
1164 response.PutChar('F');
1165 response.Printf("%i", err);
1166 if (save_errno)
1167 response.Printf(",%i", save_errno);
Greg Clayton2b98c562013-11-22 18:53:12 +00001168 return SendPacketNoLock(response.GetData(), response.GetSize());
Daniel Maleae0f8f572013-08-26 23:57:52 +00001169}
1170
1171bool
1172GDBRemoteCommunicationServer::Handle_vFile_pRead (StringExtractorGDBRemote &packet)
1173{
Virgile Belloae12a362013-08-27 16:21:49 +00001174#ifdef _WIN32
1175 // Not implemented on Windows
Greg Clayton2b98c562013-11-22 18:53:12 +00001176 return SendUnimplementedResponse("GDBRemoteCommunicationServer::Handle_vFile_pRead() unimplemented");
Virgile Belloae12a362013-08-27 16:21:49 +00001177#else
Daniel Maleae0f8f572013-08-26 23:57:52 +00001178 StreamGDBRemote response;
1179 packet.SetFilePos(::strlen("vFile:pread:"));
1180 int fd = packet.GetS32(-1);
Greg Clayton2b98c562013-11-22 18:53:12 +00001181 if (packet.GetChar() == ',')
Daniel Maleae0f8f572013-08-26 23:57:52 +00001182 {
Greg Clayton2b98c562013-11-22 18:53:12 +00001183 uint64_t count = packet.GetU64(UINT64_MAX);
1184 if (packet.GetChar() == ',')
1185 {
1186 uint64_t offset = packet.GetU64(UINT32_MAX);
1187 if (count == UINT64_MAX)
1188 {
1189 response.Printf("F-1:%i", EINVAL);
1190 return SendPacketNoLock(response.GetData(), response.GetSize());
1191 }
1192
1193 std::string buffer(count, 0);
1194 const ssize_t bytes_read = ::pread (fd, &buffer[0], buffer.size(), offset);
1195 const int save_errno = bytes_read == -1 ? errno : 0;
1196 response.PutChar('F');
1197 response.Printf("%zi", bytes_read);
1198 if (save_errno)
1199 response.Printf(",%i", save_errno);
1200 else
1201 {
1202 response.PutChar(';');
1203 response.PutEscapedBytes(&buffer[0], bytes_read);
1204 }
1205 return SendPacketNoLock(response.GetData(), response.GetSize());
1206 }
Daniel Maleae0f8f572013-08-26 23:57:52 +00001207 }
Greg Clayton2b98c562013-11-22 18:53:12 +00001208 return SendErrorResponse(21);
1209
Virgile Belloae12a362013-08-27 16:21:49 +00001210#endif
Daniel Maleae0f8f572013-08-26 23:57:52 +00001211}
1212
1213bool
1214GDBRemoteCommunicationServer::Handle_vFile_pWrite (StringExtractorGDBRemote &packet)
1215{
Virgile Belloae12a362013-08-27 16:21:49 +00001216#ifdef _WIN32
Greg Clayton2b98c562013-11-22 18:53:12 +00001217 return SendUnimplementedResponse("GDBRemoteCommunicationServer::Handle_vFile_pWrite() unimplemented");
Virgile Belloae12a362013-08-27 16:21:49 +00001218#else
Daniel Maleae0f8f572013-08-26 23:57:52 +00001219 packet.SetFilePos(::strlen("vFile:pwrite:"));
1220
1221 StreamGDBRemote response;
1222 response.PutChar('F');
1223
1224 int fd = packet.GetU32(UINT32_MAX);
Greg Clayton2b98c562013-11-22 18:53:12 +00001225 if (packet.GetChar() == ',')
Daniel Maleae0f8f572013-08-26 23:57:52 +00001226 {
Greg Clayton2b98c562013-11-22 18:53:12 +00001227 off_t offset = packet.GetU64(UINT32_MAX);
1228 if (packet.GetChar() == ',')
1229 {
1230 std::string buffer;
1231 if (packet.GetEscapedBinaryData(buffer))
1232 {
1233 const ssize_t bytes_written = ::pwrite (fd, buffer.data(), buffer.size(), offset);
1234 const int save_errno = bytes_written == -1 ? errno : 0;
1235 response.Printf("%zi", bytes_written);
1236 if (save_errno)
1237 response.Printf(",%i", save_errno);
1238 }
1239 else
1240 {
1241 response.Printf ("-1,%i", EINVAL);
1242 }
1243 return SendPacketNoLock(response.GetData(), response.GetSize());
1244 }
Daniel Maleae0f8f572013-08-26 23:57:52 +00001245 }
Greg Clayton2b98c562013-11-22 18:53:12 +00001246 return SendErrorResponse(27);
Virgile Belloae12a362013-08-27 16:21:49 +00001247#endif
Daniel Maleae0f8f572013-08-26 23:57:52 +00001248}
1249
1250bool
1251GDBRemoteCommunicationServer::Handle_vFile_Size (StringExtractorGDBRemote &packet)
1252{
1253 packet.SetFilePos(::strlen("vFile:size:"));
1254 std::string path;
1255 packet.GetHexByteString(path);
Greg Clayton2b98c562013-11-22 18:53:12 +00001256 if (!path.empty())
Daniel Maleae0f8f572013-08-26 23:57:52 +00001257 {
Greg Clayton2b98c562013-11-22 18:53:12 +00001258 lldb::user_id_t retcode = Host::GetFileSize(FileSpec(path.c_str(), false));
1259 StreamString response;
1260 response.PutChar('F');
1261 response.PutHex64(retcode);
1262 if (retcode == UINT64_MAX)
1263 {
1264 response.PutChar(',');
1265 response.PutHex64(retcode); // TODO: replace with Host::GetSyswideErrorCode()
1266 }
1267 return SendPacketNoLock(response.GetData(), response.GetSize());
Daniel Maleae0f8f572013-08-26 23:57:52 +00001268 }
Greg Clayton2b98c562013-11-22 18:53:12 +00001269 return SendErrorResponse(22);
Daniel Maleae0f8f572013-08-26 23:57:52 +00001270}
1271
1272bool
1273GDBRemoteCommunicationServer::Handle_vFile_Mode (StringExtractorGDBRemote &packet)
1274{
1275 packet.SetFilePos(::strlen("vFile:mode:"));
1276 std::string path;
1277 packet.GetHexByteString(path);
Greg Clayton2b98c562013-11-22 18:53:12 +00001278 if (!path.empty())
1279 {
1280 Error error;
1281 const uint32_t mode = File::GetPermissions(path.c_str(), error);
1282 StreamString response;
1283 response.Printf("F%u", mode);
1284 if (mode == 0 || error.Fail())
1285 response.Printf(",%i", (int)error.GetError());
1286 return SendPacketNoLock(response.GetData(), response.GetSize());
1287 }
1288 return SendErrorResponse(23);
Daniel Maleae0f8f572013-08-26 23:57:52 +00001289}
1290
1291bool
1292GDBRemoteCommunicationServer::Handle_vFile_Exists (StringExtractorGDBRemote &packet)
1293{
1294 packet.SetFilePos(::strlen("vFile:exists:"));
1295 std::string path;
1296 packet.GetHexByteString(path);
Greg Clayton2b98c562013-11-22 18:53:12 +00001297 if (!path.empty())
1298 {
1299 bool retcode = Host::GetFileExists(FileSpec(path.c_str(), false));
1300 StreamString response;
1301 response.PutChar('F');
1302 response.PutChar(',');
1303 if (retcode)
1304 response.PutChar('1');
1305 else
1306 response.PutChar('0');
1307 return SendPacketNoLock(response.GetData(), response.GetSize());
1308 }
1309 return SendErrorResponse(24);
Daniel Maleae0f8f572013-08-26 23:57:52 +00001310}
1311
1312bool
Greg Claytonfbb76342013-11-20 21:07:01 +00001313GDBRemoteCommunicationServer::Handle_vFile_symlink (StringExtractorGDBRemote &packet)
Daniel Maleae0f8f572013-08-26 23:57:52 +00001314{
Greg Claytonfbb76342013-11-20 21:07:01 +00001315 packet.SetFilePos(::strlen("vFile:symlink:"));
1316 std::string dst, src;
1317 packet.GetHexByteStringTerminatedBy(dst, ',');
1318 packet.GetChar(); // Skip ',' char
1319 packet.GetHexByteString(src);
1320 Error error = Host::Symlink(src.c_str(), dst.c_str());
1321 StreamString response;
1322 response.Printf("F%u,%u", error.GetError(), error.GetError());
Greg Clayton2b98c562013-11-22 18:53:12 +00001323 return SendPacketNoLock(response.GetData(), response.GetSize());
Greg Claytonfbb76342013-11-20 21:07:01 +00001324}
1325
1326bool
1327GDBRemoteCommunicationServer::Handle_vFile_unlink (StringExtractorGDBRemote &packet)
1328{
1329 packet.SetFilePos(::strlen("vFile:unlink:"));
1330 std::string path;
1331 packet.GetHexByteString(path);
1332 Error error = Host::Unlink(path.c_str());
1333 StreamString response;
1334 response.Printf("F%u,%u", error.GetError(), error.GetError());
Greg Clayton2b98c562013-11-22 18:53:12 +00001335 return SendPacketNoLock(response.GetData(), response.GetSize());
Greg Claytonfbb76342013-11-20 21:07:01 +00001336}
1337
1338bool
1339GDBRemoteCommunicationServer::Handle_qPlatform_shell (StringExtractorGDBRemote &packet)
1340{
1341 packet.SetFilePos(::strlen("qPlatform_shell:"));
Daniel Maleae0f8f572013-08-26 23:57:52 +00001342 std::string path;
1343 std::string working_dir;
1344 packet.GetHexByteStringTerminatedBy(path,',');
Greg Clayton2b98c562013-11-22 18:53:12 +00001345 if (!path.empty())
Daniel Maleae0f8f572013-08-26 23:57:52 +00001346 {
Greg Clayton2b98c562013-11-22 18:53:12 +00001347 if (packet.GetChar() == ',')
1348 {
1349 // FIXME: add timeout to qPlatform_shell packet
1350 // uint32_t timeout = packet.GetHexMaxU32(false, 32);
1351 uint32_t timeout = 10;
1352 if (packet.GetChar() == ',')
1353 packet.GetHexByteString(working_dir);
1354 int status, signo;
1355 std::string output;
1356 Error err = Host::RunShellCommand(path.c_str(),
1357 working_dir.empty() ? NULL : working_dir.c_str(),
1358 &status, &signo, &output, timeout);
1359 StreamGDBRemote response;
1360 if (err.Fail())
1361 {
1362 response.PutCString("F,");
1363 response.PutHex32(UINT32_MAX);
1364 }
1365 else
1366 {
1367 response.PutCString("F,");
1368 response.PutHex32(status);
1369 response.PutChar(',');
1370 response.PutHex32(signo);
1371 response.PutChar(',');
1372 response.PutEscapedBytes(output.c_str(), output.size());
1373 }
1374 return SendPacketNoLock(response.GetData(), response.GetSize());
1375 }
Daniel Maleae0f8f572013-08-26 23:57:52 +00001376 }
Greg Clayton2b98c562013-11-22 18:53:12 +00001377 return SendErrorResponse(24);
Daniel Maleae0f8f572013-08-26 23:57:52 +00001378}
1379
1380bool
1381GDBRemoteCommunicationServer::Handle_vFile_Stat (StringExtractorGDBRemote &packet)
1382{
Greg Clayton2b98c562013-11-22 18:53:12 +00001383 return SendUnimplementedResponse("GDBRemoteCommunicationServer::Handle_vFile_Stat() unimplemented");
Daniel Maleae0f8f572013-08-26 23:57:52 +00001384}
1385
1386bool
1387GDBRemoteCommunicationServer::Handle_vFile_MD5 (StringExtractorGDBRemote &packet)
1388{
Greg Clayton2b98c562013-11-22 18:53:12 +00001389 packet.SetFilePos(::strlen("vFile:MD5:"));
Daniel Maleae0f8f572013-08-26 23:57:52 +00001390 std::string path;
1391 packet.GetHexByteString(path);
Greg Clayton2b98c562013-11-22 18:53:12 +00001392 if (!path.empty())
Daniel Maleae0f8f572013-08-26 23:57:52 +00001393 {
Greg Clayton2b98c562013-11-22 18:53:12 +00001394 uint64_t a,b;
1395 StreamGDBRemote response;
1396 if (Host::CalculateMD5(FileSpec(path.c_str(),false),a,b) == false)
1397 {
1398 response.PutCString("F,");
1399 response.PutCString("x");
1400 }
1401 else
1402 {
1403 response.PutCString("F,");
1404 response.PutHex64(a);
1405 response.PutHex64(b);
1406 }
1407 return SendPacketNoLock(response.GetData(), response.GetSize());
Daniel Maleae0f8f572013-08-26 23:57:52 +00001408 }
Greg Clayton2b98c562013-11-22 18:53:12 +00001409 return SendErrorResponse(25);
Daniel Maleae0f8f572013-08-26 23:57:52 +00001410}
Greg Clayton2b98c562013-11-22 18:53:12 +00001411