1 //===-- GDBRemoteCommunicationServer.cpp ------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
12 #include "GDBRemoteCommunicationServer.h"
13 #include "lldb/Core/StreamGDBRemote.h"
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"
24 #include "lldb/Host/Endian.h"
25 #include "lldb/Host/File.h"
26 #include "lldb/Host/Host.h"
27 #include "lldb/Host/TimeValue.h"
28 #include "lldb/Target/Platform.h"
29 #include "lldb/Target/Process.h"
32 #include "Utility/StringExtractorGDBRemote.h"
33 #include "ProcessGDBRemote.h"
34 #include "ProcessGDBRemoteLog.h"
37 using namespace lldb_private;
39 //----------------------------------------------------------------------
40 // GDBRemoteCommunicationServer constructor
41 //----------------------------------------------------------------------
42 GDBRemoteCommunicationServer::GDBRemoteCommunicationServer(bool is_platform) :
43 GDBRemoteCommunication ("gdb-remote.server", "gdb-remote.server.rx_packet", is_platform),
44 m_platform_sp (Platform::GetDefaultPlatform ()),
45 m_async_thread (LLDB_INVALID_HOST_THREAD),
46 m_process_launch_info (),
47 m_process_launch_error (),
49 m_spawned_pids_mutex (Mutex::eMutexTypeRecursive),
51 m_proc_infos_index (0),
57 GDBRemoteCommunicationServer::GDBRemoteCommunicationServer(bool is_platform,
58 const lldb::PlatformSP& platform_sp) :
59 GDBRemoteCommunication ("gdb-remote.server", "gdb-remote.server.rx_packet", is_platform),
60 m_platform_sp (platform_sp),
61 m_async_thread (LLDB_INVALID_HOST_THREAD),
62 m_process_launch_info (),
63 m_process_launch_error (),
65 m_spawned_pids_mutex (Mutex::eMutexTypeRecursive),
67 m_proc_infos_index (0),
74 //----------------------------------------------------------------------
76 //----------------------------------------------------------------------
77 GDBRemoteCommunicationServer::~GDBRemoteCommunicationServer()
83 //GDBRemoteCommunicationServer::AsyncThread (void *arg)
85 // GDBRemoteCommunicationServer *server = (GDBRemoteCommunicationServer*) arg;
87 // Log *log;// (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PROCESS));
89 // log->Printf ("ProcessGDBRemote::%s (arg = %p, pid = %i) thread starting...", __FUNCTION__, arg, process->GetID());
91 // StringExtractorGDBRemote packet;
99 // log->Printf ("ProcessGDBRemote::%s (arg = %p, pid = %i) thread exiting...", __FUNCTION__, arg, process->GetID());
101 // process->m_async_thread = LLDB_INVALID_HOST_THREAD;
106 GDBRemoteCommunicationServer::GetPacketAndSendResponse (uint32_t timeout_usec,
111 StringExtractorGDBRemote packet;
112 PacketResult packet_result = WaitForPacketWithTimeoutMicroSecondsNoLock (packet, timeout_usec);
113 if (packet_result == PacketResult::Success)
115 const StringExtractorGDBRemote::ServerPacketType packet_type = packet.GetServerPacketType ();
118 case StringExtractorGDBRemote::eServerPacketType_nack:
119 case StringExtractorGDBRemote::eServerPacketType_ack:
122 case StringExtractorGDBRemote::eServerPacketType_invalid:
123 error.SetErrorString("invalid packet");
127 case StringExtractorGDBRemote::eServerPacketType_interrupt:
128 error.SetErrorString("interrupt received");
133 case StringExtractorGDBRemote::eServerPacketType_unimplemented:
134 packet_result = SendUnimplementedResponse (packet.GetStringRef().c_str());
137 case StringExtractorGDBRemote::eServerPacketType_A:
138 packet_result = Handle_A (packet);
141 case StringExtractorGDBRemote::eServerPacketType_qfProcessInfo:
142 packet_result = Handle_qfProcessInfo (packet);
145 case StringExtractorGDBRemote::eServerPacketType_qsProcessInfo:
146 packet_result = Handle_qsProcessInfo (packet);
149 case StringExtractorGDBRemote::eServerPacketType_qC:
150 packet_result = Handle_qC (packet);
153 case StringExtractorGDBRemote::eServerPacketType_qHostInfo:
154 packet_result = Handle_qHostInfo (packet);
157 case StringExtractorGDBRemote::eServerPacketType_qLaunchGDBServer:
158 packet_result = Handle_qLaunchGDBServer (packet);
161 case StringExtractorGDBRemote::eServerPacketType_qKillSpawnedProcess:
162 packet_result = Handle_qKillSpawnedProcess (packet);
165 case StringExtractorGDBRemote::eServerPacketType_k:
166 packet_result = Handle_k (packet);
169 case StringExtractorGDBRemote::eServerPacketType_qLaunchSuccess:
170 packet_result = Handle_qLaunchSuccess (packet);
173 case StringExtractorGDBRemote::eServerPacketType_qGroupName:
174 packet_result = Handle_qGroupName (packet);
177 case StringExtractorGDBRemote::eServerPacketType_qProcessInfoPID:
178 packet_result = Handle_qProcessInfoPID (packet);
181 case StringExtractorGDBRemote::eServerPacketType_qSpeedTest:
182 packet_result = Handle_qSpeedTest (packet);
185 case StringExtractorGDBRemote::eServerPacketType_qUserName:
186 packet_result = Handle_qUserName (packet);
189 case StringExtractorGDBRemote::eServerPacketType_qGetWorkingDir:
190 packet_result = Handle_qGetWorkingDir(packet);
193 case StringExtractorGDBRemote::eServerPacketType_QEnvironment:
194 packet_result = Handle_QEnvironment (packet);
197 case StringExtractorGDBRemote::eServerPacketType_QLaunchArch:
198 packet_result = Handle_QLaunchArch (packet);
201 case StringExtractorGDBRemote::eServerPacketType_QSetDisableASLR:
202 packet_result = Handle_QSetDisableASLR (packet);
205 case StringExtractorGDBRemote::eServerPacketType_QSetSTDIN:
206 packet_result = Handle_QSetSTDIN (packet);
209 case StringExtractorGDBRemote::eServerPacketType_QSetSTDOUT:
210 packet_result = Handle_QSetSTDOUT (packet);
213 case StringExtractorGDBRemote::eServerPacketType_QSetSTDERR:
214 packet_result = Handle_QSetSTDERR (packet);
217 case StringExtractorGDBRemote::eServerPacketType_QSetWorkingDir:
218 packet_result = Handle_QSetWorkingDir (packet);
221 case StringExtractorGDBRemote::eServerPacketType_QStartNoAckMode:
222 packet_result = Handle_QStartNoAckMode (packet);
225 case StringExtractorGDBRemote::eServerPacketType_qPlatform_mkdir:
226 packet_result = Handle_qPlatform_mkdir (packet);
229 case StringExtractorGDBRemote::eServerPacketType_qPlatform_chmod:
230 packet_result = Handle_qPlatform_chmod (packet);
233 case StringExtractorGDBRemote::eServerPacketType_qPlatform_shell:
234 packet_result = Handle_qPlatform_shell (packet);
237 case StringExtractorGDBRemote::eServerPacketType_vFile_open:
238 packet_result = Handle_vFile_Open (packet);
241 case StringExtractorGDBRemote::eServerPacketType_vFile_close:
242 packet_result = Handle_vFile_Close (packet);
245 case StringExtractorGDBRemote::eServerPacketType_vFile_pread:
246 packet_result = Handle_vFile_pRead (packet);
249 case StringExtractorGDBRemote::eServerPacketType_vFile_pwrite:
250 packet_result = Handle_vFile_pWrite (packet);
253 case StringExtractorGDBRemote::eServerPacketType_vFile_size:
254 packet_result = Handle_vFile_Size (packet);
257 case StringExtractorGDBRemote::eServerPacketType_vFile_mode:
258 packet_result = Handle_vFile_Mode (packet);
261 case StringExtractorGDBRemote::eServerPacketType_vFile_exists:
262 packet_result = Handle_vFile_Exists (packet);
265 case StringExtractorGDBRemote::eServerPacketType_vFile_stat:
266 packet_result = Handle_vFile_Stat (packet);
269 case StringExtractorGDBRemote::eServerPacketType_vFile_md5:
270 packet_result = Handle_vFile_MD5 (packet);
273 case StringExtractorGDBRemote::eServerPacketType_vFile_symlink:
274 packet_result = Handle_vFile_symlink (packet);
277 case StringExtractorGDBRemote::eServerPacketType_vFile_unlink:
278 packet_result = Handle_vFile_unlink (packet);
286 error.SetErrorString("lost connection");
291 error.SetErrorString("timeout");
294 return packet_result == PacketResult::Success;
298 GDBRemoteCommunicationServer::SetLaunchArguments (const char *const args[], int argc)
300 if ((argc < 1) || !args || !args[0] || !args[0][0])
301 return lldb_private::Error ("%s: no process command line specified to launch", __FUNCTION__);
303 m_process_launch_info.SetArguments (const_cast<const char**> (args), true);
304 return lldb_private::Error ();
308 GDBRemoteCommunicationServer::SetLaunchFlags (unsigned int launch_flags)
310 m_process_launch_info.GetFlags ().Set (launch_flags);
311 return lldb_private::Error ();
315 GDBRemoteCommunicationServer::LaunchProcess ()
317 if (!m_process_launch_info.GetArguments ().GetArgumentCount ())
318 return lldb_private::Error ("%s: no process command line specified to launch", __FUNCTION__);
320 // specify the process monitor if not already set. This should
321 // generally be what happens since we need to reap started
323 if (!m_process_launch_info.GetMonitorProcessCallback ())
324 m_process_launch_info.SetMonitorProcessCallback(ReapDebuggedProcess, this, false);
326 lldb_private::Error error = m_platform_sp->LaunchProcess (m_process_launch_info);
327 if (!error.Success ())
329 fprintf (stderr, "%s: failed to launch executable %s", __FUNCTION__, m_process_launch_info.GetArguments ().GetArgumentAtIndex (0));
333 printf ("Launched '%s' as process %" PRIu64 "...\n", m_process_launch_info.GetArguments ().GetArgumentAtIndex (0), m_process_launch_info.GetProcessID());
335 // add to list of spawned processes. On an lldb-gdbserver, we
336 // would expect there to be only one.
338 if ( (pid = m_process_launch_info.GetProcessID()) != LLDB_INVALID_PROCESS_ID )
340 Mutex::Locker locker (m_spawned_pids_mutex);
341 m_spawned_pids.insert(pid);
347 GDBRemoteCommunication::PacketResult
348 GDBRemoteCommunicationServer::SendUnimplementedResponse (const char *)
350 // TODO: Log the packet we aren't handling...
351 return SendPacketNoLock ("", 0);
354 GDBRemoteCommunication::PacketResult
355 GDBRemoteCommunicationServer::SendErrorResponse (uint8_t err)
358 int packet_len = ::snprintf (packet, sizeof(packet), "E%2.2x", err);
359 assert (packet_len < (int)sizeof(packet));
360 return SendPacketNoLock (packet, packet_len);
364 GDBRemoteCommunication::PacketResult
365 GDBRemoteCommunicationServer::SendOKResponse ()
367 return SendPacketNoLock ("OK", 2);
371 GDBRemoteCommunicationServer::HandshakeWithClient(Error *error_ptr)
373 return GetAck() == PacketResult::Success;
376 GDBRemoteCommunication::PacketResult
377 GDBRemoteCommunicationServer::Handle_qHostInfo (StringExtractorGDBRemote &packet)
379 StreamString response;
381 // $cputype:16777223;cpusubtype:3;ostype:Darwin;vendor:apple;endian:little;ptrsize:8;#00
383 ArchSpec host_arch (Host::GetArchitecture ());
384 const llvm::Triple &host_triple = host_arch.GetTriple();
385 response.PutCString("triple:");
386 response.PutCStringAsRawHex8(host_triple.getTriple().c_str());
387 response.Printf (";ptrsize:%u;",host_arch.GetAddressByteSize());
389 const char* distribution_id = host_arch.GetDistributionId ().AsCString ();
392 response.PutCString("distribution_id:");
393 response.PutCStringAsRawHex8(distribution_id);
394 response.PutCString(";");
397 uint32_t cpu = host_arch.GetMachOCPUType();
398 uint32_t sub = host_arch.GetMachOCPUSubType();
399 if (cpu != LLDB_INVALID_CPUTYPE)
400 response.Printf ("cputype:%u;", cpu);
401 if (sub != LLDB_INVALID_CPUTYPE)
402 response.Printf ("cpusubtype:%u;", sub);
404 if (cpu == ArchSpec::kCore_arm_any)
405 response.Printf("watchpoint_exceptions_received:before;"); // On armv7 we use "synchronous" watchpoints which means the exception is delivered before the instruction executes.
407 response.Printf("watchpoint_exceptions_received:after;");
409 switch (lldb::endian::InlHostByteOrder())
411 case eByteOrderBig: response.PutCString ("endian:big;"); break;
412 case eByteOrderLittle: response.PutCString ("endian:little;"); break;
413 case eByteOrderPDP: response.PutCString ("endian:pdp;"); break;
414 default: response.PutCString ("endian:unknown;"); break;
417 uint32_t major = UINT32_MAX;
418 uint32_t minor = UINT32_MAX;
419 uint32_t update = UINT32_MAX;
420 if (Host::GetOSVersion (major, minor, update))
422 if (major != UINT32_MAX)
424 response.Printf("os_version:%u", major);
425 if (minor != UINT32_MAX)
427 response.Printf(".%u", minor);
428 if (update != UINT32_MAX)
429 response.Printf(".%u", update);
431 response.PutChar(';');
436 if (Host::GetOSBuildString (s))
438 response.PutCString ("os_build:");
439 response.PutCStringAsRawHex8(s.c_str());
440 response.PutChar(';');
442 if (Host::GetOSKernelDescription (s))
444 response.PutCString ("os_kernel:");
445 response.PutCStringAsRawHex8(s.c_str());
446 response.PutChar(';');
448 #if defined(__APPLE__)
451 // For iOS devices, we are connected through a USB Mux so we never pretend
452 // to actually have a hostname as far as the remote lldb that is connecting
453 // to this lldb-platform is concerned
454 response.PutCString ("hostname:");
455 response.PutCStringAsRawHex8("localhost");
456 response.PutChar(';');
457 #else // #if defined(__arm__)
458 if (Host::GetHostname (s))
460 response.PutCString ("hostname:");
461 response.PutCStringAsRawHex8(s.c_str());
462 response.PutChar(';');
465 #endif // #if defined(__arm__)
467 #else // #if defined(__APPLE__)
468 if (Host::GetHostname (s))
470 response.PutCString ("hostname:");
471 response.PutCStringAsRawHex8(s.c_str());
472 response.PutChar(';');
474 #endif // #if defined(__APPLE__)
476 return SendPacketNoLock (response.GetData(), response.GetSize());
480 CreateProcessInfoResponse (const ProcessInstanceInfo &proc_info, StreamString &response)
482 response.Printf ("pid:%" PRIu64 ";ppid:%" PRIu64 ";uid:%i;gid:%i;euid:%i;egid:%i;",
483 proc_info.GetProcessID(),
484 proc_info.GetParentProcessID(),
485 proc_info.GetUserID(),
486 proc_info.GetGroupID(),
487 proc_info.GetEffectiveUserID(),
488 proc_info.GetEffectiveGroupID());
489 response.PutCString ("name:");
490 response.PutCStringAsRawHex8(proc_info.GetName());
491 response.PutChar(';');
492 const ArchSpec &proc_arch = proc_info.GetArchitecture();
493 if (proc_arch.IsValid())
495 const llvm::Triple &proc_triple = proc_arch.GetTriple();
496 response.PutCString("triple:");
497 response.PutCStringAsRawHex8(proc_triple.getTriple().c_str());
498 response.PutChar(';');
502 GDBRemoteCommunication::PacketResult
503 GDBRemoteCommunicationServer::Handle_qProcessInfoPID (StringExtractorGDBRemote &packet)
505 // Packet format: "qProcessInfoPID:%i" where %i is the pid
506 packet.SetFilePos(::strlen ("qProcessInfoPID:"));
507 lldb::pid_t pid = packet.GetU32 (LLDB_INVALID_PROCESS_ID);
508 if (pid != LLDB_INVALID_PROCESS_ID)
510 ProcessInstanceInfo proc_info;
511 if (Host::GetProcessInfo(pid, proc_info))
513 StreamString response;
514 CreateProcessInfoResponse (proc_info, response);
515 return SendPacketNoLock (response.GetData(), response.GetSize());
518 return SendErrorResponse (1);
521 GDBRemoteCommunication::PacketResult
522 GDBRemoteCommunicationServer::Handle_qfProcessInfo (StringExtractorGDBRemote &packet)
524 m_proc_infos_index = 0;
525 m_proc_infos.Clear();
527 ProcessInstanceInfoMatch match_info;
528 packet.SetFilePos(::strlen ("qfProcessInfo"));
529 if (packet.GetChar() == ':')
534 while (packet.GetNameColonValue(key, value))
537 if (key.compare("name") == 0)
539 StringExtractor extractor;
540 extractor.GetStringRef().swap(value);
541 extractor.GetHexByteString (value);
542 match_info.GetProcessInfo().GetExecutableFile().SetFile(value.c_str(), false);
544 else if (key.compare("name_match") == 0)
546 if (value.compare("equals") == 0)
548 match_info.SetNameMatchType (eNameMatchEquals);
550 else if (value.compare("starts_with") == 0)
552 match_info.SetNameMatchType (eNameMatchStartsWith);
554 else if (value.compare("ends_with") == 0)
556 match_info.SetNameMatchType (eNameMatchEndsWith);
558 else if (value.compare("contains") == 0)
560 match_info.SetNameMatchType (eNameMatchContains);
562 else if (value.compare("regex") == 0)
564 match_info.SetNameMatchType (eNameMatchRegularExpression);
571 else if (key.compare("pid") == 0)
573 match_info.GetProcessInfo().SetProcessID (Args::StringToUInt32(value.c_str(), LLDB_INVALID_PROCESS_ID, 0, &success));
575 else if (key.compare("parent_pid") == 0)
577 match_info.GetProcessInfo().SetParentProcessID (Args::StringToUInt32(value.c_str(), LLDB_INVALID_PROCESS_ID, 0, &success));
579 else if (key.compare("uid") == 0)
581 match_info.GetProcessInfo().SetUserID (Args::StringToUInt32(value.c_str(), UINT32_MAX, 0, &success));
583 else if (key.compare("gid") == 0)
585 match_info.GetProcessInfo().SetGroupID (Args::StringToUInt32(value.c_str(), UINT32_MAX, 0, &success));
587 else if (key.compare("euid") == 0)
589 match_info.GetProcessInfo().SetEffectiveUserID (Args::StringToUInt32(value.c_str(), UINT32_MAX, 0, &success));
591 else if (key.compare("egid") == 0)
593 match_info.GetProcessInfo().SetEffectiveGroupID (Args::StringToUInt32(value.c_str(), UINT32_MAX, 0, &success));
595 else if (key.compare("all_users") == 0)
597 match_info.SetMatchAllUsers(Args::StringToBoolean(value.c_str(), false, &success));
599 else if (key.compare("triple") == 0)
601 match_info.GetProcessInfo().GetArchitecture().SetTriple (value.c_str(), NULL);
609 return SendErrorResponse (2);
613 if (Host::FindProcesses (match_info, m_proc_infos))
615 // We found something, return the first item by calling the get
616 // subsequent process info packet handler...
617 return Handle_qsProcessInfo (packet);
619 return SendErrorResponse (3);
622 GDBRemoteCommunication::PacketResult
623 GDBRemoteCommunicationServer::Handle_qsProcessInfo (StringExtractorGDBRemote &packet)
625 if (m_proc_infos_index < m_proc_infos.GetSize())
627 StreamString response;
628 CreateProcessInfoResponse (m_proc_infos.GetProcessInfoAtIndex(m_proc_infos_index), response);
629 ++m_proc_infos_index;
630 return SendPacketNoLock (response.GetData(), response.GetSize());
632 return SendErrorResponse (4);
635 GDBRemoteCommunication::PacketResult
636 GDBRemoteCommunicationServer::Handle_qUserName (StringExtractorGDBRemote &packet)
638 // Packet format: "qUserName:%i" where %i is the uid
639 packet.SetFilePos(::strlen ("qUserName:"));
640 uint32_t uid = packet.GetU32 (UINT32_MAX);
641 if (uid != UINT32_MAX)
644 if (Host::GetUserName (uid, name))
646 StreamString response;
647 response.PutCStringAsRawHex8 (name.c_str());
648 return SendPacketNoLock (response.GetData(), response.GetSize());
651 return SendErrorResponse (5);
655 GDBRemoteCommunication::PacketResult
656 GDBRemoteCommunicationServer::Handle_qGroupName (StringExtractorGDBRemote &packet)
658 // Packet format: "qGroupName:%i" where %i is the gid
659 packet.SetFilePos(::strlen ("qGroupName:"));
660 uint32_t gid = packet.GetU32 (UINT32_MAX);
661 if (gid != UINT32_MAX)
664 if (Host::GetGroupName (gid, name))
666 StreamString response;
667 response.PutCStringAsRawHex8 (name.c_str());
668 return SendPacketNoLock (response.GetData(), response.GetSize());
671 return SendErrorResponse (6);
674 GDBRemoteCommunication::PacketResult
675 GDBRemoteCommunicationServer::Handle_qSpeedTest (StringExtractorGDBRemote &packet)
677 packet.SetFilePos(::strlen ("qSpeedTest:"));
681 bool success = packet.GetNameColonValue(key, value);
682 if (success && key.compare("response_size") == 0)
684 uint32_t response_size = Args::StringToUInt32(value.c_str(), 0, 0, &success);
687 if (response_size == 0)
688 return SendOKResponse();
689 StreamString response;
690 uint32_t bytes_left = response_size;
691 response.PutCString("data:");
692 while (bytes_left > 0)
694 if (bytes_left >= 26)
696 response.PutCString("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
701 response.Printf ("%*.*s;", bytes_left, bytes_left, "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
705 return SendPacketNoLock (response.GetData(), response.GetSize());
708 return SendErrorResponse (7);
713 AcceptPortFromInferior (void *arg)
715 const char *connect_url = (const char *)arg;
716 ConnectionFileDescriptor file_conn;
718 if (file_conn.Connect (connect_url, &error) == eConnectionStatusSuccess)
721 ::memset (pid_str, 0, sizeof(pid_str));
722 ConnectionStatus status;
723 const size_t pid_str_len = file_conn.Read (pid_str, sizeof(pid_str), 0, status, NULL);
726 int pid = atoi (pid_str);
727 return (void *)(intptr_t)pid;
734 //WaitForProcessToSIGSTOP (const lldb::pid_t pid, const int timeout_in_seconds)
736 // const int time_delta_usecs = 100000;
737 // const int num_retries = timeout_in_seconds/time_delta_usecs;
738 // for (int i=0; i<num_retries; i++)
740 // struct proc_bsdinfo bsd_info;
741 // int error = ::proc_pidinfo (pid, PROC_PIDTBSDINFO,
744 // PROC_PIDTBSDINFO_SIZE);
758 // if (bsd_info.pbi_status == SSTOP)
761 // ::usleep (time_delta_usecs);
766 GDBRemoteCommunication::PacketResult
767 GDBRemoteCommunicationServer::Handle_A (StringExtractorGDBRemote &packet)
769 // The 'A' packet is the most over designed packet ever here with
770 // redundant argument indexes, redundant argument lengths and needed hex
771 // encoded argument string values. Really all that is needed is a comma
772 // separated hex encoded argument value list, but we will stay true to the
773 // documented version of the 'A' packet here...
775 packet.SetFilePos(1); // Skip the 'A'
777 while (success && packet.GetBytesLeft() > 0)
779 // Decode the decimal argument string length. This length is the
780 // number of hex nibbles in the argument string value.
781 const uint32_t arg_len = packet.GetU32(UINT32_MAX);
782 if (arg_len == UINT32_MAX)
786 // Make sure the argument hex string length is followed by a comma
787 if (packet.GetChar() != ',')
791 // Decode the argument index. We ignore this really becuase
792 // who would really send down the arguments in a random order???
793 const uint32_t arg_idx = packet.GetU32(UINT32_MAX);
794 if (arg_idx == UINT32_MAX)
798 // Make sure the argument index is followed by a comma
799 if (packet.GetChar() != ',')
803 // Decode the argument string value from hex bytes
804 // back into a UTF8 string and make sure the length
805 // matches the one supplied in the packet
807 if (packet.GetHexByteString(arg) != (arg_len / 2))
811 // If there are any bytes lft
812 if (packet.GetBytesLeft())
814 if (packet.GetChar() != ',')
821 m_process_launch_info.GetExecutableFile().SetFile(arg.c_str(), false);
822 m_process_launch_info.GetArguments().AppendArgument(arg.c_str());
833 // FIXME: remove linux restriction once eLaunchFlagDebug is supported
834 #if !defined (__linux__)
835 m_process_launch_info.GetFlags().Set (eLaunchFlagDebug);
837 m_process_launch_error = LaunchProcess ();
838 if (m_process_launch_info.GetProcessID() != LLDB_INVALID_PROCESS_ID)
840 return SendOKResponse ();
843 return SendErrorResponse (8);
846 GDBRemoteCommunication::PacketResult
847 GDBRemoteCommunicationServer::Handle_qC (StringExtractorGDBRemote &packet)
849 lldb::pid_t pid = m_process_launch_info.GetProcessID();
850 StreamString response;
851 response.Printf("QC%" PRIx64, pid);
854 // If we launch a process and this GDB server is acting as a platform,
855 // then we need to clear the process launch state so we can start
856 // launching another process. In order to launch a process a bunch or
857 // packets need to be sent: environment packets, working directory,
858 // disable ASLR, and many more settings. When we launch a process we
859 // then need to know when to clear this information. Currently we are
860 // selecting the 'qC' packet as that packet which seems to make the most
862 if (pid != LLDB_INVALID_PROCESS_ID)
864 m_process_launch_info.Clear();
867 return SendPacketNoLock (response.GetData(), response.GetSize());
871 GDBRemoteCommunicationServer::DebugserverProcessReaped (lldb::pid_t pid)
873 Mutex::Locker locker (m_spawned_pids_mutex);
874 FreePortForProcess(pid);
875 return m_spawned_pids.erase(pid) > 0;
878 GDBRemoteCommunicationServer::ReapDebugserverProcess (void *callback_baton,
881 int signal, // Zero for no signal
882 int status) // Exit value of process if signal is zero
884 GDBRemoteCommunicationServer *server = (GDBRemoteCommunicationServer *)callback_baton;
885 server->DebugserverProcessReaped (pid);
890 GDBRemoteCommunicationServer::DebuggedProcessReaped (lldb::pid_t pid)
892 // reap a process that we were debugging (but not debugserver)
893 Mutex::Locker locker (m_spawned_pids_mutex);
894 return m_spawned_pids.erase(pid) > 0;
898 GDBRemoteCommunicationServer::ReapDebuggedProcess (void *callback_baton,
901 int signal, // Zero for no signal
902 int status) // Exit value of process if signal is zero
904 GDBRemoteCommunicationServer *server = (GDBRemoteCommunicationServer *)callback_baton;
905 server->DebuggedProcessReaped (pid);
909 GDBRemoteCommunication::PacketResult
910 GDBRemoteCommunicationServer::Handle_qLaunchGDBServer (StringExtractorGDBRemote &packet)
913 return SendErrorResponse(9);
915 // Spawn a local debugserver as a platform so we can then attach or launch
920 // Sleep and wait a bit for debugserver to start to listen...
921 ConnectionFileDescriptor file_conn;
923 std::string hostname;
924 // TODO: /tmp/ should not be hardcoded. User might want to override /tmp
925 // with the TMPDIR environnement variable
926 packet.SetFilePos(::strlen ("qLaunchGDBServer;"));
929 uint16_t port = UINT16_MAX;
930 while (packet.GetNameColonValue(name, value))
932 if (name.compare ("host") == 0)
933 hostname.swap(value);
934 else if (name.compare ("port") == 0)
935 port = Args::StringToUInt32(value.c_str(), 0, 0);
937 if (port == UINT16_MAX)
938 port = GetNextAvailablePort();
940 // Spawn a new thread to accept the port that gets bound after
941 // binding to port 0 (zero).
945 // Spawn a debugserver and try to get the port it listens to.
946 ProcessLaunchInfo debugserver_launch_info;
947 if (hostname.empty())
948 hostname = "localhost";
949 Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PLATFORM));
951 log->Printf("Launching debugserver with: %s:%u...\n", hostname.c_str(), port);
953 debugserver_launch_info.SetMonitorProcessCallback(ReapDebugserverProcess, this, false);
955 error = StartDebugserverProcess (hostname.empty() ? NULL : hostname.c_str(),
957 debugserver_launch_info,
960 lldb::pid_t debugserver_pid = debugserver_launch_info.GetProcessID();
963 if (debugserver_pid != LLDB_INVALID_PROCESS_ID)
965 Mutex::Locker locker (m_spawned_pids_mutex);
966 m_spawned_pids.insert(debugserver_pid);
968 AssociatePortWithProcess(port, debugserver_pid);
979 const int response_len = ::snprintf (response, sizeof(response), "pid:%" PRIu64 ";port:%u;", debugserver_pid, port + m_port_offset);
980 assert (response_len < sizeof(response));
981 PacketResult packet_result = SendPacketNoLock (response, response_len);
983 if (packet_result != PacketResult::Success)
985 if (debugserver_pid != LLDB_INVALID_PROCESS_ID)
986 ::kill (debugserver_pid, SIGINT);
988 return packet_result;
992 return SendErrorResponse (9);
997 GDBRemoteCommunicationServer::KillSpawnedProcess (lldb::pid_t pid)
999 // make sure we know about this process
1001 Mutex::Locker locker (m_spawned_pids_mutex);
1002 if (m_spawned_pids.find(pid) == m_spawned_pids.end())
1006 // first try a SIGTERM (standard kill)
1007 Host::Kill (pid, SIGTERM);
1009 // check if that worked
1010 for (size_t i=0; i<10; ++i)
1013 Mutex::Locker locker (m_spawned_pids_mutex);
1014 if (m_spawned_pids.find(pid) == m_spawned_pids.end())
1023 // check one more time after the final usleep
1025 Mutex::Locker locker (m_spawned_pids_mutex);
1026 if (m_spawned_pids.find(pid) == m_spawned_pids.end())
1030 // the launched process still lives. Now try killling it again,
1031 // this time with an unblockable signal.
1032 Host::Kill (pid, SIGKILL);
1034 for (size_t i=0; i<10; ++i)
1037 Mutex::Locker locker (m_spawned_pids_mutex);
1038 if (m_spawned_pids.find(pid) == m_spawned_pids.end())
1047 // check one more time after the final usleep
1050 Mutex::Locker locker (m_spawned_pids_mutex);
1051 if (m_spawned_pids.find(pid) == m_spawned_pids.end())
1055 // no luck - the process still lives
1059 GDBRemoteCommunication::PacketResult
1060 GDBRemoteCommunicationServer::Handle_qKillSpawnedProcess (StringExtractorGDBRemote &packet)
1062 packet.SetFilePos(::strlen ("qKillSpawnedProcess:"));
1064 lldb::pid_t pid = packet.GetU64(LLDB_INVALID_PROCESS_ID);
1066 // verify that we know anything about this pid.
1069 Mutex::Locker locker (m_spawned_pids_mutex);
1070 if (m_spawned_pids.find(pid) == m_spawned_pids.end())
1072 // not a pid we know about
1073 return SendErrorResponse (10);
1077 // go ahead and attempt to kill the spawned process
1078 if (KillSpawnedProcess (pid))
1079 return SendOKResponse ();
1081 return SendErrorResponse (11);
1084 GDBRemoteCommunication::PacketResult
1085 GDBRemoteCommunicationServer::Handle_k (StringExtractorGDBRemote &packet)
1087 // ignore for now if we're lldb_platform
1089 return SendUnimplementedResponse (packet.GetStringRef().c_str());
1091 // shutdown all spawned processes
1092 std::set<lldb::pid_t> spawned_pids_copy;
1096 Mutex::Locker locker (m_spawned_pids_mutex);
1097 spawned_pids_copy.insert (m_spawned_pids.begin (), m_spawned_pids.end ());
1100 // nuke the spawned processes
1101 for (auto it = spawned_pids_copy.begin (); it != spawned_pids_copy.end (); ++it)
1103 lldb::pid_t spawned_pid = *it;
1104 if (!KillSpawnedProcess (spawned_pid))
1106 fprintf (stderr, "%s: failed to kill spawned pid %" PRIu64 ", ignoring.\n", __FUNCTION__, spawned_pid);
1110 // TODO figure out how to shut down gracefully at this point
1111 return SendOKResponse ();
1114 GDBRemoteCommunication::PacketResult
1115 GDBRemoteCommunicationServer::Handle_qLaunchSuccess (StringExtractorGDBRemote &packet)
1117 if (m_process_launch_error.Success())
1118 return SendOKResponse();
1119 StreamString response;
1120 response.PutChar('E');
1121 response.PutCString(m_process_launch_error.AsCString("<unknown error>"));
1122 return SendPacketNoLock (response.GetData(), response.GetSize());
1125 GDBRemoteCommunication::PacketResult
1126 GDBRemoteCommunicationServer::Handle_QEnvironment (StringExtractorGDBRemote &packet)
1128 packet.SetFilePos(::strlen ("QEnvironment:"));
1129 const uint32_t bytes_left = packet.GetBytesLeft();
1132 m_process_launch_info.GetEnvironmentEntries ().AppendArgument (packet.Peek());
1133 return SendOKResponse ();
1135 return SendErrorResponse (12);
1138 GDBRemoteCommunication::PacketResult
1139 GDBRemoteCommunicationServer::Handle_QLaunchArch (StringExtractorGDBRemote &packet)
1141 packet.SetFilePos(::strlen ("QLaunchArch:"));
1142 const uint32_t bytes_left = packet.GetBytesLeft();
1145 const char* arch_triple = packet.Peek();
1146 ArchSpec arch_spec(arch_triple,NULL);
1147 m_process_launch_info.SetArchitecture(arch_spec);
1148 return SendOKResponse();
1150 return SendErrorResponse(13);
1153 GDBRemoteCommunication::PacketResult
1154 GDBRemoteCommunicationServer::Handle_QSetDisableASLR (StringExtractorGDBRemote &packet)
1156 packet.SetFilePos(::strlen ("QSetDisableASLR:"));
1157 if (packet.GetU32(0))
1158 m_process_launch_info.GetFlags().Set (eLaunchFlagDisableASLR);
1160 m_process_launch_info.GetFlags().Clear (eLaunchFlagDisableASLR);
1161 return SendOKResponse ();
1164 GDBRemoteCommunication::PacketResult
1165 GDBRemoteCommunicationServer::Handle_QSetWorkingDir (StringExtractorGDBRemote &packet)
1167 packet.SetFilePos(::strlen ("QSetWorkingDir:"));
1169 packet.GetHexByteString(path);
1173 // Not implemented on Windows
1174 return SendUnimplementedResponse("GDBRemoteCommunicationServer::Handle_QSetWorkingDir unimplemented");
1176 // If this packet is sent to a platform, then change the current working directory
1177 if (::chdir(path.c_str()) != 0)
1178 return SendErrorResponse(errno);
1183 m_process_launch_info.SwapWorkingDirectory (path);
1185 return SendOKResponse ();
1188 GDBRemoteCommunication::PacketResult
1189 GDBRemoteCommunicationServer::Handle_qGetWorkingDir (StringExtractorGDBRemote &packet)
1191 StreamString response;
1195 // If this packet is sent to a platform, then change the current working directory
1197 if (getcwd(cwd, sizeof(cwd)) == NULL)
1199 return SendErrorResponse(errno);
1203 response.PutBytesAsRawHex8(cwd, strlen(cwd));
1204 return SendPacketNoLock(response.GetData(), response.GetSize());
1209 const char *working_dir = m_process_launch_info.GetWorkingDirectory();
1210 if (working_dir && working_dir[0])
1212 response.PutBytesAsRawHex8(working_dir, strlen(working_dir));
1213 return SendPacketNoLock(response.GetData(), response.GetSize());
1217 return SendErrorResponse(14);
1222 GDBRemoteCommunication::PacketResult
1223 GDBRemoteCommunicationServer::Handle_QSetSTDIN (StringExtractorGDBRemote &packet)
1225 packet.SetFilePos(::strlen ("QSetSTDIN:"));
1226 ProcessLaunchInfo::FileAction file_action;
1228 packet.GetHexByteString(path);
1229 const bool read = false;
1230 const bool write = true;
1231 if (file_action.Open(STDIN_FILENO, path.c_str(), read, write))
1233 m_process_launch_info.AppendFileAction(file_action);
1234 return SendOKResponse ();
1236 return SendErrorResponse (15);
1239 GDBRemoteCommunication::PacketResult
1240 GDBRemoteCommunicationServer::Handle_QSetSTDOUT (StringExtractorGDBRemote &packet)
1242 packet.SetFilePos(::strlen ("QSetSTDOUT:"));
1243 ProcessLaunchInfo::FileAction file_action;
1245 packet.GetHexByteString(path);
1246 const bool read = true;
1247 const bool write = false;
1248 if (file_action.Open(STDOUT_FILENO, path.c_str(), read, write))
1250 m_process_launch_info.AppendFileAction(file_action);
1251 return SendOKResponse ();
1253 return SendErrorResponse (16);
1256 GDBRemoteCommunication::PacketResult
1257 GDBRemoteCommunicationServer::Handle_QSetSTDERR (StringExtractorGDBRemote &packet)
1259 packet.SetFilePos(::strlen ("QSetSTDERR:"));
1260 ProcessLaunchInfo::FileAction file_action;
1262 packet.GetHexByteString(path);
1263 const bool read = true;
1264 const bool write = false;
1265 if (file_action.Open(STDERR_FILENO, path.c_str(), read, write))
1267 m_process_launch_info.AppendFileAction(file_action);
1268 return SendOKResponse ();
1270 return SendErrorResponse (17);
1273 GDBRemoteCommunication::PacketResult
1274 GDBRemoteCommunicationServer::Handle_QStartNoAckMode (StringExtractorGDBRemote &packet)
1276 // Send response first before changing m_send_acks to we ack this packet
1277 PacketResult packet_result = SendOKResponse ();
1278 m_send_acks = false;
1279 return packet_result;
1282 GDBRemoteCommunication::PacketResult
1283 GDBRemoteCommunicationServer::Handle_qPlatform_mkdir (StringExtractorGDBRemote &packet)
1285 packet.SetFilePos(::strlen("qPlatform_mkdir:"));
1286 mode_t mode = packet.GetHexMaxU32(false, UINT32_MAX);
1287 if (packet.GetChar() == ',')
1290 packet.GetHexByteString(path);
1291 Error error = Host::MakeDirectory(path.c_str(),mode);
1292 if (error.Success())
1293 return SendPacketNoLock ("OK", 2);
1295 return SendErrorResponse(error.GetError());
1297 return SendErrorResponse(20);
1300 GDBRemoteCommunication::PacketResult
1301 GDBRemoteCommunicationServer::Handle_qPlatform_chmod (StringExtractorGDBRemote &packet)
1303 packet.SetFilePos(::strlen("qPlatform_chmod:"));
1305 mode_t mode = packet.GetHexMaxU32(false, UINT32_MAX);
1306 if (packet.GetChar() == ',')
1309 packet.GetHexByteString(path);
1310 Error error = Host::SetFilePermissions (path.c_str(), mode);
1311 if (error.Success())
1312 return SendPacketNoLock ("OK", 2);
1314 return SendErrorResponse(error.GetError());
1316 return SendErrorResponse(19);
1319 GDBRemoteCommunication::PacketResult
1320 GDBRemoteCommunicationServer::Handle_vFile_Open (StringExtractorGDBRemote &packet)
1322 packet.SetFilePos(::strlen("vFile:open:"));
1324 packet.GetHexByteStringTerminatedBy(path,',');
1327 if (packet.GetChar() == ',')
1329 uint32_t flags = packet.GetHexMaxU32(false, 0);
1330 if (packet.GetChar() == ',')
1332 mode_t mode = packet.GetHexMaxU32(false, 0600);
1334 int fd = ::open (path.c_str(), flags, mode);
1335 const int save_errno = fd == -1 ? errno : 0;
1336 StreamString response;
1337 response.PutChar('F');
1338 response.Printf("%i", fd);
1340 response.Printf(",%i", save_errno);
1341 return SendPacketNoLock(response.GetData(), response.GetSize());
1345 return SendErrorResponse(18);
1348 GDBRemoteCommunication::PacketResult
1349 GDBRemoteCommunicationServer::Handle_vFile_Close (StringExtractorGDBRemote &packet)
1351 packet.SetFilePos(::strlen("vFile:close:"));
1352 int fd = packet.GetS32(-1);
1359 save_errno = err == -1 ? errno : 0;
1363 save_errno = EINVAL;
1365 StreamString response;
1366 response.PutChar('F');
1367 response.Printf("%i", err);
1369 response.Printf(",%i", save_errno);
1370 return SendPacketNoLock(response.GetData(), response.GetSize());
1373 GDBRemoteCommunication::PacketResult
1374 GDBRemoteCommunicationServer::Handle_vFile_pRead (StringExtractorGDBRemote &packet)
1377 // Not implemented on Windows
1378 return SendUnimplementedResponse("GDBRemoteCommunicationServer::Handle_vFile_pRead() unimplemented");
1380 StreamGDBRemote response;
1381 packet.SetFilePos(::strlen("vFile:pread:"));
1382 int fd = packet.GetS32(-1);
1383 if (packet.GetChar() == ',')
1385 uint64_t count = packet.GetU64(UINT64_MAX);
1386 if (packet.GetChar() == ',')
1388 uint64_t offset = packet.GetU64(UINT32_MAX);
1389 if (count == UINT64_MAX)
1391 response.Printf("F-1:%i", EINVAL);
1392 return SendPacketNoLock(response.GetData(), response.GetSize());
1395 std::string buffer(count, 0);
1396 const ssize_t bytes_read = ::pread (fd, &buffer[0], buffer.size(), offset);
1397 const int save_errno = bytes_read == -1 ? errno : 0;
1398 response.PutChar('F');
1399 response.Printf("%zi", bytes_read);
1401 response.Printf(",%i", save_errno);
1404 response.PutChar(';');
1405 response.PutEscapedBytes(&buffer[0], bytes_read);
1407 return SendPacketNoLock(response.GetData(), response.GetSize());
1410 return SendErrorResponse(21);
1415 GDBRemoteCommunication::PacketResult
1416 GDBRemoteCommunicationServer::Handle_vFile_pWrite (StringExtractorGDBRemote &packet)
1419 return SendUnimplementedResponse("GDBRemoteCommunicationServer::Handle_vFile_pWrite() unimplemented");
1421 packet.SetFilePos(::strlen("vFile:pwrite:"));
1423 StreamGDBRemote response;
1424 response.PutChar('F');
1426 int fd = packet.GetU32(UINT32_MAX);
1427 if (packet.GetChar() == ',')
1429 off_t offset = packet.GetU64(UINT32_MAX);
1430 if (packet.GetChar() == ',')
1433 if (packet.GetEscapedBinaryData(buffer))
1435 const ssize_t bytes_written = ::pwrite (fd, buffer.data(), buffer.size(), offset);
1436 const int save_errno = bytes_written == -1 ? errno : 0;
1437 response.Printf("%zi", bytes_written);
1439 response.Printf(",%i", save_errno);
1443 response.Printf ("-1,%i", EINVAL);
1445 return SendPacketNoLock(response.GetData(), response.GetSize());
1448 return SendErrorResponse(27);
1452 GDBRemoteCommunication::PacketResult
1453 GDBRemoteCommunicationServer::Handle_vFile_Size (StringExtractorGDBRemote &packet)
1455 packet.SetFilePos(::strlen("vFile:size:"));
1457 packet.GetHexByteString(path);
1460 lldb::user_id_t retcode = Host::GetFileSize(FileSpec(path.c_str(), false));
1461 StreamString response;
1462 response.PutChar('F');
1463 response.PutHex64(retcode);
1464 if (retcode == UINT64_MAX)
1466 response.PutChar(',');
1467 response.PutHex64(retcode); // TODO: replace with Host::GetSyswideErrorCode()
1469 return SendPacketNoLock(response.GetData(), response.GetSize());
1471 return SendErrorResponse(22);
1474 GDBRemoteCommunication::PacketResult
1475 GDBRemoteCommunicationServer::Handle_vFile_Mode (StringExtractorGDBRemote &packet)
1477 packet.SetFilePos(::strlen("vFile:mode:"));
1479 packet.GetHexByteString(path);
1483 const uint32_t mode = File::GetPermissions(path.c_str(), error);
1484 StreamString response;
1485 response.Printf("F%u", mode);
1486 if (mode == 0 || error.Fail())
1487 response.Printf(",%i", (int)error.GetError());
1488 return SendPacketNoLock(response.GetData(), response.GetSize());
1490 return SendErrorResponse(23);
1493 GDBRemoteCommunication::PacketResult
1494 GDBRemoteCommunicationServer::Handle_vFile_Exists (StringExtractorGDBRemote &packet)
1496 packet.SetFilePos(::strlen("vFile:exists:"));
1498 packet.GetHexByteString(path);
1501 bool retcode = Host::GetFileExists(FileSpec(path.c_str(), false));
1502 StreamString response;
1503 response.PutChar('F');
1504 response.PutChar(',');
1506 response.PutChar('1');
1508 response.PutChar('0');
1509 return SendPacketNoLock(response.GetData(), response.GetSize());
1511 return SendErrorResponse(24);
1514 GDBRemoteCommunication::PacketResult
1515 GDBRemoteCommunicationServer::Handle_vFile_symlink (StringExtractorGDBRemote &packet)
1517 packet.SetFilePos(::strlen("vFile:symlink:"));
1518 std::string dst, src;
1519 packet.GetHexByteStringTerminatedBy(dst, ',');
1520 packet.GetChar(); // Skip ',' char
1521 packet.GetHexByteString(src);
1522 Error error = Host::Symlink(src.c_str(), dst.c_str());
1523 StreamString response;
1524 response.Printf("F%u,%u", error.GetError(), error.GetError());
1525 return SendPacketNoLock(response.GetData(), response.GetSize());
1528 GDBRemoteCommunication::PacketResult
1529 GDBRemoteCommunicationServer::Handle_vFile_unlink (StringExtractorGDBRemote &packet)
1531 packet.SetFilePos(::strlen("vFile:unlink:"));
1533 packet.GetHexByteString(path);
1534 Error error = Host::Unlink(path.c_str());
1535 StreamString response;
1536 response.Printf("F%u,%u", error.GetError(), error.GetError());
1537 return SendPacketNoLock(response.GetData(), response.GetSize());
1540 GDBRemoteCommunication::PacketResult
1541 GDBRemoteCommunicationServer::Handle_qPlatform_shell (StringExtractorGDBRemote &packet)
1543 packet.SetFilePos(::strlen("qPlatform_shell:"));
1545 std::string working_dir;
1546 packet.GetHexByteStringTerminatedBy(path,',');
1549 if (packet.GetChar() == ',')
1551 // FIXME: add timeout to qPlatform_shell packet
1552 // uint32_t timeout = packet.GetHexMaxU32(false, 32);
1553 uint32_t timeout = 10;
1554 if (packet.GetChar() == ',')
1555 packet.GetHexByteString(working_dir);
1558 Error err = Host::RunShellCommand(path.c_str(),
1559 working_dir.empty() ? NULL : working_dir.c_str(),
1560 &status, &signo, &output, timeout);
1561 StreamGDBRemote response;
1564 response.PutCString("F,");
1565 response.PutHex32(UINT32_MAX);
1569 response.PutCString("F,");
1570 response.PutHex32(status);
1571 response.PutChar(',');
1572 response.PutHex32(signo);
1573 response.PutChar(',');
1574 response.PutEscapedBytes(output.c_str(), output.size());
1576 return SendPacketNoLock(response.GetData(), response.GetSize());
1579 return SendErrorResponse(24);
1582 GDBRemoteCommunication::PacketResult
1583 GDBRemoteCommunicationServer::Handle_vFile_Stat (StringExtractorGDBRemote &packet)
1585 return SendUnimplementedResponse("GDBRemoteCommunicationServer::Handle_vFile_Stat() unimplemented");
1588 GDBRemoteCommunication::PacketResult
1589 GDBRemoteCommunicationServer::Handle_vFile_MD5 (StringExtractorGDBRemote &packet)
1591 packet.SetFilePos(::strlen("vFile:MD5:"));
1593 packet.GetHexByteString(path);
1597 StreamGDBRemote response;
1598 if (Host::CalculateMD5(FileSpec(path.c_str(),false),a,b) == false)
1600 response.PutCString("F,");
1601 response.PutCString("x");
1605 response.PutCString("F,");
1606 response.PutHex64(a);
1607 response.PutHex64(b);
1609 return SendPacketNoLock(response.GetData(), response.GetSize());
1611 return SendErrorResponse(25);