Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 1 | //===-- 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 Ledru | d28b993 | 2013-09-28 15:23:41 +0000 | [diff] [blame] | 10 | #include <errno.h> |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 11 | |
| 12 | #include "GDBRemoteCommunicationServer.h" |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 13 | #include "lldb/Core/StreamGDBRemote.h" |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 14 | |
| 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 Granata | f2bbf71 | 2011-07-15 02:26:42 +0000 | [diff] [blame] | 24 | #include "lldb/Host/Endian.h" |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 25 | #include "lldb/Host/File.h" |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 26 | #include "lldb/Host/Host.h" |
| 27 | #include "lldb/Host/TimeValue.h" |
Todd Fiala | b8b49ec | 2014-01-28 00:34:23 +0000 | [diff] [blame^] | 28 | #include "lldb/Target/Platform.h" |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 29 | #include "lldb/Target/Process.h" |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 30 | |
| 31 | // Project includes |
| 32 | #include "Utility/StringExtractorGDBRemote.h" |
| 33 | #include "ProcessGDBRemote.h" |
| 34 | #include "ProcessGDBRemoteLog.h" |
| 35 | |
| 36 | using namespace lldb; |
| 37 | using namespace lldb_private; |
| 38 | |
| 39 | //---------------------------------------------------------------------- |
| 40 | // GDBRemoteCommunicationServer constructor |
| 41 | //---------------------------------------------------------------------- |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 42 | GDBRemoteCommunicationServer::GDBRemoteCommunicationServer(bool is_platform) : |
| 43 | GDBRemoteCommunication ("gdb-remote.server", "gdb-remote.server.rx_packet", is_platform), |
Todd Fiala | b8b49ec | 2014-01-28 00:34:23 +0000 | [diff] [blame^] | 44 | m_platform_sp (Platform::GetDefaultPlatform ()), |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 45 | m_async_thread (LLDB_INVALID_HOST_THREAD), |
| 46 | m_process_launch_info (), |
| 47 | m_process_launch_error (), |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 48 | m_spawned_pids (), |
| 49 | m_spawned_pids_mutex (Mutex::eMutexTypeRecursive), |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 50 | m_proc_infos (), |
| 51 | m_proc_infos_index (0), |
Greg Clayton | 2b98c56 | 2013-11-22 18:53:12 +0000 | [diff] [blame] | 52 | m_port_map (), |
| 53 | m_port_offset(0) |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 54 | { |
| 55 | } |
| 56 | |
Todd Fiala | b8b49ec | 2014-01-28 00:34:23 +0000 | [diff] [blame^] | 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 (), |
| 64 | m_spawned_pids (), |
| 65 | m_spawned_pids_mutex (Mutex::eMutexTypeRecursive), |
| 66 | m_proc_infos (), |
| 67 | m_proc_infos_index (0), |
| 68 | m_port_map (), |
| 69 | m_port_offset(0) |
| 70 | { |
| 71 | assert(platform_sp); |
| 72 | } |
| 73 | |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 74 | //---------------------------------------------------------------------- |
| 75 | // Destructor |
| 76 | //---------------------------------------------------------------------- |
| 77 | GDBRemoteCommunicationServer::~GDBRemoteCommunicationServer() |
| 78 | { |
| 79 | } |
| 80 | |
| 81 | |
| 82 | //void * |
| 83 | //GDBRemoteCommunicationServer::AsyncThread (void *arg) |
| 84 | //{ |
| 85 | // GDBRemoteCommunicationServer *server = (GDBRemoteCommunicationServer*) arg; |
| 86 | // |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 87 | // Log *log;// (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PROCESS)); |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 88 | // if (log) |
| 89 | // log->Printf ("ProcessGDBRemote::%s (arg = %p, pid = %i) thread starting...", __FUNCTION__, arg, process->GetID()); |
| 90 | // |
| 91 | // StringExtractorGDBRemote packet; |
Sylvestre Ledru | b027bd2 | 2013-09-28 14:35:00 +0000 | [diff] [blame] | 92 | // |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 93 | // while () |
| 94 | // { |
| 95 | // if (packet. |
| 96 | // } |
| 97 | // |
| 98 | // if (log) |
| 99 | // log->Printf ("ProcessGDBRemote::%s (arg = %p, pid = %i) thread exiting...", __FUNCTION__, arg, process->GetID()); |
| 100 | // |
| 101 | // process->m_async_thread = LLDB_INVALID_HOST_THREAD; |
| 102 | // return NULL; |
| 103 | //} |
| 104 | // |
| 105 | bool |
Sylvestre Ledru | b027bd2 | 2013-09-28 14:35:00 +0000 | [diff] [blame] | 106 | GDBRemoteCommunicationServer::GetPacketAndSendResponse (uint32_t timeout_usec, |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 107 | Error &error, |
Sylvestre Ledru | b027bd2 | 2013-09-28 14:35:00 +0000 | [diff] [blame] | 108 | bool &interrupt, |
Greg Clayton | d314e81 | 2011-03-23 00:09:55 +0000 | [diff] [blame] | 109 | bool &quit) |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 110 | { |
| 111 | StringExtractorGDBRemote packet; |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 112 | PacketResult packet_result = WaitForPacketWithTimeoutMicroSecondsNoLock (packet, timeout_usec); |
| 113 | if (packet_result == PacketResult::Success) |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 114 | { |
| 115 | const StringExtractorGDBRemote::ServerPacketType packet_type = packet.GetServerPacketType (); |
| 116 | switch (packet_type) |
| 117 | { |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 118 | case StringExtractorGDBRemote::eServerPacketType_nack: |
| 119 | case StringExtractorGDBRemote::eServerPacketType_ack: |
| 120 | break; |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 121 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 122 | case StringExtractorGDBRemote::eServerPacketType_invalid: |
| 123 | error.SetErrorString("invalid packet"); |
| 124 | quit = true; |
| 125 | break; |
Greg Clayton | d314e81 | 2011-03-23 00:09:55 +0000 | [diff] [blame] | 126 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 127 | case StringExtractorGDBRemote::eServerPacketType_interrupt: |
| 128 | error.SetErrorString("interrupt received"); |
| 129 | interrupt = true; |
| 130 | break; |
Sylvestre Ledru | b027bd2 | 2013-09-28 14:35:00 +0000 | [diff] [blame] | 131 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 132 | default: |
| 133 | case StringExtractorGDBRemote::eServerPacketType_unimplemented: |
| 134 | packet_result = SendUnimplementedResponse (packet.GetStringRef().c_str()); |
| 135 | break; |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 136 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 137 | case StringExtractorGDBRemote::eServerPacketType_A: |
| 138 | packet_result = Handle_A (packet); |
| 139 | break; |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 140 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 141 | case StringExtractorGDBRemote::eServerPacketType_qfProcessInfo: |
| 142 | packet_result = Handle_qfProcessInfo (packet); |
| 143 | break; |
Sylvestre Ledru | b027bd2 | 2013-09-28 14:35:00 +0000 | [diff] [blame] | 144 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 145 | case StringExtractorGDBRemote::eServerPacketType_qsProcessInfo: |
| 146 | packet_result = Handle_qsProcessInfo (packet); |
| 147 | break; |
Sylvestre Ledru | b027bd2 | 2013-09-28 14:35:00 +0000 | [diff] [blame] | 148 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 149 | case StringExtractorGDBRemote::eServerPacketType_qC: |
| 150 | packet_result = Handle_qC (packet); |
| 151 | break; |
Sylvestre Ledru | b027bd2 | 2013-09-28 14:35:00 +0000 | [diff] [blame] | 152 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 153 | case StringExtractorGDBRemote::eServerPacketType_qHostInfo: |
| 154 | packet_result = Handle_qHostInfo (packet); |
| 155 | break; |
Sylvestre Ledru | b027bd2 | 2013-09-28 14:35:00 +0000 | [diff] [blame] | 156 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 157 | case StringExtractorGDBRemote::eServerPacketType_qLaunchGDBServer: |
| 158 | packet_result = Handle_qLaunchGDBServer (packet); |
| 159 | break; |
Sylvestre Ledru | b027bd2 | 2013-09-28 14:35:00 +0000 | [diff] [blame] | 160 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 161 | case StringExtractorGDBRemote::eServerPacketType_qKillSpawnedProcess: |
| 162 | packet_result = Handle_qKillSpawnedProcess (packet); |
| 163 | break; |
Sylvestre Ledru | b027bd2 | 2013-09-28 14:35:00 +0000 | [diff] [blame] | 164 | |
Todd Fiala | 403edc5 | 2014-01-23 22:05:44 +0000 | [diff] [blame] | 165 | case StringExtractorGDBRemote::eServerPacketType_k: |
| 166 | packet_result = Handle_k (packet); |
| 167 | break; |
| 168 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 169 | case StringExtractorGDBRemote::eServerPacketType_qLaunchSuccess: |
| 170 | packet_result = Handle_qLaunchSuccess (packet); |
| 171 | break; |
Sylvestre Ledru | b027bd2 | 2013-09-28 14:35:00 +0000 | [diff] [blame] | 172 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 173 | case StringExtractorGDBRemote::eServerPacketType_qGroupName: |
| 174 | packet_result = Handle_qGroupName (packet); |
| 175 | break; |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 176 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 177 | case StringExtractorGDBRemote::eServerPacketType_qProcessInfoPID: |
| 178 | packet_result = Handle_qProcessInfoPID (packet); |
| 179 | break; |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 180 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 181 | case StringExtractorGDBRemote::eServerPacketType_qSpeedTest: |
| 182 | packet_result = Handle_qSpeedTest (packet); |
| 183 | break; |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 184 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 185 | case StringExtractorGDBRemote::eServerPacketType_qUserName: |
| 186 | packet_result = Handle_qUserName (packet); |
| 187 | break; |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 188 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 189 | case StringExtractorGDBRemote::eServerPacketType_qGetWorkingDir: |
| 190 | packet_result = Handle_qGetWorkingDir(packet); |
| 191 | break; |
Sylvestre Ledru | b027bd2 | 2013-09-28 14:35:00 +0000 | [diff] [blame] | 192 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 193 | case StringExtractorGDBRemote::eServerPacketType_QEnvironment: |
| 194 | packet_result = Handle_QEnvironment (packet); |
| 195 | break; |
Sylvestre Ledru | b027bd2 | 2013-09-28 14:35:00 +0000 | [diff] [blame] | 196 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 197 | case StringExtractorGDBRemote::eServerPacketType_QLaunchArch: |
| 198 | packet_result = Handle_QLaunchArch (packet); |
| 199 | break; |
Sylvestre Ledru | b027bd2 | 2013-09-28 14:35:00 +0000 | [diff] [blame] | 200 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 201 | case StringExtractorGDBRemote::eServerPacketType_QSetDisableASLR: |
| 202 | packet_result = Handle_QSetDisableASLR (packet); |
| 203 | break; |
Sylvestre Ledru | b027bd2 | 2013-09-28 14:35:00 +0000 | [diff] [blame] | 204 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 205 | case StringExtractorGDBRemote::eServerPacketType_QSetSTDIN: |
| 206 | packet_result = Handle_QSetSTDIN (packet); |
| 207 | break; |
Sylvestre Ledru | b027bd2 | 2013-09-28 14:35:00 +0000 | [diff] [blame] | 208 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 209 | case StringExtractorGDBRemote::eServerPacketType_QSetSTDOUT: |
| 210 | packet_result = Handle_QSetSTDOUT (packet); |
| 211 | break; |
Sylvestre Ledru | b027bd2 | 2013-09-28 14:35:00 +0000 | [diff] [blame] | 212 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 213 | case StringExtractorGDBRemote::eServerPacketType_QSetSTDERR: |
| 214 | packet_result = Handle_QSetSTDERR (packet); |
| 215 | break; |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 216 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 217 | case StringExtractorGDBRemote::eServerPacketType_QSetWorkingDir: |
| 218 | packet_result = Handle_QSetWorkingDir (packet); |
| 219 | break; |
Sylvestre Ledru | b027bd2 | 2013-09-28 14:35:00 +0000 | [diff] [blame] | 220 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 221 | case StringExtractorGDBRemote::eServerPacketType_QStartNoAckMode: |
| 222 | packet_result = Handle_QStartNoAckMode (packet); |
| 223 | break; |
Sylvestre Ledru | b027bd2 | 2013-09-28 14:35:00 +0000 | [diff] [blame] | 224 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 225 | case StringExtractorGDBRemote::eServerPacketType_qPlatform_mkdir: |
| 226 | packet_result = Handle_qPlatform_mkdir (packet); |
| 227 | break; |
Sylvestre Ledru | b027bd2 | 2013-09-28 14:35:00 +0000 | [diff] [blame] | 228 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 229 | case StringExtractorGDBRemote::eServerPacketType_qPlatform_chmod: |
| 230 | packet_result = Handle_qPlatform_chmod (packet); |
| 231 | break; |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 232 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 233 | case StringExtractorGDBRemote::eServerPacketType_qPlatform_shell: |
| 234 | packet_result = Handle_qPlatform_shell (packet); |
| 235 | break; |
Sylvestre Ledru | b027bd2 | 2013-09-28 14:35:00 +0000 | [diff] [blame] | 236 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 237 | case StringExtractorGDBRemote::eServerPacketType_vFile_open: |
| 238 | packet_result = Handle_vFile_Open (packet); |
| 239 | break; |
Sylvestre Ledru | b027bd2 | 2013-09-28 14:35:00 +0000 | [diff] [blame] | 240 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 241 | case StringExtractorGDBRemote::eServerPacketType_vFile_close: |
| 242 | packet_result = Handle_vFile_Close (packet); |
| 243 | break; |
Sylvestre Ledru | b027bd2 | 2013-09-28 14:35:00 +0000 | [diff] [blame] | 244 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 245 | case StringExtractorGDBRemote::eServerPacketType_vFile_pread: |
| 246 | packet_result = Handle_vFile_pRead (packet); |
| 247 | break; |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 248 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 249 | case StringExtractorGDBRemote::eServerPacketType_vFile_pwrite: |
| 250 | packet_result = Handle_vFile_pWrite (packet); |
| 251 | break; |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 252 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 253 | case StringExtractorGDBRemote::eServerPacketType_vFile_size: |
| 254 | packet_result = Handle_vFile_Size (packet); |
| 255 | break; |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 256 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 257 | case StringExtractorGDBRemote::eServerPacketType_vFile_mode: |
| 258 | packet_result = Handle_vFile_Mode (packet); |
| 259 | break; |
Sylvestre Ledru | b027bd2 | 2013-09-28 14:35:00 +0000 | [diff] [blame] | 260 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 261 | case StringExtractorGDBRemote::eServerPacketType_vFile_exists: |
| 262 | packet_result = Handle_vFile_Exists (packet); |
| 263 | break; |
Sylvestre Ledru | b027bd2 | 2013-09-28 14:35:00 +0000 | [diff] [blame] | 264 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 265 | case StringExtractorGDBRemote::eServerPacketType_vFile_stat: |
| 266 | packet_result = Handle_vFile_Stat (packet); |
| 267 | break; |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 268 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 269 | case StringExtractorGDBRemote::eServerPacketType_vFile_md5: |
| 270 | packet_result = Handle_vFile_MD5 (packet); |
| 271 | break; |
| 272 | |
| 273 | case StringExtractorGDBRemote::eServerPacketType_vFile_symlink: |
| 274 | packet_result = Handle_vFile_symlink (packet); |
| 275 | break; |
| 276 | |
| 277 | case StringExtractorGDBRemote::eServerPacketType_vFile_unlink: |
| 278 | packet_result = Handle_vFile_unlink (packet); |
| 279 | break; |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 280 | } |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 281 | } |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 282 | else |
| 283 | { |
| 284 | if (!IsConnected()) |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 285 | { |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 286 | error.SetErrorString("lost connection"); |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 287 | quit = true; |
| 288 | } |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 289 | else |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 290 | { |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 291 | error.SetErrorString("timeout"); |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 292 | } |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 293 | } |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 294 | return packet_result == PacketResult::Success; |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 295 | } |
| 296 | |
Todd Fiala | 403edc5 | 2014-01-23 22:05:44 +0000 | [diff] [blame] | 297 | lldb_private::Error |
Todd Fiala | 3e92a2b | 2014-01-24 00:52:53 +0000 | [diff] [blame] | 298 | GDBRemoteCommunicationServer::SetLaunchArguments (const char *const args[], int argc) |
Todd Fiala | 403edc5 | 2014-01-23 22:05:44 +0000 | [diff] [blame] | 299 | { |
| 300 | if ((argc < 1) || !args || !args[0] || !args[0][0]) |
Todd Fiala | 3e92a2b | 2014-01-24 00:52:53 +0000 | [diff] [blame] | 301 | return lldb_private::Error ("%s: no process command line specified to launch", __FUNCTION__); |
Todd Fiala | 403edc5 | 2014-01-23 22:05:44 +0000 | [diff] [blame] | 302 | |
Todd Fiala | 403edc5 | 2014-01-23 22:05:44 +0000 | [diff] [blame] | 303 | m_process_launch_info.SetArguments (const_cast<const char**> (args), true); |
Todd Fiala | 3e92a2b | 2014-01-24 00:52:53 +0000 | [diff] [blame] | 304 | return lldb_private::Error (); |
| 305 | } |
| 306 | |
| 307 | lldb_private::Error |
| 308 | GDBRemoteCommunicationServer::SetLaunchFlags (unsigned int launch_flags) |
| 309 | { |
Todd Fiala | 403edc5 | 2014-01-23 22:05:44 +0000 | [diff] [blame] | 310 | m_process_launch_info.GetFlags ().Set (launch_flags); |
Todd Fiala | 3e92a2b | 2014-01-24 00:52:53 +0000 | [diff] [blame] | 311 | return lldb_private::Error (); |
| 312 | } |
| 313 | |
| 314 | lldb_private::Error |
| 315 | GDBRemoteCommunicationServer::LaunchProcess () |
| 316 | { |
| 317 | if (!m_process_launch_info.GetArguments ().GetArgumentCount ()) |
| 318 | return lldb_private::Error ("%s: no process command line specified to launch", __FUNCTION__); |
| 319 | |
| 320 | // specify the process monitor if not already set. This should |
| 321 | // generally be what happens since we need to reap started |
| 322 | // processes. |
| 323 | if (!m_process_launch_info.GetMonitorProcessCallback ()) |
| 324 | m_process_launch_info.SetMonitorProcessCallback(ReapDebuggedProcess, this, false); |
Todd Fiala | 403edc5 | 2014-01-23 22:05:44 +0000 | [diff] [blame] | 325 | |
Todd Fiala | b8b49ec | 2014-01-28 00:34:23 +0000 | [diff] [blame^] | 326 | lldb_private::Error error = m_platform_sp->LaunchProcess (m_process_launch_info); |
Todd Fiala | 403edc5 | 2014-01-23 22:05:44 +0000 | [diff] [blame] | 327 | if (!error.Success ()) |
| 328 | { |
Todd Fiala | 3e92a2b | 2014-01-24 00:52:53 +0000 | [diff] [blame] | 329 | fprintf (stderr, "%s: failed to launch executable %s", __FUNCTION__, m_process_launch_info.GetArguments ().GetArgumentAtIndex (0)); |
Todd Fiala | 403edc5 | 2014-01-23 22:05:44 +0000 | [diff] [blame] | 330 | return error; |
| 331 | } |
| 332 | |
Todd Fiala | 3e92a2b | 2014-01-24 00:52:53 +0000 | [diff] [blame] | 333 | printf ("Launched '%s' as process %" PRIu64 "...\n", m_process_launch_info.GetArguments ().GetArgumentAtIndex (0), m_process_launch_info.GetProcessID()); |
Todd Fiala | 403edc5 | 2014-01-23 22:05:44 +0000 | [diff] [blame] | 334 | |
| 335 | // add to list of spawned processes. On an lldb-gdbserver, we |
| 336 | // would expect there to be only one. |
| 337 | lldb::pid_t pid; |
| 338 | if ( (pid = m_process_launch_info.GetProcessID()) != LLDB_INVALID_PROCESS_ID ) |
| 339 | { |
| 340 | Mutex::Locker locker (m_spawned_pids_mutex); |
| 341 | m_spawned_pids.insert(pid); |
| 342 | } |
| 343 | |
| 344 | return error; |
| 345 | } |
| 346 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 347 | GDBRemoteCommunication::PacketResult |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 348 | GDBRemoteCommunicationServer::SendUnimplementedResponse (const char *) |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 349 | { |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 350 | // TODO: Log the packet we aren't handling... |
Greg Clayton | 37a0a24 | 2012-04-11 00:24:49 +0000 | [diff] [blame] | 351 | return SendPacketNoLock ("", 0); |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 352 | } |
| 353 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 354 | GDBRemoteCommunication::PacketResult |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 355 | GDBRemoteCommunicationServer::SendErrorResponse (uint8_t err) |
| 356 | { |
| 357 | char packet[16]; |
| 358 | int packet_len = ::snprintf (packet, sizeof(packet), "E%2.2x", err); |
Andy Gibbs | a297a97 | 2013-06-19 19:04:53 +0000 | [diff] [blame] | 359 | assert (packet_len < (int)sizeof(packet)); |
Greg Clayton | 37a0a24 | 2012-04-11 00:24:49 +0000 | [diff] [blame] | 360 | return SendPacketNoLock (packet, packet_len); |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 364 | GDBRemoteCommunication::PacketResult |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 365 | GDBRemoteCommunicationServer::SendOKResponse () |
| 366 | { |
Greg Clayton | 37a0a24 | 2012-04-11 00:24:49 +0000 | [diff] [blame] | 367 | return SendPacketNoLock ("OK", 2); |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | bool |
| 371 | GDBRemoteCommunicationServer::HandshakeWithClient(Error *error_ptr) |
| 372 | { |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 373 | return GetAck() == PacketResult::Success; |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 374 | } |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 375 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 376 | GDBRemoteCommunication::PacketResult |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 377 | GDBRemoteCommunicationServer::Handle_qHostInfo (StringExtractorGDBRemote &packet) |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 378 | { |
| 379 | StreamString response; |
Sylvestre Ledru | b027bd2 | 2013-09-28 14:35:00 +0000 | [diff] [blame] | 380 | |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 381 | // $cputype:16777223;cpusubtype:3;ostype:Darwin;vendor:apple;endian:little;ptrsize:8;#00 |
| 382 | |
| 383 | ArchSpec host_arch (Host::GetArchitecture ()); |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 384 | const llvm::Triple &host_triple = host_arch.GetTriple(); |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 385 | response.PutCString("triple:"); |
| 386 | response.PutCStringAsRawHex8(host_triple.getTriple().c_str()); |
| 387 | response.Printf (";ptrsize:%u;",host_arch.GetAddressByteSize()); |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 388 | |
Todd Fiala | a9ddb0e | 2014-01-18 03:02:39 +0000 | [diff] [blame] | 389 | const char* distribution_id = host_arch.GetDistributionId ().AsCString (); |
| 390 | if (distribution_id) |
| 391 | { |
| 392 | response.PutCString("distribution_id:"); |
| 393 | response.PutCStringAsRawHex8(distribution_id); |
| 394 | response.PutCString(";"); |
| 395 | } |
| 396 | |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 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); |
Sylvestre Ledru | b027bd2 | 2013-09-28 14:35:00 +0000 | [diff] [blame] | 403 | |
Enrico Granata | 1c5431a | 2012-07-13 23:55:22 +0000 | [diff] [blame] | 404 | if (cpu == ArchSpec::kCore_arm_any) |
Enrico Granata | f04a219 | 2012-07-13 23:18:48 +0000 | [diff] [blame] | 405 | response.Printf("watchpoint_exceptions_received:before;"); // On armv7 we use "synchronous" watchpoints which means the exception is delivered before the instruction executes. |
| 406 | else |
| 407 | response.Printf("watchpoint_exceptions_received:after;"); |
Sylvestre Ledru | b027bd2 | 2013-09-28 14:35:00 +0000 | [diff] [blame] | 408 | |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 409 | switch (lldb::endian::InlHostByteOrder()) |
| 410 | { |
| 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; |
| 415 | } |
Sylvestre Ledru | b027bd2 | 2013-09-28 14:35:00 +0000 | [diff] [blame] | 416 | |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 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)) |
| 421 | { |
| 422 | if (major != UINT32_MAX) |
| 423 | { |
| 424 | response.Printf("os_version:%u", major); |
| 425 | if (minor != UINT32_MAX) |
| 426 | { |
| 427 | response.Printf(".%u", minor); |
| 428 | if (update != UINT32_MAX) |
| 429 | response.Printf(".%u", update); |
| 430 | } |
| 431 | response.PutChar(';'); |
| 432 | } |
| 433 | } |
| 434 | |
| 435 | std::string s; |
| 436 | if (Host::GetOSBuildString (s)) |
| 437 | { |
| 438 | response.PutCString ("os_build:"); |
| 439 | response.PutCStringAsRawHex8(s.c_str()); |
| 440 | response.PutChar(';'); |
| 441 | } |
| 442 | if (Host::GetOSKernelDescription (s)) |
| 443 | { |
| 444 | response.PutCString ("os_kernel:"); |
| 445 | response.PutCStringAsRawHex8(s.c_str()); |
| 446 | response.PutChar(';'); |
| 447 | } |
Greg Clayton | 2b98c56 | 2013-11-22 18:53:12 +0000 | [diff] [blame] | 448 | #if defined(__APPLE__) |
| 449 | |
| 450 | #if defined(__arm__) |
| 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__) |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 458 | if (Host::GetHostname (s)) |
| 459 | { |
| 460 | response.PutCString ("hostname:"); |
| 461 | response.PutCStringAsRawHex8(s.c_str()); |
| 462 | response.PutChar(';'); |
| 463 | } |
Sylvestre Ledru | b027bd2 | 2013-09-28 14:35:00 +0000 | [diff] [blame] | 464 | |
Greg Clayton | 2b98c56 | 2013-11-22 18:53:12 +0000 | [diff] [blame] | 465 | #endif // #if defined(__arm__) |
| 466 | |
| 467 | #else // #if defined(__APPLE__) |
| 468 | if (Host::GetHostname (s)) |
| 469 | { |
| 470 | response.PutCString ("hostname:"); |
| 471 | response.PutCStringAsRawHex8(s.c_str()); |
| 472 | response.PutChar(';'); |
| 473 | } |
| 474 | #endif // #if defined(__APPLE__) |
| 475 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 476 | return SendPacketNoLock (response.GetData(), response.GetSize()); |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 477 | } |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 478 | |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 479 | static void |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 480 | CreateProcessInfoResponse (const ProcessInstanceInfo &proc_info, StreamString &response) |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 481 | { |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 482 | response.Printf ("pid:%" PRIu64 ";ppid:%" PRIu64 ";uid:%i;gid:%i;euid:%i;egid:%i;", |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 483 | proc_info.GetProcessID(), |
| 484 | proc_info.GetParentProcessID(), |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 485 | proc_info.GetUserID(), |
| 486 | proc_info.GetGroupID(), |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 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()) |
| 494 | { |
| 495 | const llvm::Triple &proc_triple = proc_arch.GetTriple(); |
| 496 | response.PutCString("triple:"); |
| 497 | response.PutCStringAsRawHex8(proc_triple.getTriple().c_str()); |
| 498 | response.PutChar(';'); |
| 499 | } |
| 500 | } |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 501 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 502 | GDBRemoteCommunication::PacketResult |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 503 | GDBRemoteCommunicationServer::Handle_qProcessInfoPID (StringExtractorGDBRemote &packet) |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 504 | { |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 505 | // Packet format: "qProcessInfoPID:%i" where %i is the pid |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 506 | packet.SetFilePos(::strlen ("qProcessInfoPID:")); |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 507 | lldb::pid_t pid = packet.GetU32 (LLDB_INVALID_PROCESS_ID); |
| 508 | if (pid != LLDB_INVALID_PROCESS_ID) |
| 509 | { |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 510 | ProcessInstanceInfo proc_info; |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 511 | if (Host::GetProcessInfo(pid, proc_info)) |
| 512 | { |
| 513 | StreamString response; |
| 514 | CreateProcessInfoResponse (proc_info, response); |
Greg Clayton | 37a0a24 | 2012-04-11 00:24:49 +0000 | [diff] [blame] | 515 | return SendPacketNoLock (response.GetData(), response.GetSize()); |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 516 | } |
| 517 | } |
| 518 | return SendErrorResponse (1); |
| 519 | } |
| 520 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 521 | GDBRemoteCommunication::PacketResult |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 522 | GDBRemoteCommunicationServer::Handle_qfProcessInfo (StringExtractorGDBRemote &packet) |
| 523 | { |
| 524 | m_proc_infos_index = 0; |
| 525 | m_proc_infos.Clear(); |
| 526 | |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 527 | ProcessInstanceInfoMatch match_info; |
| 528 | packet.SetFilePos(::strlen ("qfProcessInfo")); |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 529 | if (packet.GetChar() == ':') |
| 530 | { |
Sylvestre Ledru | b027bd2 | 2013-09-28 14:35:00 +0000 | [diff] [blame] | 531 | |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 532 | std::string key; |
| 533 | std::string value; |
| 534 | while (packet.GetNameColonValue(key, value)) |
| 535 | { |
| 536 | bool success = true; |
| 537 | if (key.compare("name") == 0) |
| 538 | { |
| 539 | StringExtractor extractor; |
| 540 | extractor.GetStringRef().swap(value); |
| 541 | extractor.GetHexByteString (value); |
Greg Clayton | 144f3a9 | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 542 | match_info.GetProcessInfo().GetExecutableFile().SetFile(value.c_str(), false); |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 543 | } |
| 544 | else if (key.compare("name_match") == 0) |
| 545 | { |
| 546 | if (value.compare("equals") == 0) |
| 547 | { |
| 548 | match_info.SetNameMatchType (eNameMatchEquals); |
| 549 | } |
| 550 | else if (value.compare("starts_with") == 0) |
| 551 | { |
| 552 | match_info.SetNameMatchType (eNameMatchStartsWith); |
| 553 | } |
| 554 | else if (value.compare("ends_with") == 0) |
| 555 | { |
| 556 | match_info.SetNameMatchType (eNameMatchEndsWith); |
| 557 | } |
| 558 | else if (value.compare("contains") == 0) |
| 559 | { |
| 560 | match_info.SetNameMatchType (eNameMatchContains); |
| 561 | } |
Sylvestre Ledru | b027bd2 | 2013-09-28 14:35:00 +0000 | [diff] [blame] | 562 | else if (value.compare("regex") == 0) |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 563 | { |
| 564 | match_info.SetNameMatchType (eNameMatchRegularExpression); |
| 565 | } |
Sylvestre Ledru | b027bd2 | 2013-09-28 14:35:00 +0000 | [diff] [blame] | 566 | else |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 567 | { |
| 568 | success = false; |
| 569 | } |
| 570 | } |
| 571 | else if (key.compare("pid") == 0) |
| 572 | { |
| 573 | match_info.GetProcessInfo().SetProcessID (Args::StringToUInt32(value.c_str(), LLDB_INVALID_PROCESS_ID, 0, &success)); |
| 574 | } |
| 575 | else if (key.compare("parent_pid") == 0) |
| 576 | { |
| 577 | match_info.GetProcessInfo().SetParentProcessID (Args::StringToUInt32(value.c_str(), LLDB_INVALID_PROCESS_ID, 0, &success)); |
| 578 | } |
| 579 | else if (key.compare("uid") == 0) |
| 580 | { |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 581 | match_info.GetProcessInfo().SetUserID (Args::StringToUInt32(value.c_str(), UINT32_MAX, 0, &success)); |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 582 | } |
| 583 | else if (key.compare("gid") == 0) |
| 584 | { |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 585 | match_info.GetProcessInfo().SetGroupID (Args::StringToUInt32(value.c_str(), UINT32_MAX, 0, &success)); |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 586 | } |
| 587 | else if (key.compare("euid") == 0) |
| 588 | { |
| 589 | match_info.GetProcessInfo().SetEffectiveUserID (Args::StringToUInt32(value.c_str(), UINT32_MAX, 0, &success)); |
| 590 | } |
| 591 | else if (key.compare("egid") == 0) |
| 592 | { |
| 593 | match_info.GetProcessInfo().SetEffectiveGroupID (Args::StringToUInt32(value.c_str(), UINT32_MAX, 0, &success)); |
| 594 | } |
| 595 | else if (key.compare("all_users") == 0) |
| 596 | { |
| 597 | match_info.SetMatchAllUsers(Args::StringToBoolean(value.c_str(), false, &success)); |
| 598 | } |
| 599 | else if (key.compare("triple") == 0) |
| 600 | { |
Greg Clayton | eb0103f | 2011-04-07 22:46:35 +0000 | [diff] [blame] | 601 | match_info.GetProcessInfo().GetArchitecture().SetTriple (value.c_str(), NULL); |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 602 | } |
| 603 | else |
| 604 | { |
| 605 | success = false; |
| 606 | } |
Sylvestre Ledru | b027bd2 | 2013-09-28 14:35:00 +0000 | [diff] [blame] | 607 | |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 608 | if (!success) |
| 609 | return SendErrorResponse (2); |
| 610 | } |
| 611 | } |
| 612 | |
| 613 | if (Host::FindProcesses (match_info, m_proc_infos)) |
| 614 | { |
| 615 | // We found something, return the first item by calling the get |
| 616 | // subsequent process info packet handler... |
| 617 | return Handle_qsProcessInfo (packet); |
| 618 | } |
| 619 | return SendErrorResponse (3); |
| 620 | } |
| 621 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 622 | GDBRemoteCommunication::PacketResult |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 623 | GDBRemoteCommunicationServer::Handle_qsProcessInfo (StringExtractorGDBRemote &packet) |
| 624 | { |
| 625 | if (m_proc_infos_index < m_proc_infos.GetSize()) |
| 626 | { |
| 627 | StreamString response; |
| 628 | CreateProcessInfoResponse (m_proc_infos.GetProcessInfoAtIndex(m_proc_infos_index), response); |
| 629 | ++m_proc_infos_index; |
Greg Clayton | 37a0a24 | 2012-04-11 00:24:49 +0000 | [diff] [blame] | 630 | return SendPacketNoLock (response.GetData(), response.GetSize()); |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 631 | } |
| 632 | return SendErrorResponse (4); |
| 633 | } |
| 634 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 635 | GDBRemoteCommunication::PacketResult |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 636 | GDBRemoteCommunicationServer::Handle_qUserName (StringExtractorGDBRemote &packet) |
| 637 | { |
| 638 | // Packet format: "qUserName:%i" where %i is the uid |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 639 | packet.SetFilePos(::strlen ("qUserName:")); |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 640 | uint32_t uid = packet.GetU32 (UINT32_MAX); |
| 641 | if (uid != UINT32_MAX) |
| 642 | { |
| 643 | std::string name; |
| 644 | if (Host::GetUserName (uid, name)) |
| 645 | { |
| 646 | StreamString response; |
| 647 | response.PutCStringAsRawHex8 (name.c_str()); |
Greg Clayton | 37a0a24 | 2012-04-11 00:24:49 +0000 | [diff] [blame] | 648 | return SendPacketNoLock (response.GetData(), response.GetSize()); |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 649 | } |
| 650 | } |
| 651 | return SendErrorResponse (5); |
Sylvestre Ledru | b027bd2 | 2013-09-28 14:35:00 +0000 | [diff] [blame] | 652 | |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 653 | } |
| 654 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 655 | GDBRemoteCommunication::PacketResult |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 656 | GDBRemoteCommunicationServer::Handle_qGroupName (StringExtractorGDBRemote &packet) |
| 657 | { |
| 658 | // Packet format: "qGroupName:%i" where %i is the gid |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 659 | packet.SetFilePos(::strlen ("qGroupName:")); |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 660 | uint32_t gid = packet.GetU32 (UINT32_MAX); |
| 661 | if (gid != UINT32_MAX) |
| 662 | { |
| 663 | std::string name; |
| 664 | if (Host::GetGroupName (gid, name)) |
| 665 | { |
| 666 | StreamString response; |
| 667 | response.PutCStringAsRawHex8 (name.c_str()); |
Greg Clayton | 37a0a24 | 2012-04-11 00:24:49 +0000 | [diff] [blame] | 668 | return SendPacketNoLock (response.GetData(), response.GetSize()); |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 669 | } |
| 670 | } |
| 671 | return SendErrorResponse (6); |
| 672 | } |
| 673 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 674 | GDBRemoteCommunication::PacketResult |
Greg Clayton | 9b1e1cd | 2011-04-04 18:18:57 +0000 | [diff] [blame] | 675 | GDBRemoteCommunicationServer::Handle_qSpeedTest (StringExtractorGDBRemote &packet) |
| 676 | { |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 677 | packet.SetFilePos(::strlen ("qSpeedTest:")); |
Greg Clayton | 9b1e1cd | 2011-04-04 18:18:57 +0000 | [diff] [blame] | 678 | |
| 679 | std::string key; |
| 680 | std::string value; |
| 681 | bool success = packet.GetNameColonValue(key, value); |
| 682 | if (success && key.compare("response_size") == 0) |
| 683 | { |
| 684 | uint32_t response_size = Args::StringToUInt32(value.c_str(), 0, 0, &success); |
| 685 | if (success) |
| 686 | { |
| 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) |
| 693 | { |
| 694 | if (bytes_left >= 26) |
| 695 | { |
| 696 | response.PutCString("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); |
| 697 | bytes_left -= 26; |
| 698 | } |
| 699 | else |
| 700 | { |
| 701 | response.Printf ("%*.*s;", bytes_left, bytes_left, "ABCDEFGHIJKLMNOPQRSTUVWXYZ"); |
| 702 | bytes_left = 0; |
| 703 | } |
| 704 | } |
Greg Clayton | 37a0a24 | 2012-04-11 00:24:49 +0000 | [diff] [blame] | 705 | return SendPacketNoLock (response.GetData(), response.GetSize()); |
Greg Clayton | 9b1e1cd | 2011-04-04 18:18:57 +0000 | [diff] [blame] | 706 | } |
| 707 | } |
| 708 | return SendErrorResponse (7); |
| 709 | } |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 710 | |
| 711 | |
| 712 | static void * |
| 713 | AcceptPortFromInferior (void *arg) |
| 714 | { |
| 715 | const char *connect_url = (const char *)arg; |
| 716 | ConnectionFileDescriptor file_conn; |
| 717 | Error error; |
| 718 | if (file_conn.Connect (connect_url, &error) == eConnectionStatusSuccess) |
| 719 | { |
| 720 | char pid_str[256]; |
| 721 | ::memset (pid_str, 0, sizeof(pid_str)); |
| 722 | ConnectionStatus status; |
Bill Wendling | ed24dcc | 2012-04-03 07:50:11 +0000 | [diff] [blame] | 723 | const size_t pid_str_len = file_conn.Read (pid_str, sizeof(pid_str), 0, status, NULL); |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 724 | if (pid_str_len > 0) |
| 725 | { |
| 726 | int pid = atoi (pid_str); |
| 727 | return (void *)(intptr_t)pid; |
| 728 | } |
| 729 | } |
| 730 | return NULL; |
| 731 | } |
| 732 | // |
| 733 | //static bool |
| 734 | //WaitForProcessToSIGSTOP (const lldb::pid_t pid, const int timeout_in_seconds) |
| 735 | //{ |
| 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++) |
| 739 | // { |
| 740 | // struct proc_bsdinfo bsd_info; |
Sylvestre Ledru | b027bd2 | 2013-09-28 14:35:00 +0000 | [diff] [blame] | 741 | // int error = ::proc_pidinfo (pid, PROC_PIDTBSDINFO, |
| 742 | // (uint64_t) 0, |
| 743 | // &bsd_info, |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 744 | // PROC_PIDTBSDINFO_SIZE); |
Sylvestre Ledru | b027bd2 | 2013-09-28 14:35:00 +0000 | [diff] [blame] | 745 | // |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 746 | // switch (error) |
| 747 | // { |
| 748 | // case EINVAL: |
| 749 | // case ENOTSUP: |
| 750 | // case ESRCH: |
| 751 | // case EPERM: |
| 752 | // return false; |
Sylvestre Ledru | b027bd2 | 2013-09-28 14:35:00 +0000 | [diff] [blame] | 753 | // |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 754 | // default: |
| 755 | // break; |
Sylvestre Ledru | b027bd2 | 2013-09-28 14:35:00 +0000 | [diff] [blame] | 756 | // |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 757 | // case 0: |
| 758 | // if (bsd_info.pbi_status == SSTOP) |
| 759 | // return true; |
| 760 | // } |
| 761 | // ::usleep (time_delta_usecs); |
| 762 | // } |
| 763 | // return false; |
| 764 | //} |
| 765 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 766 | GDBRemoteCommunication::PacketResult |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 767 | GDBRemoteCommunicationServer::Handle_A (StringExtractorGDBRemote &packet) |
| 768 | { |
Sylvestre Ledru | b027bd2 | 2013-09-28 14:35:00 +0000 | [diff] [blame] | 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 |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 772 | // separated hex encoded argument value list, but we will stay true to the |
| 773 | // documented version of the 'A' packet here... |
| 774 | |
| 775 | packet.SetFilePos(1); // Skip the 'A' |
| 776 | bool success = true; |
| 777 | while (success && packet.GetBytesLeft() > 0) |
| 778 | { |
| 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) |
| 783 | success = false; |
| 784 | else |
| 785 | { |
| 786 | // Make sure the argument hex string length is followed by a comma |
| 787 | if (packet.GetChar() != ',') |
| 788 | success = false; |
| 789 | else |
| 790 | { |
| 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) |
| 795 | success = false; |
| 796 | else |
| 797 | { |
| 798 | // Make sure the argument index is followed by a comma |
| 799 | if (packet.GetChar() != ',') |
| 800 | success = false; |
| 801 | else |
| 802 | { |
| 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 |
| 806 | std::string arg; |
| 807 | if (packet.GetHexByteString(arg) != (arg_len / 2)) |
| 808 | success = false; |
| 809 | else |
| 810 | { |
| 811 | // If there are any bytes lft |
| 812 | if (packet.GetBytesLeft()) |
| 813 | { |
| 814 | if (packet.GetChar() != ',') |
| 815 | success = false; |
| 816 | } |
Sylvestre Ledru | b027bd2 | 2013-09-28 14:35:00 +0000 | [diff] [blame] | 817 | |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 818 | if (success) |
| 819 | { |
| 820 | if (arg_idx == 0) |
| 821 | m_process_launch_info.GetExecutableFile().SetFile(arg.c_str(), false); |
| 822 | m_process_launch_info.GetArguments().AppendArgument(arg.c_str()); |
| 823 | } |
| 824 | } |
| 825 | } |
| 826 | } |
| 827 | } |
| 828 | } |
| 829 | } |
| 830 | |
| 831 | if (success) |
| 832 | { |
Todd Fiala | 9f37737 | 2014-01-27 20:44:50 +0000 | [diff] [blame] | 833 | // FIXME: remove linux restriction once eLaunchFlagDebug is supported |
| 834 | #if !defined (__linux__) |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 835 | m_process_launch_info.GetFlags().Set (eLaunchFlagDebug); |
Todd Fiala | 9f37737 | 2014-01-27 20:44:50 +0000 | [diff] [blame] | 836 | #endif |
| 837 | m_process_launch_error = LaunchProcess (); |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 838 | if (m_process_launch_info.GetProcessID() != LLDB_INVALID_PROCESS_ID) |
| 839 | { |
| 840 | return SendOKResponse (); |
| 841 | } |
| 842 | } |
| 843 | return SendErrorResponse (8); |
| 844 | } |
| 845 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 846 | GDBRemoteCommunication::PacketResult |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 847 | GDBRemoteCommunicationServer::Handle_qC (StringExtractorGDBRemote &packet) |
| 848 | { |
| 849 | lldb::pid_t pid = m_process_launch_info.GetProcessID(); |
| 850 | StreamString response; |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 851 | response.Printf("QC%" PRIx64, pid); |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 852 | if (m_is_platform) |
| 853 | { |
Sylvestre Ledru | b027bd2 | 2013-09-28 14:35:00 +0000 | [diff] [blame] | 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 |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 856 | // launching another process. In order to launch a process a bunch or |
| 857 | // packets need to be sent: environment packets, working directory, |
Sylvestre Ledru | b027bd2 | 2013-09-28 14:35:00 +0000 | [diff] [blame] | 858 | // disable ASLR, and many more settings. When we launch a process we |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 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 |
| 861 | // sense. |
| 862 | if (pid != LLDB_INVALID_PROCESS_ID) |
| 863 | { |
| 864 | m_process_launch_info.Clear(); |
| 865 | } |
| 866 | } |
Greg Clayton | 37a0a24 | 2012-04-11 00:24:49 +0000 | [diff] [blame] | 867 | return SendPacketNoLock (response.GetData(), response.GetSize()); |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 868 | } |
| 869 | |
| 870 | bool |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 871 | GDBRemoteCommunicationServer::DebugserverProcessReaped (lldb::pid_t pid) |
| 872 | { |
| 873 | Mutex::Locker locker (m_spawned_pids_mutex); |
Greg Clayton | 29b8fc4 | 2013-11-21 01:44:58 +0000 | [diff] [blame] | 874 | FreePortForProcess(pid); |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 875 | return m_spawned_pids.erase(pid) > 0; |
| 876 | } |
| 877 | bool |
| 878 | GDBRemoteCommunicationServer::ReapDebugserverProcess (void *callback_baton, |
| 879 | lldb::pid_t pid, |
| 880 | bool exited, |
| 881 | int signal, // Zero for no signal |
| 882 | int status) // Exit value of process if signal is zero |
| 883 | { |
| 884 | GDBRemoteCommunicationServer *server = (GDBRemoteCommunicationServer *)callback_baton; |
| 885 | server->DebugserverProcessReaped (pid); |
| 886 | return true; |
| 887 | } |
| 888 | |
Todd Fiala | 3e92a2b | 2014-01-24 00:52:53 +0000 | [diff] [blame] | 889 | bool |
| 890 | GDBRemoteCommunicationServer::DebuggedProcessReaped (lldb::pid_t pid) |
| 891 | { |
| 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; |
| 895 | } |
| 896 | |
| 897 | bool |
| 898 | GDBRemoteCommunicationServer::ReapDebuggedProcess (void *callback_baton, |
| 899 | lldb::pid_t pid, |
| 900 | bool exited, |
| 901 | int signal, // Zero for no signal |
| 902 | int status) // Exit value of process if signal is zero |
| 903 | { |
| 904 | GDBRemoteCommunicationServer *server = (GDBRemoteCommunicationServer *)callback_baton; |
| 905 | server->DebuggedProcessReaped (pid); |
| 906 | return true; |
| 907 | } |
| 908 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 909 | GDBRemoteCommunication::PacketResult |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 910 | GDBRemoteCommunicationServer::Handle_qLaunchGDBServer (StringExtractorGDBRemote &packet) |
| 911 | { |
Virgile Bello | b2f1fb2 | 2013-08-23 12:44:05 +0000 | [diff] [blame] | 912 | #ifdef _WIN32 |
Deepak Panickal | 263fde0 | 2014-01-14 11:34:44 +0000 | [diff] [blame] | 913 | return SendErrorResponse(9); |
Virgile Bello | b2f1fb2 | 2013-08-23 12:44:05 +0000 | [diff] [blame] | 914 | #else |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 915 | // Spawn a local debugserver as a platform so we can then attach or launch |
| 916 | // a process... |
| 917 | |
| 918 | if (m_is_platform) |
| 919 | { |
| 920 | // Sleep and wait a bit for debugserver to start to listen... |
| 921 | ConnectionFileDescriptor file_conn; |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 922 | Error error; |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 923 | std::string hostname; |
Sylvestre Ledru | faa63ce | 2013-09-28 15:57:37 +0000 | [diff] [blame] | 924 | // TODO: /tmp/ should not be hardcoded. User might want to override /tmp |
| 925 | // with the TMPDIR environnement variable |
Greg Clayton | 29b8fc4 | 2013-11-21 01:44:58 +0000 | [diff] [blame] | 926 | packet.SetFilePos(::strlen ("qLaunchGDBServer;")); |
| 927 | std::string name; |
| 928 | std::string value; |
| 929 | uint16_t port = UINT16_MAX; |
| 930 | while (packet.GetNameColonValue(name, value)) |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 931 | { |
Greg Clayton | 29b8fc4 | 2013-11-21 01:44:58 +0000 | [diff] [blame] | 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); |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 936 | } |
Greg Clayton | 29b8fc4 | 2013-11-21 01:44:58 +0000 | [diff] [blame] | 937 | if (port == UINT16_MAX) |
| 938 | port = GetNextAvailablePort(); |
| 939 | |
| 940 | // Spawn a new thread to accept the port that gets bound after |
| 941 | // binding to port 0 (zero). |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 942 | |
Greg Clayton | 29b8fc4 | 2013-11-21 01:44:58 +0000 | [diff] [blame] | 943 | if (error.Success()) |
| 944 | { |
| 945 | // Spawn a debugserver and try to get the port it listens to. |
| 946 | ProcessLaunchInfo debugserver_launch_info; |
Greg Clayton | 29b8fc4 | 2013-11-21 01:44:58 +0000 | [diff] [blame] | 947 | if (hostname.empty()) |
| 948 | hostname = "localhost"; |
Greg Clayton | 29b8fc4 | 2013-11-21 01:44:58 +0000 | [diff] [blame] | 949 | Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PLATFORM)); |
| 950 | if (log) |
Greg Clayton | fda4fab | 2014-01-10 22:24:11 +0000 | [diff] [blame] | 951 | log->Printf("Launching debugserver with: %s:%u...\n", hostname.c_str(), port); |
Sylvestre Ledru | b027bd2 | 2013-09-28 14:35:00 +0000 | [diff] [blame] | 952 | |
Greg Clayton | 29b8fc4 | 2013-11-21 01:44:58 +0000 | [diff] [blame] | 953 | debugserver_launch_info.SetMonitorProcessCallback(ReapDebugserverProcess, this, false); |
| 954 | |
Greg Clayton | fda4fab | 2014-01-10 22:24:11 +0000 | [diff] [blame] | 955 | error = StartDebugserverProcess (hostname.empty() ? NULL : hostname.c_str(), |
| 956 | port, |
Greg Clayton | 00fe87b | 2013-12-05 22:58:22 +0000 | [diff] [blame] | 957 | debugserver_launch_info, |
| 958 | port); |
Greg Clayton | 29b8fc4 | 2013-11-21 01:44:58 +0000 | [diff] [blame] | 959 | |
| 960 | lldb::pid_t debugserver_pid = debugserver_launch_info.GetProcessID(); |
Sylvestre Ledru | b027bd2 | 2013-09-28 14:35:00 +0000 | [diff] [blame] | 961 | |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 962 | |
Greg Clayton | 29b8fc4 | 2013-11-21 01:44:58 +0000 | [diff] [blame] | 963 | if (debugserver_pid != LLDB_INVALID_PROCESS_ID) |
| 964 | { |
| 965 | Mutex::Locker locker (m_spawned_pids_mutex); |
| 966 | m_spawned_pids.insert(debugserver_pid); |
| 967 | if (port > 0) |
| 968 | AssociatePortWithProcess(port, debugserver_pid); |
| 969 | } |
| 970 | else |
| 971 | { |
| 972 | if (port > 0) |
| 973 | FreePort (port); |
| 974 | } |
| 975 | |
| 976 | if (error.Success()) |
| 977 | { |
Greg Clayton | 91a9b247 | 2013-12-04 19:19:12 +0000 | [diff] [blame] | 978 | char response[256]; |
| 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)); |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 981 | PacketResult packet_result = SendPacketNoLock (response, response_len); |
Greg Clayton | 29b8fc4 | 2013-11-21 01:44:58 +0000 | [diff] [blame] | 982 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 983 | if (packet_result != PacketResult::Success) |
Greg Clayton | 29b8fc4 | 2013-11-21 01:44:58 +0000 | [diff] [blame] | 984 | { |
| 985 | if (debugserver_pid != LLDB_INVALID_PROCESS_ID) |
| 986 | ::kill (debugserver_pid, SIGINT); |
| 987 | } |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 988 | return packet_result; |
Greg Clayton | 29b8fc4 | 2013-11-21 01:44:58 +0000 | [diff] [blame] | 989 | } |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 990 | } |
| 991 | } |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 992 | return SendErrorResponse (9); |
Virgile Bello | b2f1fb2 | 2013-08-23 12:44:05 +0000 | [diff] [blame] | 993 | #endif |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 994 | } |
| 995 | |
Todd Fiala | 403edc5 | 2014-01-23 22:05:44 +0000 | [diff] [blame] | 996 | bool |
| 997 | GDBRemoteCommunicationServer::KillSpawnedProcess (lldb::pid_t pid) |
| 998 | { |
| 999 | // make sure we know about this process |
| 1000 | { |
| 1001 | Mutex::Locker locker (m_spawned_pids_mutex); |
| 1002 | if (m_spawned_pids.find(pid) == m_spawned_pids.end()) |
| 1003 | return false; |
| 1004 | } |
| 1005 | |
| 1006 | // first try a SIGTERM (standard kill) |
| 1007 | Host::Kill (pid, SIGTERM); |
| 1008 | |
| 1009 | // check if that worked |
| 1010 | for (size_t i=0; i<10; ++i) |
| 1011 | { |
| 1012 | { |
| 1013 | Mutex::Locker locker (m_spawned_pids_mutex); |
| 1014 | if (m_spawned_pids.find(pid) == m_spawned_pids.end()) |
| 1015 | { |
| 1016 | // it is now killed |
| 1017 | return true; |
| 1018 | } |
| 1019 | } |
| 1020 | usleep (10000); |
| 1021 | } |
| 1022 | |
| 1023 | // check one more time after the final usleep |
| 1024 | { |
| 1025 | Mutex::Locker locker (m_spawned_pids_mutex); |
| 1026 | if (m_spawned_pids.find(pid) == m_spawned_pids.end()) |
| 1027 | return true; |
| 1028 | } |
| 1029 | |
| 1030 | // the launched process still lives. Now try killling it again, |
| 1031 | // this time with an unblockable signal. |
| 1032 | Host::Kill (pid, SIGKILL); |
| 1033 | |
| 1034 | for (size_t i=0; i<10; ++i) |
| 1035 | { |
| 1036 | { |
| 1037 | Mutex::Locker locker (m_spawned_pids_mutex); |
| 1038 | if (m_spawned_pids.find(pid) == m_spawned_pids.end()) |
| 1039 | { |
| 1040 | // it is now killed |
| 1041 | return true; |
| 1042 | } |
| 1043 | } |
| 1044 | usleep (10000); |
| 1045 | } |
| 1046 | |
| 1047 | // check one more time after the final usleep |
| 1048 | // Scope for locker |
| 1049 | { |
| 1050 | Mutex::Locker locker (m_spawned_pids_mutex); |
| 1051 | if (m_spawned_pids.find(pid) == m_spawned_pids.end()) |
| 1052 | return true; |
| 1053 | } |
| 1054 | |
| 1055 | // no luck - the process still lives |
| 1056 | return false; |
| 1057 | } |
| 1058 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 1059 | GDBRemoteCommunication::PacketResult |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1060 | GDBRemoteCommunicationServer::Handle_qKillSpawnedProcess (StringExtractorGDBRemote &packet) |
| 1061 | { |
Todd Fiala | 403edc5 | 2014-01-23 22:05:44 +0000 | [diff] [blame] | 1062 | packet.SetFilePos(::strlen ("qKillSpawnedProcess:")); |
Sylvestre Ledru | b027bd2 | 2013-09-28 14:35:00 +0000 | [diff] [blame] | 1063 | |
Todd Fiala | 403edc5 | 2014-01-23 22:05:44 +0000 | [diff] [blame] | 1064 | lldb::pid_t pid = packet.GetU64(LLDB_INVALID_PROCESS_ID); |
| 1065 | |
| 1066 | // verify that we know anything about this pid. |
| 1067 | // Scope for locker |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1068 | { |
Todd Fiala | 403edc5 | 2014-01-23 22:05:44 +0000 | [diff] [blame] | 1069 | Mutex::Locker locker (m_spawned_pids_mutex); |
| 1070 | if (m_spawned_pids.find(pid) == m_spawned_pids.end()) |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1071 | { |
Todd Fiala | 403edc5 | 2014-01-23 22:05:44 +0000 | [diff] [blame] | 1072 | // not a pid we know about |
| 1073 | return SendErrorResponse (10); |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1074 | } |
| 1075 | } |
Todd Fiala | 403edc5 | 2014-01-23 22:05:44 +0000 | [diff] [blame] | 1076 | |
| 1077 | // go ahead and attempt to kill the spawned process |
| 1078 | if (KillSpawnedProcess (pid)) |
| 1079 | return SendOKResponse (); |
| 1080 | else |
| 1081 | return SendErrorResponse (11); |
| 1082 | } |
| 1083 | |
| 1084 | GDBRemoteCommunication::PacketResult |
| 1085 | GDBRemoteCommunicationServer::Handle_k (StringExtractorGDBRemote &packet) |
| 1086 | { |
| 1087 | // ignore for now if we're lldb_platform |
| 1088 | if (m_is_platform) |
| 1089 | return SendUnimplementedResponse (packet.GetStringRef().c_str()); |
| 1090 | |
| 1091 | // shutdown all spawned processes |
| 1092 | std::set<lldb::pid_t> spawned_pids_copy; |
| 1093 | |
| 1094 | // copy pids |
| 1095 | { |
| 1096 | Mutex::Locker locker (m_spawned_pids_mutex); |
| 1097 | spawned_pids_copy.insert (m_spawned_pids.begin (), m_spawned_pids.end ()); |
| 1098 | } |
| 1099 | |
| 1100 | // nuke the spawned processes |
| 1101 | for (auto it = spawned_pids_copy.begin (); it != spawned_pids_copy.end (); ++it) |
| 1102 | { |
| 1103 | lldb::pid_t spawned_pid = *it; |
| 1104 | if (!KillSpawnedProcess (spawned_pid)) |
| 1105 | { |
| 1106 | fprintf (stderr, "%s: failed to kill spawned pid %" PRIu64 ", ignoring.\n", __FUNCTION__, spawned_pid); |
| 1107 | } |
| 1108 | } |
| 1109 | |
| 1110 | // TODO figure out how to shut down gracefully at this point |
| 1111 | return SendOKResponse (); |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1112 | } |
| 1113 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 1114 | GDBRemoteCommunication::PacketResult |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 1115 | GDBRemoteCommunicationServer::Handle_qLaunchSuccess (StringExtractorGDBRemote &packet) |
| 1116 | { |
| 1117 | if (m_process_launch_error.Success()) |
| 1118 | return SendOKResponse(); |
Sylvestre Ledru | b027bd2 | 2013-09-28 14:35:00 +0000 | [diff] [blame] | 1119 | StreamString response; |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 1120 | response.PutChar('E'); |
| 1121 | response.PutCString(m_process_launch_error.AsCString("<unknown error>")); |
Greg Clayton | 37a0a24 | 2012-04-11 00:24:49 +0000 | [diff] [blame] | 1122 | return SendPacketNoLock (response.GetData(), response.GetSize()); |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 1123 | } |
| 1124 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 1125 | GDBRemoteCommunication::PacketResult |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 1126 | GDBRemoteCommunicationServer::Handle_QEnvironment (StringExtractorGDBRemote &packet) |
| 1127 | { |
| 1128 | packet.SetFilePos(::strlen ("QEnvironment:")); |
| 1129 | const uint32_t bytes_left = packet.GetBytesLeft(); |
| 1130 | if (bytes_left > 0) |
| 1131 | { |
| 1132 | m_process_launch_info.GetEnvironmentEntries ().AppendArgument (packet.Peek()); |
| 1133 | return SendOKResponse (); |
| 1134 | } |
Greg Clayton | 2b98c56 | 2013-11-22 18:53:12 +0000 | [diff] [blame] | 1135 | return SendErrorResponse (12); |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1136 | } |
| 1137 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 1138 | GDBRemoteCommunication::PacketResult |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1139 | GDBRemoteCommunicationServer::Handle_QLaunchArch (StringExtractorGDBRemote &packet) |
| 1140 | { |
| 1141 | packet.SetFilePos(::strlen ("QLaunchArch:")); |
| 1142 | const uint32_t bytes_left = packet.GetBytesLeft(); |
| 1143 | if (bytes_left > 0) |
| 1144 | { |
| 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(); |
| 1149 | } |
Greg Clayton | 2b98c56 | 2013-11-22 18:53:12 +0000 | [diff] [blame] | 1150 | return SendErrorResponse(13); |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 1151 | } |
| 1152 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 1153 | GDBRemoteCommunication::PacketResult |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 1154 | GDBRemoteCommunicationServer::Handle_QSetDisableASLR (StringExtractorGDBRemote &packet) |
| 1155 | { |
| 1156 | packet.SetFilePos(::strlen ("QSetDisableASLR:")); |
| 1157 | if (packet.GetU32(0)) |
| 1158 | m_process_launch_info.GetFlags().Set (eLaunchFlagDisableASLR); |
| 1159 | else |
| 1160 | m_process_launch_info.GetFlags().Clear (eLaunchFlagDisableASLR); |
| 1161 | return SendOKResponse (); |
| 1162 | } |
| 1163 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 1164 | GDBRemoteCommunication::PacketResult |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 1165 | GDBRemoteCommunicationServer::Handle_QSetWorkingDir (StringExtractorGDBRemote &packet) |
| 1166 | { |
| 1167 | packet.SetFilePos(::strlen ("QSetWorkingDir:")); |
| 1168 | std::string path; |
| 1169 | packet.GetHexByteString(path); |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 1170 | if (m_is_platform) |
| 1171 | { |
Colin Riley | 909bb7a | 2013-11-26 15:10:46 +0000 | [diff] [blame] | 1172 | #ifdef _WIN32 |
| 1173 | // Not implemented on Windows |
| 1174 | return SendUnimplementedResponse("GDBRemoteCommunicationServer::Handle_QSetWorkingDir unimplemented"); |
| 1175 | #else |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 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); |
Colin Riley | 909bb7a | 2013-11-26 15:10:46 +0000 | [diff] [blame] | 1179 | #endif |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 1180 | } |
| 1181 | else |
| 1182 | { |
| 1183 | m_process_launch_info.SwapWorkingDirectory (path); |
| 1184 | } |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 1185 | return SendOKResponse (); |
| 1186 | } |
| 1187 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 1188 | GDBRemoteCommunication::PacketResult |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 1189 | GDBRemoteCommunicationServer::Handle_qGetWorkingDir (StringExtractorGDBRemote &packet) |
| 1190 | { |
| 1191 | StreamString response; |
| 1192 | |
| 1193 | if (m_is_platform) |
| 1194 | { |
| 1195 | // If this packet is sent to a platform, then change the current working directory |
| 1196 | char cwd[PATH_MAX]; |
| 1197 | if (getcwd(cwd, sizeof(cwd)) == NULL) |
| 1198 | { |
| 1199 | return SendErrorResponse(errno); |
| 1200 | } |
| 1201 | else |
| 1202 | { |
| 1203 | response.PutBytesAsRawHex8(cwd, strlen(cwd)); |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 1204 | return SendPacketNoLock(response.GetData(), response.GetSize()); |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 1205 | } |
| 1206 | } |
| 1207 | else |
| 1208 | { |
| 1209 | const char *working_dir = m_process_launch_info.GetWorkingDirectory(); |
| 1210 | if (working_dir && working_dir[0]) |
| 1211 | { |
| 1212 | response.PutBytesAsRawHex8(working_dir, strlen(working_dir)); |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 1213 | return SendPacketNoLock(response.GetData(), response.GetSize()); |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 1214 | } |
| 1215 | else |
| 1216 | { |
Greg Clayton | 2b98c56 | 2013-11-22 18:53:12 +0000 | [diff] [blame] | 1217 | return SendErrorResponse(14); |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 1218 | } |
| 1219 | } |
| 1220 | } |
| 1221 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 1222 | GDBRemoteCommunication::PacketResult |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 1223 | GDBRemoteCommunicationServer::Handle_QSetSTDIN (StringExtractorGDBRemote &packet) |
| 1224 | { |
| 1225 | packet.SetFilePos(::strlen ("QSetSTDIN:")); |
| 1226 | ProcessLaunchInfo::FileAction file_action; |
| 1227 | std::string path; |
| 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)) |
| 1232 | { |
| 1233 | m_process_launch_info.AppendFileAction(file_action); |
| 1234 | return SendOKResponse (); |
| 1235 | } |
Greg Clayton | 2b98c56 | 2013-11-22 18:53:12 +0000 | [diff] [blame] | 1236 | return SendErrorResponse (15); |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 1237 | } |
| 1238 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 1239 | GDBRemoteCommunication::PacketResult |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 1240 | GDBRemoteCommunicationServer::Handle_QSetSTDOUT (StringExtractorGDBRemote &packet) |
| 1241 | { |
| 1242 | packet.SetFilePos(::strlen ("QSetSTDOUT:")); |
| 1243 | ProcessLaunchInfo::FileAction file_action; |
| 1244 | std::string path; |
| 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)) |
| 1249 | { |
| 1250 | m_process_launch_info.AppendFileAction(file_action); |
| 1251 | return SendOKResponse (); |
| 1252 | } |
Greg Clayton | 2b98c56 | 2013-11-22 18:53:12 +0000 | [diff] [blame] | 1253 | return SendErrorResponse (16); |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 1254 | } |
| 1255 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 1256 | GDBRemoteCommunication::PacketResult |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 1257 | GDBRemoteCommunicationServer::Handle_QSetSTDERR (StringExtractorGDBRemote &packet) |
| 1258 | { |
| 1259 | packet.SetFilePos(::strlen ("QSetSTDERR:")); |
| 1260 | ProcessLaunchInfo::FileAction file_action; |
| 1261 | std::string path; |
| 1262 | packet.GetHexByteString(path); |
| 1263 | const bool read = true; |
Greg Clayton | 9845a8d | 2012-03-06 04:01:04 +0000 | [diff] [blame] | 1264 | const bool write = false; |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 1265 | if (file_action.Open(STDERR_FILENO, path.c_str(), read, write)) |
| 1266 | { |
| 1267 | m_process_launch_info.AppendFileAction(file_action); |
| 1268 | return SendOKResponse (); |
| 1269 | } |
Greg Clayton | 2b98c56 | 2013-11-22 18:53:12 +0000 | [diff] [blame] | 1270 | return SendErrorResponse (17); |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 1271 | } |
| 1272 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 1273 | GDBRemoteCommunication::PacketResult |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 1274 | GDBRemoteCommunicationServer::Handle_QStartNoAckMode (StringExtractorGDBRemote &packet) |
| 1275 | { |
| 1276 | // Send response first before changing m_send_acks to we ack this packet |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 1277 | PacketResult packet_result = SendOKResponse (); |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 1278 | m_send_acks = false; |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 1279 | return packet_result; |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 1280 | } |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1281 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 1282 | GDBRemoteCommunication::PacketResult |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 1283 | GDBRemoteCommunicationServer::Handle_qPlatform_mkdir (StringExtractorGDBRemote &packet) |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1284 | { |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 1285 | packet.SetFilePos(::strlen("qPlatform_mkdir:")); |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1286 | mode_t mode = packet.GetHexMaxU32(false, UINT32_MAX); |
Greg Clayton | 2b98c56 | 2013-11-22 18:53:12 +0000 | [diff] [blame] | 1287 | if (packet.GetChar() == ',') |
| 1288 | { |
| 1289 | std::string path; |
| 1290 | packet.GetHexByteString(path); |
| 1291 | Error error = Host::MakeDirectory(path.c_str(),mode); |
| 1292 | if (error.Success()) |
| 1293 | return SendPacketNoLock ("OK", 2); |
| 1294 | else |
| 1295 | return SendErrorResponse(error.GetError()); |
| 1296 | } |
| 1297 | return SendErrorResponse(20); |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 1298 | } |
| 1299 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 1300 | GDBRemoteCommunication::PacketResult |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 1301 | GDBRemoteCommunicationServer::Handle_qPlatform_chmod (StringExtractorGDBRemote &packet) |
| 1302 | { |
| 1303 | packet.SetFilePos(::strlen("qPlatform_chmod:")); |
| 1304 | |
| 1305 | mode_t mode = packet.GetHexMaxU32(false, UINT32_MAX); |
Greg Clayton | 2b98c56 | 2013-11-22 18:53:12 +0000 | [diff] [blame] | 1306 | if (packet.GetChar() == ',') |
| 1307 | { |
| 1308 | std::string path; |
| 1309 | packet.GetHexByteString(path); |
| 1310 | Error error = Host::SetFilePermissions (path.c_str(), mode); |
| 1311 | if (error.Success()) |
| 1312 | return SendPacketNoLock ("OK", 2); |
| 1313 | else |
| 1314 | return SendErrorResponse(error.GetError()); |
| 1315 | } |
| 1316 | return SendErrorResponse(19); |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1317 | } |
| 1318 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 1319 | GDBRemoteCommunication::PacketResult |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1320 | GDBRemoteCommunicationServer::Handle_vFile_Open (StringExtractorGDBRemote &packet) |
| 1321 | { |
| 1322 | packet.SetFilePos(::strlen("vFile:open:")); |
| 1323 | std::string path; |
| 1324 | packet.GetHexByteStringTerminatedBy(path,','); |
Greg Clayton | 2b98c56 | 2013-11-22 18:53:12 +0000 | [diff] [blame] | 1325 | if (!path.empty()) |
| 1326 | { |
| 1327 | if (packet.GetChar() == ',') |
| 1328 | { |
| 1329 | uint32_t flags = packet.GetHexMaxU32(false, 0); |
| 1330 | if (packet.GetChar() == ',') |
| 1331 | { |
| 1332 | mode_t mode = packet.GetHexMaxU32(false, 0600); |
| 1333 | Error error; |
| 1334 | int fd = ::open (path.c_str(), flags, mode); |
Greg Clayton | 2b98c56 | 2013-11-22 18:53:12 +0000 | [diff] [blame] | 1335 | const int save_errno = fd == -1 ? errno : 0; |
| 1336 | StreamString response; |
| 1337 | response.PutChar('F'); |
| 1338 | response.Printf("%i", fd); |
| 1339 | if (save_errno) |
| 1340 | response.Printf(",%i", save_errno); |
| 1341 | return SendPacketNoLock(response.GetData(), response.GetSize()); |
| 1342 | } |
| 1343 | } |
| 1344 | } |
| 1345 | return SendErrorResponse(18); |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1346 | } |
| 1347 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 1348 | GDBRemoteCommunication::PacketResult |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1349 | GDBRemoteCommunicationServer::Handle_vFile_Close (StringExtractorGDBRemote &packet) |
| 1350 | { |
| 1351 | packet.SetFilePos(::strlen("vFile:close:")); |
| 1352 | int fd = packet.GetS32(-1); |
| 1353 | Error error; |
| 1354 | int err = -1; |
| 1355 | int save_errno = 0; |
| 1356 | if (fd >= 0) |
| 1357 | { |
| 1358 | err = close(fd); |
| 1359 | save_errno = err == -1 ? errno : 0; |
| 1360 | } |
| 1361 | else |
| 1362 | { |
| 1363 | save_errno = EINVAL; |
| 1364 | } |
| 1365 | StreamString response; |
| 1366 | response.PutChar('F'); |
| 1367 | response.Printf("%i", err); |
| 1368 | if (save_errno) |
| 1369 | response.Printf(",%i", save_errno); |
Greg Clayton | 2b98c56 | 2013-11-22 18:53:12 +0000 | [diff] [blame] | 1370 | return SendPacketNoLock(response.GetData(), response.GetSize()); |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1371 | } |
| 1372 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 1373 | GDBRemoteCommunication::PacketResult |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1374 | GDBRemoteCommunicationServer::Handle_vFile_pRead (StringExtractorGDBRemote &packet) |
| 1375 | { |
Virgile Bello | ae12a36 | 2013-08-27 16:21:49 +0000 | [diff] [blame] | 1376 | #ifdef _WIN32 |
| 1377 | // Not implemented on Windows |
Greg Clayton | 2b98c56 | 2013-11-22 18:53:12 +0000 | [diff] [blame] | 1378 | return SendUnimplementedResponse("GDBRemoteCommunicationServer::Handle_vFile_pRead() unimplemented"); |
Virgile Bello | ae12a36 | 2013-08-27 16:21:49 +0000 | [diff] [blame] | 1379 | #else |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1380 | StreamGDBRemote response; |
| 1381 | packet.SetFilePos(::strlen("vFile:pread:")); |
| 1382 | int fd = packet.GetS32(-1); |
Greg Clayton | 2b98c56 | 2013-11-22 18:53:12 +0000 | [diff] [blame] | 1383 | if (packet.GetChar() == ',') |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1384 | { |
Greg Clayton | 2b98c56 | 2013-11-22 18:53:12 +0000 | [diff] [blame] | 1385 | uint64_t count = packet.GetU64(UINT64_MAX); |
| 1386 | if (packet.GetChar() == ',') |
| 1387 | { |
| 1388 | uint64_t offset = packet.GetU64(UINT32_MAX); |
| 1389 | if (count == UINT64_MAX) |
| 1390 | { |
| 1391 | response.Printf("F-1:%i", EINVAL); |
| 1392 | return SendPacketNoLock(response.GetData(), response.GetSize()); |
| 1393 | } |
| 1394 | |
| 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); |
| 1400 | if (save_errno) |
| 1401 | response.Printf(",%i", save_errno); |
| 1402 | else |
| 1403 | { |
| 1404 | response.PutChar(';'); |
| 1405 | response.PutEscapedBytes(&buffer[0], bytes_read); |
| 1406 | } |
| 1407 | return SendPacketNoLock(response.GetData(), response.GetSize()); |
| 1408 | } |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1409 | } |
Greg Clayton | 2b98c56 | 2013-11-22 18:53:12 +0000 | [diff] [blame] | 1410 | return SendErrorResponse(21); |
| 1411 | |
Virgile Bello | ae12a36 | 2013-08-27 16:21:49 +0000 | [diff] [blame] | 1412 | #endif |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1413 | } |
| 1414 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 1415 | GDBRemoteCommunication::PacketResult |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1416 | GDBRemoteCommunicationServer::Handle_vFile_pWrite (StringExtractorGDBRemote &packet) |
| 1417 | { |
Virgile Bello | ae12a36 | 2013-08-27 16:21:49 +0000 | [diff] [blame] | 1418 | #ifdef _WIN32 |
Greg Clayton | 2b98c56 | 2013-11-22 18:53:12 +0000 | [diff] [blame] | 1419 | return SendUnimplementedResponse("GDBRemoteCommunicationServer::Handle_vFile_pWrite() unimplemented"); |
Virgile Bello | ae12a36 | 2013-08-27 16:21:49 +0000 | [diff] [blame] | 1420 | #else |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1421 | packet.SetFilePos(::strlen("vFile:pwrite:")); |
| 1422 | |
| 1423 | StreamGDBRemote response; |
| 1424 | response.PutChar('F'); |
| 1425 | |
| 1426 | int fd = packet.GetU32(UINT32_MAX); |
Greg Clayton | 2b98c56 | 2013-11-22 18:53:12 +0000 | [diff] [blame] | 1427 | if (packet.GetChar() == ',') |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1428 | { |
Greg Clayton | 2b98c56 | 2013-11-22 18:53:12 +0000 | [diff] [blame] | 1429 | off_t offset = packet.GetU64(UINT32_MAX); |
| 1430 | if (packet.GetChar() == ',') |
| 1431 | { |
| 1432 | std::string buffer; |
| 1433 | if (packet.GetEscapedBinaryData(buffer)) |
| 1434 | { |
| 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); |
| 1438 | if (save_errno) |
| 1439 | response.Printf(",%i", save_errno); |
| 1440 | } |
| 1441 | else |
| 1442 | { |
| 1443 | response.Printf ("-1,%i", EINVAL); |
| 1444 | } |
| 1445 | return SendPacketNoLock(response.GetData(), response.GetSize()); |
| 1446 | } |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1447 | } |
Greg Clayton | 2b98c56 | 2013-11-22 18:53:12 +0000 | [diff] [blame] | 1448 | return SendErrorResponse(27); |
Virgile Bello | ae12a36 | 2013-08-27 16:21:49 +0000 | [diff] [blame] | 1449 | #endif |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1450 | } |
| 1451 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 1452 | GDBRemoteCommunication::PacketResult |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1453 | GDBRemoteCommunicationServer::Handle_vFile_Size (StringExtractorGDBRemote &packet) |
| 1454 | { |
| 1455 | packet.SetFilePos(::strlen("vFile:size:")); |
| 1456 | std::string path; |
| 1457 | packet.GetHexByteString(path); |
Greg Clayton | 2b98c56 | 2013-11-22 18:53:12 +0000 | [diff] [blame] | 1458 | if (!path.empty()) |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1459 | { |
Greg Clayton | 2b98c56 | 2013-11-22 18:53:12 +0000 | [diff] [blame] | 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) |
| 1465 | { |
| 1466 | response.PutChar(','); |
| 1467 | response.PutHex64(retcode); // TODO: replace with Host::GetSyswideErrorCode() |
| 1468 | } |
| 1469 | return SendPacketNoLock(response.GetData(), response.GetSize()); |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1470 | } |
Greg Clayton | 2b98c56 | 2013-11-22 18:53:12 +0000 | [diff] [blame] | 1471 | return SendErrorResponse(22); |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1472 | } |
| 1473 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 1474 | GDBRemoteCommunication::PacketResult |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1475 | GDBRemoteCommunicationServer::Handle_vFile_Mode (StringExtractorGDBRemote &packet) |
| 1476 | { |
| 1477 | packet.SetFilePos(::strlen("vFile:mode:")); |
| 1478 | std::string path; |
| 1479 | packet.GetHexByteString(path); |
Greg Clayton | 2b98c56 | 2013-11-22 18:53:12 +0000 | [diff] [blame] | 1480 | if (!path.empty()) |
| 1481 | { |
| 1482 | Error error; |
| 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()); |
| 1489 | } |
| 1490 | return SendErrorResponse(23); |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1491 | } |
| 1492 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 1493 | GDBRemoteCommunication::PacketResult |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1494 | GDBRemoteCommunicationServer::Handle_vFile_Exists (StringExtractorGDBRemote &packet) |
| 1495 | { |
| 1496 | packet.SetFilePos(::strlen("vFile:exists:")); |
| 1497 | std::string path; |
| 1498 | packet.GetHexByteString(path); |
Greg Clayton | 2b98c56 | 2013-11-22 18:53:12 +0000 | [diff] [blame] | 1499 | if (!path.empty()) |
| 1500 | { |
| 1501 | bool retcode = Host::GetFileExists(FileSpec(path.c_str(), false)); |
| 1502 | StreamString response; |
| 1503 | response.PutChar('F'); |
| 1504 | response.PutChar(','); |
| 1505 | if (retcode) |
| 1506 | response.PutChar('1'); |
| 1507 | else |
| 1508 | response.PutChar('0'); |
| 1509 | return SendPacketNoLock(response.GetData(), response.GetSize()); |
| 1510 | } |
| 1511 | return SendErrorResponse(24); |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1512 | } |
| 1513 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 1514 | GDBRemoteCommunication::PacketResult |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 1515 | GDBRemoteCommunicationServer::Handle_vFile_symlink (StringExtractorGDBRemote &packet) |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1516 | { |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 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()); |
Greg Clayton | 2b98c56 | 2013-11-22 18:53:12 +0000 | [diff] [blame] | 1525 | return SendPacketNoLock(response.GetData(), response.GetSize()); |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 1526 | } |
| 1527 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 1528 | GDBRemoteCommunication::PacketResult |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 1529 | GDBRemoteCommunicationServer::Handle_vFile_unlink (StringExtractorGDBRemote &packet) |
| 1530 | { |
| 1531 | packet.SetFilePos(::strlen("vFile:unlink:")); |
| 1532 | std::string path; |
| 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()); |
Greg Clayton | 2b98c56 | 2013-11-22 18:53:12 +0000 | [diff] [blame] | 1537 | return SendPacketNoLock(response.GetData(), response.GetSize()); |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 1538 | } |
| 1539 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 1540 | GDBRemoteCommunication::PacketResult |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 1541 | GDBRemoteCommunicationServer::Handle_qPlatform_shell (StringExtractorGDBRemote &packet) |
| 1542 | { |
| 1543 | packet.SetFilePos(::strlen("qPlatform_shell:")); |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1544 | std::string path; |
| 1545 | std::string working_dir; |
| 1546 | packet.GetHexByteStringTerminatedBy(path,','); |
Greg Clayton | 2b98c56 | 2013-11-22 18:53:12 +0000 | [diff] [blame] | 1547 | if (!path.empty()) |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1548 | { |
Greg Clayton | 2b98c56 | 2013-11-22 18:53:12 +0000 | [diff] [blame] | 1549 | if (packet.GetChar() == ',') |
| 1550 | { |
| 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); |
| 1556 | int status, signo; |
| 1557 | std::string output; |
| 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; |
| 1562 | if (err.Fail()) |
| 1563 | { |
| 1564 | response.PutCString("F,"); |
| 1565 | response.PutHex32(UINT32_MAX); |
| 1566 | } |
| 1567 | else |
| 1568 | { |
| 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()); |
| 1575 | } |
| 1576 | return SendPacketNoLock(response.GetData(), response.GetSize()); |
| 1577 | } |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1578 | } |
Greg Clayton | 2b98c56 | 2013-11-22 18:53:12 +0000 | [diff] [blame] | 1579 | return SendErrorResponse(24); |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1580 | } |
| 1581 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 1582 | GDBRemoteCommunication::PacketResult |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1583 | GDBRemoteCommunicationServer::Handle_vFile_Stat (StringExtractorGDBRemote &packet) |
| 1584 | { |
Greg Clayton | 2b98c56 | 2013-11-22 18:53:12 +0000 | [diff] [blame] | 1585 | return SendUnimplementedResponse("GDBRemoteCommunicationServer::Handle_vFile_Stat() unimplemented"); |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1586 | } |
| 1587 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 1588 | GDBRemoteCommunication::PacketResult |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1589 | GDBRemoteCommunicationServer::Handle_vFile_MD5 (StringExtractorGDBRemote &packet) |
| 1590 | { |
Greg Clayton | 2b98c56 | 2013-11-22 18:53:12 +0000 | [diff] [blame] | 1591 | packet.SetFilePos(::strlen("vFile:MD5:")); |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1592 | std::string path; |
| 1593 | packet.GetHexByteString(path); |
Greg Clayton | 2b98c56 | 2013-11-22 18:53:12 +0000 | [diff] [blame] | 1594 | if (!path.empty()) |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1595 | { |
Greg Clayton | 2b98c56 | 2013-11-22 18:53:12 +0000 | [diff] [blame] | 1596 | uint64_t a,b; |
| 1597 | StreamGDBRemote response; |
| 1598 | if (Host::CalculateMD5(FileSpec(path.c_str(),false),a,b) == false) |
| 1599 | { |
| 1600 | response.PutCString("F,"); |
| 1601 | response.PutCString("x"); |
| 1602 | } |
| 1603 | else |
| 1604 | { |
| 1605 | response.PutCString("F,"); |
| 1606 | response.PutHex64(a); |
| 1607 | response.PutHex64(b); |
| 1608 | } |
| 1609 | return SendPacketNoLock(response.GetData(), response.GetSize()); |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1610 | } |
Greg Clayton | 2b98c56 | 2013-11-22 18:53:12 +0000 | [diff] [blame] | 1611 | return SendErrorResponse(25); |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1612 | } |
Greg Clayton | 2b98c56 | 2013-11-22 18:53:12 +0000 | [diff] [blame] | 1613 | |