Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 1 | //===-- GDBRemoteCommunicationClient.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 | |
| 10 | |
| 11 | #include "GDBRemoteCommunicationClient.h" |
| 12 | |
| 13 | // C Includes |
| 14 | // C++ Includes |
| 15 | // Other libraries and framework includes |
| 16 | #include "llvm/ADT/Triple.h" |
| 17 | #include "lldb/Interpreter/Args.h" |
| 18 | #include "lldb/Core/ConnectionFileDescriptor.h" |
| 19 | #include "lldb/Core/Log.h" |
| 20 | #include "lldb/Core/State.h" |
| 21 | #include "lldb/Core/StreamString.h" |
| 22 | #include "lldb/Host/Endian.h" |
| 23 | #include "lldb/Host/Host.h" |
| 24 | #include "lldb/Host/TimeValue.h" |
| 25 | |
| 26 | // Project includes |
| 27 | #include "Utility/StringExtractorGDBRemote.h" |
| 28 | #include "ProcessGDBRemote.h" |
| 29 | #include "ProcessGDBRemoteLog.h" |
| 30 | |
| 31 | using namespace lldb; |
| 32 | using namespace lldb_private; |
| 33 | |
| 34 | //---------------------------------------------------------------------- |
| 35 | // GDBRemoteCommunicationClient constructor |
| 36 | //---------------------------------------------------------------------- |
Greg Clayton | b72d0f0 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 37 | GDBRemoteCommunicationClient::GDBRemoteCommunicationClient(bool is_platform) : |
| 38 | GDBRemoteCommunication("gdb-remote.client", "gdb-remote.client.rx_packet", is_platform), |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 39 | m_supports_not_sending_acks (eLazyBoolCalculate), |
| 40 | m_supports_thread_suffix (eLazyBoolCalculate), |
Greg Clayton | a1f645e | 2012-04-10 03:22:03 +0000 | [diff] [blame] | 41 | m_supports_threads_in_stop_reply (eLazyBoolCalculate), |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 42 | m_supports_vCont_all (eLazyBoolCalculate), |
| 43 | m_supports_vCont_any (eLazyBoolCalculate), |
| 44 | m_supports_vCont_c (eLazyBoolCalculate), |
| 45 | m_supports_vCont_C (eLazyBoolCalculate), |
| 46 | m_supports_vCont_s (eLazyBoolCalculate), |
| 47 | m_supports_vCont_S (eLazyBoolCalculate), |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 48 | m_qHostInfo_is_valid (eLazyBoolCalculate), |
Greg Clayton | 2f085c6 | 2011-05-15 01:25:55 +0000 | [diff] [blame] | 49 | m_supports_alloc_dealloc_memory (eLazyBoolCalculate), |
Greg Clayton | a938553 | 2011-11-18 07:03:08 +0000 | [diff] [blame] | 50 | m_supports_memory_region_info (eLazyBoolCalculate), |
Johnny Chen | 7cbdcfb | 2012-05-23 21:09:52 +0000 | [diff] [blame] | 51 | m_supports_watchpoint_support_info (eLazyBoolCalculate), |
Enrico Granata | 7de2a3b | 2012-07-13 23:18:48 +0000 | [diff] [blame] | 52 | m_watchpoints_trigger_after_instruction(eLazyBoolCalculate), |
Jim Ingham | 3a458eb | 2012-07-20 21:37:13 +0000 | [diff] [blame] | 53 | m_attach_or_wait_reply(eLazyBoolCalculate), |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 54 | m_supports_qProcessInfoPID (true), |
| 55 | m_supports_qfProcessInfo (true), |
| 56 | m_supports_qUserName (true), |
| 57 | m_supports_qGroupName (true), |
Greg Clayton | b72d0f0 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 58 | m_supports_qThreadStopInfo (true), |
| 59 | m_supports_z0 (true), |
| 60 | m_supports_z1 (true), |
| 61 | m_supports_z2 (true), |
| 62 | m_supports_z3 (true), |
| 63 | m_supports_z4 (true), |
| 64 | m_curr_tid (LLDB_INVALID_THREAD_ID), |
| 65 | m_curr_tid_run (LLDB_INVALID_THREAD_ID), |
Johnny Chen | 7cbdcfb | 2012-05-23 21:09:52 +0000 | [diff] [blame] | 66 | m_num_supported_hardware_watchpoints (0), |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 67 | m_async_mutex (Mutex::eMutexTypeRecursive), |
| 68 | m_async_packet_predicate (false), |
| 69 | m_async_packet (), |
| 70 | m_async_response (), |
| 71 | m_async_signal (-1), |
Greg Clayton | 58e26e0 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 72 | m_host_arch(), |
| 73 | m_os_version_major (UINT32_MAX), |
| 74 | m_os_version_minor (UINT32_MAX), |
| 75 | m_os_version_update (UINT32_MAX) |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 76 | { |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | //---------------------------------------------------------------------- |
| 80 | // Destructor |
| 81 | //---------------------------------------------------------------------- |
| 82 | GDBRemoteCommunicationClient::~GDBRemoteCommunicationClient() |
| 83 | { |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 84 | if (IsConnected()) |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 85 | Disconnect(); |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | bool |
Greg Clayton | 58e26e0 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 89 | GDBRemoteCommunicationClient::HandshakeWithServer (Error *error_ptr) |
| 90 | { |
| 91 | // Start the read thread after we send the handshake ack since if we |
| 92 | // fail to send the handshake ack, there is no reason to continue... |
| 93 | if (SendAck()) |
Greg Clayton | 63afdb0 | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 94 | return true; |
Greg Clayton | 58e26e0 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 95 | |
| 96 | if (error_ptr) |
| 97 | error_ptr->SetErrorString("failed to send the handshake ack"); |
| 98 | return false; |
| 99 | } |
| 100 | |
| 101 | void |
| 102 | GDBRemoteCommunicationClient::QueryNoAckModeSupported () |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 103 | { |
| 104 | if (m_supports_not_sending_acks == eLazyBoolCalculate) |
| 105 | { |
Greg Clayton | 58e26e0 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 106 | m_send_acks = true; |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 107 | m_supports_not_sending_acks = eLazyBoolNo; |
Greg Clayton | 58e26e0 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 108 | |
| 109 | StringExtractorGDBRemote response; |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 110 | if (SendPacketAndWaitForResponse("QStartNoAckMode", response, false)) |
| 111 | { |
| 112 | if (response.IsOKResponse()) |
Greg Clayton | 58e26e0 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 113 | { |
| 114 | m_send_acks = false; |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 115 | m_supports_not_sending_acks = eLazyBoolYes; |
Greg Clayton | 58e26e0 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 116 | } |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 117 | } |
| 118 | } |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | void |
Greg Clayton | a1f645e | 2012-04-10 03:22:03 +0000 | [diff] [blame] | 122 | GDBRemoteCommunicationClient::GetListThreadsInStopReplySupported () |
| 123 | { |
| 124 | if (m_supports_threads_in_stop_reply == eLazyBoolCalculate) |
| 125 | { |
| 126 | m_supports_threads_in_stop_reply = eLazyBoolNo; |
| 127 | |
| 128 | StringExtractorGDBRemote response; |
| 129 | if (SendPacketAndWaitForResponse("QListThreadsInStopReply", response, false)) |
| 130 | { |
| 131 | if (response.IsOKResponse()) |
| 132 | m_supports_threads_in_stop_reply = eLazyBoolYes; |
| 133 | } |
| 134 | } |
| 135 | } |
| 136 | |
Jim Ingham | 3a458eb | 2012-07-20 21:37:13 +0000 | [diff] [blame] | 137 | bool |
| 138 | GDBRemoteCommunicationClient::GetVAttachOrWaitSupported () |
| 139 | { |
| 140 | if (m_attach_or_wait_reply == eLazyBoolCalculate) |
| 141 | { |
| 142 | m_attach_or_wait_reply = eLazyBoolNo; |
| 143 | |
| 144 | StringExtractorGDBRemote response; |
| 145 | if (SendPacketAndWaitForResponse("qVAttachOrWaitSupported", response, false)) |
| 146 | { |
| 147 | if (response.IsOKResponse()) |
| 148 | m_attach_or_wait_reply = eLazyBoolYes; |
| 149 | } |
| 150 | } |
| 151 | if (m_attach_or_wait_reply == eLazyBoolYes) |
| 152 | return true; |
| 153 | else |
| 154 | return false; |
| 155 | } |
| 156 | |
Greg Clayton | a1f645e | 2012-04-10 03:22:03 +0000 | [diff] [blame] | 157 | |
| 158 | void |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 159 | GDBRemoteCommunicationClient::ResetDiscoverableSettings() |
| 160 | { |
| 161 | m_supports_not_sending_acks = eLazyBoolCalculate; |
| 162 | m_supports_thread_suffix = eLazyBoolCalculate; |
Greg Clayton | a1f645e | 2012-04-10 03:22:03 +0000 | [diff] [blame] | 163 | m_supports_threads_in_stop_reply = eLazyBoolCalculate; |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 164 | m_supports_vCont_c = eLazyBoolCalculate; |
| 165 | m_supports_vCont_C = eLazyBoolCalculate; |
| 166 | m_supports_vCont_s = eLazyBoolCalculate; |
| 167 | m_supports_vCont_S = eLazyBoolCalculate; |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 168 | m_qHostInfo_is_valid = eLazyBoolCalculate; |
Greg Clayton | 2f085c6 | 2011-05-15 01:25:55 +0000 | [diff] [blame] | 169 | m_supports_alloc_dealloc_memory = eLazyBoolCalculate; |
Greg Clayton | a938553 | 2011-11-18 07:03:08 +0000 | [diff] [blame] | 170 | m_supports_memory_region_info = eLazyBoolCalculate; |
Greg Clayton | 989816b | 2011-05-14 01:50:35 +0000 | [diff] [blame] | 171 | |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 172 | m_supports_qProcessInfoPID = true; |
| 173 | m_supports_qfProcessInfo = true; |
| 174 | m_supports_qUserName = true; |
| 175 | m_supports_qGroupName = true; |
Greg Clayton | b72d0f0 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 176 | m_supports_qThreadStopInfo = true; |
| 177 | m_supports_z0 = true; |
| 178 | m_supports_z1 = true; |
| 179 | m_supports_z2 = true; |
| 180 | m_supports_z3 = true; |
| 181 | m_supports_z4 = true; |
Greg Clayton | cb8977d | 2011-03-23 00:09:55 +0000 | [diff] [blame] | 182 | m_host_arch.Clear(); |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | |
| 186 | bool |
| 187 | GDBRemoteCommunicationClient::GetThreadSuffixSupported () |
| 188 | { |
| 189 | if (m_supports_thread_suffix == eLazyBoolCalculate) |
| 190 | { |
| 191 | StringExtractorGDBRemote response; |
| 192 | m_supports_thread_suffix = eLazyBoolNo; |
| 193 | if (SendPacketAndWaitForResponse("QThreadSuffixSupported", response, false)) |
| 194 | { |
| 195 | if (response.IsOKResponse()) |
| 196 | m_supports_thread_suffix = eLazyBoolYes; |
| 197 | } |
| 198 | } |
| 199 | return m_supports_thread_suffix; |
| 200 | } |
| 201 | bool |
| 202 | GDBRemoteCommunicationClient::GetVContSupported (char flavor) |
| 203 | { |
| 204 | if (m_supports_vCont_c == eLazyBoolCalculate) |
| 205 | { |
| 206 | StringExtractorGDBRemote response; |
| 207 | m_supports_vCont_any = eLazyBoolNo; |
| 208 | m_supports_vCont_all = eLazyBoolNo; |
| 209 | m_supports_vCont_c = eLazyBoolNo; |
| 210 | m_supports_vCont_C = eLazyBoolNo; |
| 211 | m_supports_vCont_s = eLazyBoolNo; |
| 212 | m_supports_vCont_S = eLazyBoolNo; |
| 213 | if (SendPacketAndWaitForResponse("vCont?", response, false)) |
| 214 | { |
| 215 | const char *response_cstr = response.GetStringRef().c_str(); |
| 216 | if (::strstr (response_cstr, ";c")) |
| 217 | m_supports_vCont_c = eLazyBoolYes; |
| 218 | |
| 219 | if (::strstr (response_cstr, ";C")) |
| 220 | m_supports_vCont_C = eLazyBoolYes; |
| 221 | |
| 222 | if (::strstr (response_cstr, ";s")) |
| 223 | m_supports_vCont_s = eLazyBoolYes; |
| 224 | |
| 225 | if (::strstr (response_cstr, ";S")) |
| 226 | m_supports_vCont_S = eLazyBoolYes; |
| 227 | |
| 228 | if (m_supports_vCont_c == eLazyBoolYes && |
| 229 | m_supports_vCont_C == eLazyBoolYes && |
| 230 | m_supports_vCont_s == eLazyBoolYes && |
| 231 | m_supports_vCont_S == eLazyBoolYes) |
| 232 | { |
| 233 | m_supports_vCont_all = eLazyBoolYes; |
| 234 | } |
| 235 | |
| 236 | if (m_supports_vCont_c == eLazyBoolYes || |
| 237 | m_supports_vCont_C == eLazyBoolYes || |
| 238 | m_supports_vCont_s == eLazyBoolYes || |
| 239 | m_supports_vCont_S == eLazyBoolYes) |
| 240 | { |
| 241 | m_supports_vCont_any = eLazyBoolYes; |
| 242 | } |
| 243 | } |
| 244 | } |
| 245 | |
| 246 | switch (flavor) |
| 247 | { |
| 248 | case 'a': return m_supports_vCont_any; |
| 249 | case 'A': return m_supports_vCont_all; |
| 250 | case 'c': return m_supports_vCont_c; |
| 251 | case 'C': return m_supports_vCont_C; |
| 252 | case 's': return m_supports_vCont_s; |
| 253 | case 'S': return m_supports_vCont_S; |
| 254 | default: break; |
| 255 | } |
| 256 | return false; |
| 257 | } |
| 258 | |
| 259 | |
| 260 | size_t |
| 261 | GDBRemoteCommunicationClient::SendPacketAndWaitForResponse |
| 262 | ( |
| 263 | const char *payload, |
| 264 | StringExtractorGDBRemote &response, |
| 265 | bool send_async |
| 266 | ) |
| 267 | { |
| 268 | return SendPacketAndWaitForResponse (payload, |
| 269 | ::strlen (payload), |
| 270 | response, |
| 271 | send_async); |
| 272 | } |
| 273 | |
| 274 | size_t |
| 275 | GDBRemoteCommunicationClient::SendPacketAndWaitForResponse |
| 276 | ( |
| 277 | const char *payload, |
| 278 | size_t payload_length, |
| 279 | StringExtractorGDBRemote &response, |
| 280 | bool send_async |
| 281 | ) |
| 282 | { |
| 283 | Mutex::Locker locker; |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 284 | LogSP log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PROCESS)); |
Greg Clayton | 801417e | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 285 | size_t response_len = 0; |
Greg Clayton | c8dd570 | 2012-04-12 19:04:34 +0000 | [diff] [blame] | 286 | if (GetSequenceMutex (locker)) |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 287 | { |
Greg Clayton | 139da72 | 2011-05-20 03:15:54 +0000 | [diff] [blame] | 288 | if (SendPacketNoLock (payload, payload_length)) |
Greg Clayton | 801417e | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 289 | response_len = WaitForPacketWithTimeoutMicroSecondsNoLock (response, GetPacketTimeoutInMicroSeconds ()); |
| 290 | else |
| 291 | { |
| 292 | if (log) |
Jason Molenda | 7e5fa7f | 2011-09-20 21:44:10 +0000 | [diff] [blame] | 293 | log->Printf("error: failed to send '%*s'", (int) payload_length, payload); |
Greg Clayton | 801417e | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 294 | } |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 295 | } |
| 296 | else |
| 297 | { |
| 298 | if (send_async) |
| 299 | { |
Greg Clayton | 70e167f | 2012-05-31 21:24:20 +0000 | [diff] [blame] | 300 | if (IsRunning()) |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 301 | { |
Greg Clayton | 70e167f | 2012-05-31 21:24:20 +0000 | [diff] [blame] | 302 | Mutex::Locker async_locker (m_async_mutex); |
| 303 | m_async_packet.assign(payload, payload_length); |
| 304 | m_async_packet_predicate.SetValue (true, eBroadcastNever); |
| 305 | |
| 306 | if (log) |
| 307 | log->Printf ("async: async packet = %s", m_async_packet.c_str()); |
| 308 | |
| 309 | bool timed_out = false; |
| 310 | if (SendInterrupt(locker, 2, timed_out)) |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 311 | { |
Greg Clayton | 70e167f | 2012-05-31 21:24:20 +0000 | [diff] [blame] | 312 | if (m_interrupt_sent) |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 313 | { |
Jim Ingham | 8247e62 | 2012-06-06 00:32:39 +0000 | [diff] [blame] | 314 | m_interrupt_sent = false; |
Greg Clayton | 70e167f | 2012-05-31 21:24:20 +0000 | [diff] [blame] | 315 | TimeValue timeout_time; |
| 316 | timeout_time = TimeValue::Now(); |
| 317 | timeout_time.OffsetWithSeconds (m_packet_timeout); |
| 318 | |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 319 | if (log) |
Greg Clayton | 70e167f | 2012-05-31 21:24:20 +0000 | [diff] [blame] | 320 | log->Printf ("async: sent interrupt"); |
Greg Clayton | 801417e | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 321 | |
Greg Clayton | 70e167f | 2012-05-31 21:24:20 +0000 | [diff] [blame] | 322 | if (m_async_packet_predicate.WaitForValueEqualTo (false, &timeout_time, &timed_out)) |
Greg Clayton | b7669b3 | 2011-10-27 22:04:16 +0000 | [diff] [blame] | 323 | { |
Greg Clayton | 70e167f | 2012-05-31 21:24:20 +0000 | [diff] [blame] | 324 | if (log) |
| 325 | log->Printf ("async: got response"); |
| 326 | |
| 327 | // Swap the response buffer to avoid malloc and string copy |
| 328 | response.GetStringRef().swap (m_async_response.GetStringRef()); |
| 329 | response_len = response.GetStringRef().size(); |
| 330 | } |
| 331 | else |
| 332 | { |
| 333 | if (log) |
| 334 | log->Printf ("async: timed out waiting for response"); |
| 335 | } |
| 336 | |
| 337 | // Make sure we wait until the continue packet has been sent again... |
| 338 | if (m_private_is_running.WaitForValueEqualTo (true, &timeout_time, &timed_out)) |
| 339 | { |
| 340 | if (log) |
| 341 | { |
| 342 | if (timed_out) |
| 343 | log->Printf ("async: timed out waiting for process to resume, but process was resumed"); |
| 344 | else |
| 345 | log->Printf ("async: async packet sent"); |
| 346 | } |
| 347 | } |
| 348 | else |
| 349 | { |
| 350 | if (log) |
| 351 | log->Printf ("async: timed out waiting for process to resume"); |
Greg Clayton | b7669b3 | 2011-10-27 22:04:16 +0000 | [diff] [blame] | 352 | } |
| 353 | } |
| 354 | else |
| 355 | { |
Greg Clayton | 70e167f | 2012-05-31 21:24:20 +0000 | [diff] [blame] | 356 | // We had a racy condition where we went to send the interrupt |
| 357 | // yet we were able to get the lock, so the process must have |
| 358 | // just stopped? |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 359 | if (log) |
Greg Clayton | 70e167f | 2012-05-31 21:24:20 +0000 | [diff] [blame] | 360 | log->Printf ("async: got lock without sending interrupt"); |
| 361 | // Send the packet normally since we got the lock |
| 362 | if (SendPacketNoLock (payload, payload_length)) |
| 363 | response_len = WaitForPacketWithTimeoutMicroSecondsNoLock (response, GetPacketTimeoutInMicroSeconds ()); |
| 364 | else |
| 365 | { |
| 366 | if (log) |
| 367 | log->Printf("error: failed to send '%*s'", (int) payload_length, payload); |
| 368 | } |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 369 | } |
| 370 | } |
| 371 | else |
| 372 | { |
Greg Clayton | 801417e | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 373 | if (log) |
Greg Clayton | 70e167f | 2012-05-31 21:24:20 +0000 | [diff] [blame] | 374 | log->Printf ("async: failed to interrupt"); |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 375 | } |
| 376 | } |
| 377 | else |
| 378 | { |
| 379 | if (log) |
Greg Clayton | 70e167f | 2012-05-31 21:24:20 +0000 | [diff] [blame] | 380 | log->Printf ("async: not running, async is ignored"); |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 381 | } |
| 382 | } |
| 383 | else |
| 384 | { |
| 385 | if (log) |
Greg Clayton | c8dd570 | 2012-04-12 19:04:34 +0000 | [diff] [blame] | 386 | log->Printf("error: failed to get packet sequence mutex, not sending packet '%*s'", (int) payload_length, payload); |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 387 | } |
| 388 | } |
Greg Clayton | 801417e | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 389 | if (response_len == 0) |
| 390 | { |
| 391 | if (log) |
Jason Molenda | 7e5fa7f | 2011-09-20 21:44:10 +0000 | [diff] [blame] | 392 | log->Printf("error: failed to get response for '%*s'", (int) payload_length, payload); |
Greg Clayton | 801417e | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 393 | } |
| 394 | return response_len; |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 395 | } |
| 396 | |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 397 | StateType |
| 398 | GDBRemoteCommunicationClient::SendContinuePacketAndWaitForResponse |
| 399 | ( |
| 400 | ProcessGDBRemote *process, |
| 401 | const char *payload, |
| 402 | size_t packet_length, |
| 403 | StringExtractorGDBRemote &response |
| 404 | ) |
| 405 | { |
Greg Clayton | 0d2c541 | 2012-07-02 22:05:25 +0000 | [diff] [blame] | 406 | m_curr_tid = LLDB_INVALID_THREAD_ID; |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 407 | LogSP log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PROCESS)); |
| 408 | if (log) |
| 409 | log->Printf ("GDBRemoteCommunicationClient::%s ()", __FUNCTION__); |
| 410 | |
| 411 | Mutex::Locker locker(m_sequence_mutex); |
| 412 | StateType state = eStateRunning; |
| 413 | |
| 414 | BroadcastEvent(eBroadcastBitRunPacketSent, NULL); |
| 415 | m_public_is_running.SetValue (true, eBroadcastNever); |
| 416 | // Set the starting continue packet into "continue_packet". This packet |
Jim Ingham | 8247e62 | 2012-06-06 00:32:39 +0000 | [diff] [blame] | 417 | // may change if we are interrupted and we continue after an async packet... |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 418 | std::string continue_packet(payload, packet_length); |
| 419 | |
Greg Clayton | 628cead | 2011-05-19 03:54:16 +0000 | [diff] [blame] | 420 | bool got_stdout = false; |
| 421 | |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 422 | while (state == eStateRunning) |
| 423 | { |
Greg Clayton | 628cead | 2011-05-19 03:54:16 +0000 | [diff] [blame] | 424 | if (!got_stdout) |
| 425 | { |
| 426 | if (log) |
| 427 | log->Printf ("GDBRemoteCommunicationClient::%s () sending continue packet: %s", __FUNCTION__, continue_packet.c_str()); |
Greg Clayton | 516f084 | 2012-04-11 00:24:49 +0000 | [diff] [blame] | 428 | if (SendPacketNoLock(continue_packet.c_str(), continue_packet.size()) == 0) |
Greg Clayton | 628cead | 2011-05-19 03:54:16 +0000 | [diff] [blame] | 429 | state = eStateInvalid; |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 430 | |
Greg Clayton | b7669b3 | 2011-10-27 22:04:16 +0000 | [diff] [blame] | 431 | m_private_is_running.SetValue (true, eBroadcastAlways); |
Greg Clayton | 628cead | 2011-05-19 03:54:16 +0000 | [diff] [blame] | 432 | } |
| 433 | |
| 434 | got_stdout = false; |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 435 | |
| 436 | if (log) |
Jason Molenda | 7e5fa7f | 2011-09-20 21:44:10 +0000 | [diff] [blame] | 437 | log->Printf ("GDBRemoteCommunicationClient::%s () WaitForPacket(%s)", __FUNCTION__, continue_packet.c_str()); |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 438 | |
Greg Clayton | 516f084 | 2012-04-11 00:24:49 +0000 | [diff] [blame] | 439 | if (WaitForPacketWithTimeoutMicroSecondsNoLock(response, UINT32_MAX)) |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 440 | { |
| 441 | if (response.Empty()) |
| 442 | state = eStateInvalid; |
| 443 | else |
| 444 | { |
| 445 | const char stop_type = response.GetChar(); |
| 446 | if (log) |
| 447 | log->Printf ("GDBRemoteCommunicationClient::%s () got packet: %s", __FUNCTION__, response.GetStringRef().c_str()); |
| 448 | switch (stop_type) |
| 449 | { |
| 450 | case 'T': |
| 451 | case 'S': |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 452 | { |
Greg Clayton | 05e4d97 | 2012-03-29 01:55:41 +0000 | [diff] [blame] | 453 | if (process->GetStopID() == 0) |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 454 | { |
Greg Clayton | 05e4d97 | 2012-03-29 01:55:41 +0000 | [diff] [blame] | 455 | if (process->GetID() == LLDB_INVALID_PROCESS_ID) |
| 456 | { |
| 457 | lldb::pid_t pid = GetCurrentProcessID (); |
| 458 | if (pid != LLDB_INVALID_PROCESS_ID) |
| 459 | process->SetID (pid); |
| 460 | } |
| 461 | process->BuildDynamicRegisterInfo (true); |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 462 | } |
Greg Clayton | 05e4d97 | 2012-03-29 01:55:41 +0000 | [diff] [blame] | 463 | |
| 464 | // Privately notify any internal threads that we have stopped |
| 465 | // in case we wanted to interrupt our process, yet we might |
| 466 | // send a packet and continue without returning control to the |
| 467 | // user. |
| 468 | m_private_is_running.SetValue (false, eBroadcastAlways); |
| 469 | |
| 470 | const uint8_t signo = response.GetHexU8 (UINT8_MAX); |
| 471 | |
Jim Ingham | 8247e62 | 2012-06-06 00:32:39 +0000 | [diff] [blame] | 472 | bool continue_after_async = m_async_signal != -1 || m_async_packet_predicate.GetValue(); |
| 473 | if (continue_after_async || m_interrupt_sent) |
Greg Clayton | 05e4d97 | 2012-03-29 01:55:41 +0000 | [diff] [blame] | 474 | { |
Greg Clayton | 05e4d97 | 2012-03-29 01:55:41 +0000 | [diff] [blame] | 475 | // We sent an interrupt packet to stop the inferior process |
| 476 | // for an async signal or to send an async packet while running |
| 477 | // but we might have been single stepping and received the |
| 478 | // stop packet for the step instead of for the interrupt packet. |
| 479 | // Typically when an interrupt is sent a SIGINT or SIGSTOP |
| 480 | // is used, so if we get anything else, we need to try and |
| 481 | // get another stop reply packet that may have been sent |
| 482 | // due to sending the interrupt when the target is stopped |
| 483 | // which will just re-send a copy of the last stop reply |
| 484 | // packet. If we don't do this, then the reply for our |
| 485 | // async packet will be the repeat stop reply packet and cause |
| 486 | // a lot of trouble for us! |
| 487 | if (signo != SIGINT && signo != SIGSTOP) |
| 488 | { |
Greg Clayton | c2c822c | 2012-05-15 02:50:49 +0000 | [diff] [blame] | 489 | continue_after_async = false; |
Greg Clayton | 05e4d97 | 2012-03-29 01:55:41 +0000 | [diff] [blame] | 490 | |
| 491 | // We didn't get a a SIGINT or SIGSTOP, so try for a |
| 492 | // very brief time (1 ms) to get another stop reply |
| 493 | // packet to make sure it doesn't get in the way |
| 494 | StringExtractorGDBRemote extra_stop_reply_packet; |
| 495 | uint32_t timeout_usec = 1000; |
| 496 | if (WaitForPacketWithTimeoutMicroSecondsNoLock (extra_stop_reply_packet, timeout_usec)) |
| 497 | { |
| 498 | switch (extra_stop_reply_packet.GetChar()) |
| 499 | { |
| 500 | case 'T': |
| 501 | case 'S': |
| 502 | // We did get an extra stop reply, which means |
| 503 | // our interrupt didn't stop the target so we |
| 504 | // shouldn't continue after the async signal |
| 505 | // or packet is sent... |
Greg Clayton | c2c822c | 2012-05-15 02:50:49 +0000 | [diff] [blame] | 506 | continue_after_async = false; |
Greg Clayton | 05e4d97 | 2012-03-29 01:55:41 +0000 | [diff] [blame] | 507 | break; |
| 508 | } |
| 509 | } |
| 510 | } |
| 511 | } |
| 512 | |
| 513 | if (m_async_signal != -1) |
| 514 | { |
| 515 | if (log) |
| 516 | log->Printf ("async: send signo = %s", Host::GetSignalAsCString (m_async_signal)); |
| 517 | |
| 518 | // Save off the async signal we are supposed to send |
| 519 | const int async_signal = m_async_signal; |
| 520 | // Clear the async signal member so we don't end up |
| 521 | // sending the signal multiple times... |
| 522 | m_async_signal = -1; |
| 523 | // Check which signal we stopped with |
| 524 | if (signo == async_signal) |
| 525 | { |
| 526 | if (log) |
| 527 | log->Printf ("async: stopped with signal %s, we are done running", Host::GetSignalAsCString (signo)); |
| 528 | |
| 529 | // We already stopped with a signal that we wanted |
| 530 | // to stop with, so we are done |
| 531 | } |
| 532 | else |
| 533 | { |
| 534 | // We stopped with a different signal that the one |
| 535 | // we wanted to stop with, so now we must resume |
| 536 | // with the signal we want |
| 537 | char signal_packet[32]; |
| 538 | int signal_packet_len = 0; |
| 539 | signal_packet_len = ::snprintf (signal_packet, |
| 540 | sizeof (signal_packet), |
| 541 | "C%2.2x", |
| 542 | async_signal); |
| 543 | |
| 544 | if (log) |
| 545 | log->Printf ("async: stopped with signal %s, resume with %s", |
| 546 | Host::GetSignalAsCString (signo), |
| 547 | Host::GetSignalAsCString (async_signal)); |
| 548 | |
| 549 | // Set the continue packet to resume even if the |
Greg Clayton | c2c822c | 2012-05-15 02:50:49 +0000 | [diff] [blame] | 550 | // interrupt didn't cause our stop (ignore continue_after_async) |
Greg Clayton | 05e4d97 | 2012-03-29 01:55:41 +0000 | [diff] [blame] | 551 | continue_packet.assign(signal_packet, signal_packet_len); |
| 552 | continue; |
| 553 | } |
| 554 | } |
| 555 | else if (m_async_packet_predicate.GetValue()) |
| 556 | { |
| 557 | LogSP packet_log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PACKETS)); |
| 558 | |
| 559 | // We are supposed to send an asynchronous packet while |
| 560 | // we are running. |
| 561 | m_async_response.Clear(); |
| 562 | if (m_async_packet.empty()) |
| 563 | { |
| 564 | if (packet_log) |
| 565 | packet_log->Printf ("async: error: empty async packet"); |
| 566 | |
| 567 | } |
| 568 | else |
| 569 | { |
| 570 | if (packet_log) |
| 571 | packet_log->Printf ("async: sending packet"); |
| 572 | |
| 573 | SendPacketAndWaitForResponse (&m_async_packet[0], |
| 574 | m_async_packet.size(), |
| 575 | m_async_response, |
| 576 | false); |
| 577 | } |
| 578 | // Let the other thread that was trying to send the async |
| 579 | // packet know that the packet has been sent and response is |
| 580 | // ready... |
| 581 | m_async_packet_predicate.SetValue(false, eBroadcastAlways); |
| 582 | |
| 583 | if (packet_log) |
Greg Clayton | c2c822c | 2012-05-15 02:50:49 +0000 | [diff] [blame] | 584 | packet_log->Printf ("async: sent packet, continue_after_async = %i", continue_after_async); |
Greg Clayton | 05e4d97 | 2012-03-29 01:55:41 +0000 | [diff] [blame] | 585 | |
| 586 | // Set the continue packet to resume if our interrupt |
| 587 | // for the async packet did cause the stop |
Greg Clayton | c2c822c | 2012-05-15 02:50:49 +0000 | [diff] [blame] | 588 | if (continue_after_async) |
Greg Clayton | 05e4d97 | 2012-03-29 01:55:41 +0000 | [diff] [blame] | 589 | { |
Greg Clayton | 8ca4fa7 | 2012-05-24 23:42:14 +0000 | [diff] [blame] | 590 | // Reverting this for now as it is causing deadlocks |
| 591 | // in programs (<rdar://problem/11529853>). In the future |
| 592 | // we should check our thread list and "do the right thing" |
| 593 | // for new threads that show up while we stop and run async |
| 594 | // packets. Setting the packet to 'c' to continue all threads |
| 595 | // is the right thing to do 99.99% of the time because if a |
| 596 | // thread was single stepping, and we sent an interrupt, we |
| 597 | // will notice above that we didn't stop due to an interrupt |
| 598 | // but stopped due to stepping and we would _not_ continue. |
| 599 | continue_packet.assign (1, 'c'); |
Greg Clayton | 05e4d97 | 2012-03-29 01:55:41 +0000 | [diff] [blame] | 600 | continue; |
| 601 | } |
| 602 | } |
| 603 | // Stop with signal and thread info |
| 604 | state = eStateStopped; |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 605 | } |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 606 | break; |
| 607 | |
| 608 | case 'W': |
| 609 | case 'X': |
| 610 | // process exited |
| 611 | state = eStateExited; |
| 612 | break; |
| 613 | |
| 614 | case 'O': |
| 615 | // STDOUT |
| 616 | { |
Greg Clayton | 628cead | 2011-05-19 03:54:16 +0000 | [diff] [blame] | 617 | got_stdout = true; |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 618 | std::string inferior_stdout; |
| 619 | inferior_stdout.reserve(response.GetBytesLeft () / 2); |
| 620 | char ch; |
| 621 | while ((ch = response.GetHexU8()) != '\0') |
| 622 | inferior_stdout.append(1, ch); |
| 623 | process->AppendSTDOUT (inferior_stdout.c_str(), inferior_stdout.size()); |
| 624 | } |
| 625 | break; |
| 626 | |
| 627 | case 'E': |
| 628 | // ERROR |
| 629 | state = eStateInvalid; |
| 630 | break; |
| 631 | |
| 632 | default: |
| 633 | if (log) |
| 634 | log->Printf ("GDBRemoteCommunicationClient::%s () unrecognized async packet", __FUNCTION__); |
| 635 | state = eStateInvalid; |
| 636 | break; |
| 637 | } |
| 638 | } |
| 639 | } |
| 640 | else |
| 641 | { |
| 642 | if (log) |
| 643 | log->Printf ("GDBRemoteCommunicationClient::%s () WaitForPacket(...) => false", __FUNCTION__); |
| 644 | state = eStateInvalid; |
| 645 | } |
| 646 | } |
| 647 | if (log) |
| 648 | log->Printf ("GDBRemoteCommunicationClient::%s () => %s", __FUNCTION__, StateAsCString(state)); |
| 649 | response.SetFilePos(0); |
| 650 | m_private_is_running.SetValue (false, eBroadcastAlways); |
| 651 | m_public_is_running.SetValue (false, eBroadcastAlways); |
| 652 | return state; |
| 653 | } |
| 654 | |
| 655 | bool |
| 656 | GDBRemoteCommunicationClient::SendAsyncSignal (int signo) |
| 657 | { |
Greg Clayton | 05e4d97 | 2012-03-29 01:55:41 +0000 | [diff] [blame] | 658 | Mutex::Locker async_locker (m_async_mutex); |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 659 | m_async_signal = signo; |
| 660 | bool timed_out = false; |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 661 | Mutex::Locker locker; |
Greg Clayton | 05e4d97 | 2012-03-29 01:55:41 +0000 | [diff] [blame] | 662 | if (SendInterrupt (locker, 1, timed_out)) |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 663 | return true; |
| 664 | m_async_signal = -1; |
| 665 | return false; |
| 666 | } |
| 667 | |
Greg Clayton | 516f084 | 2012-04-11 00:24:49 +0000 | [diff] [blame] | 668 | // This function takes a mutex locker as a parameter in case the GetSequenceMutex |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 669 | // actually succeeds. If it doesn't succeed in acquiring the sequence mutex |
| 670 | // (the expected result), then it will send the halt packet. If it does succeed |
| 671 | // then the caller that requested the interrupt will want to keep the sequence |
| 672 | // locked down so that no one else can send packets while the caller has control. |
| 673 | // This function usually gets called when we are running and need to stop the |
| 674 | // target. It can also be used when we are running and and we need to do something |
| 675 | // else (like read/write memory), so we need to interrupt the running process |
| 676 | // (gdb remote protocol requires this), and do what we need to do, then resume. |
| 677 | |
| 678 | bool |
Greg Clayton | 05e4d97 | 2012-03-29 01:55:41 +0000 | [diff] [blame] | 679 | GDBRemoteCommunicationClient::SendInterrupt |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 680 | ( |
| 681 | Mutex::Locker& locker, |
| 682 | uint32_t seconds_to_wait_for_stop, |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 683 | bool &timed_out |
| 684 | ) |
| 685 | { |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 686 | timed_out = false; |
Greg Clayton | 05e4d97 | 2012-03-29 01:55:41 +0000 | [diff] [blame] | 687 | LogSP log (ProcessGDBRemoteLog::GetLogIfAnyCategoryIsSet (GDBR_LOG_PROCESS | GDBR_LOG_PACKETS)); |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 688 | |
| 689 | if (IsRunning()) |
| 690 | { |
| 691 | // Only send an interrupt if our debugserver is running... |
Greg Clayton | c8dd570 | 2012-04-12 19:04:34 +0000 | [diff] [blame] | 692 | if (GetSequenceMutex (locker)) |
Greg Clayton | 516f084 | 2012-04-11 00:24:49 +0000 | [diff] [blame] | 693 | { |
| 694 | if (log) |
| 695 | log->Printf ("SendInterrupt () - got sequence mutex without having to interrupt"); |
| 696 | } |
| 697 | else |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 698 | { |
| 699 | // Someone has the mutex locked waiting for a response or for the |
| 700 | // inferior to stop, so send the interrupt on the down low... |
| 701 | char ctrl_c = '\x03'; |
| 702 | ConnectionStatus status = eConnectionStatusSuccess; |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 703 | size_t bytes_written = Write (&ctrl_c, 1, status, NULL); |
Greg Clayton | 05e4d97 | 2012-03-29 01:55:41 +0000 | [diff] [blame] | 704 | if (log) |
| 705 | log->PutCString("send packet: \\x03"); |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 706 | if (bytes_written > 0) |
| 707 | { |
Greg Clayton | 05e4d97 | 2012-03-29 01:55:41 +0000 | [diff] [blame] | 708 | m_interrupt_sent = true; |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 709 | if (seconds_to_wait_for_stop) |
| 710 | { |
Greg Clayton | 05e4d97 | 2012-03-29 01:55:41 +0000 | [diff] [blame] | 711 | TimeValue timeout; |
| 712 | if (seconds_to_wait_for_stop) |
| 713 | { |
| 714 | timeout = TimeValue::Now(); |
| 715 | timeout.OffsetWithSeconds (seconds_to_wait_for_stop); |
| 716 | } |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 717 | if (m_private_is_running.WaitForValueEqualTo (false, &timeout, &timed_out)) |
| 718 | { |
| 719 | if (log) |
Greg Clayton | 05e4d97 | 2012-03-29 01:55:41 +0000 | [diff] [blame] | 720 | log->PutCString ("SendInterrupt () - sent interrupt, private state stopped"); |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 721 | return true; |
| 722 | } |
| 723 | else |
| 724 | { |
| 725 | if (log) |
Greg Clayton | 05e4d97 | 2012-03-29 01:55:41 +0000 | [diff] [blame] | 726 | log->Printf ("SendInterrupt () - sent interrupt, timed out wating for async thread resume"); |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 727 | } |
| 728 | } |
| 729 | else |
| 730 | { |
| 731 | if (log) |
Greg Clayton | 05e4d97 | 2012-03-29 01:55:41 +0000 | [diff] [blame] | 732 | log->Printf ("SendInterrupt () - sent interrupt, not waiting for stop..."); |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 733 | return true; |
| 734 | } |
| 735 | } |
| 736 | else |
| 737 | { |
| 738 | if (log) |
Greg Clayton | 05e4d97 | 2012-03-29 01:55:41 +0000 | [diff] [blame] | 739 | log->Printf ("SendInterrupt () - failed to write interrupt"); |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 740 | } |
| 741 | return false; |
| 742 | } |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 743 | } |
Greg Clayton | 05e4d97 | 2012-03-29 01:55:41 +0000 | [diff] [blame] | 744 | else |
| 745 | { |
| 746 | if (log) |
| 747 | log->Printf ("SendInterrupt () - not running"); |
| 748 | } |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 749 | return true; |
| 750 | } |
| 751 | |
| 752 | lldb::pid_t |
| 753 | GDBRemoteCommunicationClient::GetCurrentProcessID () |
| 754 | { |
| 755 | StringExtractorGDBRemote response; |
| 756 | if (SendPacketAndWaitForResponse("qC", strlen("qC"), response, false)) |
| 757 | { |
| 758 | if (response.GetChar() == 'Q') |
| 759 | if (response.GetChar() == 'C') |
| 760 | return response.GetHexMaxU32 (false, LLDB_INVALID_PROCESS_ID); |
| 761 | } |
| 762 | return LLDB_INVALID_PROCESS_ID; |
| 763 | } |
| 764 | |
| 765 | bool |
| 766 | GDBRemoteCommunicationClient::GetLaunchSuccess (std::string &error_str) |
| 767 | { |
| 768 | error_str.clear(); |
| 769 | StringExtractorGDBRemote response; |
| 770 | if (SendPacketAndWaitForResponse("qLaunchSuccess", strlen("qLaunchSuccess"), response, false)) |
| 771 | { |
| 772 | if (response.IsOKResponse()) |
| 773 | return true; |
| 774 | if (response.GetChar() == 'E') |
| 775 | { |
| 776 | // A string the describes what failed when launching... |
| 777 | error_str = response.GetStringRef().substr(1); |
| 778 | } |
| 779 | else |
| 780 | { |
| 781 | error_str.assign ("unknown error occurred launching process"); |
| 782 | } |
| 783 | } |
| 784 | else |
| 785 | { |
Jim Ingham | 7b3a49b | 2012-06-28 20:30:23 +0000 | [diff] [blame] | 786 | error_str.assign ("timed out waiting for app to launch"); |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 787 | } |
| 788 | return false; |
| 789 | } |
| 790 | |
| 791 | int |
| 792 | GDBRemoteCommunicationClient::SendArgumentsPacket (char const *argv[]) |
| 793 | { |
| 794 | if (argv && argv[0]) |
| 795 | { |
| 796 | StreamString packet; |
| 797 | packet.PutChar('A'); |
| 798 | const char *arg; |
| 799 | for (uint32_t i = 0; (arg = argv[i]) != NULL; ++i) |
| 800 | { |
| 801 | const int arg_len = strlen(arg); |
| 802 | if (i > 0) |
| 803 | packet.PutChar(','); |
| 804 | packet.Printf("%i,%i,", arg_len * 2, i); |
| 805 | packet.PutBytesAsRawHex8 (arg, arg_len); |
| 806 | } |
| 807 | |
| 808 | StringExtractorGDBRemote response; |
| 809 | if (SendPacketAndWaitForResponse (packet.GetData(), packet.GetSize(), response, false)) |
| 810 | { |
| 811 | if (response.IsOKResponse()) |
| 812 | return 0; |
| 813 | uint8_t error = response.GetError(); |
| 814 | if (error) |
| 815 | return error; |
| 816 | } |
| 817 | } |
| 818 | return -1; |
| 819 | } |
| 820 | |
| 821 | int |
| 822 | GDBRemoteCommunicationClient::SendEnvironmentPacket (char const *name_equal_value) |
| 823 | { |
| 824 | if (name_equal_value && name_equal_value[0]) |
| 825 | { |
| 826 | StreamString packet; |
| 827 | packet.Printf("QEnvironment:%s", name_equal_value); |
| 828 | StringExtractorGDBRemote response; |
| 829 | if (SendPacketAndWaitForResponse (packet.GetData(), packet.GetSize(), response, false)) |
| 830 | { |
| 831 | if (response.IsOKResponse()) |
| 832 | return 0; |
| 833 | uint8_t error = response.GetError(); |
| 834 | if (error) |
| 835 | return error; |
| 836 | } |
| 837 | } |
| 838 | return -1; |
| 839 | } |
| 840 | |
Greg Clayton | a458240 | 2011-05-08 04:53:50 +0000 | [diff] [blame] | 841 | int |
| 842 | GDBRemoteCommunicationClient::SendLaunchArchPacket (char const *arch) |
| 843 | { |
| 844 | if (arch && arch[0]) |
| 845 | { |
| 846 | StreamString packet; |
| 847 | packet.Printf("QLaunchArch:%s", arch); |
| 848 | StringExtractorGDBRemote response; |
| 849 | if (SendPacketAndWaitForResponse (packet.GetData(), packet.GetSize(), response, false)) |
| 850 | { |
| 851 | if (response.IsOKResponse()) |
| 852 | return 0; |
| 853 | uint8_t error = response.GetError(); |
| 854 | if (error) |
| 855 | return error; |
| 856 | } |
| 857 | } |
| 858 | return -1; |
| 859 | } |
| 860 | |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 861 | bool |
Greg Clayton | 58e26e0 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 862 | GDBRemoteCommunicationClient::GetOSVersion (uint32_t &major, |
| 863 | uint32_t &minor, |
| 864 | uint32_t &update) |
| 865 | { |
| 866 | if (GetHostInfo ()) |
| 867 | { |
| 868 | if (m_os_version_major != UINT32_MAX) |
| 869 | { |
| 870 | major = m_os_version_major; |
| 871 | minor = m_os_version_minor; |
| 872 | update = m_os_version_update; |
| 873 | return true; |
| 874 | } |
| 875 | } |
| 876 | return false; |
| 877 | } |
| 878 | |
| 879 | bool |
| 880 | GDBRemoteCommunicationClient::GetOSBuildString (std::string &s) |
| 881 | { |
| 882 | if (GetHostInfo ()) |
| 883 | { |
| 884 | if (!m_os_build.empty()) |
| 885 | { |
| 886 | s = m_os_build; |
| 887 | return true; |
| 888 | } |
| 889 | } |
| 890 | s.clear(); |
| 891 | return false; |
| 892 | } |
| 893 | |
| 894 | |
| 895 | bool |
| 896 | GDBRemoteCommunicationClient::GetOSKernelDescription (std::string &s) |
| 897 | { |
| 898 | if (GetHostInfo ()) |
| 899 | { |
| 900 | if (!m_os_kernel.empty()) |
| 901 | { |
| 902 | s = m_os_kernel; |
| 903 | return true; |
| 904 | } |
| 905 | } |
| 906 | s.clear(); |
| 907 | return false; |
| 908 | } |
| 909 | |
| 910 | bool |
| 911 | GDBRemoteCommunicationClient::GetHostname (std::string &s) |
| 912 | { |
| 913 | if (GetHostInfo ()) |
| 914 | { |
| 915 | if (!m_hostname.empty()) |
| 916 | { |
| 917 | s = m_hostname; |
| 918 | return true; |
| 919 | } |
| 920 | } |
| 921 | s.clear(); |
| 922 | return false; |
| 923 | } |
| 924 | |
| 925 | ArchSpec |
| 926 | GDBRemoteCommunicationClient::GetSystemArchitecture () |
| 927 | { |
| 928 | if (GetHostInfo ()) |
| 929 | return m_host_arch; |
| 930 | return ArchSpec(); |
| 931 | } |
| 932 | |
| 933 | |
| 934 | bool |
Greg Clayton | 06d7cc8 | 2011-04-04 18:18:57 +0000 | [diff] [blame] | 935 | GDBRemoteCommunicationClient::GetHostInfo (bool force) |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 936 | { |
Greg Clayton | 06d7cc8 | 2011-04-04 18:18:57 +0000 | [diff] [blame] | 937 | if (force || m_qHostInfo_is_valid == eLazyBoolCalculate) |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 938 | { |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 939 | m_qHostInfo_is_valid = eLazyBoolNo; |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 940 | StringExtractorGDBRemote response; |
| 941 | if (SendPacketAndWaitForResponse ("qHostInfo", response, false)) |
| 942 | { |
Greg Clayton | 5b53e8e | 2011-05-15 23:46:54 +0000 | [diff] [blame] | 943 | if (response.IsNormalResponse()) |
Greg Clayton | cb8977d | 2011-03-23 00:09:55 +0000 | [diff] [blame] | 944 | { |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 945 | std::string name; |
| 946 | std::string value; |
| 947 | uint32_t cpu = LLDB_INVALID_CPUTYPE; |
| 948 | uint32_t sub = 0; |
| 949 | std::string arch_name; |
| 950 | std::string os_name; |
| 951 | std::string vendor_name; |
| 952 | std::string triple; |
| 953 | uint32_t pointer_byte_size = 0; |
| 954 | StringExtractor extractor; |
| 955 | ByteOrder byte_order = eByteOrderInvalid; |
| 956 | uint32_t num_keys_decoded = 0; |
| 957 | while (response.GetNameColonValue(name, value)) |
Greg Clayton | cb8977d | 2011-03-23 00:09:55 +0000 | [diff] [blame] | 958 | { |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 959 | if (name.compare("cputype") == 0) |
Greg Clayton | 58e26e0 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 960 | { |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 961 | // exception type in big endian hex |
| 962 | cpu = Args::StringToUInt32 (value.c_str(), LLDB_INVALID_CPUTYPE, 0); |
| 963 | if (cpu != LLDB_INVALID_CPUTYPE) |
| 964 | ++num_keys_decoded; |
| 965 | } |
| 966 | else if (name.compare("cpusubtype") == 0) |
| 967 | { |
| 968 | // exception count in big endian hex |
| 969 | sub = Args::StringToUInt32 (value.c_str(), 0, 0); |
| 970 | if (sub != 0) |
| 971 | ++num_keys_decoded; |
| 972 | } |
| 973 | else if (name.compare("arch") == 0) |
| 974 | { |
| 975 | arch_name.swap (value); |
| 976 | ++num_keys_decoded; |
| 977 | } |
| 978 | else if (name.compare("triple") == 0) |
| 979 | { |
| 980 | // The triple comes as ASCII hex bytes since it contains '-' chars |
| 981 | extractor.GetStringRef().swap(value); |
| 982 | extractor.SetFilePos(0); |
| 983 | extractor.GetHexByteString (triple); |
| 984 | ++num_keys_decoded; |
| 985 | } |
| 986 | else if (name.compare("os_build") == 0) |
| 987 | { |
| 988 | extractor.GetStringRef().swap(value); |
| 989 | extractor.SetFilePos(0); |
| 990 | extractor.GetHexByteString (m_os_build); |
| 991 | ++num_keys_decoded; |
| 992 | } |
| 993 | else if (name.compare("hostname") == 0) |
| 994 | { |
| 995 | extractor.GetStringRef().swap(value); |
| 996 | extractor.SetFilePos(0); |
| 997 | extractor.GetHexByteString (m_hostname); |
| 998 | ++num_keys_decoded; |
| 999 | } |
| 1000 | else if (name.compare("os_kernel") == 0) |
| 1001 | { |
| 1002 | extractor.GetStringRef().swap(value); |
| 1003 | extractor.SetFilePos(0); |
| 1004 | extractor.GetHexByteString (m_os_kernel); |
| 1005 | ++num_keys_decoded; |
| 1006 | } |
| 1007 | else if (name.compare("ostype") == 0) |
| 1008 | { |
| 1009 | os_name.swap (value); |
| 1010 | ++num_keys_decoded; |
| 1011 | } |
| 1012 | else if (name.compare("vendor") == 0) |
| 1013 | { |
| 1014 | vendor_name.swap(value); |
| 1015 | ++num_keys_decoded; |
| 1016 | } |
| 1017 | else if (name.compare("endian") == 0) |
| 1018 | { |
| 1019 | ++num_keys_decoded; |
| 1020 | if (value.compare("little") == 0) |
| 1021 | byte_order = eByteOrderLittle; |
| 1022 | else if (value.compare("big") == 0) |
| 1023 | byte_order = eByteOrderBig; |
| 1024 | else if (value.compare("pdp") == 0) |
| 1025 | byte_order = eByteOrderPDP; |
| 1026 | else |
| 1027 | --num_keys_decoded; |
| 1028 | } |
| 1029 | else if (name.compare("ptrsize") == 0) |
| 1030 | { |
| 1031 | pointer_byte_size = Args::StringToUInt32 (value.c_str(), 0, 0); |
| 1032 | if (pointer_byte_size != 0) |
| 1033 | ++num_keys_decoded; |
| 1034 | } |
| 1035 | else if (name.compare("os_version") == 0) |
| 1036 | { |
| 1037 | Args::StringToVersion (value.c_str(), |
| 1038 | m_os_version_major, |
| 1039 | m_os_version_minor, |
| 1040 | m_os_version_update); |
| 1041 | if (m_os_version_major != UINT32_MAX) |
| 1042 | ++num_keys_decoded; |
| 1043 | } |
Enrico Granata | 7de2a3b | 2012-07-13 23:18:48 +0000 | [diff] [blame] | 1044 | else if (name.compare("watchpoint_exceptions_received") == 0) |
| 1045 | { |
| 1046 | ++num_keys_decoded; |
| 1047 | if (strcmp(value.c_str(),"before") == 0) |
| 1048 | m_watchpoints_trigger_after_instruction = eLazyBoolNo; |
| 1049 | else if (strcmp(value.c_str(),"after") == 0) |
| 1050 | m_watchpoints_trigger_after_instruction = eLazyBoolYes; |
| 1051 | else |
| 1052 | --num_keys_decoded; |
| 1053 | } |
| 1054 | |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 1055 | } |
| 1056 | |
| 1057 | if (num_keys_decoded > 0) |
| 1058 | m_qHostInfo_is_valid = eLazyBoolYes; |
| 1059 | |
| 1060 | if (triple.empty()) |
| 1061 | { |
| 1062 | if (arch_name.empty()) |
| 1063 | { |
| 1064 | if (cpu != LLDB_INVALID_CPUTYPE) |
| 1065 | { |
| 1066 | m_host_arch.SetArchitecture (eArchTypeMachO, cpu, sub); |
| 1067 | if (pointer_byte_size) |
| 1068 | { |
| 1069 | assert (pointer_byte_size == m_host_arch.GetAddressByteSize()); |
| 1070 | } |
| 1071 | if (byte_order != eByteOrderInvalid) |
| 1072 | { |
| 1073 | assert (byte_order == m_host_arch.GetByteOrder()); |
| 1074 | } |
Greg Clayton | b170aee | 2012-05-08 01:45:38 +0000 | [diff] [blame] | 1075 | |
| 1076 | if (!os_name.empty() && vendor_name.compare("apple") == 0 && os_name.find("darwin") == 0) |
| 1077 | { |
| 1078 | switch (m_host_arch.GetMachine()) |
| 1079 | { |
| 1080 | case llvm::Triple::arm: |
| 1081 | case llvm::Triple::thumb: |
| 1082 | os_name = "ios"; |
| 1083 | break; |
| 1084 | default: |
| 1085 | os_name = "macosx"; |
| 1086 | break; |
| 1087 | } |
| 1088 | } |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 1089 | if (!vendor_name.empty()) |
| 1090 | m_host_arch.GetTriple().setVendorName (llvm::StringRef (vendor_name)); |
| 1091 | if (!os_name.empty()) |
Greg Clayton | 89798cc | 2011-09-15 00:21:03 +0000 | [diff] [blame] | 1092 | m_host_arch.GetTriple().setOSName (llvm::StringRef (os_name)); |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 1093 | |
| 1094 | } |
| 1095 | } |
| 1096 | else |
| 1097 | { |
| 1098 | std::string triple; |
| 1099 | triple += arch_name; |
Greg Clayton | b170aee | 2012-05-08 01:45:38 +0000 | [diff] [blame] | 1100 | if (!vendor_name.empty() || !os_name.empty()) |
| 1101 | { |
| 1102 | triple += '-'; |
| 1103 | if (vendor_name.empty()) |
| 1104 | triple += "unknown"; |
| 1105 | else |
| 1106 | triple += vendor_name; |
| 1107 | triple += '-'; |
| 1108 | if (os_name.empty()) |
| 1109 | triple += "unknown"; |
| 1110 | else |
| 1111 | triple += os_name; |
| 1112 | } |
| 1113 | m_host_arch.SetTriple (triple.c_str()); |
| 1114 | |
| 1115 | llvm::Triple &host_triple = m_host_arch.GetTriple(); |
| 1116 | if (host_triple.getVendor() == llvm::Triple::Apple && host_triple.getOS() == llvm::Triple::Darwin) |
| 1117 | { |
| 1118 | switch (m_host_arch.GetMachine()) |
| 1119 | { |
| 1120 | case llvm::Triple::arm: |
| 1121 | case llvm::Triple::thumb: |
| 1122 | host_triple.setOS(llvm::Triple::IOS); |
| 1123 | break; |
| 1124 | default: |
| 1125 | host_triple.setOS(llvm::Triple::MacOSX); |
| 1126 | break; |
| 1127 | } |
| 1128 | } |
Greg Clayton | 58e26e0 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 1129 | if (pointer_byte_size) |
| 1130 | { |
| 1131 | assert (pointer_byte_size == m_host_arch.GetAddressByteSize()); |
| 1132 | } |
| 1133 | if (byte_order != eByteOrderInvalid) |
| 1134 | { |
| 1135 | assert (byte_order == m_host_arch.GetByteOrder()); |
| 1136 | } |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 1137 | |
Greg Clayton | 58e26e0 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 1138 | } |
| 1139 | } |
| 1140 | else |
| 1141 | { |
Greg Clayton | b170aee | 2012-05-08 01:45:38 +0000 | [diff] [blame] | 1142 | m_host_arch.SetTriple (triple.c_str()); |
Greg Clayton | cb8977d | 2011-03-23 00:09:55 +0000 | [diff] [blame] | 1143 | if (pointer_byte_size) |
| 1144 | { |
| 1145 | assert (pointer_byte_size == m_host_arch.GetAddressByteSize()); |
| 1146 | } |
| 1147 | if (byte_order != eByteOrderInvalid) |
| 1148 | { |
| 1149 | assert (byte_order == m_host_arch.GetByteOrder()); |
| 1150 | } |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 1151 | } |
Greg Clayton | cb8977d | 2011-03-23 00:09:55 +0000 | [diff] [blame] | 1152 | } |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 1153 | } |
| 1154 | } |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 1155 | return m_qHostInfo_is_valid == eLazyBoolYes; |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 1156 | } |
| 1157 | |
| 1158 | int |
| 1159 | GDBRemoteCommunicationClient::SendAttach |
| 1160 | ( |
| 1161 | lldb::pid_t pid, |
| 1162 | StringExtractorGDBRemote& response |
| 1163 | ) |
| 1164 | { |
| 1165 | if (pid != LLDB_INVALID_PROCESS_ID) |
| 1166 | { |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 1167 | char packet[64]; |
Greg Clayton | d9919d3 | 2011-12-01 23:28:38 +0000 | [diff] [blame] | 1168 | const int packet_len = ::snprintf (packet, sizeof(packet), "vAttach;%llx", pid); |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 1169 | assert (packet_len < sizeof(packet)); |
| 1170 | if (SendPacketAndWaitForResponse (packet, packet_len, response, false)) |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 1171 | { |
| 1172 | if (response.IsErrorResponse()) |
| 1173 | return response.GetError(); |
| 1174 | return 0; |
| 1175 | } |
| 1176 | } |
| 1177 | return -1; |
| 1178 | } |
| 1179 | |
| 1180 | const lldb_private::ArchSpec & |
| 1181 | GDBRemoteCommunicationClient::GetHostArchitecture () |
| 1182 | { |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 1183 | if (m_qHostInfo_is_valid == eLazyBoolCalculate) |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 1184 | GetHostInfo (); |
Greg Clayton | cb8977d | 2011-03-23 00:09:55 +0000 | [diff] [blame] | 1185 | return m_host_arch; |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 1186 | } |
| 1187 | |
| 1188 | addr_t |
| 1189 | GDBRemoteCommunicationClient::AllocateMemory (size_t size, uint32_t permissions) |
| 1190 | { |
Greg Clayton | 2f085c6 | 2011-05-15 01:25:55 +0000 | [diff] [blame] | 1191 | if (m_supports_alloc_dealloc_memory != eLazyBoolNo) |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 1192 | { |
Greg Clayton | 2f085c6 | 2011-05-15 01:25:55 +0000 | [diff] [blame] | 1193 | m_supports_alloc_dealloc_memory = eLazyBoolYes; |
Greg Clayton | 989816b | 2011-05-14 01:50:35 +0000 | [diff] [blame] | 1194 | char packet[64]; |
| 1195 | const int packet_len = ::snprintf (packet, sizeof(packet), "_M%zx,%s%s%s", size, |
| 1196 | permissions & lldb::ePermissionsReadable ? "r" : "", |
| 1197 | permissions & lldb::ePermissionsWritable ? "w" : "", |
| 1198 | permissions & lldb::ePermissionsExecutable ? "x" : ""); |
| 1199 | assert (packet_len < sizeof(packet)); |
| 1200 | StringExtractorGDBRemote response; |
| 1201 | if (SendPacketAndWaitForResponse (packet, packet_len, response, false)) |
| 1202 | { |
Greg Clayton | 5b53e8e | 2011-05-15 23:46:54 +0000 | [diff] [blame] | 1203 | if (!response.IsErrorResponse()) |
Greg Clayton | 989816b | 2011-05-14 01:50:35 +0000 | [diff] [blame] | 1204 | return response.GetHexMaxU64(false, LLDB_INVALID_ADDRESS); |
| 1205 | } |
Greg Clayton | 5b53e8e | 2011-05-15 23:46:54 +0000 | [diff] [blame] | 1206 | else |
| 1207 | { |
| 1208 | m_supports_alloc_dealloc_memory = eLazyBoolNo; |
| 1209 | } |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 1210 | } |
| 1211 | return LLDB_INVALID_ADDRESS; |
| 1212 | } |
| 1213 | |
| 1214 | bool |
| 1215 | GDBRemoteCommunicationClient::DeallocateMemory (addr_t addr) |
| 1216 | { |
Greg Clayton | 2f085c6 | 2011-05-15 01:25:55 +0000 | [diff] [blame] | 1217 | if (m_supports_alloc_dealloc_memory != eLazyBoolNo) |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 1218 | { |
Greg Clayton | 2f085c6 | 2011-05-15 01:25:55 +0000 | [diff] [blame] | 1219 | m_supports_alloc_dealloc_memory = eLazyBoolYes; |
Greg Clayton | 989816b | 2011-05-14 01:50:35 +0000 | [diff] [blame] | 1220 | char packet[64]; |
| 1221 | const int packet_len = ::snprintf(packet, sizeof(packet), "_m%llx", (uint64_t)addr); |
| 1222 | assert (packet_len < sizeof(packet)); |
| 1223 | StringExtractorGDBRemote response; |
| 1224 | if (SendPacketAndWaitForResponse (packet, packet_len, response, false)) |
| 1225 | { |
| 1226 | if (response.IsOKResponse()) |
| 1227 | return true; |
Greg Clayton | 5b53e8e | 2011-05-15 23:46:54 +0000 | [diff] [blame] | 1228 | } |
| 1229 | else |
| 1230 | { |
| 1231 | m_supports_alloc_dealloc_memory = eLazyBoolNo; |
Greg Clayton | 989816b | 2011-05-14 01:50:35 +0000 | [diff] [blame] | 1232 | } |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 1233 | } |
| 1234 | return false; |
| 1235 | } |
| 1236 | |
Greg Clayton | 516f084 | 2012-04-11 00:24:49 +0000 | [diff] [blame] | 1237 | bool |
| 1238 | GDBRemoteCommunicationClient::Detach () |
| 1239 | { |
| 1240 | return SendPacket ("D", 1) > 0; |
| 1241 | } |
| 1242 | |
Greg Clayton | a938553 | 2011-11-18 07:03:08 +0000 | [diff] [blame] | 1243 | Error |
| 1244 | GDBRemoteCommunicationClient::GetMemoryRegionInfo (lldb::addr_t addr, |
| 1245 | lldb_private::MemoryRegionInfo ®ion_info) |
| 1246 | { |
| 1247 | Error error; |
| 1248 | region_info.Clear(); |
| 1249 | |
| 1250 | if (m_supports_memory_region_info != eLazyBoolNo) |
| 1251 | { |
| 1252 | m_supports_memory_region_info = eLazyBoolYes; |
| 1253 | char packet[64]; |
| 1254 | const int packet_len = ::snprintf(packet, sizeof(packet), "qMemoryRegionInfo:%llx", (uint64_t)addr); |
| 1255 | assert (packet_len < sizeof(packet)); |
| 1256 | StringExtractorGDBRemote response; |
| 1257 | if (SendPacketAndWaitForResponse (packet, packet_len, response, false)) |
| 1258 | { |
| 1259 | std::string name; |
| 1260 | std::string value; |
| 1261 | addr_t addr_value; |
| 1262 | bool success = true; |
Jason Molenda | 1f9c39c | 2011-12-13 05:39:38 +0000 | [diff] [blame] | 1263 | bool saw_permissions = false; |
Greg Clayton | a938553 | 2011-11-18 07:03:08 +0000 | [diff] [blame] | 1264 | while (success && response.GetNameColonValue(name, value)) |
| 1265 | { |
| 1266 | if (name.compare ("start") == 0) |
| 1267 | { |
| 1268 | addr_value = Args::StringToUInt64(value.c_str(), LLDB_INVALID_ADDRESS, 16, &success); |
| 1269 | if (success) |
| 1270 | region_info.GetRange().SetRangeBase(addr_value); |
| 1271 | } |
| 1272 | else if (name.compare ("size") == 0) |
| 1273 | { |
| 1274 | addr_value = Args::StringToUInt64(value.c_str(), 0, 16, &success); |
| 1275 | if (success) |
| 1276 | region_info.GetRange().SetByteSize (addr_value); |
| 1277 | } |
Jason Molenda | 1f9c39c | 2011-12-13 05:39:38 +0000 | [diff] [blame] | 1278 | else if (name.compare ("permissions") == 0 && region_info.GetRange().IsValid()) |
Greg Clayton | a938553 | 2011-11-18 07:03:08 +0000 | [diff] [blame] | 1279 | { |
Jason Molenda | 1f9c39c | 2011-12-13 05:39:38 +0000 | [diff] [blame] | 1280 | saw_permissions = true; |
| 1281 | if (region_info.GetRange().Contains (addr)) |
| 1282 | { |
| 1283 | if (value.find('r') != std::string::npos) |
| 1284 | region_info.SetReadable (MemoryRegionInfo::eYes); |
| 1285 | else |
| 1286 | region_info.SetReadable (MemoryRegionInfo::eNo); |
| 1287 | |
| 1288 | if (value.find('w') != std::string::npos) |
| 1289 | region_info.SetWritable (MemoryRegionInfo::eYes); |
| 1290 | else |
| 1291 | region_info.SetWritable (MemoryRegionInfo::eNo); |
| 1292 | |
| 1293 | if (value.find('x') != std::string::npos) |
| 1294 | region_info.SetExecutable (MemoryRegionInfo::eYes); |
| 1295 | else |
| 1296 | region_info.SetExecutable (MemoryRegionInfo::eNo); |
| 1297 | } |
| 1298 | else |
| 1299 | { |
| 1300 | // The reported region does not contain this address -- we're looking at an unmapped page |
| 1301 | region_info.SetReadable (MemoryRegionInfo::eNo); |
| 1302 | region_info.SetWritable (MemoryRegionInfo::eNo); |
| 1303 | region_info.SetExecutable (MemoryRegionInfo::eNo); |
| 1304 | } |
Greg Clayton | a938553 | 2011-11-18 07:03:08 +0000 | [diff] [blame] | 1305 | } |
| 1306 | else if (name.compare ("error") == 0) |
| 1307 | { |
| 1308 | StringExtractorGDBRemote name_extractor; |
| 1309 | // Swap "value" over into "name_extractor" |
| 1310 | name_extractor.GetStringRef().swap(value); |
| 1311 | // Now convert the HEX bytes into a string value |
| 1312 | name_extractor.GetHexByteString (value); |
| 1313 | error.SetErrorString(value.c_str()); |
| 1314 | } |
| 1315 | } |
Jason Molenda | 1f9c39c | 2011-12-13 05:39:38 +0000 | [diff] [blame] | 1316 | |
| 1317 | // We got a valid address range back but no permissions -- which means this is an unmapped page |
| 1318 | if (region_info.GetRange().IsValid() && saw_permissions == false) |
| 1319 | { |
| 1320 | region_info.SetReadable (MemoryRegionInfo::eNo); |
| 1321 | region_info.SetWritable (MemoryRegionInfo::eNo); |
| 1322 | region_info.SetExecutable (MemoryRegionInfo::eNo); |
| 1323 | } |
Greg Clayton | a938553 | 2011-11-18 07:03:08 +0000 | [diff] [blame] | 1324 | } |
| 1325 | else |
| 1326 | { |
| 1327 | m_supports_memory_region_info = eLazyBoolNo; |
| 1328 | } |
| 1329 | } |
| 1330 | |
| 1331 | if (m_supports_memory_region_info == eLazyBoolNo) |
| 1332 | { |
| 1333 | error.SetErrorString("qMemoryRegionInfo is not supported"); |
| 1334 | } |
| 1335 | if (error.Fail()) |
| 1336 | region_info.Clear(); |
| 1337 | return error; |
| 1338 | |
| 1339 | } |
| 1340 | |
Johnny Chen | 7cbdcfb | 2012-05-23 21:09:52 +0000 | [diff] [blame] | 1341 | Error |
| 1342 | GDBRemoteCommunicationClient::GetWatchpointSupportInfo (uint32_t &num) |
| 1343 | { |
| 1344 | Error error; |
| 1345 | |
| 1346 | if (m_supports_watchpoint_support_info == eLazyBoolYes) |
| 1347 | { |
| 1348 | num = m_num_supported_hardware_watchpoints; |
| 1349 | return error; |
| 1350 | } |
| 1351 | |
| 1352 | // Set num to 0 first. |
| 1353 | num = 0; |
| 1354 | if (m_supports_watchpoint_support_info != eLazyBoolNo) |
| 1355 | { |
| 1356 | char packet[64]; |
| 1357 | const int packet_len = ::snprintf(packet, sizeof(packet), "qWatchpointSupportInfo:"); |
| 1358 | assert (packet_len < sizeof(packet)); |
| 1359 | StringExtractorGDBRemote response; |
| 1360 | if (SendPacketAndWaitForResponse (packet, packet_len, response, false)) |
| 1361 | { |
| 1362 | m_supports_watchpoint_support_info = eLazyBoolYes; |
| 1363 | std::string name; |
| 1364 | std::string value; |
| 1365 | while (response.GetNameColonValue(name, value)) |
| 1366 | { |
| 1367 | if (name.compare ("num") == 0) |
| 1368 | { |
| 1369 | num = Args::StringToUInt32(value.c_str(), 0, 0); |
| 1370 | m_num_supported_hardware_watchpoints = num; |
| 1371 | } |
| 1372 | } |
| 1373 | } |
| 1374 | else |
| 1375 | { |
| 1376 | m_supports_watchpoint_support_info = eLazyBoolNo; |
| 1377 | } |
| 1378 | } |
| 1379 | |
| 1380 | if (m_supports_watchpoint_support_info == eLazyBoolNo) |
| 1381 | { |
| 1382 | error.SetErrorString("qWatchpointSupportInfo is not supported"); |
| 1383 | } |
| 1384 | return error; |
| 1385 | |
| 1386 | } |
Greg Clayton | a938553 | 2011-11-18 07:03:08 +0000 | [diff] [blame] | 1387 | |
Enrico Granata | 7de2a3b | 2012-07-13 23:18:48 +0000 | [diff] [blame] | 1388 | lldb_private::Error |
| 1389 | GDBRemoteCommunicationClient::GetWatchpointSupportInfo (uint32_t &num, bool& after) |
| 1390 | { |
| 1391 | Error error(GetWatchpointSupportInfo(num)); |
| 1392 | if (error.Success()) |
| 1393 | error = GetWatchpointsTriggerAfterInstruction(after); |
| 1394 | return error; |
| 1395 | } |
| 1396 | |
| 1397 | lldb_private::Error |
| 1398 | GDBRemoteCommunicationClient::GetWatchpointsTriggerAfterInstruction (bool &after) |
| 1399 | { |
| 1400 | Error error; |
| 1401 | |
| 1402 | // we assume watchpoints will happen after running the relevant opcode |
| 1403 | // and we only want to override this behavior if we have explicitly |
| 1404 | // received a qHostInfo telling us otherwise |
| 1405 | if (m_qHostInfo_is_valid != eLazyBoolYes) |
| 1406 | after = true; |
| 1407 | else |
| 1408 | after = (m_watchpoints_trigger_after_instruction != eLazyBoolNo); |
| 1409 | return error; |
| 1410 | } |
| 1411 | |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 1412 | int |
| 1413 | GDBRemoteCommunicationClient::SetSTDIN (char const *path) |
| 1414 | { |
| 1415 | if (path && path[0]) |
| 1416 | { |
| 1417 | StreamString packet; |
| 1418 | packet.PutCString("QSetSTDIN:"); |
| 1419 | packet.PutBytesAsRawHex8(path, strlen(path)); |
| 1420 | |
| 1421 | StringExtractorGDBRemote response; |
| 1422 | if (SendPacketAndWaitForResponse (packet.GetData(), packet.GetSize(), response, false)) |
| 1423 | { |
| 1424 | if (response.IsOKResponse()) |
| 1425 | return 0; |
| 1426 | uint8_t error = response.GetError(); |
| 1427 | if (error) |
| 1428 | return error; |
| 1429 | } |
| 1430 | } |
| 1431 | return -1; |
| 1432 | } |
| 1433 | |
| 1434 | int |
| 1435 | GDBRemoteCommunicationClient::SetSTDOUT (char const *path) |
| 1436 | { |
| 1437 | if (path && path[0]) |
| 1438 | { |
| 1439 | StreamString packet; |
| 1440 | packet.PutCString("QSetSTDOUT:"); |
| 1441 | packet.PutBytesAsRawHex8(path, strlen(path)); |
| 1442 | |
| 1443 | StringExtractorGDBRemote response; |
| 1444 | if (SendPacketAndWaitForResponse (packet.GetData(), packet.GetSize(), response, false)) |
| 1445 | { |
| 1446 | if (response.IsOKResponse()) |
| 1447 | return 0; |
| 1448 | uint8_t error = response.GetError(); |
| 1449 | if (error) |
| 1450 | return error; |
| 1451 | } |
| 1452 | } |
| 1453 | return -1; |
| 1454 | } |
| 1455 | |
| 1456 | int |
| 1457 | GDBRemoteCommunicationClient::SetSTDERR (char const *path) |
| 1458 | { |
| 1459 | if (path && path[0]) |
| 1460 | { |
| 1461 | StreamString packet; |
| 1462 | packet.PutCString("QSetSTDERR:"); |
| 1463 | packet.PutBytesAsRawHex8(path, strlen(path)); |
| 1464 | |
| 1465 | StringExtractorGDBRemote response; |
| 1466 | if (SendPacketAndWaitForResponse (packet.GetData(), packet.GetSize(), response, false)) |
| 1467 | { |
| 1468 | if (response.IsOKResponse()) |
| 1469 | return 0; |
| 1470 | uint8_t error = response.GetError(); |
| 1471 | if (error) |
| 1472 | return error; |
| 1473 | } |
| 1474 | } |
| 1475 | return -1; |
| 1476 | } |
| 1477 | |
| 1478 | int |
| 1479 | GDBRemoteCommunicationClient::SetWorkingDir (char const *path) |
| 1480 | { |
| 1481 | if (path && path[0]) |
| 1482 | { |
| 1483 | StreamString packet; |
| 1484 | packet.PutCString("QSetWorkingDir:"); |
| 1485 | packet.PutBytesAsRawHex8(path, strlen(path)); |
| 1486 | |
| 1487 | StringExtractorGDBRemote response; |
| 1488 | if (SendPacketAndWaitForResponse (packet.GetData(), packet.GetSize(), response, false)) |
| 1489 | { |
| 1490 | if (response.IsOKResponse()) |
| 1491 | return 0; |
| 1492 | uint8_t error = response.GetError(); |
| 1493 | if (error) |
| 1494 | return error; |
| 1495 | } |
| 1496 | } |
| 1497 | return -1; |
| 1498 | } |
| 1499 | |
| 1500 | int |
| 1501 | GDBRemoteCommunicationClient::SetDisableASLR (bool enable) |
| 1502 | { |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 1503 | char packet[32]; |
| 1504 | const int packet_len = ::snprintf (packet, sizeof (packet), "QSetDisableASLR:%i", enable ? 1 : 0); |
| 1505 | assert (packet_len < sizeof(packet)); |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 1506 | StringExtractorGDBRemote response; |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 1507 | if (SendPacketAndWaitForResponse (packet, packet_len, response, false)) |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 1508 | { |
| 1509 | if (response.IsOKResponse()) |
| 1510 | return 0; |
| 1511 | uint8_t error = response.GetError(); |
| 1512 | if (error) |
| 1513 | return error; |
| 1514 | } |
| 1515 | return -1; |
| 1516 | } |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 1517 | |
| 1518 | bool |
Greg Clayton | b72d0f0 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 1519 | GDBRemoteCommunicationClient::DecodeProcessInfoResponse (StringExtractorGDBRemote &response, ProcessInstanceInfo &process_info) |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 1520 | { |
| 1521 | if (response.IsNormalResponse()) |
| 1522 | { |
| 1523 | std::string name; |
| 1524 | std::string value; |
| 1525 | StringExtractor extractor; |
| 1526 | |
| 1527 | while (response.GetNameColonValue(name, value)) |
| 1528 | { |
| 1529 | if (name.compare("pid") == 0) |
| 1530 | { |
| 1531 | process_info.SetProcessID (Args::StringToUInt32 (value.c_str(), LLDB_INVALID_PROCESS_ID, 0)); |
| 1532 | } |
| 1533 | else if (name.compare("ppid") == 0) |
| 1534 | { |
| 1535 | process_info.SetParentProcessID (Args::StringToUInt32 (value.c_str(), LLDB_INVALID_PROCESS_ID, 0)); |
| 1536 | } |
| 1537 | else if (name.compare("uid") == 0) |
| 1538 | { |
Greg Clayton | b72d0f0 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 1539 | process_info.SetUserID (Args::StringToUInt32 (value.c_str(), UINT32_MAX, 0)); |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 1540 | } |
| 1541 | else if (name.compare("euid") == 0) |
| 1542 | { |
| 1543 | process_info.SetEffectiveUserID (Args::StringToUInt32 (value.c_str(), UINT32_MAX, 0)); |
| 1544 | } |
| 1545 | else if (name.compare("gid") == 0) |
| 1546 | { |
Greg Clayton | b72d0f0 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 1547 | process_info.SetGroupID (Args::StringToUInt32 (value.c_str(), UINT32_MAX, 0)); |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 1548 | } |
| 1549 | else if (name.compare("egid") == 0) |
| 1550 | { |
| 1551 | process_info.SetEffectiveGroupID (Args::StringToUInt32 (value.c_str(), UINT32_MAX, 0)); |
| 1552 | } |
| 1553 | else if (name.compare("triple") == 0) |
| 1554 | { |
| 1555 | // The triple comes as ASCII hex bytes since it contains '-' chars |
| 1556 | extractor.GetStringRef().swap(value); |
| 1557 | extractor.SetFilePos(0); |
| 1558 | extractor.GetHexByteString (value); |
Greg Clayton | b170aee | 2012-05-08 01:45:38 +0000 | [diff] [blame] | 1559 | process_info.GetArchitecture ().SetTriple (value.c_str()); |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 1560 | } |
| 1561 | else if (name.compare("name") == 0) |
| 1562 | { |
| 1563 | StringExtractor extractor; |
Filipe Cabecinhas | e61ec7f | 2012-05-07 09:30:51 +0000 | [diff] [blame] | 1564 | // The process name from ASCII hex bytes since we can't |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 1565 | // control the characters in a process name |
| 1566 | extractor.GetStringRef().swap(value); |
| 1567 | extractor.SetFilePos(0); |
| 1568 | extractor.GetHexByteString (value); |
Greg Clayton | 527154d | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 1569 | process_info.GetExecutableFile().SetFile (value.c_str(), false); |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 1570 | } |
| 1571 | } |
| 1572 | |
| 1573 | if (process_info.GetProcessID() != LLDB_INVALID_PROCESS_ID) |
| 1574 | return true; |
| 1575 | } |
| 1576 | return false; |
| 1577 | } |
| 1578 | |
| 1579 | bool |
Greg Clayton | b72d0f0 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 1580 | GDBRemoteCommunicationClient::GetProcessInfo (lldb::pid_t pid, ProcessInstanceInfo &process_info) |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 1581 | { |
| 1582 | process_info.Clear(); |
| 1583 | |
| 1584 | if (m_supports_qProcessInfoPID) |
| 1585 | { |
| 1586 | char packet[32]; |
Greg Clayton | d9919d3 | 2011-12-01 23:28:38 +0000 | [diff] [blame] | 1587 | const int packet_len = ::snprintf (packet, sizeof (packet), "qProcessInfoPID:%llu", pid); |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 1588 | assert (packet_len < sizeof(packet)); |
| 1589 | StringExtractorGDBRemote response; |
| 1590 | if (SendPacketAndWaitForResponse (packet, packet_len, response, false)) |
| 1591 | { |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 1592 | return DecodeProcessInfoResponse (response, process_info); |
| 1593 | } |
Greg Clayton | 5b53e8e | 2011-05-15 23:46:54 +0000 | [diff] [blame] | 1594 | else |
| 1595 | { |
| 1596 | m_supports_qProcessInfoPID = false; |
| 1597 | return false; |
| 1598 | } |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 1599 | } |
| 1600 | return false; |
| 1601 | } |
| 1602 | |
| 1603 | uint32_t |
Greg Clayton | b72d0f0 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 1604 | GDBRemoteCommunicationClient::FindProcesses (const ProcessInstanceInfoMatch &match_info, |
| 1605 | ProcessInstanceInfoList &process_infos) |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 1606 | { |
| 1607 | process_infos.Clear(); |
| 1608 | |
| 1609 | if (m_supports_qfProcessInfo) |
| 1610 | { |
| 1611 | StreamString packet; |
| 1612 | packet.PutCString ("qfProcessInfo"); |
| 1613 | if (!match_info.MatchAllProcesses()) |
| 1614 | { |
| 1615 | packet.PutChar (':'); |
| 1616 | const char *name = match_info.GetProcessInfo().GetName(); |
| 1617 | bool has_name_match = false; |
| 1618 | if (name && name[0]) |
| 1619 | { |
| 1620 | has_name_match = true; |
| 1621 | NameMatchType name_match_type = match_info.GetNameMatchType(); |
| 1622 | switch (name_match_type) |
| 1623 | { |
| 1624 | case eNameMatchIgnore: |
| 1625 | has_name_match = false; |
| 1626 | break; |
| 1627 | |
| 1628 | case eNameMatchEquals: |
| 1629 | packet.PutCString ("name_match:equals;"); |
| 1630 | break; |
| 1631 | |
| 1632 | case eNameMatchContains: |
| 1633 | packet.PutCString ("name_match:contains;"); |
| 1634 | break; |
| 1635 | |
| 1636 | case eNameMatchStartsWith: |
| 1637 | packet.PutCString ("name_match:starts_with;"); |
| 1638 | break; |
| 1639 | |
| 1640 | case eNameMatchEndsWith: |
| 1641 | packet.PutCString ("name_match:ends_with;"); |
| 1642 | break; |
| 1643 | |
| 1644 | case eNameMatchRegularExpression: |
| 1645 | packet.PutCString ("name_match:regex;"); |
| 1646 | break; |
| 1647 | } |
| 1648 | if (has_name_match) |
| 1649 | { |
| 1650 | packet.PutCString ("name:"); |
| 1651 | packet.PutBytesAsRawHex8(name, ::strlen(name)); |
| 1652 | packet.PutChar (';'); |
| 1653 | } |
| 1654 | } |
| 1655 | |
| 1656 | if (match_info.GetProcessInfo().ProcessIDIsValid()) |
Greg Clayton | d9919d3 | 2011-12-01 23:28:38 +0000 | [diff] [blame] | 1657 | packet.Printf("pid:%llu;",match_info.GetProcessInfo().GetProcessID()); |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 1658 | if (match_info.GetProcessInfo().ParentProcessIDIsValid()) |
Greg Clayton | d9919d3 | 2011-12-01 23:28:38 +0000 | [diff] [blame] | 1659 | packet.Printf("parent_pid:%llu;",match_info.GetProcessInfo().GetParentProcessID()); |
Greg Clayton | b72d0f0 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 1660 | if (match_info.GetProcessInfo().UserIDIsValid()) |
| 1661 | packet.Printf("uid:%u;",match_info.GetProcessInfo().GetUserID()); |
| 1662 | if (match_info.GetProcessInfo().GroupIDIsValid()) |
| 1663 | packet.Printf("gid:%u;",match_info.GetProcessInfo().GetGroupID()); |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 1664 | if (match_info.GetProcessInfo().EffectiveUserIDIsValid()) |
| 1665 | packet.Printf("euid:%u;",match_info.GetProcessInfo().GetEffectiveUserID()); |
| 1666 | if (match_info.GetProcessInfo().EffectiveGroupIDIsValid()) |
| 1667 | packet.Printf("egid:%u;",match_info.GetProcessInfo().GetEffectiveGroupID()); |
| 1668 | if (match_info.GetProcessInfo().EffectiveGroupIDIsValid()) |
| 1669 | packet.Printf("all_users:%u;",match_info.GetMatchAllUsers() ? 1 : 0); |
| 1670 | if (match_info.GetProcessInfo().GetArchitecture().IsValid()) |
| 1671 | { |
| 1672 | const ArchSpec &match_arch = match_info.GetProcessInfo().GetArchitecture(); |
| 1673 | const llvm::Triple &triple = match_arch.GetTriple(); |
| 1674 | packet.PutCString("triple:"); |
| 1675 | packet.PutCStringAsRawHex8(triple.getTriple().c_str()); |
| 1676 | packet.PutChar (';'); |
| 1677 | } |
| 1678 | } |
| 1679 | StringExtractorGDBRemote response; |
| 1680 | if (SendPacketAndWaitForResponse (packet.GetData(), packet.GetSize(), response, false)) |
| 1681 | { |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 1682 | do |
| 1683 | { |
Greg Clayton | b72d0f0 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 1684 | ProcessInstanceInfo process_info; |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 1685 | if (!DecodeProcessInfoResponse (response, process_info)) |
| 1686 | break; |
| 1687 | process_infos.Append(process_info); |
| 1688 | response.GetStringRef().clear(); |
| 1689 | response.SetFilePos(0); |
| 1690 | } while (SendPacketAndWaitForResponse ("qsProcessInfo", strlen ("qsProcessInfo"), response, false)); |
| 1691 | } |
Greg Clayton | 5b53e8e | 2011-05-15 23:46:54 +0000 | [diff] [blame] | 1692 | else |
| 1693 | { |
| 1694 | m_supports_qfProcessInfo = false; |
| 1695 | return 0; |
| 1696 | } |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 1697 | } |
| 1698 | return process_infos.GetSize(); |
| 1699 | |
| 1700 | } |
| 1701 | |
| 1702 | bool |
| 1703 | GDBRemoteCommunicationClient::GetUserName (uint32_t uid, std::string &name) |
| 1704 | { |
| 1705 | if (m_supports_qUserName) |
| 1706 | { |
| 1707 | char packet[32]; |
| 1708 | const int packet_len = ::snprintf (packet, sizeof (packet), "qUserName:%i", uid); |
| 1709 | assert (packet_len < sizeof(packet)); |
| 1710 | StringExtractorGDBRemote response; |
| 1711 | if (SendPacketAndWaitForResponse (packet, packet_len, response, false)) |
| 1712 | { |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 1713 | if (response.IsNormalResponse()) |
| 1714 | { |
| 1715 | // Make sure we parsed the right number of characters. The response is |
| 1716 | // the hex encoded user name and should make up the entire packet. |
| 1717 | // If there are any non-hex ASCII bytes, the length won't match below.. |
| 1718 | if (response.GetHexByteString (name) * 2 == response.GetStringRef().size()) |
| 1719 | return true; |
| 1720 | } |
| 1721 | } |
Greg Clayton | 5b53e8e | 2011-05-15 23:46:54 +0000 | [diff] [blame] | 1722 | else |
| 1723 | { |
| 1724 | m_supports_qUserName = false; |
| 1725 | return false; |
| 1726 | } |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 1727 | } |
| 1728 | return false; |
| 1729 | |
| 1730 | } |
| 1731 | |
| 1732 | bool |
| 1733 | GDBRemoteCommunicationClient::GetGroupName (uint32_t gid, std::string &name) |
| 1734 | { |
| 1735 | if (m_supports_qGroupName) |
| 1736 | { |
| 1737 | char packet[32]; |
| 1738 | const int packet_len = ::snprintf (packet, sizeof (packet), "qGroupName:%i", gid); |
| 1739 | assert (packet_len < sizeof(packet)); |
| 1740 | StringExtractorGDBRemote response; |
| 1741 | if (SendPacketAndWaitForResponse (packet, packet_len, response, false)) |
| 1742 | { |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 1743 | if (response.IsNormalResponse()) |
| 1744 | { |
| 1745 | // Make sure we parsed the right number of characters. The response is |
| 1746 | // the hex encoded group name and should make up the entire packet. |
| 1747 | // If there are any non-hex ASCII bytes, the length won't match below.. |
| 1748 | if (response.GetHexByteString (name) * 2 == response.GetStringRef().size()) |
| 1749 | return true; |
| 1750 | } |
| 1751 | } |
Greg Clayton | 5b53e8e | 2011-05-15 23:46:54 +0000 | [diff] [blame] | 1752 | else |
| 1753 | { |
| 1754 | m_supports_qGroupName = false; |
| 1755 | return false; |
| 1756 | } |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 1757 | } |
| 1758 | return false; |
Greg Clayton | 06d7cc8 | 2011-04-04 18:18:57 +0000 | [diff] [blame] | 1759 | } |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 1760 | |
Greg Clayton | 06d7cc8 | 2011-04-04 18:18:57 +0000 | [diff] [blame] | 1761 | void |
| 1762 | GDBRemoteCommunicationClient::TestPacketSpeed (const uint32_t num_packets) |
| 1763 | { |
| 1764 | uint32_t i; |
| 1765 | TimeValue start_time, end_time; |
| 1766 | uint64_t total_time_nsec; |
| 1767 | float packets_per_second; |
| 1768 | if (SendSpeedTestPacket (0, 0)) |
| 1769 | { |
| 1770 | for (uint32_t send_size = 0; send_size <= 1024; send_size *= 2) |
| 1771 | { |
| 1772 | for (uint32_t recv_size = 0; recv_size <= 1024; recv_size *= 2) |
| 1773 | { |
| 1774 | start_time = TimeValue::Now(); |
| 1775 | for (i=0; i<num_packets; ++i) |
| 1776 | { |
| 1777 | SendSpeedTestPacket (send_size, recv_size); |
| 1778 | } |
| 1779 | end_time = TimeValue::Now(); |
| 1780 | total_time_nsec = end_time.GetAsNanoSecondsSinceJan1_1970() - start_time.GetAsNanoSecondsSinceJan1_1970(); |
Peter Collingbourne | 20fe30c | 2011-06-18 23:52:14 +0000 | [diff] [blame] | 1781 | packets_per_second = (((float)num_packets)/(float)total_time_nsec) * (float)TimeValue::NanoSecPerSec; |
Greg Clayton | 153ccd7 | 2011-08-10 02:10:13 +0000 | [diff] [blame] | 1782 | printf ("%u qSpeedTest(send=%-5u, recv=%-5u) in %llu.%9.9llu sec for %f packets/sec.\n", |
Greg Clayton | 06d7cc8 | 2011-04-04 18:18:57 +0000 | [diff] [blame] | 1783 | num_packets, |
| 1784 | send_size, |
| 1785 | recv_size, |
Peter Collingbourne | 20fe30c | 2011-06-18 23:52:14 +0000 | [diff] [blame] | 1786 | total_time_nsec / TimeValue::NanoSecPerSec, |
| 1787 | total_time_nsec % TimeValue::NanoSecPerSec, |
Greg Clayton | 06d7cc8 | 2011-04-04 18:18:57 +0000 | [diff] [blame] | 1788 | packets_per_second); |
| 1789 | if (recv_size == 0) |
| 1790 | recv_size = 32; |
| 1791 | } |
| 1792 | if (send_size == 0) |
| 1793 | send_size = 32; |
| 1794 | } |
| 1795 | } |
| 1796 | else |
| 1797 | { |
| 1798 | start_time = TimeValue::Now(); |
| 1799 | for (i=0; i<num_packets; ++i) |
| 1800 | { |
| 1801 | GetCurrentProcessID (); |
| 1802 | } |
| 1803 | end_time = TimeValue::Now(); |
| 1804 | total_time_nsec = end_time.GetAsNanoSecondsSinceJan1_1970() - start_time.GetAsNanoSecondsSinceJan1_1970(); |
Peter Collingbourne | 20fe30c | 2011-06-18 23:52:14 +0000 | [diff] [blame] | 1805 | packets_per_second = (((float)num_packets)/(float)total_time_nsec) * (float)TimeValue::NanoSecPerSec; |
Greg Clayton | 153ccd7 | 2011-08-10 02:10:13 +0000 | [diff] [blame] | 1806 | printf ("%u 'qC' packets packets in 0x%llu%9.9llu sec for %f packets/sec.\n", |
Greg Clayton | 06d7cc8 | 2011-04-04 18:18:57 +0000 | [diff] [blame] | 1807 | num_packets, |
Peter Collingbourne | 20fe30c | 2011-06-18 23:52:14 +0000 | [diff] [blame] | 1808 | total_time_nsec / TimeValue::NanoSecPerSec, |
| 1809 | total_time_nsec % TimeValue::NanoSecPerSec, |
Greg Clayton | 06d7cc8 | 2011-04-04 18:18:57 +0000 | [diff] [blame] | 1810 | packets_per_second); |
| 1811 | } |
| 1812 | } |
| 1813 | |
| 1814 | bool |
| 1815 | GDBRemoteCommunicationClient::SendSpeedTestPacket (uint32_t send_size, uint32_t recv_size) |
| 1816 | { |
| 1817 | StreamString packet; |
| 1818 | packet.Printf ("qSpeedTest:response_size:%i;data:", recv_size); |
| 1819 | uint32_t bytes_left = send_size; |
| 1820 | while (bytes_left > 0) |
| 1821 | { |
| 1822 | if (bytes_left >= 26) |
| 1823 | { |
| 1824 | packet.PutCString("abcdefghijklmnopqrstuvwxyz"); |
| 1825 | bytes_left -= 26; |
| 1826 | } |
| 1827 | else |
| 1828 | { |
| 1829 | packet.Printf ("%*.*s;", bytes_left, bytes_left, "abcdefghijklmnopqrstuvwxyz"); |
| 1830 | bytes_left = 0; |
| 1831 | } |
| 1832 | } |
| 1833 | |
| 1834 | StringExtractorGDBRemote response; |
Greg Clayton | 5b53e8e | 2011-05-15 23:46:54 +0000 | [diff] [blame] | 1835 | return SendPacketAndWaitForResponse (packet.GetData(), packet.GetSize(), response, false) > 0; |
Greg Clayton | 06d7cc8 | 2011-04-04 18:18:57 +0000 | [diff] [blame] | 1836 | return false; |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 1837 | } |
Greg Clayton | b72d0f0 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 1838 | |
| 1839 | uint16_t |
| 1840 | GDBRemoteCommunicationClient::LaunchGDBserverAndGetPort () |
| 1841 | { |
| 1842 | StringExtractorGDBRemote response; |
| 1843 | if (SendPacketAndWaitForResponse("qLaunchGDBServer", strlen("qLaunchGDBServer"), response, false)) |
| 1844 | { |
| 1845 | std::string name; |
| 1846 | std::string value; |
| 1847 | uint16_t port = 0; |
Greg Clayton | 4a379b1 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 1848 | //lldb::pid_t pid = LLDB_INVALID_PROCESS_ID; |
Greg Clayton | b72d0f0 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 1849 | while (response.GetNameColonValue(name, value)) |
| 1850 | { |
| 1851 | if (name.size() == 4 && name.compare("port") == 0) |
| 1852 | port = Args::StringToUInt32(value.c_str(), 0, 0); |
Greg Clayton | 4a379b1 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 1853 | // if (name.size() == 3 && name.compare("pid") == 0) |
| 1854 | // pid = Args::StringToUInt32(value.c_str(), LLDB_INVALID_PROCESS_ID, 0); |
Greg Clayton | b72d0f0 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 1855 | } |
| 1856 | return port; |
| 1857 | } |
| 1858 | return 0; |
| 1859 | } |
| 1860 | |
| 1861 | bool |
| 1862 | GDBRemoteCommunicationClient::SetCurrentThread (int tid) |
| 1863 | { |
| 1864 | if (m_curr_tid == tid) |
| 1865 | return true; |
| 1866 | |
| 1867 | char packet[32]; |
| 1868 | int packet_len; |
| 1869 | if (tid <= 0) |
| 1870 | packet_len = ::snprintf (packet, sizeof(packet), "Hg%i", tid); |
| 1871 | else |
| 1872 | packet_len = ::snprintf (packet, sizeof(packet), "Hg%x", tid); |
| 1873 | assert (packet_len + 1 < sizeof(packet)); |
| 1874 | StringExtractorGDBRemote response; |
| 1875 | if (SendPacketAndWaitForResponse(packet, packet_len, response, false)) |
| 1876 | { |
| 1877 | if (response.IsOKResponse()) |
| 1878 | { |
| 1879 | m_curr_tid = tid; |
| 1880 | return true; |
| 1881 | } |
| 1882 | } |
| 1883 | return false; |
| 1884 | } |
| 1885 | |
| 1886 | bool |
| 1887 | GDBRemoteCommunicationClient::SetCurrentThreadForRun (int tid) |
| 1888 | { |
| 1889 | if (m_curr_tid_run == tid) |
| 1890 | return true; |
| 1891 | |
| 1892 | char packet[32]; |
| 1893 | int packet_len; |
| 1894 | if (tid <= 0) |
| 1895 | packet_len = ::snprintf (packet, sizeof(packet), "Hc%i", tid); |
| 1896 | else |
| 1897 | packet_len = ::snprintf (packet, sizeof(packet), "Hc%x", tid); |
| 1898 | |
| 1899 | assert (packet_len + 1 < sizeof(packet)); |
| 1900 | StringExtractorGDBRemote response; |
| 1901 | if (SendPacketAndWaitForResponse(packet, packet_len, response, false)) |
| 1902 | { |
| 1903 | if (response.IsOKResponse()) |
| 1904 | { |
| 1905 | m_curr_tid_run = tid; |
| 1906 | return true; |
| 1907 | } |
| 1908 | } |
| 1909 | return false; |
| 1910 | } |
| 1911 | |
| 1912 | bool |
| 1913 | GDBRemoteCommunicationClient::GetStopReply (StringExtractorGDBRemote &response) |
| 1914 | { |
| 1915 | if (SendPacketAndWaitForResponse("?", 1, response, false)) |
| 1916 | return response.IsNormalResponse(); |
| 1917 | return false; |
| 1918 | } |
| 1919 | |
| 1920 | bool |
| 1921 | GDBRemoteCommunicationClient::GetThreadStopInfo (uint32_t tid, StringExtractorGDBRemote &response) |
| 1922 | { |
| 1923 | if (m_supports_qThreadStopInfo) |
| 1924 | { |
| 1925 | char packet[256]; |
| 1926 | int packet_len = ::snprintf(packet, sizeof(packet), "qThreadStopInfo%x", tid); |
| 1927 | assert (packet_len < sizeof(packet)); |
| 1928 | if (SendPacketAndWaitForResponse(packet, packet_len, response, false)) |
| 1929 | { |
Greg Clayton | 5b53e8e | 2011-05-15 23:46:54 +0000 | [diff] [blame] | 1930 | if (response.IsNormalResponse()) |
Greg Clayton | b72d0f0 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 1931 | return true; |
| 1932 | else |
| 1933 | return false; |
| 1934 | } |
Greg Clayton | 5b53e8e | 2011-05-15 23:46:54 +0000 | [diff] [blame] | 1935 | else |
| 1936 | { |
| 1937 | m_supports_qThreadStopInfo = false; |
| 1938 | } |
Greg Clayton | b72d0f0 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 1939 | } |
Greg Clayton | 139da72 | 2011-05-20 03:15:54 +0000 | [diff] [blame] | 1940 | // if (SetCurrentThread (tid)) |
| 1941 | // return GetStopReply (response); |
Greg Clayton | b72d0f0 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 1942 | return false; |
| 1943 | } |
| 1944 | |
| 1945 | |
| 1946 | uint8_t |
| 1947 | GDBRemoteCommunicationClient::SendGDBStoppointTypePacket (GDBStoppointType type, bool insert, addr_t addr, uint32_t length) |
| 1948 | { |
| 1949 | switch (type) |
| 1950 | { |
| 1951 | case eBreakpointSoftware: if (!m_supports_z0) return UINT8_MAX; break; |
| 1952 | case eBreakpointHardware: if (!m_supports_z1) return UINT8_MAX; break; |
| 1953 | case eWatchpointWrite: if (!m_supports_z2) return UINT8_MAX; break; |
| 1954 | case eWatchpointRead: if (!m_supports_z3) return UINT8_MAX; break; |
| 1955 | case eWatchpointReadWrite: if (!m_supports_z4) return UINT8_MAX; break; |
| 1956 | default: return UINT8_MAX; |
| 1957 | } |
| 1958 | |
| 1959 | char packet[64]; |
| 1960 | const int packet_len = ::snprintf (packet, |
| 1961 | sizeof(packet), |
| 1962 | "%c%i,%llx,%x", |
| 1963 | insert ? 'Z' : 'z', |
| 1964 | type, |
| 1965 | addr, |
| 1966 | length); |
| 1967 | |
| 1968 | assert (packet_len + 1 < sizeof(packet)); |
| 1969 | StringExtractorGDBRemote response; |
| 1970 | if (SendPacketAndWaitForResponse(packet, packet_len, response, true)) |
| 1971 | { |
| 1972 | if (response.IsOKResponse()) |
| 1973 | return 0; |
Greg Clayton | b72d0f0 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 1974 | else if (response.IsErrorResponse()) |
| 1975 | return response.GetError(); |
| 1976 | } |
Greg Clayton | 5b53e8e | 2011-05-15 23:46:54 +0000 | [diff] [blame] | 1977 | else |
| 1978 | { |
| 1979 | switch (type) |
| 1980 | { |
| 1981 | case eBreakpointSoftware: m_supports_z0 = false; break; |
| 1982 | case eBreakpointHardware: m_supports_z1 = false; break; |
| 1983 | case eWatchpointWrite: m_supports_z2 = false; break; |
| 1984 | case eWatchpointRead: m_supports_z3 = false; break; |
| 1985 | case eWatchpointReadWrite: m_supports_z4 = false; break; |
| 1986 | default: break; |
| 1987 | } |
| 1988 | } |
| 1989 | |
Greg Clayton | b72d0f0 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 1990 | return UINT8_MAX; |
| 1991 | } |
Greg Clayton | 4a60f9e | 2011-05-20 23:38:13 +0000 | [diff] [blame] | 1992 | |
| 1993 | size_t |
| 1994 | GDBRemoteCommunicationClient::GetCurrentThreadIDs (std::vector<lldb::tid_t> &thread_ids, |
| 1995 | bool &sequence_mutex_unavailable) |
| 1996 | { |
| 1997 | Mutex::Locker locker; |
| 1998 | thread_ids.clear(); |
| 1999 | |
Jim Ingham | 088684d | 2012-06-08 22:50:40 +0000 | [diff] [blame] | 2000 | if (GetSequenceMutex (locker, "ProcessGDBRemote::UpdateThreadList() failed due to not getting the sequence mutex")) |
Greg Clayton | 4a60f9e | 2011-05-20 23:38:13 +0000 | [diff] [blame] | 2001 | { |
| 2002 | sequence_mutex_unavailable = false; |
| 2003 | StringExtractorGDBRemote response; |
| 2004 | |
Greg Clayton | 63afdb0 | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 2005 | for (SendPacketNoLock ("qfThreadInfo", strlen("qfThreadInfo")) && WaitForPacketWithTimeoutMicroSecondsNoLock (response, GetPacketTimeoutInMicroSeconds ()); |
Greg Clayton | 4a60f9e | 2011-05-20 23:38:13 +0000 | [diff] [blame] | 2006 | response.IsNormalResponse(); |
Greg Clayton | 63afdb0 | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 2007 | SendPacketNoLock ("qsThreadInfo", strlen("qsThreadInfo")) && WaitForPacketWithTimeoutMicroSecondsNoLock (response, GetPacketTimeoutInMicroSeconds ())) |
Greg Clayton | 4a60f9e | 2011-05-20 23:38:13 +0000 | [diff] [blame] | 2008 | { |
| 2009 | char ch = response.GetChar(); |
| 2010 | if (ch == 'l') |
| 2011 | break; |
| 2012 | if (ch == 'm') |
| 2013 | { |
| 2014 | do |
| 2015 | { |
| 2016 | tid_t tid = response.GetHexMaxU32(false, LLDB_INVALID_THREAD_ID); |
| 2017 | |
| 2018 | if (tid != LLDB_INVALID_THREAD_ID) |
| 2019 | { |
| 2020 | thread_ids.push_back (tid); |
| 2021 | } |
| 2022 | ch = response.GetChar(); // Skip the command separator |
| 2023 | } while (ch == ','); // Make sure we got a comma separator |
| 2024 | } |
| 2025 | } |
| 2026 | } |
| 2027 | else |
| 2028 | { |
Jim Ingham | 088684d | 2012-06-08 22:50:40 +0000 | [diff] [blame] | 2029 | #if defined (LLDB_CONFIGURATION_DEBUG) |
| 2030 | // assert(!"ProcessGDBRemote::UpdateThreadList() failed due to not getting the sequence mutex"); |
| 2031 | #else |
Greg Clayton | c8dd570 | 2012-04-12 19:04:34 +0000 | [diff] [blame] | 2032 | LogSP log (ProcessGDBRemoteLog::GetLogIfAnyCategoryIsSet (GDBR_LOG_PROCESS | GDBR_LOG_PACKETS)); |
| 2033 | if (log) |
| 2034 | log->Printf("error: failed to get packet sequence mutex, not sending packet 'qfThreadInfo'"); |
Jim Ingham | 088684d | 2012-06-08 22:50:40 +0000 | [diff] [blame] | 2035 | #endif |
Greg Clayton | 4a60f9e | 2011-05-20 23:38:13 +0000 | [diff] [blame] | 2036 | sequence_mutex_unavailable = true; |
| 2037 | } |
| 2038 | return thread_ids.size(); |
| 2039 | } |
Greg Clayton | 516f084 | 2012-04-11 00:24:49 +0000 | [diff] [blame] | 2040 | |
| 2041 | lldb::addr_t |
| 2042 | GDBRemoteCommunicationClient::GetShlibInfoAddr() |
| 2043 | { |
| 2044 | if (!IsRunning()) |
| 2045 | { |
| 2046 | StringExtractorGDBRemote response; |
| 2047 | if (SendPacketAndWaitForResponse("qShlibInfoAddr", ::strlen ("qShlibInfoAddr"), response, false)) |
| 2048 | { |
| 2049 | if (response.IsNormalResponse()) |
| 2050 | return response.GetHexMaxU64(false, LLDB_INVALID_ADDRESS); |
| 2051 | } |
| 2052 | } |
| 2053 | return LLDB_INVALID_ADDRESS; |
| 2054 | } |
| 2055 | |