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