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 |
Daniel Malea | b89d049 | 2013-08-28 16:06:16 +0000 | [diff] [blame] | 14 | #include <sys/stat.h> |
| 15 | |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 16 | // C++ Includes |
Han Ming Ong | 4b6459f | 2013-01-18 23:11:53 +0000 | [diff] [blame] | 17 | #include <sstream> |
| 18 | |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 19 | // Other libraries and framework includes |
Saleem Abdulrasool | 2860695 | 2014-06-27 05:17:41 +0000 | [diff] [blame] | 20 | #include "llvm/ADT/STLExtras.h" |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 21 | #include "llvm/ADT/Triple.h" |
| 22 | #include "lldb/Interpreter/Args.h" |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 23 | #include "lldb/Core/Log.h" |
| 24 | #include "lldb/Core/State.h" |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 25 | #include "lldb/Core/StreamGDBRemote.h" |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 26 | #include "lldb/Core/StreamString.h" |
Zachary Turner | 93a66fc | 2014-10-06 21:22:36 +0000 | [diff] [blame] | 27 | #include "lldb/Host/ConnectionFileDescriptor.h" |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 28 | #include "lldb/Host/Endian.h" |
| 29 | #include "lldb/Host/Host.h" |
Zachary Turner | 97a14e6 | 2014-08-19 17:18:29 +0000 | [diff] [blame] | 30 | #include "lldb/Host/HostInfo.h" |
Vince Harron | 5275aaa | 2015-01-15 20:08:35 +0000 | [diff] [blame] | 31 | #include "lldb/Host/StringConvert.h" |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 32 | #include "lldb/Host/TimeValue.h" |
Jason Molenda | a332978 | 2014-03-29 18:54:20 +0000 | [diff] [blame] | 33 | #include "lldb/Target/Target.h" |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 34 | |
| 35 | // Project includes |
| 36 | #include "Utility/StringExtractorGDBRemote.h" |
| 37 | #include "ProcessGDBRemote.h" |
| 38 | #include "ProcessGDBRemoteLog.h" |
Virgile Bello | b2f1fb2 | 2013-08-23 12:44:05 +0000 | [diff] [blame] | 39 | #include "lldb/Host/Config.h" |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 40 | |
| 41 | using namespace lldb; |
| 42 | using namespace lldb_private; |
| 43 | |
Todd Fiala | 0a70a84 | 2014-05-28 16:43:26 +0000 | [diff] [blame] | 44 | #if defined(LLDB_DISABLE_POSIX) && !defined(SIGSTOP) |
Virgile Bello | b2f1fb2 | 2013-08-23 12:44:05 +0000 | [diff] [blame] | 45 | #define SIGSTOP 17 |
| 46 | #endif |
| 47 | |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 48 | //---------------------------------------------------------------------- |
| 49 | // GDBRemoteCommunicationClient constructor |
| 50 | //---------------------------------------------------------------------- |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 51 | GDBRemoteCommunicationClient::GDBRemoteCommunicationClient(bool is_platform) : |
| 52 | GDBRemoteCommunication("gdb-remote.client", "gdb-remote.client.rx_packet", is_platform), |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 53 | m_supports_not_sending_acks (eLazyBoolCalculate), |
| 54 | m_supports_thread_suffix (eLazyBoolCalculate), |
Greg Clayton | 4463399 | 2012-04-10 03:22:03 +0000 | [diff] [blame] | 55 | m_supports_threads_in_stop_reply (eLazyBoolCalculate), |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 56 | m_supports_vCont_all (eLazyBoolCalculate), |
| 57 | m_supports_vCont_any (eLazyBoolCalculate), |
| 58 | m_supports_vCont_c (eLazyBoolCalculate), |
| 59 | m_supports_vCont_C (eLazyBoolCalculate), |
| 60 | m_supports_vCont_s (eLazyBoolCalculate), |
| 61 | m_supports_vCont_S (eLazyBoolCalculate), |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 62 | m_qHostInfo_is_valid (eLazyBoolCalculate), |
Todd Fiala | 9f72b3a | 2014-05-07 19:28:21 +0000 | [diff] [blame] | 63 | m_curr_pid_is_valid (eLazyBoolCalculate), |
Jason Molenda | f17b5ac | 2012-12-19 02:54:03 +0000 | [diff] [blame] | 64 | m_qProcessInfo_is_valid (eLazyBoolCalculate), |
Jason Molenda | a332978 | 2014-03-29 18:54:20 +0000 | [diff] [blame] | 65 | m_qGDBServerVersion_is_valid (eLazyBoolCalculate), |
Greg Clayton | 70b5765 | 2011-05-15 01:25:55 +0000 | [diff] [blame] | 66 | m_supports_alloc_dealloc_memory (eLazyBoolCalculate), |
Greg Clayton | 46fb558 | 2011-11-18 07:03:08 +0000 | [diff] [blame] | 67 | m_supports_memory_region_info (eLazyBoolCalculate), |
Johnny Chen | 6463720 | 2012-05-23 21:09:52 +0000 | [diff] [blame] | 68 | m_supports_watchpoint_support_info (eLazyBoolCalculate), |
Jim Ingham | acff895 | 2013-05-02 00:27:30 +0000 | [diff] [blame] | 69 | m_supports_detach_stay_stopped (eLazyBoolCalculate), |
Enrico Granata | f04a219 | 2012-07-13 23:18:48 +0000 | [diff] [blame] | 70 | m_watchpoints_trigger_after_instruction(eLazyBoolCalculate), |
Jim Ingham | cd16df9 | 2012-07-20 21:37:13 +0000 | [diff] [blame] | 71 | m_attach_or_wait_reply(eLazyBoolCalculate), |
Jim Ingham | 279ceec | 2012-07-25 21:12:43 +0000 | [diff] [blame] | 72 | m_prepare_for_reg_writing_reply (eLazyBoolCalculate), |
Eric Christopher | 2490f5c | 2013-08-30 17:50:57 +0000 | [diff] [blame] | 73 | m_supports_p (eLazyBoolCalculate), |
Jason Molenda | bdc4f12 | 2014-05-06 02:59:39 +0000 | [diff] [blame] | 74 | m_supports_x (eLazyBoolCalculate), |
Jason Molenda | a332978 | 2014-03-29 18:54:20 +0000 | [diff] [blame] | 75 | m_avoid_g_packets (eLazyBoolCalculate), |
Greg Clayton | f74cf86 | 2013-11-13 23:28:31 +0000 | [diff] [blame] | 76 | m_supports_QSaveRegisterState (eLazyBoolCalculate), |
Steve Pucci | 03904ac | 2014-03-04 23:18:46 +0000 | [diff] [blame] | 77 | m_supports_qXfer_auxv_read (eLazyBoolCalculate), |
Steve Pucci | 5ae54ae | 2014-01-25 05:46:51 +0000 | [diff] [blame] | 78 | m_supports_qXfer_libraries_read (eLazyBoolCalculate), |
| 79 | m_supports_qXfer_libraries_svr4_read (eLazyBoolCalculate), |
| 80 | m_supports_augmented_libraries_svr4_read (eLazyBoolCalculate), |
Jason Molenda | 705b180 | 2014-06-13 02:37:02 +0000 | [diff] [blame] | 81 | m_supports_jThreadExtendedInfo (eLazyBoolCalculate), |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 82 | m_supports_qProcessInfoPID (true), |
| 83 | m_supports_qfProcessInfo (true), |
| 84 | m_supports_qUserName (true), |
| 85 | m_supports_qGroupName (true), |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 86 | m_supports_qThreadStopInfo (true), |
| 87 | m_supports_z0 (true), |
| 88 | m_supports_z1 (true), |
| 89 | m_supports_z2 (true), |
| 90 | m_supports_z3 (true), |
| 91 | m_supports_z4 (true), |
Greg Clayton | 8960058 | 2013-10-10 17:53:50 +0000 | [diff] [blame] | 92 | m_supports_QEnvironment (true), |
| 93 | m_supports_QEnvironmentHexEncoded (true), |
Todd Fiala | 9f72b3a | 2014-05-07 19:28:21 +0000 | [diff] [blame] | 94 | m_curr_pid (LLDB_INVALID_PROCESS_ID), |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 95 | m_curr_tid (LLDB_INVALID_THREAD_ID), |
| 96 | m_curr_tid_run (LLDB_INVALID_THREAD_ID), |
Johnny Chen | 6463720 | 2012-05-23 21:09:52 +0000 | [diff] [blame] | 97 | m_num_supported_hardware_watchpoints (0), |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 98 | m_async_mutex (Mutex::eMutexTypeRecursive), |
| 99 | m_async_packet_predicate (false), |
| 100 | m_async_packet (), |
Jim Ingham | a6195b7 | 2013-12-18 01:24:33 +0000 | [diff] [blame] | 101 | m_async_result (PacketResult::Success), |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 102 | m_async_response (), |
| 103 | m_async_signal (-1), |
Jim Ingham | b8cd575 | 2014-04-16 02:24:17 +0000 | [diff] [blame] | 104 | m_interrupt_sent (false), |
Han Ming Ong | 4b6459f | 2013-01-18 23:11:53 +0000 | [diff] [blame] | 105 | m_thread_id_to_used_usec_map (), |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 106 | m_host_arch(), |
Jason Molenda | f17b5ac | 2012-12-19 02:54:03 +0000 | [diff] [blame] | 107 | m_process_arch(), |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 108 | m_os_version_major (UINT32_MAX), |
| 109 | m_os_version_minor (UINT32_MAX), |
Greg Clayton | 9ac6d2d | 2013-10-25 18:13:17 +0000 | [diff] [blame] | 110 | m_os_version_update (UINT32_MAX), |
| 111 | m_os_build (), |
| 112 | m_os_kernel (), |
| 113 | m_hostname (), |
Jason Molenda | a332978 | 2014-03-29 18:54:20 +0000 | [diff] [blame] | 114 | m_gdb_server_name(), |
| 115 | m_gdb_server_version(UINT32_MAX), |
Steve Pucci | 5ae54ae | 2014-01-25 05:46:51 +0000 | [diff] [blame] | 116 | m_default_packet_timeout (0), |
| 117 | m_max_packet_size (0) |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 118 | { |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | //---------------------------------------------------------------------- |
| 122 | // Destructor |
| 123 | //---------------------------------------------------------------------- |
| 124 | GDBRemoteCommunicationClient::~GDBRemoteCommunicationClient() |
| 125 | { |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 126 | if (IsConnected()) |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 127 | Disconnect(); |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | bool |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 131 | GDBRemoteCommunicationClient::HandshakeWithServer (Error *error_ptr) |
| 132 | { |
Greg Clayton | fb90931 | 2013-11-23 01:58:15 +0000 | [diff] [blame] | 133 | ResetDiscoverableSettings(); |
| 134 | |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 135 | // Start the read thread after we send the handshake ack since if we |
| 136 | // fail to send the handshake ack, there is no reason to continue... |
| 137 | if (SendAck()) |
Greg Clayton | fb90931 | 2013-11-23 01:58:15 +0000 | [diff] [blame] | 138 | { |
Ed Maste | 48f986f | 2013-12-18 15:31:45 +0000 | [diff] [blame] | 139 | // Wait for any responses that might have been queued up in the remote |
| 140 | // GDB server and flush them all |
| 141 | StringExtractorGDBRemote response; |
| 142 | PacketResult packet_result = PacketResult::Success; |
| 143 | const uint32_t timeout_usec = 10 * 1000; // Wait for 10 ms for a response |
| 144 | while (packet_result == PacketResult::Success) |
| 145 | packet_result = WaitForPacketWithTimeoutMicroSecondsNoLock (response, timeout_usec); |
| 146 | |
Greg Clayton | fb90931 | 2013-11-23 01:58:15 +0000 | [diff] [blame] | 147 | // The return value from QueryNoAckModeSupported() is true if the packet |
| 148 | // was sent and _any_ response (including UNIMPLEMENTED) was received), |
| 149 | // or false if no response was received. This quickly tells us if we have |
| 150 | // a live connection to a remote GDB server... |
| 151 | if (QueryNoAckModeSupported()) |
| 152 | { |
Greg Clayton | 700e508 | 2014-02-21 19:11:28 +0000 | [diff] [blame] | 153 | #if 0 |
| 154 | // Set above line to "#if 1" to test packet speed if remote GDB server |
| 155 | // supports the qSpeedTest packet... |
| 156 | TestPacketSpeed(10000); |
| 157 | #endif |
Greg Clayton | fb90931 | 2013-11-23 01:58:15 +0000 | [diff] [blame] | 158 | return true; |
| 159 | } |
| 160 | else |
| 161 | { |
| 162 | if (error_ptr) |
| 163 | error_ptr->SetErrorString("failed to get reply to handshake packet"); |
| 164 | } |
| 165 | } |
| 166 | else |
| 167 | { |
| 168 | if (error_ptr) |
| 169 | error_ptr->SetErrorString("failed to send the handshake ack"); |
| 170 | } |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 171 | return false; |
| 172 | } |
| 173 | |
Greg Clayton | fb90931 | 2013-11-23 01:58:15 +0000 | [diff] [blame] | 174 | bool |
Steve Pucci | 5ae54ae | 2014-01-25 05:46:51 +0000 | [diff] [blame] | 175 | GDBRemoteCommunicationClient::GetAugmentedLibrariesSVR4ReadSupported () |
| 176 | { |
| 177 | if (m_supports_augmented_libraries_svr4_read == eLazyBoolCalculate) |
| 178 | { |
| 179 | GetRemoteQSupported(); |
| 180 | } |
| 181 | return (m_supports_augmented_libraries_svr4_read == eLazyBoolYes); |
| 182 | } |
| 183 | |
| 184 | bool |
| 185 | GDBRemoteCommunicationClient::GetQXferLibrariesSVR4ReadSupported () |
| 186 | { |
| 187 | if (m_supports_qXfer_libraries_svr4_read == eLazyBoolCalculate) |
| 188 | { |
| 189 | GetRemoteQSupported(); |
| 190 | } |
| 191 | return (m_supports_qXfer_libraries_svr4_read == eLazyBoolYes); |
| 192 | } |
| 193 | |
| 194 | bool |
| 195 | GDBRemoteCommunicationClient::GetQXferLibrariesReadSupported () |
| 196 | { |
| 197 | if (m_supports_qXfer_libraries_read == eLazyBoolCalculate) |
| 198 | { |
| 199 | GetRemoteQSupported(); |
| 200 | } |
| 201 | return (m_supports_qXfer_libraries_read == eLazyBoolYes); |
| 202 | } |
| 203 | |
Steve Pucci | 03904ac | 2014-03-04 23:18:46 +0000 | [diff] [blame] | 204 | bool |
| 205 | GDBRemoteCommunicationClient::GetQXferAuxvReadSupported () |
| 206 | { |
| 207 | if (m_supports_qXfer_auxv_read == eLazyBoolCalculate) |
| 208 | { |
| 209 | GetRemoteQSupported(); |
| 210 | } |
| 211 | return (m_supports_qXfer_auxv_read == eLazyBoolYes); |
| 212 | } |
| 213 | |
Steve Pucci | 5ae54ae | 2014-01-25 05:46:51 +0000 | [diff] [blame] | 214 | uint64_t |
| 215 | GDBRemoteCommunicationClient::GetRemoteMaxPacketSize() |
| 216 | { |
| 217 | if (m_max_packet_size == 0) |
| 218 | { |
| 219 | GetRemoteQSupported(); |
| 220 | } |
| 221 | return m_max_packet_size; |
| 222 | } |
| 223 | |
| 224 | bool |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 225 | GDBRemoteCommunicationClient::QueryNoAckModeSupported () |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 226 | { |
| 227 | if (m_supports_not_sending_acks == eLazyBoolCalculate) |
| 228 | { |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 229 | m_send_acks = true; |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 230 | m_supports_not_sending_acks = eLazyBoolNo; |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 231 | |
Jason Molenda | 36a216e | 2014-07-24 01:36:24 +0000 | [diff] [blame] | 232 | // This is the first real packet that we'll send in a debug session and it may take a little |
| 233 | // longer than normal to receive a reply. Wait at least 6 seconds for a reply to this packet. |
| 234 | |
| 235 | const uint32_t minimum_timeout = 6; |
| 236 | uint32_t old_timeout = GetPacketTimeoutInMicroSeconds() / lldb_private::TimeValue::MicroSecPerSec; |
| 237 | SetPacketTimeout (std::max (old_timeout, minimum_timeout)); |
| 238 | |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 239 | StringExtractorGDBRemote response; |
Jason Molenda | 36a216e | 2014-07-24 01:36:24 +0000 | [diff] [blame] | 240 | PacketResult packet_send_result = SendPacketAndWaitForResponse("QStartNoAckMode", response, false); |
| 241 | SetPacketTimeout (old_timeout); |
| 242 | |
| 243 | if (packet_send_result == PacketResult::Success) |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 244 | { |
| 245 | if (response.IsOKResponse()) |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 246 | { |
| 247 | m_send_acks = false; |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 248 | m_supports_not_sending_acks = eLazyBoolYes; |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 249 | } |
Greg Clayton | fb90931 | 2013-11-23 01:58:15 +0000 | [diff] [blame] | 250 | return true; |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 251 | } |
| 252 | } |
Greg Clayton | fb90931 | 2013-11-23 01:58:15 +0000 | [diff] [blame] | 253 | return false; |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | void |
Greg Clayton | 4463399 | 2012-04-10 03:22:03 +0000 | [diff] [blame] | 257 | GDBRemoteCommunicationClient::GetListThreadsInStopReplySupported () |
| 258 | { |
| 259 | if (m_supports_threads_in_stop_reply == eLazyBoolCalculate) |
| 260 | { |
| 261 | m_supports_threads_in_stop_reply = eLazyBoolNo; |
| 262 | |
| 263 | StringExtractorGDBRemote response; |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 264 | if (SendPacketAndWaitForResponse("QListThreadsInStopReply", response, false) == PacketResult::Success) |
Greg Clayton | 4463399 | 2012-04-10 03:22:03 +0000 | [diff] [blame] | 265 | { |
| 266 | if (response.IsOKResponse()) |
| 267 | m_supports_threads_in_stop_reply = eLazyBoolYes; |
| 268 | } |
| 269 | } |
| 270 | } |
| 271 | |
Jim Ingham | cd16df9 | 2012-07-20 21:37:13 +0000 | [diff] [blame] | 272 | bool |
| 273 | GDBRemoteCommunicationClient::GetVAttachOrWaitSupported () |
| 274 | { |
| 275 | if (m_attach_or_wait_reply == eLazyBoolCalculate) |
| 276 | { |
| 277 | m_attach_or_wait_reply = eLazyBoolNo; |
| 278 | |
| 279 | StringExtractorGDBRemote response; |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 280 | if (SendPacketAndWaitForResponse("qVAttachOrWaitSupported", response, false) == PacketResult::Success) |
Jim Ingham | cd16df9 | 2012-07-20 21:37:13 +0000 | [diff] [blame] | 281 | { |
| 282 | if (response.IsOKResponse()) |
| 283 | m_attach_or_wait_reply = eLazyBoolYes; |
| 284 | } |
| 285 | } |
| 286 | if (m_attach_or_wait_reply == eLazyBoolYes) |
| 287 | return true; |
| 288 | else |
| 289 | return false; |
| 290 | } |
| 291 | |
Jim Ingham | 279ceec | 2012-07-25 21:12:43 +0000 | [diff] [blame] | 292 | bool |
| 293 | GDBRemoteCommunicationClient::GetSyncThreadStateSupported () |
| 294 | { |
| 295 | if (m_prepare_for_reg_writing_reply == eLazyBoolCalculate) |
| 296 | { |
| 297 | m_prepare_for_reg_writing_reply = eLazyBoolNo; |
| 298 | |
| 299 | StringExtractorGDBRemote response; |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 300 | if (SendPacketAndWaitForResponse("qSyncThreadStateSupported", response, false) == PacketResult::Success) |
Jim Ingham | 279ceec | 2012-07-25 21:12:43 +0000 | [diff] [blame] | 301 | { |
| 302 | if (response.IsOKResponse()) |
| 303 | m_prepare_for_reg_writing_reply = eLazyBoolYes; |
| 304 | } |
| 305 | } |
| 306 | if (m_prepare_for_reg_writing_reply == eLazyBoolYes) |
| 307 | return true; |
| 308 | else |
| 309 | return false; |
| 310 | } |
| 311 | |
Greg Clayton | 4463399 | 2012-04-10 03:22:03 +0000 | [diff] [blame] | 312 | |
| 313 | void |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 314 | GDBRemoteCommunicationClient::ResetDiscoverableSettings() |
| 315 | { |
| 316 | m_supports_not_sending_acks = eLazyBoolCalculate; |
| 317 | m_supports_thread_suffix = eLazyBoolCalculate; |
Greg Clayton | 4463399 | 2012-04-10 03:22:03 +0000 | [diff] [blame] | 318 | m_supports_threads_in_stop_reply = eLazyBoolCalculate; |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 319 | m_supports_vCont_c = eLazyBoolCalculate; |
| 320 | m_supports_vCont_C = eLazyBoolCalculate; |
| 321 | m_supports_vCont_s = eLazyBoolCalculate; |
| 322 | m_supports_vCont_S = eLazyBoolCalculate; |
Hafiz Abid Qadeer | 9a78cdf | 2013-08-29 09:09:45 +0000 | [diff] [blame] | 323 | m_supports_p = eLazyBoolCalculate; |
Jason Molenda | bdc4f12 | 2014-05-06 02:59:39 +0000 | [diff] [blame] | 324 | m_supports_x = eLazyBoolCalculate; |
Greg Clayton | f74cf86 | 2013-11-13 23:28:31 +0000 | [diff] [blame] | 325 | m_supports_QSaveRegisterState = eLazyBoolCalculate; |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 326 | m_qHostInfo_is_valid = eLazyBoolCalculate; |
Todd Fiala | 9f72b3a | 2014-05-07 19:28:21 +0000 | [diff] [blame] | 327 | m_curr_pid_is_valid = eLazyBoolCalculate; |
Jason Molenda | f17b5ac | 2012-12-19 02:54:03 +0000 | [diff] [blame] | 328 | m_qProcessInfo_is_valid = eLazyBoolCalculate; |
Jason Molenda | a332978 | 2014-03-29 18:54:20 +0000 | [diff] [blame] | 329 | m_qGDBServerVersion_is_valid = eLazyBoolCalculate; |
Greg Clayton | 70b5765 | 2011-05-15 01:25:55 +0000 | [diff] [blame] | 330 | m_supports_alloc_dealloc_memory = eLazyBoolCalculate; |
Greg Clayton | 46fb558 | 2011-11-18 07:03:08 +0000 | [diff] [blame] | 331 | m_supports_memory_region_info = eLazyBoolCalculate; |
Jim Ingham | 279ceec | 2012-07-25 21:12:43 +0000 | [diff] [blame] | 332 | m_prepare_for_reg_writing_reply = eLazyBoolCalculate; |
| 333 | m_attach_or_wait_reply = eLazyBoolCalculate; |
Jason Molenda | a332978 | 2014-03-29 18:54:20 +0000 | [diff] [blame] | 334 | m_avoid_g_packets = eLazyBoolCalculate; |
Steve Pucci | 03904ac | 2014-03-04 23:18:46 +0000 | [diff] [blame] | 335 | m_supports_qXfer_auxv_read = eLazyBoolCalculate; |
Steve Pucci | 5ae54ae | 2014-01-25 05:46:51 +0000 | [diff] [blame] | 336 | m_supports_qXfer_libraries_read = eLazyBoolCalculate; |
| 337 | m_supports_qXfer_libraries_svr4_read = eLazyBoolCalculate; |
| 338 | m_supports_augmented_libraries_svr4_read = eLazyBoolCalculate; |
Greg Clayton | 2a48f52 | 2011-05-14 01:50:35 +0000 | [diff] [blame] | 339 | |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 340 | m_supports_qProcessInfoPID = true; |
| 341 | m_supports_qfProcessInfo = true; |
| 342 | m_supports_qUserName = true; |
| 343 | m_supports_qGroupName = true; |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 344 | m_supports_qThreadStopInfo = true; |
| 345 | m_supports_z0 = true; |
| 346 | m_supports_z1 = true; |
| 347 | m_supports_z2 = true; |
| 348 | m_supports_z3 = true; |
| 349 | m_supports_z4 = true; |
Greg Clayton | 8960058 | 2013-10-10 17:53:50 +0000 | [diff] [blame] | 350 | m_supports_QEnvironment = true; |
| 351 | m_supports_QEnvironmentHexEncoded = true; |
Jason Molenda | a332978 | 2014-03-29 18:54:20 +0000 | [diff] [blame] | 352 | |
Greg Clayton | d314e81 | 2011-03-23 00:09:55 +0000 | [diff] [blame] | 353 | m_host_arch.Clear(); |
Jason Molenda | f17b5ac | 2012-12-19 02:54:03 +0000 | [diff] [blame] | 354 | m_process_arch.Clear(); |
Jason Molenda | a332978 | 2014-03-29 18:54:20 +0000 | [diff] [blame] | 355 | m_os_version_major = UINT32_MAX; |
| 356 | m_os_version_minor = UINT32_MAX; |
| 357 | m_os_version_update = UINT32_MAX; |
| 358 | m_os_build.clear(); |
| 359 | m_os_kernel.clear(); |
| 360 | m_hostname.clear(); |
| 361 | m_gdb_server_name.clear(); |
| 362 | m_gdb_server_version = UINT32_MAX; |
| 363 | m_default_packet_timeout = 0; |
Steve Pucci | 5ae54ae | 2014-01-25 05:46:51 +0000 | [diff] [blame] | 364 | |
| 365 | m_max_packet_size = 0; |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 366 | } |
| 367 | |
Steve Pucci | 5ae54ae | 2014-01-25 05:46:51 +0000 | [diff] [blame] | 368 | void |
| 369 | GDBRemoteCommunicationClient::GetRemoteQSupported () |
| 370 | { |
| 371 | // Clear out any capabilities we expect to see in the qSupported response |
Steve Pucci | 03904ac | 2014-03-04 23:18:46 +0000 | [diff] [blame] | 372 | m_supports_qXfer_auxv_read = eLazyBoolNo; |
Steve Pucci | 5ae54ae | 2014-01-25 05:46:51 +0000 | [diff] [blame] | 373 | m_supports_qXfer_libraries_read = eLazyBoolNo; |
Steve Pucci | 03904ac | 2014-03-04 23:18:46 +0000 | [diff] [blame] | 374 | m_supports_qXfer_libraries_svr4_read = eLazyBoolNo; |
Steve Pucci | 5ae54ae | 2014-01-25 05:46:51 +0000 | [diff] [blame] | 375 | m_supports_augmented_libraries_svr4_read = eLazyBoolNo; |
| 376 | m_max_packet_size = UINT64_MAX; // It's supposed to always be there, but if not, we assume no limit |
| 377 | |
| 378 | StringExtractorGDBRemote response; |
| 379 | if (SendPacketAndWaitForResponse("qSupported", |
| 380 | response, |
| 381 | /*send_async=*/false) == PacketResult::Success) |
| 382 | { |
| 383 | const char *response_cstr = response.GetStringRef().c_str(); |
Steve Pucci | 03904ac | 2014-03-04 23:18:46 +0000 | [diff] [blame] | 384 | if (::strstr (response_cstr, "qXfer:auxv:read+")) |
| 385 | m_supports_qXfer_auxv_read = eLazyBoolYes; |
Steve Pucci | 5ae54ae | 2014-01-25 05:46:51 +0000 | [diff] [blame] | 386 | if (::strstr (response_cstr, "qXfer:libraries-svr4:read+")) |
| 387 | m_supports_qXfer_libraries_svr4_read = eLazyBoolYes; |
| 388 | if (::strstr (response_cstr, "augmented-libraries-svr4-read")) |
| 389 | { |
| 390 | m_supports_qXfer_libraries_svr4_read = eLazyBoolYes; // implied |
| 391 | m_supports_augmented_libraries_svr4_read = eLazyBoolYes; |
| 392 | } |
| 393 | if (::strstr (response_cstr, "qXfer:libraries:read+")) |
| 394 | m_supports_qXfer_libraries_read = eLazyBoolYes; |
| 395 | |
| 396 | const char *packet_size_str = ::strstr (response_cstr, "PacketSize="); |
| 397 | if (packet_size_str) |
| 398 | { |
| 399 | StringExtractorGDBRemote packet_response(packet_size_str + strlen("PacketSize=")); |
| 400 | m_max_packet_size = packet_response.GetHexMaxU64(/*little_endian=*/false, UINT64_MAX); |
| 401 | if (m_max_packet_size == 0) |
| 402 | { |
| 403 | m_max_packet_size = UINT64_MAX; // Must have been a garbled response |
| 404 | Log *log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PROCESS)); |
| 405 | if (log) |
| 406 | log->Printf ("Garbled PacketSize spec in qSupported response"); |
| 407 | } |
| 408 | } |
| 409 | } |
| 410 | } |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 411 | |
| 412 | bool |
| 413 | GDBRemoteCommunicationClient::GetThreadSuffixSupported () |
| 414 | { |
| 415 | if (m_supports_thread_suffix == eLazyBoolCalculate) |
| 416 | { |
| 417 | StringExtractorGDBRemote response; |
| 418 | m_supports_thread_suffix = eLazyBoolNo; |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 419 | if (SendPacketAndWaitForResponse("QThreadSuffixSupported", response, false) == PacketResult::Success) |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 420 | { |
| 421 | if (response.IsOKResponse()) |
| 422 | m_supports_thread_suffix = eLazyBoolYes; |
| 423 | } |
| 424 | } |
| 425 | return m_supports_thread_suffix; |
| 426 | } |
| 427 | bool |
| 428 | GDBRemoteCommunicationClient::GetVContSupported (char flavor) |
| 429 | { |
| 430 | if (m_supports_vCont_c == eLazyBoolCalculate) |
| 431 | { |
| 432 | StringExtractorGDBRemote response; |
| 433 | m_supports_vCont_any = eLazyBoolNo; |
| 434 | m_supports_vCont_all = eLazyBoolNo; |
| 435 | m_supports_vCont_c = eLazyBoolNo; |
| 436 | m_supports_vCont_C = eLazyBoolNo; |
| 437 | m_supports_vCont_s = eLazyBoolNo; |
| 438 | m_supports_vCont_S = eLazyBoolNo; |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 439 | if (SendPacketAndWaitForResponse("vCont?", response, false) == PacketResult::Success) |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 440 | { |
| 441 | const char *response_cstr = response.GetStringRef().c_str(); |
| 442 | if (::strstr (response_cstr, ";c")) |
| 443 | m_supports_vCont_c = eLazyBoolYes; |
| 444 | |
| 445 | if (::strstr (response_cstr, ";C")) |
| 446 | m_supports_vCont_C = eLazyBoolYes; |
| 447 | |
| 448 | if (::strstr (response_cstr, ";s")) |
| 449 | m_supports_vCont_s = eLazyBoolYes; |
| 450 | |
| 451 | if (::strstr (response_cstr, ";S")) |
| 452 | m_supports_vCont_S = eLazyBoolYes; |
| 453 | |
| 454 | if (m_supports_vCont_c == eLazyBoolYes && |
| 455 | m_supports_vCont_C == eLazyBoolYes && |
| 456 | m_supports_vCont_s == eLazyBoolYes && |
| 457 | m_supports_vCont_S == eLazyBoolYes) |
| 458 | { |
| 459 | m_supports_vCont_all = eLazyBoolYes; |
| 460 | } |
| 461 | |
| 462 | if (m_supports_vCont_c == eLazyBoolYes || |
| 463 | m_supports_vCont_C == eLazyBoolYes || |
| 464 | m_supports_vCont_s == eLazyBoolYes || |
| 465 | m_supports_vCont_S == eLazyBoolYes) |
| 466 | { |
| 467 | m_supports_vCont_any = eLazyBoolYes; |
| 468 | } |
| 469 | } |
| 470 | } |
| 471 | |
| 472 | switch (flavor) |
| 473 | { |
| 474 | case 'a': return m_supports_vCont_any; |
| 475 | case 'A': return m_supports_vCont_all; |
| 476 | case 'c': return m_supports_vCont_c; |
| 477 | case 'C': return m_supports_vCont_C; |
| 478 | case 's': return m_supports_vCont_s; |
| 479 | case 'S': return m_supports_vCont_S; |
| 480 | default: break; |
| 481 | } |
| 482 | return false; |
| 483 | } |
| 484 | |
Hafiz Abid Qadeer | 9a78cdf | 2013-08-29 09:09:45 +0000 | [diff] [blame] | 485 | // Check if the target supports 'p' packet. It sends out a 'p' |
| 486 | // packet and checks the response. A normal packet will tell us |
| 487 | // that support is available. |
Sean Callanan | b1de114 | 2013-09-04 23:24:15 +0000 | [diff] [blame] | 488 | // |
| 489 | // Takes a valid thread ID because p needs to apply to a thread. |
Hafiz Abid Qadeer | 9a78cdf | 2013-08-29 09:09:45 +0000 | [diff] [blame] | 490 | bool |
Sean Callanan | b1de114 | 2013-09-04 23:24:15 +0000 | [diff] [blame] | 491 | GDBRemoteCommunicationClient::GetpPacketSupported (lldb::tid_t tid) |
Hafiz Abid Qadeer | 9a78cdf | 2013-08-29 09:09:45 +0000 | [diff] [blame] | 492 | { |
| 493 | if (m_supports_p == eLazyBoolCalculate) |
| 494 | { |
| 495 | StringExtractorGDBRemote response; |
| 496 | m_supports_p = eLazyBoolNo; |
Sean Callanan | b1de114 | 2013-09-04 23:24:15 +0000 | [diff] [blame] | 497 | char packet[256]; |
| 498 | if (GetThreadSuffixSupported()) |
| 499 | snprintf(packet, sizeof(packet), "p0;thread:%" PRIx64 ";", tid); |
| 500 | else |
| 501 | snprintf(packet, sizeof(packet), "p0"); |
| 502 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 503 | if (SendPacketAndWaitForResponse(packet, response, false) == PacketResult::Success) |
Hafiz Abid Qadeer | 9a78cdf | 2013-08-29 09:09:45 +0000 | [diff] [blame] | 504 | { |
| 505 | if (response.IsNormalResponse()) |
| 506 | m_supports_p = eLazyBoolYes; |
| 507 | } |
| 508 | } |
| 509 | return m_supports_p; |
| 510 | } |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 511 | |
Jason Molenda | bdc4f12 | 2014-05-06 02:59:39 +0000 | [diff] [blame] | 512 | bool |
Jason Molenda | 705b180 | 2014-06-13 02:37:02 +0000 | [diff] [blame] | 513 | GDBRemoteCommunicationClient::GetThreadExtendedInfoSupported () |
| 514 | { |
| 515 | if (m_supports_jThreadExtendedInfo == eLazyBoolCalculate) |
| 516 | { |
| 517 | StringExtractorGDBRemote response; |
| 518 | m_supports_jThreadExtendedInfo = eLazyBoolNo; |
| 519 | if (SendPacketAndWaitForResponse("jThreadExtendedInfo:", response, false) == PacketResult::Success) |
| 520 | { |
| 521 | if (response.IsOKResponse()) |
| 522 | { |
| 523 | m_supports_jThreadExtendedInfo = eLazyBoolYes; |
| 524 | } |
| 525 | } |
| 526 | } |
| 527 | return m_supports_jThreadExtendedInfo; |
| 528 | } |
| 529 | |
| 530 | bool |
Jason Molenda | bdc4f12 | 2014-05-06 02:59:39 +0000 | [diff] [blame] | 531 | GDBRemoteCommunicationClient::GetxPacketSupported () |
| 532 | { |
| 533 | if (m_supports_x == eLazyBoolCalculate) |
| 534 | { |
| 535 | StringExtractorGDBRemote response; |
| 536 | m_supports_x = eLazyBoolNo; |
| 537 | char packet[256]; |
| 538 | snprintf (packet, sizeof (packet), "x0,0"); |
| 539 | if (SendPacketAndWaitForResponse(packet, response, false) == PacketResult::Success) |
| 540 | { |
| 541 | if (response.IsOKResponse()) |
| 542 | m_supports_x = eLazyBoolYes; |
| 543 | } |
| 544 | } |
| 545 | return m_supports_x; |
| 546 | } |
| 547 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 548 | GDBRemoteCommunicationClient::PacketResult |
Steve Pucci | 5ae54ae | 2014-01-25 05:46:51 +0000 | [diff] [blame] | 549 | GDBRemoteCommunicationClient::SendPacketsAndConcatenateResponses |
| 550 | ( |
| 551 | const char *payload_prefix, |
| 552 | std::string &response_string |
| 553 | ) |
| 554 | { |
| 555 | Mutex::Locker locker; |
| 556 | if (!GetSequenceMutex(locker, |
| 557 | "ProcessGDBRemote::SendPacketsAndConcatenateResponses() failed due to not getting the sequence mutex")) |
| 558 | { |
| 559 | Log *log (ProcessGDBRemoteLog::GetLogIfAnyCategoryIsSet (GDBR_LOG_PROCESS | GDBR_LOG_PACKETS)); |
| 560 | if (log) |
| 561 | log->Printf("error: failed to get packet sequence mutex, not sending packets with prefix '%s'", |
| 562 | payload_prefix); |
| 563 | return PacketResult::ErrorNoSequenceLock; |
| 564 | } |
| 565 | |
| 566 | response_string = ""; |
| 567 | std::string payload_prefix_str(payload_prefix); |
| 568 | unsigned int response_size = 0x1000; |
| 569 | if (response_size > GetRemoteMaxPacketSize()) { // May send qSupported packet |
| 570 | response_size = GetRemoteMaxPacketSize(); |
| 571 | } |
| 572 | |
| 573 | for (unsigned int offset = 0; true; offset += response_size) |
| 574 | { |
| 575 | StringExtractorGDBRemote this_response; |
| 576 | // Construct payload |
| 577 | char sizeDescriptor[128]; |
| 578 | snprintf(sizeDescriptor, sizeof(sizeDescriptor), "%x,%x", offset, response_size); |
| 579 | PacketResult result = SendPacketAndWaitForResponse((payload_prefix_str + sizeDescriptor).c_str(), |
| 580 | this_response, |
| 581 | /*send_async=*/false); |
| 582 | if (result != PacketResult::Success) |
| 583 | return result; |
| 584 | |
| 585 | const std::string &this_string = this_response.GetStringRef(); |
| 586 | |
| 587 | // Check for m or l as first character; l seems to mean this is the last chunk |
| 588 | char first_char = *this_string.c_str(); |
| 589 | if (first_char != 'm' && first_char != 'l') |
| 590 | { |
| 591 | return PacketResult::ErrorReplyInvalid; |
| 592 | } |
Steve Pucci | 03904ac | 2014-03-04 23:18:46 +0000 | [diff] [blame] | 593 | // Concatenate the result so far (skipping 'm' or 'l') |
| 594 | response_string.append(this_string, 1, std::string::npos); |
Steve Pucci | 5ae54ae | 2014-01-25 05:46:51 +0000 | [diff] [blame] | 595 | if (first_char == 'l') |
| 596 | // We're done |
| 597 | return PacketResult::Success; |
| 598 | } |
| 599 | } |
| 600 | |
| 601 | GDBRemoteCommunicationClient::PacketResult |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 602 | GDBRemoteCommunicationClient::SendPacketAndWaitForResponse |
| 603 | ( |
| 604 | const char *payload, |
| 605 | StringExtractorGDBRemote &response, |
| 606 | bool send_async |
| 607 | ) |
| 608 | { |
| 609 | return SendPacketAndWaitForResponse (payload, |
| 610 | ::strlen (payload), |
| 611 | response, |
| 612 | send_async); |
| 613 | } |
| 614 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 615 | GDBRemoteCommunicationClient::PacketResult |
| 616 | GDBRemoteCommunicationClient::SendPacketAndWaitForResponseNoLock (const char *payload, |
| 617 | size_t payload_length, |
| 618 | StringExtractorGDBRemote &response) |
| 619 | { |
| 620 | PacketResult packet_result = SendPacketNoLock (payload, payload_length); |
| 621 | if (packet_result == PacketResult::Success) |
| 622 | packet_result = WaitForPacketWithTimeoutMicroSecondsNoLock (response, GetPacketTimeoutInMicroSeconds ()); |
| 623 | return packet_result; |
| 624 | } |
| 625 | |
| 626 | GDBRemoteCommunicationClient::PacketResult |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 627 | GDBRemoteCommunicationClient::SendPacketAndWaitForResponse |
| 628 | ( |
| 629 | const char *payload, |
| 630 | size_t payload_length, |
| 631 | StringExtractorGDBRemote &response, |
| 632 | bool send_async |
| 633 | ) |
| 634 | { |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 635 | PacketResult packet_result = PacketResult::ErrorSendFailed; |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 636 | Mutex::Locker locker; |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 637 | Log *log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PROCESS)); |
Greg Clayton | c3c0b0e | 2012-04-12 19:04:34 +0000 | [diff] [blame] | 638 | if (GetSequenceMutex (locker)) |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 639 | { |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 640 | packet_result = SendPacketAndWaitForResponseNoLock (payload, payload_length, response); |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 641 | } |
| 642 | else |
| 643 | { |
| 644 | if (send_async) |
| 645 | { |
Greg Clayton | d354405 | 2012-05-31 21:24:20 +0000 | [diff] [blame] | 646 | if (IsRunning()) |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 647 | { |
Greg Clayton | d354405 | 2012-05-31 21:24:20 +0000 | [diff] [blame] | 648 | Mutex::Locker async_locker (m_async_mutex); |
| 649 | m_async_packet.assign(payload, payload_length); |
| 650 | m_async_packet_predicate.SetValue (true, eBroadcastNever); |
| 651 | |
| 652 | if (log) |
| 653 | log->Printf ("async: async packet = %s", m_async_packet.c_str()); |
| 654 | |
| 655 | bool timed_out = false; |
| 656 | if (SendInterrupt(locker, 2, timed_out)) |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 657 | { |
Greg Clayton | d354405 | 2012-05-31 21:24:20 +0000 | [diff] [blame] | 658 | if (m_interrupt_sent) |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 659 | { |
Jim Ingham | babfc38 | 2012-06-06 00:32:39 +0000 | [diff] [blame] | 660 | m_interrupt_sent = false; |
Greg Clayton | d354405 | 2012-05-31 21:24:20 +0000 | [diff] [blame] | 661 | TimeValue timeout_time; |
| 662 | timeout_time = TimeValue::Now(); |
| 663 | timeout_time.OffsetWithSeconds (m_packet_timeout); |
| 664 | |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 665 | if (log) |
Greg Clayton | d354405 | 2012-05-31 21:24:20 +0000 | [diff] [blame] | 666 | log->Printf ("async: sent interrupt"); |
Greg Clayton | 644247c | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 667 | |
Greg Clayton | d354405 | 2012-05-31 21:24:20 +0000 | [diff] [blame] | 668 | if (m_async_packet_predicate.WaitForValueEqualTo (false, &timeout_time, &timed_out)) |
Greg Clayton | e889ad6 | 2011-10-27 22:04:16 +0000 | [diff] [blame] | 669 | { |
Greg Clayton | d354405 | 2012-05-31 21:24:20 +0000 | [diff] [blame] | 670 | if (log) |
| 671 | log->Printf ("async: got response"); |
| 672 | |
| 673 | // Swap the response buffer to avoid malloc and string copy |
| 674 | response.GetStringRef().swap (m_async_response.GetStringRef()); |
Jim Ingham | a6195b7 | 2013-12-18 01:24:33 +0000 | [diff] [blame] | 675 | packet_result = m_async_result; |
Greg Clayton | d354405 | 2012-05-31 21:24:20 +0000 | [diff] [blame] | 676 | } |
| 677 | else |
| 678 | { |
| 679 | if (log) |
| 680 | log->Printf ("async: timed out waiting for response"); |
| 681 | } |
| 682 | |
| 683 | // Make sure we wait until the continue packet has been sent again... |
| 684 | if (m_private_is_running.WaitForValueEqualTo (true, &timeout_time, &timed_out)) |
| 685 | { |
| 686 | if (log) |
| 687 | { |
| 688 | if (timed_out) |
| 689 | log->Printf ("async: timed out waiting for process to resume, but process was resumed"); |
| 690 | else |
| 691 | log->Printf ("async: async packet sent"); |
| 692 | } |
| 693 | } |
| 694 | else |
| 695 | { |
| 696 | if (log) |
| 697 | log->Printf ("async: timed out waiting for process to resume"); |
Greg Clayton | e889ad6 | 2011-10-27 22:04:16 +0000 | [diff] [blame] | 698 | } |
| 699 | } |
| 700 | else |
| 701 | { |
Greg Clayton | d354405 | 2012-05-31 21:24:20 +0000 | [diff] [blame] | 702 | // We had a racy condition where we went to send the interrupt |
| 703 | // yet we were able to get the lock, so the process must have |
| 704 | // just stopped? |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 705 | if (log) |
Greg Clayton | d354405 | 2012-05-31 21:24:20 +0000 | [diff] [blame] | 706 | log->Printf ("async: got lock without sending interrupt"); |
| 707 | // Send the packet normally since we got the lock |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 708 | packet_result = SendPacketAndWaitForResponseNoLock (payload, payload_length, response); |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 709 | } |
| 710 | } |
| 711 | else |
| 712 | { |
Greg Clayton | 644247c | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 713 | if (log) |
Greg Clayton | d354405 | 2012-05-31 21:24:20 +0000 | [diff] [blame] | 714 | log->Printf ("async: failed to interrupt"); |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 715 | } |
| 716 | } |
| 717 | else |
| 718 | { |
| 719 | if (log) |
Greg Clayton | d354405 | 2012-05-31 21:24:20 +0000 | [diff] [blame] | 720 | log->Printf ("async: not running, async is ignored"); |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 721 | } |
| 722 | } |
| 723 | else |
| 724 | { |
| 725 | if (log) |
Greg Clayton | c3c0b0e | 2012-04-12 19:04:34 +0000 | [diff] [blame] | 726 | 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] | 727 | } |
| 728 | } |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 729 | return packet_result; |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 730 | } |
| 731 | |
Han Ming Ong | 4b6459f | 2013-01-18 23:11:53 +0000 | [diff] [blame] | 732 | static const char *end_delimiter = "--end--;"; |
| 733 | static const int end_delimiter_len = 8; |
| 734 | |
| 735 | std::string |
| 736 | GDBRemoteCommunicationClient::HarmonizeThreadIdsForProfileData |
| 737 | ( ProcessGDBRemote *process, |
| 738 | StringExtractorGDBRemote& profileDataExtractor |
| 739 | ) |
| 740 | { |
| 741 | std::map<uint64_t, uint32_t> new_thread_id_to_used_usec_map; |
| 742 | std::stringstream final_output; |
| 743 | std::string name, value; |
| 744 | |
| 745 | // Going to assuming thread_used_usec comes first, else bail out. |
| 746 | while (profileDataExtractor.GetNameColonValue(name, value)) |
| 747 | { |
| 748 | if (name.compare("thread_used_id") == 0) |
| 749 | { |
| 750 | StringExtractor threadIDHexExtractor(value.c_str()); |
| 751 | uint64_t thread_id = threadIDHexExtractor.GetHexMaxU64(false, 0); |
| 752 | |
| 753 | bool has_used_usec = false; |
| 754 | uint32_t curr_used_usec = 0; |
| 755 | std::string usec_name, usec_value; |
| 756 | uint32_t input_file_pos = profileDataExtractor.GetFilePos(); |
| 757 | if (profileDataExtractor.GetNameColonValue(usec_name, usec_value)) |
| 758 | { |
| 759 | if (usec_name.compare("thread_used_usec") == 0) |
| 760 | { |
| 761 | has_used_usec = true; |
| 762 | curr_used_usec = strtoull(usec_value.c_str(), NULL, 0); |
| 763 | } |
| 764 | else |
| 765 | { |
| 766 | // We didn't find what we want, it is probably |
| 767 | // an older version. Bail out. |
| 768 | profileDataExtractor.SetFilePos(input_file_pos); |
| 769 | } |
| 770 | } |
| 771 | |
| 772 | if (has_used_usec) |
| 773 | { |
| 774 | uint32_t prev_used_usec = 0; |
| 775 | std::map<uint64_t, uint32_t>::iterator iterator = m_thread_id_to_used_usec_map.find(thread_id); |
| 776 | if (iterator != m_thread_id_to_used_usec_map.end()) |
| 777 | { |
| 778 | prev_used_usec = m_thread_id_to_used_usec_map[thread_id]; |
| 779 | } |
| 780 | |
| 781 | uint32_t real_used_usec = curr_used_usec - prev_used_usec; |
| 782 | // A good first time record is one that runs for at least 0.25 sec |
| 783 | bool good_first_time = (prev_used_usec == 0) && (real_used_usec > 250000); |
| 784 | bool good_subsequent_time = (prev_used_usec > 0) && |
| 785 | ((real_used_usec > 0) || (process->HasAssignedIndexIDToThread(thread_id))); |
| 786 | |
| 787 | if (good_first_time || good_subsequent_time) |
| 788 | { |
| 789 | // We try to avoid doing too many index id reservation, |
| 790 | // resulting in fast increase of index ids. |
| 791 | |
| 792 | final_output << name << ":"; |
| 793 | int32_t index_id = process->AssignIndexIDToThread(thread_id); |
| 794 | final_output << index_id << ";"; |
| 795 | |
| 796 | final_output << usec_name << ":" << usec_value << ";"; |
| 797 | } |
| 798 | else |
| 799 | { |
| 800 | // Skip past 'thread_used_name'. |
| 801 | std::string local_name, local_value; |
| 802 | profileDataExtractor.GetNameColonValue(local_name, local_value); |
| 803 | } |
| 804 | |
| 805 | // Store current time as previous time so that they can be compared later. |
| 806 | new_thread_id_to_used_usec_map[thread_id] = curr_used_usec; |
| 807 | } |
| 808 | else |
| 809 | { |
| 810 | // Bail out and use old string. |
| 811 | final_output << name << ":" << value << ";"; |
| 812 | } |
| 813 | } |
| 814 | else |
| 815 | { |
| 816 | final_output << name << ":" << value << ";"; |
| 817 | } |
| 818 | } |
| 819 | final_output << end_delimiter; |
| 820 | m_thread_id_to_used_usec_map = new_thread_id_to_used_usec_map; |
| 821 | |
| 822 | return final_output.str(); |
| 823 | } |
| 824 | |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 825 | StateType |
| 826 | GDBRemoteCommunicationClient::SendContinuePacketAndWaitForResponse |
| 827 | ( |
| 828 | ProcessGDBRemote *process, |
| 829 | const char *payload, |
| 830 | size_t packet_length, |
| 831 | StringExtractorGDBRemote &response |
| 832 | ) |
| 833 | { |
Greg Clayton | 1f5181a | 2012-07-02 22:05:25 +0000 | [diff] [blame] | 834 | m_curr_tid = LLDB_INVALID_THREAD_ID; |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 835 | Log *log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PROCESS)); |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 836 | if (log) |
| 837 | log->Printf ("GDBRemoteCommunicationClient::%s ()", __FUNCTION__); |
| 838 | |
| 839 | Mutex::Locker locker(m_sequence_mutex); |
| 840 | StateType state = eStateRunning; |
| 841 | |
| 842 | BroadcastEvent(eBroadcastBitRunPacketSent, NULL); |
| 843 | m_public_is_running.SetValue (true, eBroadcastNever); |
| 844 | // Set the starting continue packet into "continue_packet". This packet |
Jim Ingham | babfc38 | 2012-06-06 00:32:39 +0000 | [diff] [blame] | 845 | // 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] | 846 | std::string continue_packet(payload, packet_length); |
| 847 | |
Greg Clayton | 3f875c5 | 2013-02-22 22:23:55 +0000 | [diff] [blame] | 848 | bool got_async_packet = false; |
Greg Clayton | af247d7 | 2011-05-19 03:54:16 +0000 | [diff] [blame] | 849 | |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 850 | while (state == eStateRunning) |
| 851 | { |
Greg Clayton | 3f875c5 | 2013-02-22 22:23:55 +0000 | [diff] [blame] | 852 | if (!got_async_packet) |
Greg Clayton | af247d7 | 2011-05-19 03:54:16 +0000 | [diff] [blame] | 853 | { |
| 854 | if (log) |
| 855 | log->Printf ("GDBRemoteCommunicationClient::%s () sending continue packet: %s", __FUNCTION__, continue_packet.c_str()); |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 856 | if (SendPacketNoLock(continue_packet.c_str(), continue_packet.size()) != PacketResult::Success) |
Greg Clayton | af247d7 | 2011-05-19 03:54:16 +0000 | [diff] [blame] | 857 | state = eStateInvalid; |
Jim Ingham | b8cd575 | 2014-04-16 02:24:17 +0000 | [diff] [blame] | 858 | else |
| 859 | m_interrupt_sent = false; |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 860 | |
Greg Clayton | e889ad6 | 2011-10-27 22:04:16 +0000 | [diff] [blame] | 861 | m_private_is_running.SetValue (true, eBroadcastAlways); |
Greg Clayton | af247d7 | 2011-05-19 03:54:16 +0000 | [diff] [blame] | 862 | } |
| 863 | |
Greg Clayton | 3f875c5 | 2013-02-22 22:23:55 +0000 | [diff] [blame] | 864 | got_async_packet = false; |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 865 | |
| 866 | if (log) |
Jason Molenda | fd54b36 | 2011-09-20 21:44:10 +0000 | [diff] [blame] | 867 | log->Printf ("GDBRemoteCommunicationClient::%s () WaitForPacket(%s)", __FUNCTION__, continue_packet.c_str()); |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 868 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 869 | if (WaitForPacketWithTimeoutMicroSecondsNoLock(response, UINT32_MAX) == PacketResult::Success) |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 870 | { |
| 871 | if (response.Empty()) |
| 872 | state = eStateInvalid; |
| 873 | else |
| 874 | { |
| 875 | const char stop_type = response.GetChar(); |
| 876 | if (log) |
| 877 | log->Printf ("GDBRemoteCommunicationClient::%s () got packet: %s", __FUNCTION__, response.GetStringRef().c_str()); |
| 878 | switch (stop_type) |
| 879 | { |
| 880 | case 'T': |
| 881 | case 'S': |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 882 | { |
Greg Clayton | 2687cd1 | 2012-03-29 01:55:41 +0000 | [diff] [blame] | 883 | if (process->GetStopID() == 0) |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 884 | { |
Greg Clayton | 2687cd1 | 2012-03-29 01:55:41 +0000 | [diff] [blame] | 885 | if (process->GetID() == LLDB_INVALID_PROCESS_ID) |
| 886 | { |
| 887 | lldb::pid_t pid = GetCurrentProcessID (); |
| 888 | if (pid != LLDB_INVALID_PROCESS_ID) |
| 889 | process->SetID (pid); |
| 890 | } |
| 891 | process->BuildDynamicRegisterInfo (true); |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 892 | } |
Greg Clayton | 2687cd1 | 2012-03-29 01:55:41 +0000 | [diff] [blame] | 893 | |
| 894 | // Privately notify any internal threads that we have stopped |
| 895 | // in case we wanted to interrupt our process, yet we might |
| 896 | // send a packet and continue without returning control to the |
| 897 | // user. |
| 898 | m_private_is_running.SetValue (false, eBroadcastAlways); |
| 899 | |
| 900 | const uint8_t signo = response.GetHexU8 (UINT8_MAX); |
| 901 | |
Jim Ingham | babfc38 | 2012-06-06 00:32:39 +0000 | [diff] [blame] | 902 | bool continue_after_async = m_async_signal != -1 || m_async_packet_predicate.GetValue(); |
| 903 | if (continue_after_async || m_interrupt_sent) |
Greg Clayton | 2687cd1 | 2012-03-29 01:55:41 +0000 | [diff] [blame] | 904 | { |
Greg Clayton | 2687cd1 | 2012-03-29 01:55:41 +0000 | [diff] [blame] | 905 | // We sent an interrupt packet to stop the inferior process |
| 906 | // for an async signal or to send an async packet while running |
| 907 | // but we might have been single stepping and received the |
| 908 | // stop packet for the step instead of for the interrupt packet. |
| 909 | // Typically when an interrupt is sent a SIGINT or SIGSTOP |
| 910 | // is used, so if we get anything else, we need to try and |
| 911 | // get another stop reply packet that may have been sent |
| 912 | // due to sending the interrupt when the target is stopped |
| 913 | // which will just re-send a copy of the last stop reply |
| 914 | // packet. If we don't do this, then the reply for our |
| 915 | // async packet will be the repeat stop reply packet and cause |
| 916 | // a lot of trouble for us! |
| 917 | if (signo != SIGINT && signo != SIGSTOP) |
| 918 | { |
Greg Clayton | fb72fde | 2012-05-15 02:50:49 +0000 | [diff] [blame] | 919 | continue_after_async = false; |
Greg Clayton | 2687cd1 | 2012-03-29 01:55:41 +0000 | [diff] [blame] | 920 | |
| 921 | // We didn't get a a SIGINT or SIGSTOP, so try for a |
| 922 | // very brief time (1 ms) to get another stop reply |
| 923 | // packet to make sure it doesn't get in the way |
| 924 | StringExtractorGDBRemote extra_stop_reply_packet; |
| 925 | uint32_t timeout_usec = 1000; |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 926 | if (WaitForPacketWithTimeoutMicroSecondsNoLock (extra_stop_reply_packet, timeout_usec) == PacketResult::Success) |
Greg Clayton | 2687cd1 | 2012-03-29 01:55:41 +0000 | [diff] [blame] | 927 | { |
| 928 | switch (extra_stop_reply_packet.GetChar()) |
| 929 | { |
| 930 | case 'T': |
| 931 | case 'S': |
| 932 | // We did get an extra stop reply, which means |
| 933 | // our interrupt didn't stop the target so we |
| 934 | // shouldn't continue after the async signal |
| 935 | // or packet is sent... |
Greg Clayton | fb72fde | 2012-05-15 02:50:49 +0000 | [diff] [blame] | 936 | continue_after_async = false; |
Greg Clayton | 2687cd1 | 2012-03-29 01:55:41 +0000 | [diff] [blame] | 937 | break; |
| 938 | } |
| 939 | } |
| 940 | } |
| 941 | } |
| 942 | |
| 943 | if (m_async_signal != -1) |
| 944 | { |
| 945 | if (log) |
| 946 | log->Printf ("async: send signo = %s", Host::GetSignalAsCString (m_async_signal)); |
| 947 | |
| 948 | // Save off the async signal we are supposed to send |
| 949 | const int async_signal = m_async_signal; |
| 950 | // Clear the async signal member so we don't end up |
| 951 | // sending the signal multiple times... |
| 952 | m_async_signal = -1; |
| 953 | // Check which signal we stopped with |
| 954 | if (signo == async_signal) |
| 955 | { |
| 956 | if (log) |
| 957 | log->Printf ("async: stopped with signal %s, we are done running", Host::GetSignalAsCString (signo)); |
| 958 | |
| 959 | // We already stopped with a signal that we wanted |
| 960 | // to stop with, so we are done |
| 961 | } |
| 962 | else |
| 963 | { |
| 964 | // We stopped with a different signal that the one |
| 965 | // we wanted to stop with, so now we must resume |
| 966 | // with the signal we want |
| 967 | char signal_packet[32]; |
| 968 | int signal_packet_len = 0; |
| 969 | signal_packet_len = ::snprintf (signal_packet, |
| 970 | sizeof (signal_packet), |
| 971 | "C%2.2x", |
| 972 | async_signal); |
| 973 | |
| 974 | if (log) |
| 975 | log->Printf ("async: stopped with signal %s, resume with %s", |
| 976 | Host::GetSignalAsCString (signo), |
| 977 | Host::GetSignalAsCString (async_signal)); |
| 978 | |
| 979 | // Set the continue packet to resume even if the |
Greg Clayton | fb72fde | 2012-05-15 02:50:49 +0000 | [diff] [blame] | 980 | // interrupt didn't cause our stop (ignore continue_after_async) |
Greg Clayton | 2687cd1 | 2012-03-29 01:55:41 +0000 | [diff] [blame] | 981 | continue_packet.assign(signal_packet, signal_packet_len); |
| 982 | continue; |
| 983 | } |
| 984 | } |
| 985 | else if (m_async_packet_predicate.GetValue()) |
| 986 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 987 | Log * packet_log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PACKETS)); |
Greg Clayton | 2687cd1 | 2012-03-29 01:55:41 +0000 | [diff] [blame] | 988 | |
| 989 | // We are supposed to send an asynchronous packet while |
Jim Ingham | a6195b7 | 2013-12-18 01:24:33 +0000 | [diff] [blame] | 990 | // we are running. |
Greg Clayton | 2687cd1 | 2012-03-29 01:55:41 +0000 | [diff] [blame] | 991 | m_async_response.Clear(); |
| 992 | if (m_async_packet.empty()) |
| 993 | { |
Jim Ingham | a6195b7 | 2013-12-18 01:24:33 +0000 | [diff] [blame] | 994 | m_async_result = PacketResult::ErrorSendFailed; |
| 995 | if (packet_log) |
Greg Clayton | 2687cd1 | 2012-03-29 01:55:41 +0000 | [diff] [blame] | 996 | packet_log->Printf ("async: error: empty async packet"); |
| 997 | |
| 998 | } |
| 999 | else |
| 1000 | { |
| 1001 | if (packet_log) |
| 1002 | packet_log->Printf ("async: sending packet"); |
| 1003 | |
Jim Ingham | a6195b7 | 2013-12-18 01:24:33 +0000 | [diff] [blame] | 1004 | m_async_result = SendPacketAndWaitForResponse (&m_async_packet[0], |
| 1005 | m_async_packet.size(), |
| 1006 | m_async_response, |
| 1007 | false); |
Greg Clayton | 2687cd1 | 2012-03-29 01:55:41 +0000 | [diff] [blame] | 1008 | } |
| 1009 | // Let the other thread that was trying to send the async |
| 1010 | // packet know that the packet has been sent and response is |
| 1011 | // ready... |
| 1012 | m_async_packet_predicate.SetValue(false, eBroadcastAlways); |
| 1013 | |
| 1014 | if (packet_log) |
Greg Clayton | fb72fde | 2012-05-15 02:50:49 +0000 | [diff] [blame] | 1015 | 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] | 1016 | |
| 1017 | // Set the continue packet to resume if our interrupt |
| 1018 | // for the async packet did cause the stop |
Greg Clayton | fb72fde | 2012-05-15 02:50:49 +0000 | [diff] [blame] | 1019 | if (continue_after_async) |
Greg Clayton | 2687cd1 | 2012-03-29 01:55:41 +0000 | [diff] [blame] | 1020 | { |
Greg Clayton | f1186de | 2012-05-24 23:42:14 +0000 | [diff] [blame] | 1021 | // Reverting this for now as it is causing deadlocks |
| 1022 | // in programs (<rdar://problem/11529853>). In the future |
| 1023 | // we should check our thread list and "do the right thing" |
| 1024 | // for new threads that show up while we stop and run async |
| 1025 | // packets. Setting the packet to 'c' to continue all threads |
| 1026 | // is the right thing to do 99.99% of the time because if a |
| 1027 | // thread was single stepping, and we sent an interrupt, we |
| 1028 | // will notice above that we didn't stop due to an interrupt |
| 1029 | // but stopped due to stepping and we would _not_ continue. |
| 1030 | continue_packet.assign (1, 'c'); |
Greg Clayton | 2687cd1 | 2012-03-29 01:55:41 +0000 | [diff] [blame] | 1031 | continue; |
| 1032 | } |
| 1033 | } |
| 1034 | // Stop with signal and thread info |
| 1035 | state = eStateStopped; |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 1036 | } |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 1037 | break; |
| 1038 | |
| 1039 | case 'W': |
| 1040 | case 'X': |
| 1041 | // process exited |
| 1042 | state = eStateExited; |
| 1043 | break; |
| 1044 | |
| 1045 | case 'O': |
| 1046 | // STDOUT |
| 1047 | { |
Greg Clayton | 3f875c5 | 2013-02-22 22:23:55 +0000 | [diff] [blame] | 1048 | got_async_packet = true; |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 1049 | std::string inferior_stdout; |
| 1050 | inferior_stdout.reserve(response.GetBytesLeft () / 2); |
| 1051 | char ch; |
| 1052 | while ((ch = response.GetHexU8()) != '\0') |
| 1053 | inferior_stdout.append(1, ch); |
| 1054 | process->AppendSTDOUT (inferior_stdout.c_str(), inferior_stdout.size()); |
| 1055 | } |
| 1056 | break; |
| 1057 | |
Han Ming Ong | ab3b8b2 | 2012-11-17 00:21:04 +0000 | [diff] [blame] | 1058 | case 'A': |
| 1059 | // Async miscellaneous reply. Right now, only profile data is coming through this channel. |
| 1060 | { |
Greg Clayton | 3f875c5 | 2013-02-22 22:23:55 +0000 | [diff] [blame] | 1061 | got_async_packet = true; |
Han Ming Ong | 4b6459f | 2013-01-18 23:11:53 +0000 | [diff] [blame] | 1062 | std::string input = response.GetStringRef().substr(1); // '1' to move beyond 'A' |
| 1063 | if (m_partial_profile_data.length() > 0) |
| 1064 | { |
| 1065 | m_partial_profile_data.append(input); |
| 1066 | input = m_partial_profile_data; |
| 1067 | m_partial_profile_data.clear(); |
| 1068 | } |
| 1069 | |
| 1070 | size_t found, pos = 0, len = input.length(); |
| 1071 | while ((found = input.find(end_delimiter, pos)) != std::string::npos) |
| 1072 | { |
| 1073 | StringExtractorGDBRemote profileDataExtractor(input.substr(pos, found).c_str()); |
Han Ming Ong | 91ed6b8 | 2013-06-24 18:15:05 +0000 | [diff] [blame] | 1074 | std::string profile_data = HarmonizeThreadIdsForProfileData(process, profileDataExtractor); |
| 1075 | process->BroadcastAsyncProfileData (profile_data); |
Han Ming Ong | 4b6459f | 2013-01-18 23:11:53 +0000 | [diff] [blame] | 1076 | |
| 1077 | pos = found + end_delimiter_len; |
| 1078 | } |
| 1079 | |
| 1080 | if (pos < len) |
| 1081 | { |
| 1082 | // Last incomplete chunk. |
| 1083 | m_partial_profile_data = input.substr(pos); |
| 1084 | } |
Han Ming Ong | ab3b8b2 | 2012-11-17 00:21:04 +0000 | [diff] [blame] | 1085 | } |
| 1086 | break; |
| 1087 | |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 1088 | case 'E': |
| 1089 | // ERROR |
| 1090 | state = eStateInvalid; |
| 1091 | break; |
| 1092 | |
| 1093 | default: |
| 1094 | if (log) |
| 1095 | log->Printf ("GDBRemoteCommunicationClient::%s () unrecognized async packet", __FUNCTION__); |
| 1096 | state = eStateInvalid; |
| 1097 | break; |
| 1098 | } |
| 1099 | } |
| 1100 | } |
| 1101 | else |
| 1102 | { |
| 1103 | if (log) |
| 1104 | log->Printf ("GDBRemoteCommunicationClient::%s () WaitForPacket(...) => false", __FUNCTION__); |
| 1105 | state = eStateInvalid; |
| 1106 | } |
| 1107 | } |
| 1108 | if (log) |
| 1109 | log->Printf ("GDBRemoteCommunicationClient::%s () => %s", __FUNCTION__, StateAsCString(state)); |
| 1110 | response.SetFilePos(0); |
| 1111 | m_private_is_running.SetValue (false, eBroadcastAlways); |
| 1112 | m_public_is_running.SetValue (false, eBroadcastAlways); |
| 1113 | return state; |
| 1114 | } |
| 1115 | |
| 1116 | bool |
| 1117 | GDBRemoteCommunicationClient::SendAsyncSignal (int signo) |
| 1118 | { |
Greg Clayton | 2687cd1 | 2012-03-29 01:55:41 +0000 | [diff] [blame] | 1119 | Mutex::Locker async_locker (m_async_mutex); |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 1120 | m_async_signal = signo; |
| 1121 | bool timed_out = false; |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 1122 | Mutex::Locker locker; |
Greg Clayton | 2687cd1 | 2012-03-29 01:55:41 +0000 | [diff] [blame] | 1123 | if (SendInterrupt (locker, 1, timed_out)) |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 1124 | return true; |
| 1125 | m_async_signal = -1; |
| 1126 | return false; |
| 1127 | } |
| 1128 | |
Greg Clayton | 37a0a24 | 2012-04-11 00:24:49 +0000 | [diff] [blame] | 1129 | // 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] | 1130 | // actually succeeds. If it doesn't succeed in acquiring the sequence mutex |
| 1131 | // (the expected result), then it will send the halt packet. If it does succeed |
| 1132 | // then the caller that requested the interrupt will want to keep the sequence |
| 1133 | // locked down so that no one else can send packets while the caller has control. |
| 1134 | // This function usually gets called when we are running and need to stop the |
Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 1135 | // target. It can also be used when we are running and we need to do something |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 1136 | // else (like read/write memory), so we need to interrupt the running process |
| 1137 | // (gdb remote protocol requires this), and do what we need to do, then resume. |
| 1138 | |
| 1139 | bool |
Greg Clayton | 2687cd1 | 2012-03-29 01:55:41 +0000 | [diff] [blame] | 1140 | GDBRemoteCommunicationClient::SendInterrupt |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 1141 | ( |
| 1142 | Mutex::Locker& locker, |
| 1143 | uint32_t seconds_to_wait_for_stop, |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 1144 | bool &timed_out |
| 1145 | ) |
| 1146 | { |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 1147 | timed_out = false; |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1148 | Log *log (ProcessGDBRemoteLog::GetLogIfAnyCategoryIsSet (GDBR_LOG_PROCESS | GDBR_LOG_PACKETS)); |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 1149 | |
| 1150 | if (IsRunning()) |
| 1151 | { |
| 1152 | // Only send an interrupt if our debugserver is running... |
Greg Clayton | c3c0b0e | 2012-04-12 19:04:34 +0000 | [diff] [blame] | 1153 | if (GetSequenceMutex (locker)) |
Greg Clayton | 37a0a24 | 2012-04-11 00:24:49 +0000 | [diff] [blame] | 1154 | { |
| 1155 | if (log) |
| 1156 | log->Printf ("SendInterrupt () - got sequence mutex without having to interrupt"); |
| 1157 | } |
| 1158 | else |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 1159 | { |
| 1160 | // Someone has the mutex locked waiting for a response or for the |
| 1161 | // inferior to stop, so send the interrupt on the down low... |
| 1162 | char ctrl_c = '\x03'; |
| 1163 | ConnectionStatus status = eConnectionStatusSuccess; |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 1164 | size_t bytes_written = Write (&ctrl_c, 1, status, NULL); |
Greg Clayton | 2687cd1 | 2012-03-29 01:55:41 +0000 | [diff] [blame] | 1165 | if (log) |
| 1166 | log->PutCString("send packet: \\x03"); |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 1167 | if (bytes_written > 0) |
| 1168 | { |
Greg Clayton | 2687cd1 | 2012-03-29 01:55:41 +0000 | [diff] [blame] | 1169 | m_interrupt_sent = true; |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 1170 | if (seconds_to_wait_for_stop) |
| 1171 | { |
Greg Clayton | 2687cd1 | 2012-03-29 01:55:41 +0000 | [diff] [blame] | 1172 | TimeValue timeout; |
| 1173 | if (seconds_to_wait_for_stop) |
| 1174 | { |
| 1175 | timeout = TimeValue::Now(); |
| 1176 | timeout.OffsetWithSeconds (seconds_to_wait_for_stop); |
| 1177 | } |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 1178 | if (m_private_is_running.WaitForValueEqualTo (false, &timeout, &timed_out)) |
| 1179 | { |
| 1180 | if (log) |
Greg Clayton | 2687cd1 | 2012-03-29 01:55:41 +0000 | [diff] [blame] | 1181 | log->PutCString ("SendInterrupt () - sent interrupt, private state stopped"); |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 1182 | return true; |
| 1183 | } |
| 1184 | else |
| 1185 | { |
| 1186 | if (log) |
Greg Clayton | 2687cd1 | 2012-03-29 01:55:41 +0000 | [diff] [blame] | 1187 | log->Printf ("SendInterrupt () - sent interrupt, timed out wating for async thread resume"); |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 1188 | } |
| 1189 | } |
| 1190 | else |
| 1191 | { |
| 1192 | if (log) |
Greg Clayton | 2687cd1 | 2012-03-29 01:55:41 +0000 | [diff] [blame] | 1193 | log->Printf ("SendInterrupt () - sent interrupt, not waiting for stop..."); |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 1194 | return true; |
| 1195 | } |
| 1196 | } |
| 1197 | else |
| 1198 | { |
| 1199 | if (log) |
Greg Clayton | 2687cd1 | 2012-03-29 01:55:41 +0000 | [diff] [blame] | 1200 | log->Printf ("SendInterrupt () - failed to write interrupt"); |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 1201 | } |
| 1202 | return false; |
| 1203 | } |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 1204 | } |
Greg Clayton | 2687cd1 | 2012-03-29 01:55:41 +0000 | [diff] [blame] | 1205 | else |
| 1206 | { |
| 1207 | if (log) |
| 1208 | log->Printf ("SendInterrupt () - not running"); |
| 1209 | } |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 1210 | return true; |
| 1211 | } |
| 1212 | |
| 1213 | lldb::pid_t |
| 1214 | GDBRemoteCommunicationClient::GetCurrentProcessID () |
| 1215 | { |
Todd Fiala | 9f72b3a | 2014-05-07 19:28:21 +0000 | [diff] [blame] | 1216 | if (m_curr_pid_is_valid == eLazyBoolYes) |
| 1217 | return m_curr_pid; |
| 1218 | |
| 1219 | // First try to retrieve the pid via the qProcessInfo request. |
| 1220 | GetCurrentProcessInfo (); |
| 1221 | if (m_curr_pid_is_valid == eLazyBoolYes) |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 1222 | { |
Todd Fiala | 9f72b3a | 2014-05-07 19:28:21 +0000 | [diff] [blame] | 1223 | // We really got it. |
| 1224 | return m_curr_pid; |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 1225 | } |
Todd Fiala | 9f72b3a | 2014-05-07 19:28:21 +0000 | [diff] [blame] | 1226 | else |
| 1227 | { |
Todd Fiala | e24614f | 2014-05-14 00:15:32 +0000 | [diff] [blame] | 1228 | // If we don't get a response for qProcessInfo, check if $qC gives us a result. |
| 1229 | // $qC only returns a real process id on older debugserver and lldb-platform stubs. |
| 1230 | // The gdb remote protocol documents $qC as returning the thread id, which newer |
| 1231 | // debugserver and lldb-gdbserver stubs return correctly. |
| 1232 | StringExtractorGDBRemote response; |
| 1233 | if (SendPacketAndWaitForResponse("qC", strlen("qC"), response, false) == PacketResult::Success) |
Todd Fiala | 9f72b3a | 2014-05-07 19:28:21 +0000 | [diff] [blame] | 1234 | { |
Todd Fiala | e24614f | 2014-05-14 00:15:32 +0000 | [diff] [blame] | 1235 | if (response.GetChar() == 'Q') |
Todd Fiala | 9f72b3a | 2014-05-07 19:28:21 +0000 | [diff] [blame] | 1236 | { |
Todd Fiala | e24614f | 2014-05-14 00:15:32 +0000 | [diff] [blame] | 1237 | if (response.GetChar() == 'C') |
Todd Fiala | 9f72b3a | 2014-05-07 19:28:21 +0000 | [diff] [blame] | 1238 | { |
Todd Fiala | e24614f | 2014-05-14 00:15:32 +0000 | [diff] [blame] | 1239 | m_curr_pid = response.GetHexMaxU32 (false, LLDB_INVALID_PROCESS_ID); |
| 1240 | if (m_curr_pid != LLDB_INVALID_PROCESS_ID) |
Todd Fiala | 9f72b3a | 2014-05-07 19:28:21 +0000 | [diff] [blame] | 1241 | { |
Todd Fiala | e24614f | 2014-05-14 00:15:32 +0000 | [diff] [blame] | 1242 | m_curr_pid_is_valid = eLazyBoolYes; |
| 1243 | return m_curr_pid; |
Todd Fiala | 9f72b3a | 2014-05-07 19:28:21 +0000 | [diff] [blame] | 1244 | } |
| 1245 | } |
| 1246 | } |
| 1247 | } |
| 1248 | } |
| 1249 | |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 1250 | return LLDB_INVALID_PROCESS_ID; |
| 1251 | } |
| 1252 | |
| 1253 | bool |
| 1254 | GDBRemoteCommunicationClient::GetLaunchSuccess (std::string &error_str) |
| 1255 | { |
| 1256 | error_str.clear(); |
| 1257 | StringExtractorGDBRemote response; |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 1258 | if (SendPacketAndWaitForResponse("qLaunchSuccess", strlen("qLaunchSuccess"), response, false) == PacketResult::Success) |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 1259 | { |
| 1260 | if (response.IsOKResponse()) |
| 1261 | return true; |
| 1262 | if (response.GetChar() == 'E') |
| 1263 | { |
| 1264 | // A string the describes what failed when launching... |
| 1265 | error_str = response.GetStringRef().substr(1); |
| 1266 | } |
| 1267 | else |
| 1268 | { |
| 1269 | error_str.assign ("unknown error occurred launching process"); |
| 1270 | } |
| 1271 | } |
| 1272 | else |
| 1273 | { |
Jim Ingham | 98d6da5 | 2012-06-28 20:30:23 +0000 | [diff] [blame] | 1274 | error_str.assign ("timed out waiting for app to launch"); |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 1275 | } |
| 1276 | return false; |
| 1277 | } |
| 1278 | |
| 1279 | int |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 1280 | GDBRemoteCommunicationClient::SendArgumentsPacket (const ProcessLaunchInfo &launch_info) |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 1281 | { |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 1282 | // Since we don't get the send argv0 separate from the executable path, we need to |
Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 1283 | // make sure to use the actual executable path found in the launch_info... |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 1284 | std::vector<const char *> argv; |
| 1285 | FileSpec exe_file = launch_info.GetExecutableFile(); |
| 1286 | std::string exe_path; |
| 1287 | const char *arg = NULL; |
| 1288 | const Args &launch_args = launch_info.GetArguments(); |
| 1289 | if (exe_file) |
| 1290 | exe_path = exe_file.GetPath(); |
| 1291 | else |
| 1292 | { |
| 1293 | arg = launch_args.GetArgumentAtIndex(0); |
| 1294 | if (arg) |
| 1295 | exe_path = arg; |
| 1296 | } |
| 1297 | if (!exe_path.empty()) |
| 1298 | { |
| 1299 | argv.push_back(exe_path.c_str()); |
| 1300 | for (uint32_t i=1; (arg = launch_args.GetArgumentAtIndex(i)) != NULL; ++i) |
| 1301 | { |
| 1302 | if (arg) |
| 1303 | argv.push_back(arg); |
| 1304 | } |
| 1305 | } |
| 1306 | if (!argv.empty()) |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 1307 | { |
| 1308 | StreamString packet; |
| 1309 | packet.PutChar('A'); |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 1310 | for (size_t i = 0, n = argv.size(); i < n; ++i) |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 1311 | { |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 1312 | arg = argv[i]; |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 1313 | const int arg_len = strlen(arg); |
| 1314 | if (i > 0) |
| 1315 | packet.PutChar(','); |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 1316 | packet.Printf("%i,%i,", arg_len * 2, (int)i); |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 1317 | packet.PutBytesAsRawHex8 (arg, arg_len); |
| 1318 | } |
| 1319 | |
| 1320 | StringExtractorGDBRemote response; |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 1321 | if (SendPacketAndWaitForResponse (packet.GetData(), packet.GetSize(), response, false) == PacketResult::Success) |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 1322 | { |
| 1323 | if (response.IsOKResponse()) |
| 1324 | return 0; |
| 1325 | uint8_t error = response.GetError(); |
| 1326 | if (error) |
| 1327 | return error; |
| 1328 | } |
| 1329 | } |
| 1330 | return -1; |
| 1331 | } |
| 1332 | |
| 1333 | int |
| 1334 | GDBRemoteCommunicationClient::SendEnvironmentPacket (char const *name_equal_value) |
| 1335 | { |
| 1336 | if (name_equal_value && name_equal_value[0]) |
| 1337 | { |
| 1338 | StreamString packet; |
Greg Clayton | 8960058 | 2013-10-10 17:53:50 +0000 | [diff] [blame] | 1339 | bool send_hex_encoding = false; |
| 1340 | for (const char *p = name_equal_value; *p != '\0' && send_hex_encoding == false; ++p) |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 1341 | { |
Greg Clayton | 8960058 | 2013-10-10 17:53:50 +0000 | [diff] [blame] | 1342 | if (isprint(*p)) |
| 1343 | { |
| 1344 | switch (*p) |
| 1345 | { |
| 1346 | case '$': |
| 1347 | case '#': |
| 1348 | send_hex_encoding = true; |
| 1349 | break; |
| 1350 | default: |
| 1351 | break; |
| 1352 | } |
| 1353 | } |
| 1354 | else |
| 1355 | { |
| 1356 | // We have non printable characters, lets hex encode this... |
| 1357 | send_hex_encoding = true; |
| 1358 | } |
| 1359 | } |
| 1360 | |
| 1361 | StringExtractorGDBRemote response; |
| 1362 | if (send_hex_encoding) |
| 1363 | { |
| 1364 | if (m_supports_QEnvironmentHexEncoded) |
| 1365 | { |
| 1366 | packet.PutCString("QEnvironmentHexEncoded:"); |
| 1367 | packet.PutBytesAsRawHex8 (name_equal_value, strlen(name_equal_value)); |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 1368 | if (SendPacketAndWaitForResponse (packet.GetData(), packet.GetSize(), response, false) == PacketResult::Success) |
Greg Clayton | 8960058 | 2013-10-10 17:53:50 +0000 | [diff] [blame] | 1369 | { |
| 1370 | if (response.IsOKResponse()) |
| 1371 | return 0; |
| 1372 | uint8_t error = response.GetError(); |
| 1373 | if (error) |
| 1374 | return error; |
| 1375 | if (response.IsUnsupportedResponse()) |
| 1376 | m_supports_QEnvironmentHexEncoded = false; |
| 1377 | } |
| 1378 | } |
| 1379 | |
| 1380 | } |
| 1381 | else if (m_supports_QEnvironment) |
| 1382 | { |
| 1383 | packet.Printf("QEnvironment:%s", name_equal_value); |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 1384 | if (SendPacketAndWaitForResponse (packet.GetData(), packet.GetSize(), response, false) == PacketResult::Success) |
Greg Clayton | 8960058 | 2013-10-10 17:53:50 +0000 | [diff] [blame] | 1385 | { |
| 1386 | if (response.IsOKResponse()) |
| 1387 | return 0; |
| 1388 | uint8_t error = response.GetError(); |
| 1389 | if (error) |
| 1390 | return error; |
| 1391 | if (response.IsUnsupportedResponse()) |
| 1392 | m_supports_QEnvironment = false; |
| 1393 | } |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 1394 | } |
| 1395 | } |
| 1396 | return -1; |
| 1397 | } |
| 1398 | |
Greg Clayton | c4103b3 | 2011-05-08 04:53:50 +0000 | [diff] [blame] | 1399 | int |
| 1400 | GDBRemoteCommunicationClient::SendLaunchArchPacket (char const *arch) |
| 1401 | { |
| 1402 | if (arch && arch[0]) |
| 1403 | { |
| 1404 | StreamString packet; |
| 1405 | packet.Printf("QLaunchArch:%s", arch); |
| 1406 | StringExtractorGDBRemote response; |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 1407 | if (SendPacketAndWaitForResponse (packet.GetData(), packet.GetSize(), response, false) == PacketResult::Success) |
Greg Clayton | c4103b3 | 2011-05-08 04:53:50 +0000 | [diff] [blame] | 1408 | { |
| 1409 | if (response.IsOKResponse()) |
| 1410 | return 0; |
| 1411 | uint8_t error = response.GetError(); |
| 1412 | if (error) |
| 1413 | return error; |
| 1414 | } |
| 1415 | } |
| 1416 | return -1; |
| 1417 | } |
| 1418 | |
Jason Molenda | a332978 | 2014-03-29 18:54:20 +0000 | [diff] [blame] | 1419 | int |
| 1420 | GDBRemoteCommunicationClient::SendLaunchEventDataPacket (char const *data, bool *was_supported) |
| 1421 | { |
| 1422 | if (data && *data != '\0') |
| 1423 | { |
| 1424 | StreamString packet; |
| 1425 | packet.Printf("QSetProcessEvent:%s", data); |
| 1426 | StringExtractorGDBRemote response; |
| 1427 | if (SendPacketAndWaitForResponse (packet.GetData(), packet.GetSize(), response, false) == PacketResult::Success) |
| 1428 | { |
| 1429 | if (response.IsOKResponse()) |
| 1430 | { |
| 1431 | if (was_supported) |
| 1432 | *was_supported = true; |
| 1433 | return 0; |
| 1434 | } |
| 1435 | else if (response.IsUnsupportedResponse()) |
| 1436 | { |
| 1437 | if (was_supported) |
| 1438 | *was_supported = false; |
| 1439 | return -1; |
| 1440 | } |
| 1441 | else |
| 1442 | { |
| 1443 | uint8_t error = response.GetError(); |
| 1444 | if (was_supported) |
| 1445 | *was_supported = true; |
| 1446 | if (error) |
| 1447 | return error; |
| 1448 | } |
| 1449 | } |
| 1450 | } |
| 1451 | return -1; |
| 1452 | } |
| 1453 | |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 1454 | bool |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 1455 | GDBRemoteCommunicationClient::GetOSVersion (uint32_t &major, |
| 1456 | uint32_t &minor, |
| 1457 | uint32_t &update) |
| 1458 | { |
| 1459 | if (GetHostInfo ()) |
| 1460 | { |
| 1461 | if (m_os_version_major != UINT32_MAX) |
| 1462 | { |
| 1463 | major = m_os_version_major; |
| 1464 | minor = m_os_version_minor; |
| 1465 | update = m_os_version_update; |
| 1466 | return true; |
| 1467 | } |
| 1468 | } |
| 1469 | return false; |
| 1470 | } |
| 1471 | |
| 1472 | bool |
| 1473 | GDBRemoteCommunicationClient::GetOSBuildString (std::string &s) |
| 1474 | { |
| 1475 | if (GetHostInfo ()) |
| 1476 | { |
| 1477 | if (!m_os_build.empty()) |
| 1478 | { |
| 1479 | s = m_os_build; |
| 1480 | return true; |
| 1481 | } |
| 1482 | } |
| 1483 | s.clear(); |
| 1484 | return false; |
| 1485 | } |
| 1486 | |
| 1487 | |
| 1488 | bool |
| 1489 | GDBRemoteCommunicationClient::GetOSKernelDescription (std::string &s) |
| 1490 | { |
| 1491 | if (GetHostInfo ()) |
| 1492 | { |
| 1493 | if (!m_os_kernel.empty()) |
| 1494 | { |
| 1495 | s = m_os_kernel; |
| 1496 | return true; |
| 1497 | } |
| 1498 | } |
| 1499 | s.clear(); |
| 1500 | return false; |
| 1501 | } |
| 1502 | |
| 1503 | bool |
| 1504 | GDBRemoteCommunicationClient::GetHostname (std::string &s) |
| 1505 | { |
| 1506 | if (GetHostInfo ()) |
| 1507 | { |
| 1508 | if (!m_hostname.empty()) |
| 1509 | { |
| 1510 | s = m_hostname; |
| 1511 | return true; |
| 1512 | } |
| 1513 | } |
| 1514 | s.clear(); |
| 1515 | return false; |
| 1516 | } |
| 1517 | |
| 1518 | ArchSpec |
| 1519 | GDBRemoteCommunicationClient::GetSystemArchitecture () |
| 1520 | { |
| 1521 | if (GetHostInfo ()) |
| 1522 | return m_host_arch; |
| 1523 | return ArchSpec(); |
| 1524 | } |
| 1525 | |
Jason Molenda | f17b5ac | 2012-12-19 02:54:03 +0000 | [diff] [blame] | 1526 | const lldb_private::ArchSpec & |
| 1527 | GDBRemoteCommunicationClient::GetProcessArchitecture () |
| 1528 | { |
| 1529 | if (m_qProcessInfo_is_valid == eLazyBoolCalculate) |
| 1530 | GetCurrentProcessInfo (); |
| 1531 | return m_process_arch; |
| 1532 | } |
| 1533 | |
Jason Molenda | a332978 | 2014-03-29 18:54:20 +0000 | [diff] [blame] | 1534 | bool |
| 1535 | GDBRemoteCommunicationClient::GetGDBServerVersion() |
| 1536 | { |
| 1537 | if (m_qGDBServerVersion_is_valid == eLazyBoolCalculate) |
| 1538 | { |
| 1539 | m_gdb_server_name.clear(); |
| 1540 | m_gdb_server_version = 0; |
| 1541 | m_qGDBServerVersion_is_valid = eLazyBoolNo; |
| 1542 | |
| 1543 | StringExtractorGDBRemote response; |
| 1544 | if (SendPacketAndWaitForResponse ("qGDBServerVersion", response, false) == PacketResult::Success) |
| 1545 | { |
| 1546 | if (response.IsNormalResponse()) |
| 1547 | { |
| 1548 | std::string name; |
| 1549 | std::string value; |
| 1550 | bool success = false; |
| 1551 | while (response.GetNameColonValue(name, value)) |
| 1552 | { |
| 1553 | if (name.compare("name") == 0) |
| 1554 | { |
| 1555 | success = true; |
| 1556 | m_gdb_server_name.swap(value); |
| 1557 | } |
| 1558 | else if (name.compare("version") == 0) |
| 1559 | { |
| 1560 | size_t dot_pos = value.find('.'); |
| 1561 | if (dot_pos != std::string::npos) |
| 1562 | value[dot_pos] = '\0'; |
Vince Harron | 5275aaa | 2015-01-15 20:08:35 +0000 | [diff] [blame] | 1563 | const uint32_t version = StringConvert::ToUInt32(value.c_str(), UINT32_MAX, 0); |
Jason Molenda | a332978 | 2014-03-29 18:54:20 +0000 | [diff] [blame] | 1564 | if (version != UINT32_MAX) |
| 1565 | { |
| 1566 | success = true; |
| 1567 | m_gdb_server_version = version; |
| 1568 | } |
| 1569 | } |
| 1570 | } |
| 1571 | if (success) |
| 1572 | m_qGDBServerVersion_is_valid = eLazyBoolYes; |
| 1573 | } |
| 1574 | } |
| 1575 | } |
| 1576 | return m_qGDBServerVersion_is_valid == eLazyBoolYes; |
| 1577 | } |
| 1578 | |
| 1579 | const char * |
| 1580 | GDBRemoteCommunicationClient::GetGDBServerProgramName() |
| 1581 | { |
| 1582 | if (GetGDBServerVersion()) |
| 1583 | { |
| 1584 | if (!m_gdb_server_name.empty()) |
| 1585 | return m_gdb_server_name.c_str(); |
| 1586 | } |
| 1587 | return NULL; |
| 1588 | } |
| 1589 | |
| 1590 | uint32_t |
| 1591 | GDBRemoteCommunicationClient::GetGDBServerProgramVersion() |
| 1592 | { |
| 1593 | if (GetGDBServerVersion()) |
| 1594 | return m_gdb_server_version; |
| 1595 | return 0; |
| 1596 | } |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 1597 | |
| 1598 | bool |
Greg Clayton | 9b1e1cd | 2011-04-04 18:18:57 +0000 | [diff] [blame] | 1599 | GDBRemoteCommunicationClient::GetHostInfo (bool force) |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 1600 | { |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 1601 | Log *log (ProcessGDBRemoteLog::GetLogIfAnyCategoryIsSet (GDBR_LOG_PROCESS)); |
| 1602 | |
Greg Clayton | 9b1e1cd | 2011-04-04 18:18:57 +0000 | [diff] [blame] | 1603 | if (force || m_qHostInfo_is_valid == eLazyBoolCalculate) |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 1604 | { |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 1605 | m_qHostInfo_is_valid = eLazyBoolNo; |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 1606 | StringExtractorGDBRemote response; |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 1607 | if (SendPacketAndWaitForResponse ("qHostInfo", response, false) == PacketResult::Success) |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 1608 | { |
Greg Clayton | 17a0cb6 | 2011-05-15 23:46:54 +0000 | [diff] [blame] | 1609 | if (response.IsNormalResponse()) |
Greg Clayton | d314e81 | 2011-03-23 00:09:55 +0000 | [diff] [blame] | 1610 | { |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 1611 | std::string name; |
| 1612 | std::string value; |
| 1613 | uint32_t cpu = LLDB_INVALID_CPUTYPE; |
| 1614 | uint32_t sub = 0; |
| 1615 | std::string arch_name; |
| 1616 | std::string os_name; |
| 1617 | std::string vendor_name; |
| 1618 | std::string triple; |
Todd Fiala | a9ddb0e | 2014-01-18 03:02:39 +0000 | [diff] [blame] | 1619 | std::string distribution_id; |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 1620 | uint32_t pointer_byte_size = 0; |
| 1621 | StringExtractor extractor; |
| 1622 | ByteOrder byte_order = eByteOrderInvalid; |
| 1623 | uint32_t num_keys_decoded = 0; |
| 1624 | while (response.GetNameColonValue(name, value)) |
Greg Clayton | d314e81 | 2011-03-23 00:09:55 +0000 | [diff] [blame] | 1625 | { |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 1626 | if (name.compare("cputype") == 0) |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 1627 | { |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 1628 | // exception type in big endian hex |
Vince Harron | 5275aaa | 2015-01-15 20:08:35 +0000 | [diff] [blame] | 1629 | cpu = StringConvert::ToUInt32 (value.c_str(), LLDB_INVALID_CPUTYPE, 0); |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 1630 | if (cpu != LLDB_INVALID_CPUTYPE) |
| 1631 | ++num_keys_decoded; |
| 1632 | } |
| 1633 | else if (name.compare("cpusubtype") == 0) |
| 1634 | { |
| 1635 | // exception count in big endian hex |
Vince Harron | 5275aaa | 2015-01-15 20:08:35 +0000 | [diff] [blame] | 1636 | sub = StringConvert::ToUInt32 (value.c_str(), 0, 0); |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 1637 | if (sub != 0) |
| 1638 | ++num_keys_decoded; |
| 1639 | } |
| 1640 | else if (name.compare("arch") == 0) |
| 1641 | { |
| 1642 | arch_name.swap (value); |
| 1643 | ++num_keys_decoded; |
| 1644 | } |
| 1645 | else if (name.compare("triple") == 0) |
| 1646 | { |
Greg Clayton | 44272a4 | 2014-09-18 00:18:32 +0000 | [diff] [blame] | 1647 | extractor.GetStringRef ().swap (value); |
| 1648 | extractor.SetFilePos(0); |
| 1649 | extractor.GetHexByteString (triple); |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 1650 | ++num_keys_decoded; |
| 1651 | } |
Todd Fiala | a9ddb0e | 2014-01-18 03:02:39 +0000 | [diff] [blame] | 1652 | else if (name.compare ("distribution_id") == 0) |
| 1653 | { |
| 1654 | extractor.GetStringRef ().swap (value); |
| 1655 | extractor.SetFilePos (0); |
| 1656 | extractor.GetHexByteString (distribution_id); |
| 1657 | ++num_keys_decoded; |
| 1658 | } |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 1659 | else if (name.compare("os_build") == 0) |
| 1660 | { |
| 1661 | extractor.GetStringRef().swap(value); |
| 1662 | extractor.SetFilePos(0); |
| 1663 | extractor.GetHexByteString (m_os_build); |
| 1664 | ++num_keys_decoded; |
| 1665 | } |
| 1666 | else if (name.compare("hostname") == 0) |
| 1667 | { |
| 1668 | extractor.GetStringRef().swap(value); |
| 1669 | extractor.SetFilePos(0); |
| 1670 | extractor.GetHexByteString (m_hostname); |
| 1671 | ++num_keys_decoded; |
| 1672 | } |
| 1673 | else if (name.compare("os_kernel") == 0) |
| 1674 | { |
| 1675 | extractor.GetStringRef().swap(value); |
| 1676 | extractor.SetFilePos(0); |
| 1677 | extractor.GetHexByteString (m_os_kernel); |
| 1678 | ++num_keys_decoded; |
| 1679 | } |
| 1680 | else if (name.compare("ostype") == 0) |
| 1681 | { |
| 1682 | os_name.swap (value); |
| 1683 | ++num_keys_decoded; |
| 1684 | } |
| 1685 | else if (name.compare("vendor") == 0) |
| 1686 | { |
| 1687 | vendor_name.swap(value); |
| 1688 | ++num_keys_decoded; |
| 1689 | } |
| 1690 | else if (name.compare("endian") == 0) |
| 1691 | { |
| 1692 | ++num_keys_decoded; |
| 1693 | if (value.compare("little") == 0) |
| 1694 | byte_order = eByteOrderLittle; |
| 1695 | else if (value.compare("big") == 0) |
| 1696 | byte_order = eByteOrderBig; |
| 1697 | else if (value.compare("pdp") == 0) |
| 1698 | byte_order = eByteOrderPDP; |
| 1699 | else |
| 1700 | --num_keys_decoded; |
| 1701 | } |
| 1702 | else if (name.compare("ptrsize") == 0) |
| 1703 | { |
Vince Harron | 5275aaa | 2015-01-15 20:08:35 +0000 | [diff] [blame] | 1704 | pointer_byte_size = StringConvert::ToUInt32 (value.c_str(), 0, 0); |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 1705 | if (pointer_byte_size != 0) |
| 1706 | ++num_keys_decoded; |
| 1707 | } |
| 1708 | else if (name.compare("os_version") == 0) |
| 1709 | { |
| 1710 | Args::StringToVersion (value.c_str(), |
| 1711 | m_os_version_major, |
| 1712 | m_os_version_minor, |
| 1713 | m_os_version_update); |
| 1714 | if (m_os_version_major != UINT32_MAX) |
| 1715 | ++num_keys_decoded; |
| 1716 | } |
Enrico Granata | f04a219 | 2012-07-13 23:18:48 +0000 | [diff] [blame] | 1717 | else if (name.compare("watchpoint_exceptions_received") == 0) |
| 1718 | { |
| 1719 | ++num_keys_decoded; |
| 1720 | if (strcmp(value.c_str(),"before") == 0) |
| 1721 | m_watchpoints_trigger_after_instruction = eLazyBoolNo; |
| 1722 | else if (strcmp(value.c_str(),"after") == 0) |
| 1723 | m_watchpoints_trigger_after_instruction = eLazyBoolYes; |
| 1724 | else |
| 1725 | --num_keys_decoded; |
| 1726 | } |
Greg Clayton | 9ac6d2d | 2013-10-25 18:13:17 +0000 | [diff] [blame] | 1727 | else if (name.compare("default_packet_timeout") == 0) |
| 1728 | { |
Vince Harron | 5275aaa | 2015-01-15 20:08:35 +0000 | [diff] [blame] | 1729 | m_default_packet_timeout = StringConvert::ToUInt32(value.c_str(), 0); |
Greg Clayton | 9ac6d2d | 2013-10-25 18:13:17 +0000 | [diff] [blame] | 1730 | if (m_default_packet_timeout > 0) |
| 1731 | { |
| 1732 | SetPacketTimeout(m_default_packet_timeout); |
| 1733 | ++num_keys_decoded; |
| 1734 | } |
| 1735 | } |
Enrico Granata | f04a219 | 2012-07-13 23:18:48 +0000 | [diff] [blame] | 1736 | |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 1737 | } |
| 1738 | |
| 1739 | if (num_keys_decoded > 0) |
| 1740 | m_qHostInfo_is_valid = eLazyBoolYes; |
| 1741 | |
| 1742 | if (triple.empty()) |
| 1743 | { |
| 1744 | if (arch_name.empty()) |
| 1745 | { |
| 1746 | if (cpu != LLDB_INVALID_CPUTYPE) |
| 1747 | { |
| 1748 | m_host_arch.SetArchitecture (eArchTypeMachO, cpu, sub); |
| 1749 | if (pointer_byte_size) |
| 1750 | { |
| 1751 | assert (pointer_byte_size == m_host_arch.GetAddressByteSize()); |
| 1752 | } |
| 1753 | if (byte_order != eByteOrderInvalid) |
| 1754 | { |
| 1755 | assert (byte_order == m_host_arch.GetByteOrder()); |
| 1756 | } |
Greg Clayton | 7051231 | 2012-05-08 01:45:38 +0000 | [diff] [blame] | 1757 | |
| 1758 | if (!os_name.empty() && vendor_name.compare("apple") == 0 && os_name.find("darwin") == 0) |
| 1759 | { |
| 1760 | switch (m_host_arch.GetMachine()) |
| 1761 | { |
Todd Fiala | d8eaa17 | 2014-07-23 14:37:35 +0000 | [diff] [blame] | 1762 | case llvm::Triple::aarch64: |
Greg Clayton | 7051231 | 2012-05-08 01:45:38 +0000 | [diff] [blame] | 1763 | case llvm::Triple::arm: |
| 1764 | case llvm::Triple::thumb: |
| 1765 | os_name = "ios"; |
| 1766 | break; |
| 1767 | default: |
| 1768 | os_name = "macosx"; |
| 1769 | break; |
| 1770 | } |
| 1771 | } |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 1772 | if (!vendor_name.empty()) |
| 1773 | m_host_arch.GetTriple().setVendorName (llvm::StringRef (vendor_name)); |
| 1774 | if (!os_name.empty()) |
Greg Clayton | e1dadb8 | 2011-09-15 00:21:03 +0000 | [diff] [blame] | 1775 | m_host_arch.GetTriple().setOSName (llvm::StringRef (os_name)); |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 1776 | |
| 1777 | } |
| 1778 | } |
| 1779 | else |
| 1780 | { |
| 1781 | std::string triple; |
| 1782 | triple += arch_name; |
Greg Clayton | 7051231 | 2012-05-08 01:45:38 +0000 | [diff] [blame] | 1783 | if (!vendor_name.empty() || !os_name.empty()) |
| 1784 | { |
| 1785 | triple += '-'; |
| 1786 | if (vendor_name.empty()) |
| 1787 | triple += "unknown"; |
| 1788 | else |
| 1789 | triple += vendor_name; |
| 1790 | triple += '-'; |
| 1791 | if (os_name.empty()) |
| 1792 | triple += "unknown"; |
| 1793 | else |
| 1794 | triple += os_name; |
| 1795 | } |
| 1796 | m_host_arch.SetTriple (triple.c_str()); |
| 1797 | |
| 1798 | llvm::Triple &host_triple = m_host_arch.GetTriple(); |
| 1799 | if (host_triple.getVendor() == llvm::Triple::Apple && host_triple.getOS() == llvm::Triple::Darwin) |
| 1800 | { |
| 1801 | switch (m_host_arch.GetMachine()) |
| 1802 | { |
Todd Fiala | d8eaa17 | 2014-07-23 14:37:35 +0000 | [diff] [blame] | 1803 | case llvm::Triple::aarch64: |
Greg Clayton | 7051231 | 2012-05-08 01:45:38 +0000 | [diff] [blame] | 1804 | case llvm::Triple::arm: |
| 1805 | case llvm::Triple::thumb: |
| 1806 | host_triple.setOS(llvm::Triple::IOS); |
| 1807 | break; |
| 1808 | default: |
| 1809 | host_triple.setOS(llvm::Triple::MacOSX); |
| 1810 | break; |
| 1811 | } |
| 1812 | } |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 1813 | if (pointer_byte_size) |
| 1814 | { |
| 1815 | assert (pointer_byte_size == m_host_arch.GetAddressByteSize()); |
| 1816 | } |
| 1817 | if (byte_order != eByteOrderInvalid) |
| 1818 | { |
| 1819 | assert (byte_order == m_host_arch.GetByteOrder()); |
| 1820 | } |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 1821 | |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 1822 | } |
| 1823 | } |
| 1824 | else |
| 1825 | { |
Greg Clayton | 7051231 | 2012-05-08 01:45:38 +0000 | [diff] [blame] | 1826 | m_host_arch.SetTriple (triple.c_str()); |
Greg Clayton | d314e81 | 2011-03-23 00:09:55 +0000 | [diff] [blame] | 1827 | if (pointer_byte_size) |
| 1828 | { |
| 1829 | assert (pointer_byte_size == m_host_arch.GetAddressByteSize()); |
| 1830 | } |
| 1831 | if (byte_order != eByteOrderInvalid) |
| 1832 | { |
| 1833 | assert (byte_order == m_host_arch.GetByteOrder()); |
| 1834 | } |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 1835 | |
| 1836 | if (log) |
| 1837 | log->Printf ("GDBRemoteCommunicationClient::%s parsed host architecture as %s, triple as %s from triple text %s", __FUNCTION__, m_host_arch.GetArchitectureName () ? m_host_arch.GetArchitectureName () : "<null-arch-name>", m_host_arch.GetTriple ().getTriple ().c_str(), triple.c_str ()); |
Todd Fiala | a9ddb0e | 2014-01-18 03:02:39 +0000 | [diff] [blame] | 1838 | } |
| 1839 | if (!distribution_id.empty ()) |
| 1840 | m_host_arch.SetDistributionId (distribution_id.c_str ()); |
Greg Clayton | d314e81 | 2011-03-23 00:09:55 +0000 | [diff] [blame] | 1841 | } |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 1842 | } |
| 1843 | } |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 1844 | return m_qHostInfo_is_valid == eLazyBoolYes; |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 1845 | } |
| 1846 | |
| 1847 | int |
| 1848 | GDBRemoteCommunicationClient::SendAttach |
| 1849 | ( |
| 1850 | lldb::pid_t pid, |
| 1851 | StringExtractorGDBRemote& response |
| 1852 | ) |
| 1853 | { |
| 1854 | if (pid != LLDB_INVALID_PROCESS_ID) |
| 1855 | { |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 1856 | char packet[64]; |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 1857 | const int packet_len = ::snprintf (packet, sizeof(packet), "vAttach;%" PRIx64, pid); |
Andy Gibbs | a297a97 | 2013-06-19 19:04:53 +0000 | [diff] [blame] | 1858 | assert (packet_len < (int)sizeof(packet)); |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 1859 | if (SendPacketAndWaitForResponse (packet, packet_len, response, false) == PacketResult::Success) |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 1860 | { |
| 1861 | if (response.IsErrorResponse()) |
| 1862 | return response.GetError(); |
| 1863 | return 0; |
| 1864 | } |
| 1865 | } |
| 1866 | return -1; |
| 1867 | } |
| 1868 | |
| 1869 | const lldb_private::ArchSpec & |
| 1870 | GDBRemoteCommunicationClient::GetHostArchitecture () |
| 1871 | { |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 1872 | if (m_qHostInfo_is_valid == eLazyBoolCalculate) |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 1873 | GetHostInfo (); |
Greg Clayton | d314e81 | 2011-03-23 00:09:55 +0000 | [diff] [blame] | 1874 | return m_host_arch; |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 1875 | } |
| 1876 | |
Greg Clayton | 9ac6d2d | 2013-10-25 18:13:17 +0000 | [diff] [blame] | 1877 | uint32_t |
| 1878 | GDBRemoteCommunicationClient::GetHostDefaultPacketTimeout () |
| 1879 | { |
| 1880 | if (m_qHostInfo_is_valid == eLazyBoolCalculate) |
| 1881 | GetHostInfo (); |
| 1882 | return m_default_packet_timeout; |
| 1883 | } |
| 1884 | |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 1885 | addr_t |
| 1886 | GDBRemoteCommunicationClient::AllocateMemory (size_t size, uint32_t permissions) |
| 1887 | { |
Greg Clayton | 70b5765 | 2011-05-15 01:25:55 +0000 | [diff] [blame] | 1888 | if (m_supports_alloc_dealloc_memory != eLazyBoolNo) |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 1889 | { |
Greg Clayton | 70b5765 | 2011-05-15 01:25:55 +0000 | [diff] [blame] | 1890 | m_supports_alloc_dealloc_memory = eLazyBoolYes; |
Greg Clayton | 2a48f52 | 2011-05-14 01:50:35 +0000 | [diff] [blame] | 1891 | char packet[64]; |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 1892 | 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] | 1893 | (uint64_t)size, |
Greg Clayton | 2a48f52 | 2011-05-14 01:50:35 +0000 | [diff] [blame] | 1894 | permissions & lldb::ePermissionsReadable ? "r" : "", |
| 1895 | permissions & lldb::ePermissionsWritable ? "w" : "", |
| 1896 | permissions & lldb::ePermissionsExecutable ? "x" : ""); |
Andy Gibbs | a297a97 | 2013-06-19 19:04:53 +0000 | [diff] [blame] | 1897 | assert (packet_len < (int)sizeof(packet)); |
Greg Clayton | 2a48f52 | 2011-05-14 01:50:35 +0000 | [diff] [blame] | 1898 | StringExtractorGDBRemote response; |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 1899 | if (SendPacketAndWaitForResponse (packet, packet_len, response, false) == PacketResult::Success) |
Greg Clayton | 2a48f52 | 2011-05-14 01:50:35 +0000 | [diff] [blame] | 1900 | { |
Todd Fiala | f105f58 | 2014-06-21 00:48:09 +0000 | [diff] [blame] | 1901 | if (response.IsUnsupportedResponse()) |
| 1902 | m_supports_alloc_dealloc_memory = eLazyBoolNo; |
| 1903 | else if (!response.IsErrorResponse()) |
Greg Clayton | 2a48f52 | 2011-05-14 01:50:35 +0000 | [diff] [blame] | 1904 | return response.GetHexMaxU64(false, LLDB_INVALID_ADDRESS); |
| 1905 | } |
Greg Clayton | 17a0cb6 | 2011-05-15 23:46:54 +0000 | [diff] [blame] | 1906 | else |
| 1907 | { |
| 1908 | m_supports_alloc_dealloc_memory = eLazyBoolNo; |
| 1909 | } |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 1910 | } |
| 1911 | return LLDB_INVALID_ADDRESS; |
| 1912 | } |
| 1913 | |
| 1914 | bool |
| 1915 | GDBRemoteCommunicationClient::DeallocateMemory (addr_t addr) |
| 1916 | { |
Greg Clayton | 70b5765 | 2011-05-15 01:25:55 +0000 | [diff] [blame] | 1917 | if (m_supports_alloc_dealloc_memory != eLazyBoolNo) |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 1918 | { |
Greg Clayton | 70b5765 | 2011-05-15 01:25:55 +0000 | [diff] [blame] | 1919 | m_supports_alloc_dealloc_memory = eLazyBoolYes; |
Greg Clayton | 2a48f52 | 2011-05-14 01:50:35 +0000 | [diff] [blame] | 1920 | char packet[64]; |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 1921 | 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] | 1922 | assert (packet_len < (int)sizeof(packet)); |
Greg Clayton | 2a48f52 | 2011-05-14 01:50:35 +0000 | [diff] [blame] | 1923 | StringExtractorGDBRemote response; |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 1924 | if (SendPacketAndWaitForResponse (packet, packet_len, response, false) == PacketResult::Success) |
Greg Clayton | 2a48f52 | 2011-05-14 01:50:35 +0000 | [diff] [blame] | 1925 | { |
Todd Fiala | f105f58 | 2014-06-21 00:48:09 +0000 | [diff] [blame] | 1926 | if (response.IsUnsupportedResponse()) |
| 1927 | m_supports_alloc_dealloc_memory = eLazyBoolNo; |
| 1928 | else if (response.IsOKResponse()) |
Greg Clayton | 2a48f52 | 2011-05-14 01:50:35 +0000 | [diff] [blame] | 1929 | return true; |
Greg Clayton | 17a0cb6 | 2011-05-15 23:46:54 +0000 | [diff] [blame] | 1930 | } |
| 1931 | else |
| 1932 | { |
| 1933 | m_supports_alloc_dealloc_memory = eLazyBoolNo; |
Greg Clayton | 2a48f52 | 2011-05-14 01:50:35 +0000 | [diff] [blame] | 1934 | } |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 1935 | } |
| 1936 | return false; |
| 1937 | } |
| 1938 | |
Jim Ingham | acff895 | 2013-05-02 00:27:30 +0000 | [diff] [blame] | 1939 | Error |
| 1940 | GDBRemoteCommunicationClient::Detach (bool keep_stopped) |
Greg Clayton | 37a0a24 | 2012-04-11 00:24:49 +0000 | [diff] [blame] | 1941 | { |
Jim Ingham | acff895 | 2013-05-02 00:27:30 +0000 | [diff] [blame] | 1942 | Error error; |
| 1943 | |
| 1944 | if (keep_stopped) |
| 1945 | { |
| 1946 | if (m_supports_detach_stay_stopped == eLazyBoolCalculate) |
| 1947 | { |
| 1948 | char packet[64]; |
| 1949 | const int packet_len = ::snprintf(packet, sizeof(packet), "qSupportsDetachAndStayStopped:"); |
Andy Gibbs | a297a97 | 2013-06-19 19:04:53 +0000 | [diff] [blame] | 1950 | assert (packet_len < (int)sizeof(packet)); |
Jim Ingham | acff895 | 2013-05-02 00:27:30 +0000 | [diff] [blame] | 1951 | StringExtractorGDBRemote response; |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 1952 | if (SendPacketAndWaitForResponse (packet, packet_len, response, false) == PacketResult::Success) |
Jim Ingham | acff895 | 2013-05-02 00:27:30 +0000 | [diff] [blame] | 1953 | { |
| 1954 | m_supports_detach_stay_stopped = eLazyBoolYes; |
| 1955 | } |
| 1956 | else |
| 1957 | { |
| 1958 | m_supports_detach_stay_stopped = eLazyBoolNo; |
| 1959 | } |
| 1960 | } |
| 1961 | |
| 1962 | if (m_supports_detach_stay_stopped == eLazyBoolNo) |
| 1963 | { |
| 1964 | error.SetErrorString("Stays stopped not supported by this target."); |
| 1965 | return error; |
| 1966 | } |
| 1967 | else |
| 1968 | { |
Jim Ingham | 6c8824d | 2014-03-28 20:00:07 +0000 | [diff] [blame] | 1969 | StringExtractorGDBRemote response; |
| 1970 | PacketResult packet_result = SendPacketAndWaitForResponse ("D1", 1, response, false); |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 1971 | if (packet_result != PacketResult::Success) |
Jim Ingham | acff895 | 2013-05-02 00:27:30 +0000 | [diff] [blame] | 1972 | error.SetErrorString ("Sending extended disconnect packet failed."); |
| 1973 | } |
| 1974 | } |
| 1975 | else |
| 1976 | { |
Jim Ingham | 6c8824d | 2014-03-28 20:00:07 +0000 | [diff] [blame] | 1977 | StringExtractorGDBRemote response; |
| 1978 | PacketResult packet_result = SendPacketAndWaitForResponse ("D", 1, response, false); |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 1979 | if (packet_result != PacketResult::Success) |
Jim Ingham | acff895 | 2013-05-02 00:27:30 +0000 | [diff] [blame] | 1980 | error.SetErrorString ("Sending disconnect packet failed."); |
| 1981 | } |
| 1982 | return error; |
Greg Clayton | 37a0a24 | 2012-04-11 00:24:49 +0000 | [diff] [blame] | 1983 | } |
| 1984 | |
Greg Clayton | 46fb558 | 2011-11-18 07:03:08 +0000 | [diff] [blame] | 1985 | Error |
| 1986 | GDBRemoteCommunicationClient::GetMemoryRegionInfo (lldb::addr_t addr, |
| 1987 | lldb_private::MemoryRegionInfo ®ion_info) |
| 1988 | { |
| 1989 | Error error; |
| 1990 | region_info.Clear(); |
| 1991 | |
| 1992 | if (m_supports_memory_region_info != eLazyBoolNo) |
| 1993 | { |
| 1994 | m_supports_memory_region_info = eLazyBoolYes; |
| 1995 | char packet[64]; |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 1996 | 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] | 1997 | assert (packet_len < (int)sizeof(packet)); |
Greg Clayton | 46fb558 | 2011-11-18 07:03:08 +0000 | [diff] [blame] | 1998 | StringExtractorGDBRemote response; |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 1999 | if (SendPacketAndWaitForResponse (packet, packet_len, response, false) == PacketResult::Success) |
Greg Clayton | 46fb558 | 2011-11-18 07:03:08 +0000 | [diff] [blame] | 2000 | { |
| 2001 | std::string name; |
| 2002 | std::string value; |
| 2003 | addr_t addr_value; |
| 2004 | bool success = true; |
Jason Molenda | cb349ee | 2011-12-13 05:39:38 +0000 | [diff] [blame] | 2005 | bool saw_permissions = false; |
Greg Clayton | 46fb558 | 2011-11-18 07:03:08 +0000 | [diff] [blame] | 2006 | while (success && response.GetNameColonValue(name, value)) |
| 2007 | { |
| 2008 | if (name.compare ("start") == 0) |
| 2009 | { |
Vince Harron | 5275aaa | 2015-01-15 20:08:35 +0000 | [diff] [blame] | 2010 | addr_value = StringConvert::ToUInt64(value.c_str(), LLDB_INVALID_ADDRESS, 16, &success); |
Greg Clayton | 46fb558 | 2011-11-18 07:03:08 +0000 | [diff] [blame] | 2011 | if (success) |
| 2012 | region_info.GetRange().SetRangeBase(addr_value); |
| 2013 | } |
| 2014 | else if (name.compare ("size") == 0) |
| 2015 | { |
Vince Harron | 5275aaa | 2015-01-15 20:08:35 +0000 | [diff] [blame] | 2016 | addr_value = StringConvert::ToUInt64(value.c_str(), 0, 16, &success); |
Greg Clayton | 46fb558 | 2011-11-18 07:03:08 +0000 | [diff] [blame] | 2017 | if (success) |
| 2018 | region_info.GetRange().SetByteSize (addr_value); |
| 2019 | } |
Jason Molenda | cb349ee | 2011-12-13 05:39:38 +0000 | [diff] [blame] | 2020 | else if (name.compare ("permissions") == 0 && region_info.GetRange().IsValid()) |
Greg Clayton | 46fb558 | 2011-11-18 07:03:08 +0000 | [diff] [blame] | 2021 | { |
Jason Molenda | cb349ee | 2011-12-13 05:39:38 +0000 | [diff] [blame] | 2022 | saw_permissions = true; |
| 2023 | if (region_info.GetRange().Contains (addr)) |
| 2024 | { |
| 2025 | if (value.find('r') != std::string::npos) |
| 2026 | region_info.SetReadable (MemoryRegionInfo::eYes); |
| 2027 | else |
| 2028 | region_info.SetReadable (MemoryRegionInfo::eNo); |
| 2029 | |
| 2030 | if (value.find('w') != std::string::npos) |
| 2031 | region_info.SetWritable (MemoryRegionInfo::eYes); |
| 2032 | else |
| 2033 | region_info.SetWritable (MemoryRegionInfo::eNo); |
| 2034 | |
| 2035 | if (value.find('x') != std::string::npos) |
| 2036 | region_info.SetExecutable (MemoryRegionInfo::eYes); |
| 2037 | else |
| 2038 | region_info.SetExecutable (MemoryRegionInfo::eNo); |
| 2039 | } |
| 2040 | else |
| 2041 | { |
| 2042 | // The reported region does not contain this address -- we're looking at an unmapped page |
| 2043 | region_info.SetReadable (MemoryRegionInfo::eNo); |
| 2044 | region_info.SetWritable (MemoryRegionInfo::eNo); |
| 2045 | region_info.SetExecutable (MemoryRegionInfo::eNo); |
| 2046 | } |
Greg Clayton | 46fb558 | 2011-11-18 07:03:08 +0000 | [diff] [blame] | 2047 | } |
| 2048 | else if (name.compare ("error") == 0) |
| 2049 | { |
| 2050 | StringExtractorGDBRemote name_extractor; |
| 2051 | // Swap "value" over into "name_extractor" |
| 2052 | name_extractor.GetStringRef().swap(value); |
| 2053 | // Now convert the HEX bytes into a string value |
| 2054 | name_extractor.GetHexByteString (value); |
| 2055 | error.SetErrorString(value.c_str()); |
| 2056 | } |
| 2057 | } |
Jason Molenda | cb349ee | 2011-12-13 05:39:38 +0000 | [diff] [blame] | 2058 | |
| 2059 | // We got a valid address range back but no permissions -- which means this is an unmapped page |
| 2060 | if (region_info.GetRange().IsValid() && saw_permissions == false) |
| 2061 | { |
| 2062 | region_info.SetReadable (MemoryRegionInfo::eNo); |
| 2063 | region_info.SetWritable (MemoryRegionInfo::eNo); |
| 2064 | region_info.SetExecutable (MemoryRegionInfo::eNo); |
| 2065 | } |
Greg Clayton | 46fb558 | 2011-11-18 07:03:08 +0000 | [diff] [blame] | 2066 | } |
| 2067 | else |
| 2068 | { |
| 2069 | m_supports_memory_region_info = eLazyBoolNo; |
| 2070 | } |
| 2071 | } |
| 2072 | |
| 2073 | if (m_supports_memory_region_info == eLazyBoolNo) |
| 2074 | { |
| 2075 | error.SetErrorString("qMemoryRegionInfo is not supported"); |
| 2076 | } |
| 2077 | if (error.Fail()) |
| 2078 | region_info.Clear(); |
| 2079 | return error; |
| 2080 | |
| 2081 | } |
| 2082 | |
Johnny Chen | 6463720 | 2012-05-23 21:09:52 +0000 | [diff] [blame] | 2083 | Error |
| 2084 | GDBRemoteCommunicationClient::GetWatchpointSupportInfo (uint32_t &num) |
| 2085 | { |
| 2086 | Error error; |
| 2087 | |
| 2088 | if (m_supports_watchpoint_support_info == eLazyBoolYes) |
| 2089 | { |
| 2090 | num = m_num_supported_hardware_watchpoints; |
| 2091 | return error; |
| 2092 | } |
| 2093 | |
| 2094 | // Set num to 0 first. |
| 2095 | num = 0; |
| 2096 | if (m_supports_watchpoint_support_info != eLazyBoolNo) |
| 2097 | { |
| 2098 | char packet[64]; |
| 2099 | const int packet_len = ::snprintf(packet, sizeof(packet), "qWatchpointSupportInfo:"); |
Andy Gibbs | a297a97 | 2013-06-19 19:04:53 +0000 | [diff] [blame] | 2100 | assert (packet_len < (int)sizeof(packet)); |
Johnny Chen | 6463720 | 2012-05-23 21:09:52 +0000 | [diff] [blame] | 2101 | StringExtractorGDBRemote response; |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 2102 | if (SendPacketAndWaitForResponse (packet, packet_len, response, false) == PacketResult::Success) |
Johnny Chen | 6463720 | 2012-05-23 21:09:52 +0000 | [diff] [blame] | 2103 | { |
| 2104 | m_supports_watchpoint_support_info = eLazyBoolYes; |
| 2105 | std::string name; |
| 2106 | std::string value; |
| 2107 | while (response.GetNameColonValue(name, value)) |
| 2108 | { |
| 2109 | if (name.compare ("num") == 0) |
| 2110 | { |
Vince Harron | 5275aaa | 2015-01-15 20:08:35 +0000 | [diff] [blame] | 2111 | num = StringConvert::ToUInt32(value.c_str(), 0, 0); |
Johnny Chen | 6463720 | 2012-05-23 21:09:52 +0000 | [diff] [blame] | 2112 | m_num_supported_hardware_watchpoints = num; |
| 2113 | } |
| 2114 | } |
| 2115 | } |
| 2116 | else |
| 2117 | { |
| 2118 | m_supports_watchpoint_support_info = eLazyBoolNo; |
| 2119 | } |
| 2120 | } |
| 2121 | |
| 2122 | if (m_supports_watchpoint_support_info == eLazyBoolNo) |
| 2123 | { |
| 2124 | error.SetErrorString("qWatchpointSupportInfo is not supported"); |
| 2125 | } |
| 2126 | return error; |
| 2127 | |
| 2128 | } |
Greg Clayton | 46fb558 | 2011-11-18 07:03:08 +0000 | [diff] [blame] | 2129 | |
Enrico Granata | f04a219 | 2012-07-13 23:18:48 +0000 | [diff] [blame] | 2130 | lldb_private::Error |
| 2131 | GDBRemoteCommunicationClient::GetWatchpointSupportInfo (uint32_t &num, bool& after) |
| 2132 | { |
| 2133 | Error error(GetWatchpointSupportInfo(num)); |
| 2134 | if (error.Success()) |
| 2135 | error = GetWatchpointsTriggerAfterInstruction(after); |
| 2136 | return error; |
| 2137 | } |
| 2138 | |
| 2139 | lldb_private::Error |
| 2140 | GDBRemoteCommunicationClient::GetWatchpointsTriggerAfterInstruction (bool &after) |
| 2141 | { |
| 2142 | Error error; |
| 2143 | |
| 2144 | // we assume watchpoints will happen after running the relevant opcode |
| 2145 | // and we only want to override this behavior if we have explicitly |
| 2146 | // received a qHostInfo telling us otherwise |
| 2147 | if (m_qHostInfo_is_valid != eLazyBoolYes) |
| 2148 | after = true; |
| 2149 | else |
| 2150 | after = (m_watchpoints_trigger_after_instruction != eLazyBoolNo); |
| 2151 | return error; |
| 2152 | } |
| 2153 | |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 2154 | int |
| 2155 | GDBRemoteCommunicationClient::SetSTDIN (char const *path) |
| 2156 | { |
| 2157 | if (path && path[0]) |
| 2158 | { |
| 2159 | StreamString packet; |
| 2160 | packet.PutCString("QSetSTDIN:"); |
| 2161 | packet.PutBytesAsRawHex8(path, strlen(path)); |
| 2162 | |
| 2163 | StringExtractorGDBRemote response; |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 2164 | if (SendPacketAndWaitForResponse (packet.GetData(), packet.GetSize(), response, false) == PacketResult::Success) |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 2165 | { |
| 2166 | if (response.IsOKResponse()) |
| 2167 | return 0; |
| 2168 | uint8_t error = response.GetError(); |
| 2169 | if (error) |
| 2170 | return error; |
| 2171 | } |
| 2172 | } |
| 2173 | return -1; |
| 2174 | } |
| 2175 | |
| 2176 | int |
| 2177 | GDBRemoteCommunicationClient::SetSTDOUT (char const *path) |
| 2178 | { |
| 2179 | if (path && path[0]) |
| 2180 | { |
| 2181 | StreamString packet; |
| 2182 | packet.PutCString("QSetSTDOUT:"); |
| 2183 | packet.PutBytesAsRawHex8(path, strlen(path)); |
| 2184 | |
| 2185 | StringExtractorGDBRemote response; |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 2186 | if (SendPacketAndWaitForResponse (packet.GetData(), packet.GetSize(), response, false) == PacketResult::Success) |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 2187 | { |
| 2188 | if (response.IsOKResponse()) |
| 2189 | return 0; |
| 2190 | uint8_t error = response.GetError(); |
| 2191 | if (error) |
| 2192 | return error; |
| 2193 | } |
| 2194 | } |
| 2195 | return -1; |
| 2196 | } |
| 2197 | |
| 2198 | int |
| 2199 | GDBRemoteCommunicationClient::SetSTDERR (char const *path) |
| 2200 | { |
| 2201 | if (path && path[0]) |
| 2202 | { |
| 2203 | StreamString packet; |
| 2204 | packet.PutCString("QSetSTDERR:"); |
| 2205 | packet.PutBytesAsRawHex8(path, strlen(path)); |
| 2206 | |
| 2207 | StringExtractorGDBRemote response; |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 2208 | if (SendPacketAndWaitForResponse (packet.GetData(), packet.GetSize(), response, false) == PacketResult::Success) |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 2209 | { |
| 2210 | if (response.IsOKResponse()) |
| 2211 | return 0; |
| 2212 | uint8_t error = response.GetError(); |
| 2213 | if (error) |
| 2214 | return error; |
| 2215 | } |
| 2216 | } |
| 2217 | return -1; |
| 2218 | } |
| 2219 | |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 2220 | bool |
| 2221 | GDBRemoteCommunicationClient::GetWorkingDir (std::string &cwd) |
| 2222 | { |
| 2223 | StringExtractorGDBRemote response; |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 2224 | if (SendPacketAndWaitForResponse ("qGetWorkingDir", response, false) == PacketResult::Success) |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 2225 | { |
| 2226 | if (response.IsUnsupportedResponse()) |
| 2227 | return false; |
| 2228 | if (response.IsErrorResponse()) |
| 2229 | return false; |
| 2230 | response.GetHexByteString (cwd); |
| 2231 | return !cwd.empty(); |
| 2232 | } |
| 2233 | return false; |
| 2234 | } |
| 2235 | |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 2236 | int |
| 2237 | GDBRemoteCommunicationClient::SetWorkingDir (char const *path) |
| 2238 | { |
| 2239 | if (path && path[0]) |
| 2240 | { |
| 2241 | StreamString packet; |
| 2242 | packet.PutCString("QSetWorkingDir:"); |
| 2243 | packet.PutBytesAsRawHex8(path, strlen(path)); |
| 2244 | |
| 2245 | StringExtractorGDBRemote response; |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 2246 | if (SendPacketAndWaitForResponse (packet.GetData(), packet.GetSize(), response, false) == PacketResult::Success) |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 2247 | { |
| 2248 | if (response.IsOKResponse()) |
| 2249 | return 0; |
| 2250 | uint8_t error = response.GetError(); |
| 2251 | if (error) |
| 2252 | return error; |
| 2253 | } |
| 2254 | } |
| 2255 | return -1; |
| 2256 | } |
| 2257 | |
| 2258 | int |
| 2259 | GDBRemoteCommunicationClient::SetDisableASLR (bool enable) |
| 2260 | { |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 2261 | char packet[32]; |
| 2262 | 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] | 2263 | assert (packet_len < (int)sizeof(packet)); |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 2264 | StringExtractorGDBRemote response; |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 2265 | if (SendPacketAndWaitForResponse (packet, packet_len, response, false) == PacketResult::Success) |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 2266 | { |
| 2267 | if (response.IsOKResponse()) |
| 2268 | return 0; |
| 2269 | uint8_t error = response.GetError(); |
| 2270 | if (error) |
| 2271 | return error; |
| 2272 | } |
| 2273 | return -1; |
| 2274 | } |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 2275 | |
Jim Ingham | 106d028 | 2014-06-25 02:32:56 +0000 | [diff] [blame] | 2276 | int |
| 2277 | GDBRemoteCommunicationClient::SetDetachOnError (bool enable) |
| 2278 | { |
| 2279 | char packet[32]; |
| 2280 | const int packet_len = ::snprintf (packet, sizeof (packet), "QSetDetachOnError:%i", enable ? 1 : 0); |
| 2281 | assert (packet_len < (int)sizeof(packet)); |
| 2282 | StringExtractorGDBRemote response; |
| 2283 | if (SendPacketAndWaitForResponse (packet, packet_len, response, false) == PacketResult::Success) |
| 2284 | { |
| 2285 | if (response.IsOKResponse()) |
| 2286 | return 0; |
| 2287 | uint8_t error = response.GetError(); |
| 2288 | if (error) |
| 2289 | return error; |
| 2290 | } |
| 2291 | return -1; |
| 2292 | } |
| 2293 | |
| 2294 | |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 2295 | bool |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 2296 | GDBRemoteCommunicationClient::DecodeProcessInfoResponse (StringExtractorGDBRemote &response, ProcessInstanceInfo &process_info) |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 2297 | { |
| 2298 | if (response.IsNormalResponse()) |
| 2299 | { |
| 2300 | std::string name; |
| 2301 | std::string value; |
| 2302 | StringExtractor extractor; |
Jason Molenda | 89c3749 | 2014-01-27 22:23:20 +0000 | [diff] [blame] | 2303 | |
| 2304 | uint32_t cpu = LLDB_INVALID_CPUTYPE; |
| 2305 | uint32_t sub = 0; |
| 2306 | std::string vendor; |
| 2307 | std::string os_type; |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 2308 | |
| 2309 | while (response.GetNameColonValue(name, value)) |
| 2310 | { |
| 2311 | if (name.compare("pid") == 0) |
| 2312 | { |
Vince Harron | 5275aaa | 2015-01-15 20:08:35 +0000 | [diff] [blame] | 2313 | process_info.SetProcessID (StringConvert::ToUInt32 (value.c_str(), LLDB_INVALID_PROCESS_ID, 0)); |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 2314 | } |
| 2315 | else if (name.compare("ppid") == 0) |
| 2316 | { |
Vince Harron | 5275aaa | 2015-01-15 20:08:35 +0000 | [diff] [blame] | 2317 | process_info.SetParentProcessID (StringConvert::ToUInt32 (value.c_str(), LLDB_INVALID_PROCESS_ID, 0)); |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 2318 | } |
| 2319 | else if (name.compare("uid") == 0) |
| 2320 | { |
Vince Harron | 5275aaa | 2015-01-15 20:08:35 +0000 | [diff] [blame] | 2321 | process_info.SetUserID (StringConvert::ToUInt32 (value.c_str(), UINT32_MAX, 0)); |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 2322 | } |
| 2323 | else if (name.compare("euid") == 0) |
| 2324 | { |
Vince Harron | 5275aaa | 2015-01-15 20:08:35 +0000 | [diff] [blame] | 2325 | process_info.SetEffectiveUserID (StringConvert::ToUInt32 (value.c_str(), UINT32_MAX, 0)); |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 2326 | } |
| 2327 | else if (name.compare("gid") == 0) |
| 2328 | { |
Vince Harron | 5275aaa | 2015-01-15 20:08:35 +0000 | [diff] [blame] | 2329 | process_info.SetGroupID (StringConvert::ToUInt32 (value.c_str(), UINT32_MAX, 0)); |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 2330 | } |
| 2331 | else if (name.compare("egid") == 0) |
| 2332 | { |
Vince Harron | 5275aaa | 2015-01-15 20:08:35 +0000 | [diff] [blame] | 2333 | process_info.SetEffectiveGroupID (StringConvert::ToUInt32 (value.c_str(), UINT32_MAX, 0)); |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 2334 | } |
| 2335 | else if (name.compare("triple") == 0) |
| 2336 | { |
Greg Clayton | 44272a4 | 2014-09-18 00:18:32 +0000 | [diff] [blame] | 2337 | StringExtractor extractor; |
| 2338 | extractor.GetStringRef().swap(value); |
| 2339 | extractor.SetFilePos(0); |
| 2340 | extractor.GetHexByteString (value); |
Greg Clayton | 7051231 | 2012-05-08 01:45:38 +0000 | [diff] [blame] | 2341 | process_info.GetArchitecture ().SetTriple (value.c_str()); |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 2342 | } |
| 2343 | else if (name.compare("name") == 0) |
| 2344 | { |
| 2345 | StringExtractor extractor; |
Filipe Cabecinhas | f86cf78 | 2012-05-07 09:30:51 +0000 | [diff] [blame] | 2346 | // The process name from ASCII hex bytes since we can't |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 2347 | // control the characters in a process name |
| 2348 | extractor.GetStringRef().swap(value); |
| 2349 | extractor.SetFilePos(0); |
| 2350 | extractor.GetHexByteString (value); |
Greg Clayton | 144f3a9 | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 2351 | process_info.GetExecutableFile().SetFile (value.c_str(), false); |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 2352 | } |
Jason Molenda | 89c3749 | 2014-01-27 22:23:20 +0000 | [diff] [blame] | 2353 | else if (name.compare("cputype") == 0) |
| 2354 | { |
Vince Harron | 5275aaa | 2015-01-15 20:08:35 +0000 | [diff] [blame] | 2355 | cpu = StringConvert::ToUInt32 (value.c_str(), LLDB_INVALID_CPUTYPE, 16); |
Jason Molenda | 89c3749 | 2014-01-27 22:23:20 +0000 | [diff] [blame] | 2356 | } |
| 2357 | else if (name.compare("cpusubtype") == 0) |
| 2358 | { |
Vince Harron | 5275aaa | 2015-01-15 20:08:35 +0000 | [diff] [blame] | 2359 | sub = StringConvert::ToUInt32 (value.c_str(), 0, 16); |
Jason Molenda | 89c3749 | 2014-01-27 22:23:20 +0000 | [diff] [blame] | 2360 | } |
| 2361 | else if (name.compare("vendor") == 0) |
| 2362 | { |
| 2363 | vendor = value; |
| 2364 | } |
| 2365 | else if (name.compare("ostype") == 0) |
| 2366 | { |
| 2367 | os_type = value; |
| 2368 | } |
| 2369 | } |
| 2370 | |
| 2371 | if (cpu != LLDB_INVALID_CPUTYPE && !vendor.empty() && !os_type.empty()) |
| 2372 | { |
| 2373 | if (vendor == "apple") |
| 2374 | { |
| 2375 | process_info.GetArchitecture().SetArchitecture (eArchTypeMachO, cpu, sub); |
| 2376 | process_info.GetArchitecture().GetTriple().setVendorName (llvm::StringRef (vendor)); |
| 2377 | process_info.GetArchitecture().GetTriple().setOSName (llvm::StringRef (os_type)); |
| 2378 | } |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 2379 | } |
| 2380 | |
| 2381 | if (process_info.GetProcessID() != LLDB_INVALID_PROCESS_ID) |
| 2382 | return true; |
| 2383 | } |
| 2384 | return false; |
| 2385 | } |
| 2386 | |
| 2387 | bool |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 2388 | GDBRemoteCommunicationClient::GetProcessInfo (lldb::pid_t pid, ProcessInstanceInfo &process_info) |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 2389 | { |
| 2390 | process_info.Clear(); |
| 2391 | |
| 2392 | if (m_supports_qProcessInfoPID) |
| 2393 | { |
| 2394 | char packet[32]; |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 2395 | const int packet_len = ::snprintf (packet, sizeof (packet), "qProcessInfoPID:%" PRIu64, pid); |
Andy Gibbs | a297a97 | 2013-06-19 19:04:53 +0000 | [diff] [blame] | 2396 | assert (packet_len < (int)sizeof(packet)); |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 2397 | StringExtractorGDBRemote response; |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 2398 | if (SendPacketAndWaitForResponse (packet, packet_len, response, false) == PacketResult::Success) |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 2399 | { |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 2400 | return DecodeProcessInfoResponse (response, process_info); |
| 2401 | } |
Greg Clayton | 17a0cb6 | 2011-05-15 23:46:54 +0000 | [diff] [blame] | 2402 | else |
| 2403 | { |
| 2404 | m_supports_qProcessInfoPID = false; |
| 2405 | return false; |
| 2406 | } |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 2407 | } |
| 2408 | return false; |
| 2409 | } |
| 2410 | |
Jason Molenda | f17b5ac | 2012-12-19 02:54:03 +0000 | [diff] [blame] | 2411 | bool |
| 2412 | GDBRemoteCommunicationClient::GetCurrentProcessInfo () |
| 2413 | { |
Todd Fiala | 3daa176 | 2014-09-15 16:01:29 +0000 | [diff] [blame] | 2414 | Log *log (ProcessGDBRemoteLog::GetLogIfAnyCategoryIsSet (GDBR_LOG_PROCESS | GDBR_LOG_PACKETS)); |
| 2415 | |
Jason Molenda | f17b5ac | 2012-12-19 02:54:03 +0000 | [diff] [blame] | 2416 | if (m_qProcessInfo_is_valid == eLazyBoolYes) |
| 2417 | return true; |
| 2418 | if (m_qProcessInfo_is_valid == eLazyBoolNo) |
| 2419 | return false; |
| 2420 | |
| 2421 | GetHostInfo (); |
| 2422 | |
| 2423 | StringExtractorGDBRemote response; |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 2424 | if (SendPacketAndWaitForResponse ("qProcessInfo", response, false) == PacketResult::Success) |
Jason Molenda | f17b5ac | 2012-12-19 02:54:03 +0000 | [diff] [blame] | 2425 | { |
| 2426 | if (response.IsNormalResponse()) |
| 2427 | { |
| 2428 | std::string name; |
| 2429 | std::string value; |
| 2430 | uint32_t cpu = LLDB_INVALID_CPUTYPE; |
| 2431 | uint32_t sub = 0; |
| 2432 | std::string arch_name; |
| 2433 | std::string os_name; |
| 2434 | std::string vendor_name; |
| 2435 | std::string triple; |
| 2436 | uint32_t pointer_byte_size = 0; |
| 2437 | StringExtractor extractor; |
Todd Fiala | 5c9d5bf | 2014-09-15 15:31:11 +0000 | [diff] [blame] | 2438 | ByteOrder byte_order = eByteOrderInvalid; |
Jason Molenda | f17b5ac | 2012-12-19 02:54:03 +0000 | [diff] [blame] | 2439 | uint32_t num_keys_decoded = 0; |
Todd Fiala | 9f72b3a | 2014-05-07 19:28:21 +0000 | [diff] [blame] | 2440 | lldb::pid_t pid = LLDB_INVALID_PROCESS_ID; |
Jason Molenda | f17b5ac | 2012-12-19 02:54:03 +0000 | [diff] [blame] | 2441 | while (response.GetNameColonValue(name, value)) |
| 2442 | { |
| 2443 | if (name.compare("cputype") == 0) |
| 2444 | { |
Vince Harron | 5275aaa | 2015-01-15 20:08:35 +0000 | [diff] [blame] | 2445 | cpu = StringConvert::ToUInt32 (value.c_str(), LLDB_INVALID_CPUTYPE, 16); |
Jason Molenda | f17b5ac | 2012-12-19 02:54:03 +0000 | [diff] [blame] | 2446 | if (cpu != LLDB_INVALID_CPUTYPE) |
| 2447 | ++num_keys_decoded; |
| 2448 | } |
| 2449 | else if (name.compare("cpusubtype") == 0) |
| 2450 | { |
Vince Harron | 5275aaa | 2015-01-15 20:08:35 +0000 | [diff] [blame] | 2451 | sub = StringConvert::ToUInt32 (value.c_str(), 0, 16); |
Jason Molenda | f17b5ac | 2012-12-19 02:54:03 +0000 | [diff] [blame] | 2452 | if (sub != 0) |
| 2453 | ++num_keys_decoded; |
| 2454 | } |
Todd Fiala | c540dd0 | 2014-08-26 18:21:02 +0000 | [diff] [blame] | 2455 | else if (name.compare("triple") == 0) |
| 2456 | { |
Greg Clayton | 44272a4 | 2014-09-18 00:18:32 +0000 | [diff] [blame] | 2457 | StringExtractor extractor; |
| 2458 | extractor.GetStringRef().swap(value); |
| 2459 | extractor.SetFilePos(0); |
| 2460 | extractor.GetHexByteString (triple); |
Todd Fiala | c540dd0 | 2014-08-26 18:21:02 +0000 | [diff] [blame] | 2461 | ++num_keys_decoded; |
| 2462 | } |
Jason Molenda | f17b5ac | 2012-12-19 02:54:03 +0000 | [diff] [blame] | 2463 | else if (name.compare("ostype") == 0) |
| 2464 | { |
| 2465 | os_name.swap (value); |
| 2466 | ++num_keys_decoded; |
| 2467 | } |
| 2468 | else if (name.compare("vendor") == 0) |
| 2469 | { |
| 2470 | vendor_name.swap(value); |
| 2471 | ++num_keys_decoded; |
| 2472 | } |
| 2473 | else if (name.compare("endian") == 0) |
| 2474 | { |
Todd Fiala | 5c9d5bf | 2014-09-15 15:31:11 +0000 | [diff] [blame] | 2475 | ++num_keys_decoded; |
| 2476 | if (value.compare("little") == 0) |
| 2477 | byte_order = eByteOrderLittle; |
| 2478 | else if (value.compare("big") == 0) |
| 2479 | byte_order = eByteOrderBig; |
| 2480 | else if (value.compare("pdp") == 0) |
| 2481 | byte_order = eByteOrderPDP; |
| 2482 | else |
| 2483 | --num_keys_decoded; |
Jason Molenda | f17b5ac | 2012-12-19 02:54:03 +0000 | [diff] [blame] | 2484 | } |
| 2485 | else if (name.compare("ptrsize") == 0) |
| 2486 | { |
Vince Harron | 5275aaa | 2015-01-15 20:08:35 +0000 | [diff] [blame] | 2487 | pointer_byte_size = StringConvert::ToUInt32 (value.c_str(), 0, 16); |
Jason Molenda | f17b5ac | 2012-12-19 02:54:03 +0000 | [diff] [blame] | 2488 | if (pointer_byte_size != 0) |
| 2489 | ++num_keys_decoded; |
| 2490 | } |
Todd Fiala | 9f72b3a | 2014-05-07 19:28:21 +0000 | [diff] [blame] | 2491 | else if (name.compare("pid") == 0) |
| 2492 | { |
Vince Harron | 5275aaa | 2015-01-15 20:08:35 +0000 | [diff] [blame] | 2493 | pid = StringConvert::ToUInt64(value.c_str(), 0, 16); |
Todd Fiala | 9f72b3a | 2014-05-07 19:28:21 +0000 | [diff] [blame] | 2494 | if (pid != LLDB_INVALID_PROCESS_ID) |
| 2495 | ++num_keys_decoded; |
| 2496 | } |
Jason Molenda | f17b5ac | 2012-12-19 02:54:03 +0000 | [diff] [blame] | 2497 | } |
| 2498 | if (num_keys_decoded > 0) |
| 2499 | m_qProcessInfo_is_valid = eLazyBoolYes; |
Todd Fiala | 9f72b3a | 2014-05-07 19:28:21 +0000 | [diff] [blame] | 2500 | if (pid != LLDB_INVALID_PROCESS_ID) |
| 2501 | { |
| 2502 | m_curr_pid_is_valid = eLazyBoolYes; |
| 2503 | m_curr_pid = pid; |
| 2504 | } |
Todd Fiala | c540dd0 | 2014-08-26 18:21:02 +0000 | [diff] [blame] | 2505 | |
| 2506 | // Set the ArchSpec from the triple if we have it. |
| 2507 | if (!triple.empty ()) |
| 2508 | { |
| 2509 | m_process_arch.SetTriple (triple.c_str ()); |
| 2510 | if (pointer_byte_size) |
| 2511 | { |
| 2512 | assert (pointer_byte_size == m_process_arch.GetAddressByteSize()); |
| 2513 | } |
| 2514 | } |
| 2515 | else if (cpu != LLDB_INVALID_CPUTYPE && !os_name.empty() && !vendor_name.empty()) |
Jason Molenda | f17b5ac | 2012-12-19 02:54:03 +0000 | [diff] [blame] | 2516 | { |
Todd Fiala | 3daa176 | 2014-09-15 16:01:29 +0000 | [diff] [blame] | 2517 | llvm::Triple triple(llvm::Twine("-") + vendor_name + "-" + os_name); |
| 2518 | |
| 2519 | assert(triple.getObjectFormat() != llvm::Triple::UnknownObjectFormat); |
| 2520 | switch (triple.getObjectFormat()) { |
| 2521 | case llvm::Triple::MachO: |
| 2522 | m_process_arch.SetArchitecture (eArchTypeMachO, cpu, sub); |
| 2523 | break; |
| 2524 | case llvm::Triple::ELF: |
| 2525 | m_process_arch.SetArchitecture (eArchTypeELF, cpu, sub); |
| 2526 | break; |
| 2527 | case llvm::Triple::COFF: |
| 2528 | m_process_arch.SetArchitecture (eArchTypeCOFF, cpu, sub); |
| 2529 | break; |
| 2530 | case llvm::Triple::UnknownObjectFormat: |
| 2531 | if (log) |
| 2532 | log->Printf("error: failed to determine target architecture"); |
| 2533 | return false; |
| 2534 | } |
| 2535 | |
Jason Molenda | f17b5ac | 2012-12-19 02:54:03 +0000 | [diff] [blame] | 2536 | if (pointer_byte_size) |
| 2537 | { |
| 2538 | assert (pointer_byte_size == m_process_arch.GetAddressByteSize()); |
| 2539 | } |
Todd Fiala | 5c9d5bf | 2014-09-15 15:31:11 +0000 | [diff] [blame] | 2540 | if (byte_order != eByteOrderInvalid) |
| 2541 | { |
| 2542 | assert (byte_order == m_process_arch.GetByteOrder()); |
| 2543 | } |
Todd Fiala | 0cc371c | 2014-09-05 14:56:13 +0000 | [diff] [blame] | 2544 | m_process_arch.GetTriple().setVendorName (llvm::StringRef (vendor_name)); |
Greg Clayton | 7ab7f89 | 2014-05-29 21:33:45 +0000 | [diff] [blame] | 2545 | m_process_arch.GetTriple().setOSName(llvm::StringRef (os_name)); |
Jason Molenda | f17b5ac | 2012-12-19 02:54:03 +0000 | [diff] [blame] | 2546 | m_host_arch.GetTriple().setVendorName (llvm::StringRef (vendor_name)); |
| 2547 | m_host_arch.GetTriple().setOSName (llvm::StringRef (os_name)); |
Jason Molenda | f17b5ac | 2012-12-19 02:54:03 +0000 | [diff] [blame] | 2548 | } |
Greg Clayton | 7ab7f89 | 2014-05-29 21:33:45 +0000 | [diff] [blame] | 2549 | return true; |
Jason Molenda | f17b5ac | 2012-12-19 02:54:03 +0000 | [diff] [blame] | 2550 | } |
| 2551 | } |
| 2552 | else |
| 2553 | { |
| 2554 | m_qProcessInfo_is_valid = eLazyBoolNo; |
| 2555 | } |
| 2556 | |
| 2557 | return false; |
| 2558 | } |
| 2559 | |
| 2560 | |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 2561 | uint32_t |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 2562 | GDBRemoteCommunicationClient::FindProcesses (const ProcessInstanceInfoMatch &match_info, |
| 2563 | ProcessInstanceInfoList &process_infos) |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 2564 | { |
| 2565 | process_infos.Clear(); |
| 2566 | |
| 2567 | if (m_supports_qfProcessInfo) |
| 2568 | { |
| 2569 | StreamString packet; |
| 2570 | packet.PutCString ("qfProcessInfo"); |
| 2571 | if (!match_info.MatchAllProcesses()) |
| 2572 | { |
| 2573 | packet.PutChar (':'); |
| 2574 | const char *name = match_info.GetProcessInfo().GetName(); |
| 2575 | bool has_name_match = false; |
| 2576 | if (name && name[0]) |
| 2577 | { |
| 2578 | has_name_match = true; |
| 2579 | NameMatchType name_match_type = match_info.GetNameMatchType(); |
| 2580 | switch (name_match_type) |
| 2581 | { |
| 2582 | case eNameMatchIgnore: |
| 2583 | has_name_match = false; |
| 2584 | break; |
| 2585 | |
| 2586 | case eNameMatchEquals: |
| 2587 | packet.PutCString ("name_match:equals;"); |
| 2588 | break; |
| 2589 | |
| 2590 | case eNameMatchContains: |
| 2591 | packet.PutCString ("name_match:contains;"); |
| 2592 | break; |
| 2593 | |
| 2594 | case eNameMatchStartsWith: |
| 2595 | packet.PutCString ("name_match:starts_with;"); |
| 2596 | break; |
| 2597 | |
| 2598 | case eNameMatchEndsWith: |
| 2599 | packet.PutCString ("name_match:ends_with;"); |
| 2600 | break; |
| 2601 | |
| 2602 | case eNameMatchRegularExpression: |
| 2603 | packet.PutCString ("name_match:regex;"); |
| 2604 | break; |
| 2605 | } |
| 2606 | if (has_name_match) |
| 2607 | { |
| 2608 | packet.PutCString ("name:"); |
| 2609 | packet.PutBytesAsRawHex8(name, ::strlen(name)); |
| 2610 | packet.PutChar (';'); |
| 2611 | } |
| 2612 | } |
| 2613 | |
| 2614 | if (match_info.GetProcessInfo().ProcessIDIsValid()) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 2615 | packet.Printf("pid:%" PRIu64 ";",match_info.GetProcessInfo().GetProcessID()); |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 2616 | if (match_info.GetProcessInfo().ParentProcessIDIsValid()) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 2617 | packet.Printf("parent_pid:%" PRIu64 ";",match_info.GetProcessInfo().GetParentProcessID()); |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 2618 | if (match_info.GetProcessInfo().UserIDIsValid()) |
| 2619 | packet.Printf("uid:%u;",match_info.GetProcessInfo().GetUserID()); |
| 2620 | if (match_info.GetProcessInfo().GroupIDIsValid()) |
| 2621 | packet.Printf("gid:%u;",match_info.GetProcessInfo().GetGroupID()); |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 2622 | if (match_info.GetProcessInfo().EffectiveUserIDIsValid()) |
| 2623 | packet.Printf("euid:%u;",match_info.GetProcessInfo().GetEffectiveUserID()); |
| 2624 | if (match_info.GetProcessInfo().EffectiveGroupIDIsValid()) |
| 2625 | packet.Printf("egid:%u;",match_info.GetProcessInfo().GetEffectiveGroupID()); |
| 2626 | if (match_info.GetProcessInfo().EffectiveGroupIDIsValid()) |
| 2627 | packet.Printf("all_users:%u;",match_info.GetMatchAllUsers() ? 1 : 0); |
| 2628 | if (match_info.GetProcessInfo().GetArchitecture().IsValid()) |
| 2629 | { |
| 2630 | const ArchSpec &match_arch = match_info.GetProcessInfo().GetArchitecture(); |
| 2631 | const llvm::Triple &triple = match_arch.GetTriple(); |
| 2632 | packet.PutCString("triple:"); |
Matthew Gardiner | f39ebbe | 2014-08-01 05:12:23 +0000 | [diff] [blame] | 2633 | packet.PutCString(triple.getTriple().c_str()); |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 2634 | packet.PutChar (';'); |
| 2635 | } |
| 2636 | } |
| 2637 | StringExtractorGDBRemote response; |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 2638 | if (SendPacketAndWaitForResponse (packet.GetData(), packet.GetSize(), response, false) == PacketResult::Success) |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 2639 | { |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 2640 | do |
| 2641 | { |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 2642 | ProcessInstanceInfo process_info; |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 2643 | if (!DecodeProcessInfoResponse (response, process_info)) |
| 2644 | break; |
| 2645 | process_infos.Append(process_info); |
| 2646 | response.GetStringRef().clear(); |
| 2647 | response.SetFilePos(0); |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 2648 | } while (SendPacketAndWaitForResponse ("qsProcessInfo", strlen ("qsProcessInfo"), response, false) == PacketResult::Success); |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 2649 | } |
Greg Clayton | 17a0cb6 | 2011-05-15 23:46:54 +0000 | [diff] [blame] | 2650 | else |
| 2651 | { |
| 2652 | m_supports_qfProcessInfo = false; |
| 2653 | return 0; |
| 2654 | } |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 2655 | } |
| 2656 | return process_infos.GetSize(); |
| 2657 | |
| 2658 | } |
| 2659 | |
| 2660 | bool |
| 2661 | GDBRemoteCommunicationClient::GetUserName (uint32_t uid, std::string &name) |
| 2662 | { |
| 2663 | if (m_supports_qUserName) |
| 2664 | { |
| 2665 | char packet[32]; |
| 2666 | const int packet_len = ::snprintf (packet, sizeof (packet), "qUserName:%i", uid); |
Andy Gibbs | a297a97 | 2013-06-19 19:04:53 +0000 | [diff] [blame] | 2667 | assert (packet_len < (int)sizeof(packet)); |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 2668 | StringExtractorGDBRemote response; |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 2669 | if (SendPacketAndWaitForResponse (packet, packet_len, response, false) == PacketResult::Success) |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 2670 | { |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 2671 | if (response.IsNormalResponse()) |
| 2672 | { |
| 2673 | // Make sure we parsed the right number of characters. The response is |
| 2674 | // the hex encoded user name and should make up the entire packet. |
| 2675 | // If there are any non-hex ASCII bytes, the length won't match below.. |
| 2676 | if (response.GetHexByteString (name) * 2 == response.GetStringRef().size()) |
| 2677 | return true; |
| 2678 | } |
| 2679 | } |
Greg Clayton | 17a0cb6 | 2011-05-15 23:46:54 +0000 | [diff] [blame] | 2680 | else |
| 2681 | { |
| 2682 | m_supports_qUserName = false; |
| 2683 | return false; |
| 2684 | } |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 2685 | } |
| 2686 | return false; |
| 2687 | |
| 2688 | } |
| 2689 | |
| 2690 | bool |
| 2691 | GDBRemoteCommunicationClient::GetGroupName (uint32_t gid, std::string &name) |
| 2692 | { |
| 2693 | if (m_supports_qGroupName) |
| 2694 | { |
| 2695 | char packet[32]; |
| 2696 | const int packet_len = ::snprintf (packet, sizeof (packet), "qGroupName:%i", gid); |
Andy Gibbs | a297a97 | 2013-06-19 19:04:53 +0000 | [diff] [blame] | 2697 | assert (packet_len < (int)sizeof(packet)); |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 2698 | StringExtractorGDBRemote response; |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 2699 | if (SendPacketAndWaitForResponse (packet, packet_len, response, false) == PacketResult::Success) |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 2700 | { |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 2701 | if (response.IsNormalResponse()) |
| 2702 | { |
| 2703 | // Make sure we parsed the right number of characters. The response is |
| 2704 | // the hex encoded group name and should make up the entire packet. |
| 2705 | // If there are any non-hex ASCII bytes, the length won't match below.. |
| 2706 | if (response.GetHexByteString (name) * 2 == response.GetStringRef().size()) |
| 2707 | return true; |
| 2708 | } |
| 2709 | } |
Greg Clayton | 17a0cb6 | 2011-05-15 23:46:54 +0000 | [diff] [blame] | 2710 | else |
| 2711 | { |
| 2712 | m_supports_qGroupName = false; |
| 2713 | return false; |
| 2714 | } |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 2715 | } |
| 2716 | return false; |
Greg Clayton | 9b1e1cd | 2011-04-04 18:18:57 +0000 | [diff] [blame] | 2717 | } |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 2718 | |
Greg Clayton | 9b1e1cd | 2011-04-04 18:18:57 +0000 | [diff] [blame] | 2719 | void |
| 2720 | GDBRemoteCommunicationClient::TestPacketSpeed (const uint32_t num_packets) |
| 2721 | { |
| 2722 | uint32_t i; |
| 2723 | TimeValue start_time, end_time; |
| 2724 | uint64_t total_time_nsec; |
Greg Clayton | 9b1e1cd | 2011-04-04 18:18:57 +0000 | [diff] [blame] | 2725 | if (SendSpeedTestPacket (0, 0)) |
| 2726 | { |
Greg Clayton | 700e508 | 2014-02-21 19:11:28 +0000 | [diff] [blame] | 2727 | static uint32_t g_send_sizes[] = { 0, 64, 128, 512, 1024 }; |
| 2728 | static uint32_t g_recv_sizes[] = { 0, 64, 128, 512, 1024 }; //, 4*1024, 8*1024, 16*1024, 32*1024, 48*1024, 64*1024, 96*1024, 128*1024 }; |
Saleem Abdulrasool | 2860695 | 2014-06-27 05:17:41 +0000 | [diff] [blame] | 2729 | const size_t k_num_send_sizes = llvm::array_lengthof(g_send_sizes); |
| 2730 | const size_t k_num_recv_sizes = llvm::array_lengthof(g_recv_sizes); |
Greg Clayton | 700e508 | 2014-02-21 19:11:28 +0000 | [diff] [blame] | 2731 | const uint64_t k_recv_amount = 4*1024*1024; // Receive 4MB |
| 2732 | for (uint32_t send_idx = 0; send_idx < k_num_send_sizes; ++send_idx) |
Greg Clayton | 9b1e1cd | 2011-04-04 18:18:57 +0000 | [diff] [blame] | 2733 | { |
Greg Clayton | 700e508 | 2014-02-21 19:11:28 +0000 | [diff] [blame] | 2734 | const uint32_t send_size = g_send_sizes[send_idx]; |
| 2735 | for (uint32_t recv_idx = 0; recv_idx < k_num_recv_sizes; ++recv_idx) |
Greg Clayton | 9b1e1cd | 2011-04-04 18:18:57 +0000 | [diff] [blame] | 2736 | { |
Greg Clayton | 700e508 | 2014-02-21 19:11:28 +0000 | [diff] [blame] | 2737 | const uint32_t recv_size = g_recv_sizes[recv_idx]; |
| 2738 | StreamString packet; |
| 2739 | packet.Printf ("qSpeedTest:response_size:%i;data:", recv_size); |
| 2740 | uint32_t bytes_left = send_size; |
| 2741 | while (bytes_left > 0) |
Greg Clayton | 9b1e1cd | 2011-04-04 18:18:57 +0000 | [diff] [blame] | 2742 | { |
Greg Clayton | 700e508 | 2014-02-21 19:11:28 +0000 | [diff] [blame] | 2743 | if (bytes_left >= 26) |
| 2744 | { |
| 2745 | packet.PutCString("abcdefghijklmnopqrstuvwxyz"); |
| 2746 | bytes_left -= 26; |
| 2747 | } |
| 2748 | else |
| 2749 | { |
| 2750 | packet.Printf ("%*.*s;", bytes_left, bytes_left, "abcdefghijklmnopqrstuvwxyz"); |
| 2751 | bytes_left = 0; |
| 2752 | } |
| 2753 | } |
| 2754 | |
| 2755 | start_time = TimeValue::Now(); |
| 2756 | if (recv_size == 0) |
| 2757 | { |
| 2758 | for (i=0; i<num_packets; ++i) |
| 2759 | { |
| 2760 | StringExtractorGDBRemote response; |
| 2761 | SendPacketAndWaitForResponse (packet.GetData(), packet.GetSize(), response, false); |
| 2762 | } |
| 2763 | } |
| 2764 | else |
| 2765 | { |
| 2766 | uint32_t bytes_read = 0; |
| 2767 | while (bytes_read < k_recv_amount) |
| 2768 | { |
| 2769 | StringExtractorGDBRemote response; |
| 2770 | SendPacketAndWaitForResponse (packet.GetData(), packet.GetSize(), response, false); |
| 2771 | bytes_read += recv_size; |
| 2772 | } |
Greg Clayton | 9b1e1cd | 2011-04-04 18:18:57 +0000 | [diff] [blame] | 2773 | } |
| 2774 | end_time = TimeValue::Now(); |
| 2775 | total_time_nsec = end_time.GetAsNanoSecondsSinceJan1_1970() - start_time.GetAsNanoSecondsSinceJan1_1970(); |
Greg Clayton | 9b1e1cd | 2011-04-04 18:18:57 +0000 | [diff] [blame] | 2776 | if (recv_size == 0) |
Greg Clayton | 700e508 | 2014-02-21 19:11:28 +0000 | [diff] [blame] | 2777 | { |
| 2778 | float packets_per_second = (((float)num_packets)/(float)total_time_nsec) * (float)TimeValue::NanoSecPerSec; |
| 2779 | printf ("%u qSpeedTest(send=%-7u, recv=%-7u) in %" PRIu64 ".%9.9" PRIu64 " sec for %f packets/sec.\n", |
| 2780 | num_packets, |
| 2781 | send_size, |
| 2782 | recv_size, |
| 2783 | total_time_nsec / TimeValue::NanoSecPerSec, |
| 2784 | total_time_nsec % TimeValue::NanoSecPerSec, |
| 2785 | packets_per_second); |
| 2786 | } |
| 2787 | else |
| 2788 | { |
| 2789 | float mb_second = ((((float)k_recv_amount)/(float)total_time_nsec) * (float)TimeValue::NanoSecPerSec) / (1024.0*1024.0); |
| 2790 | printf ("%u qSpeedTest(send=%-7u, recv=%-7u) sent 4MB in %" PRIu64 ".%9.9" PRIu64 " sec for %f MB/sec.\n", |
| 2791 | num_packets, |
| 2792 | send_size, |
| 2793 | recv_size, |
| 2794 | total_time_nsec / TimeValue::NanoSecPerSec, |
| 2795 | total_time_nsec % TimeValue::NanoSecPerSec, |
| 2796 | mb_second); |
| 2797 | } |
Greg Clayton | 9b1e1cd | 2011-04-04 18:18:57 +0000 | [diff] [blame] | 2798 | } |
Greg Clayton | 9b1e1cd | 2011-04-04 18:18:57 +0000 | [diff] [blame] | 2799 | } |
| 2800 | } |
Greg Clayton | 9b1e1cd | 2011-04-04 18:18:57 +0000 | [diff] [blame] | 2801 | } |
| 2802 | |
| 2803 | bool |
| 2804 | GDBRemoteCommunicationClient::SendSpeedTestPacket (uint32_t send_size, uint32_t recv_size) |
| 2805 | { |
| 2806 | StreamString packet; |
| 2807 | packet.Printf ("qSpeedTest:response_size:%i;data:", recv_size); |
| 2808 | uint32_t bytes_left = send_size; |
| 2809 | while (bytes_left > 0) |
| 2810 | { |
| 2811 | if (bytes_left >= 26) |
| 2812 | { |
| 2813 | packet.PutCString("abcdefghijklmnopqrstuvwxyz"); |
| 2814 | bytes_left -= 26; |
| 2815 | } |
| 2816 | else |
| 2817 | { |
| 2818 | packet.Printf ("%*.*s;", bytes_left, bytes_left, "abcdefghijklmnopqrstuvwxyz"); |
| 2819 | bytes_left = 0; |
| 2820 | } |
| 2821 | } |
| 2822 | |
| 2823 | StringExtractorGDBRemote response; |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 2824 | return SendPacketAndWaitForResponse (packet.GetData(), packet.GetSize(), response, false) == PacketResult::Success; |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 2825 | } |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 2826 | |
| 2827 | uint16_t |
Greg Clayton | dbf0457 | 2013-12-04 19:40:33 +0000 | [diff] [blame] | 2828 | GDBRemoteCommunicationClient::LaunchGDBserverAndGetPort (lldb::pid_t &pid, const char *remote_accept_hostname) |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 2829 | { |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 2830 | pid = LLDB_INVALID_PROCESS_ID; |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 2831 | StringExtractorGDBRemote response; |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 2832 | StreamString stream; |
Greg Clayton | 29b8fc4 | 2013-11-21 01:44:58 +0000 | [diff] [blame] | 2833 | stream.PutCString("qLaunchGDBServer;"); |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 2834 | std::string hostname; |
Greg Clayton | dbf0457 | 2013-12-04 19:40:33 +0000 | [diff] [blame] | 2835 | if (remote_accept_hostname && remote_accept_hostname[0]) |
| 2836 | hostname = remote_accept_hostname; |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 2837 | else |
| 2838 | { |
Zachary Turner | 97a14e6 | 2014-08-19 17:18:29 +0000 | [diff] [blame] | 2839 | if (HostInfo::GetHostname(hostname)) |
Greg Clayton | dbf0457 | 2013-12-04 19:40:33 +0000 | [diff] [blame] | 2840 | { |
| 2841 | // Make the GDB server we launch only accept connections from this host |
| 2842 | stream.Printf("host:%s;", hostname.c_str()); |
| 2843 | } |
| 2844 | else |
| 2845 | { |
| 2846 | // Make the GDB server we launch accept connections from any host since we can't figure out the hostname |
| 2847 | stream.Printf("host:*;"); |
| 2848 | } |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 2849 | } |
| 2850 | const char *packet = stream.GetData(); |
| 2851 | int packet_len = stream.GetSize(); |
| 2852 | |
Vince Harron | 1b5a74e | 2015-01-21 22:42:49 +0000 | [diff] [blame] | 2853 | // give the process a few seconds to startup |
| 2854 | const uint32_t old_packet_timeout = SetPacketTimeout (10); |
| 2855 | auto result = SendPacketAndWaitForResponse(packet, packet_len, response, false); |
| 2856 | SetPacketTimeout (old_packet_timeout); |
| 2857 | if (result == PacketResult::Success) |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 2858 | { |
| 2859 | std::string name; |
| 2860 | std::string value; |
| 2861 | uint16_t port = 0; |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 2862 | while (response.GetNameColonValue(name, value)) |
| 2863 | { |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 2864 | if (name.compare("port") == 0) |
Vince Harron | 5275aaa | 2015-01-15 20:08:35 +0000 | [diff] [blame] | 2865 | port = StringConvert::ToUInt32(value.c_str(), 0, 0); |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 2866 | else if (name.compare("pid") == 0) |
Vince Harron | 5275aaa | 2015-01-15 20:08:35 +0000 | [diff] [blame] | 2867 | pid = StringConvert::ToUInt64(value.c_str(), LLDB_INVALID_PROCESS_ID, 0); |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 2868 | } |
| 2869 | return port; |
| 2870 | } |
| 2871 | return 0; |
| 2872 | } |
| 2873 | |
| 2874 | bool |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 2875 | GDBRemoteCommunicationClient::KillSpawnedProcess (lldb::pid_t pid) |
| 2876 | { |
| 2877 | StreamString stream; |
| 2878 | stream.Printf ("qKillSpawnedProcess:%" PRId64 , pid); |
| 2879 | const char *packet = stream.GetData(); |
| 2880 | int packet_len = stream.GetSize(); |
Sylvestre Ledru | fd654c4 | 2013-10-06 09:51:02 +0000 | [diff] [blame] | 2881 | |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 2882 | StringExtractorGDBRemote response; |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 2883 | if (SendPacketAndWaitForResponse(packet, packet_len, response, false) == PacketResult::Success) |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 2884 | { |
| 2885 | if (response.IsOKResponse()) |
| 2886 | return true; |
| 2887 | } |
| 2888 | return false; |
| 2889 | } |
| 2890 | |
| 2891 | bool |
Jason Molenda | e9ca4af | 2013-02-23 02:04:45 +0000 | [diff] [blame] | 2892 | GDBRemoteCommunicationClient::SetCurrentThread (uint64_t tid) |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 2893 | { |
| 2894 | if (m_curr_tid == tid) |
| 2895 | return true; |
Jason Molenda | e9ca4af | 2013-02-23 02:04:45 +0000 | [diff] [blame] | 2896 | |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 2897 | char packet[32]; |
| 2898 | int packet_len; |
Jason Molenda | e9ca4af | 2013-02-23 02:04:45 +0000 | [diff] [blame] | 2899 | if (tid == UINT64_MAX) |
| 2900 | packet_len = ::snprintf (packet, sizeof(packet), "Hg-1"); |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 2901 | else |
Jason Molenda | e9ca4af | 2013-02-23 02:04:45 +0000 | [diff] [blame] | 2902 | packet_len = ::snprintf (packet, sizeof(packet), "Hg%" PRIx64, tid); |
Andy Gibbs | a297a97 | 2013-06-19 19:04:53 +0000 | [diff] [blame] | 2903 | assert (packet_len + 1 < (int)sizeof(packet)); |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 2904 | StringExtractorGDBRemote response; |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 2905 | if (SendPacketAndWaitForResponse(packet, packet_len, response, false) == PacketResult::Success) |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 2906 | { |
| 2907 | if (response.IsOKResponse()) |
| 2908 | { |
| 2909 | m_curr_tid = tid; |
| 2910 | return true; |
| 2911 | } |
| 2912 | } |
| 2913 | return false; |
| 2914 | } |
| 2915 | |
| 2916 | bool |
Jason Molenda | e9ca4af | 2013-02-23 02:04:45 +0000 | [diff] [blame] | 2917 | GDBRemoteCommunicationClient::SetCurrentThreadForRun (uint64_t tid) |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 2918 | { |
| 2919 | if (m_curr_tid_run == tid) |
| 2920 | return true; |
Jason Molenda | e9ca4af | 2013-02-23 02:04:45 +0000 | [diff] [blame] | 2921 | |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 2922 | char packet[32]; |
| 2923 | int packet_len; |
Jason Molenda | e9ca4af | 2013-02-23 02:04:45 +0000 | [diff] [blame] | 2924 | if (tid == UINT64_MAX) |
| 2925 | packet_len = ::snprintf (packet, sizeof(packet), "Hc-1"); |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 2926 | else |
Jason Molenda | e9ca4af | 2013-02-23 02:04:45 +0000 | [diff] [blame] | 2927 | packet_len = ::snprintf (packet, sizeof(packet), "Hc%" PRIx64, tid); |
| 2928 | |
Andy Gibbs | a297a97 | 2013-06-19 19:04:53 +0000 | [diff] [blame] | 2929 | assert (packet_len + 1 < (int)sizeof(packet)); |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 2930 | StringExtractorGDBRemote response; |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 2931 | if (SendPacketAndWaitForResponse(packet, packet_len, response, false) == PacketResult::Success) |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 2932 | { |
| 2933 | if (response.IsOKResponse()) |
| 2934 | { |
| 2935 | m_curr_tid_run = tid; |
| 2936 | return true; |
| 2937 | } |
| 2938 | } |
| 2939 | return false; |
| 2940 | } |
| 2941 | |
| 2942 | bool |
| 2943 | GDBRemoteCommunicationClient::GetStopReply (StringExtractorGDBRemote &response) |
| 2944 | { |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 2945 | if (SendPacketAndWaitForResponse("?", 1, response, false) == PacketResult::Success) |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 2946 | return response.IsNormalResponse(); |
| 2947 | return false; |
| 2948 | } |
| 2949 | |
| 2950 | bool |
Greg Clayton | f402f78 | 2012-10-13 02:11:55 +0000 | [diff] [blame] | 2951 | GDBRemoteCommunicationClient::GetThreadStopInfo (lldb::tid_t tid, StringExtractorGDBRemote &response) |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 2952 | { |
| 2953 | if (m_supports_qThreadStopInfo) |
| 2954 | { |
| 2955 | char packet[256]; |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 2956 | int packet_len = ::snprintf(packet, sizeof(packet), "qThreadStopInfo%" PRIx64, tid); |
Andy Gibbs | a297a97 | 2013-06-19 19:04:53 +0000 | [diff] [blame] | 2957 | assert (packet_len < (int)sizeof(packet)); |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 2958 | if (SendPacketAndWaitForResponse(packet, packet_len, response, false) == PacketResult::Success) |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 2959 | { |
Greg Clayton | ef8180a | 2013-10-15 00:14:28 +0000 | [diff] [blame] | 2960 | if (response.IsUnsupportedResponse()) |
| 2961 | m_supports_qThreadStopInfo = false; |
| 2962 | else if (response.IsNormalResponse()) |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 2963 | return true; |
| 2964 | else |
| 2965 | return false; |
| 2966 | } |
Greg Clayton | 17a0cb6 | 2011-05-15 23:46:54 +0000 | [diff] [blame] | 2967 | else |
| 2968 | { |
| 2969 | m_supports_qThreadStopInfo = false; |
| 2970 | } |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 2971 | } |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 2972 | return false; |
| 2973 | } |
| 2974 | |
| 2975 | |
| 2976 | uint8_t |
| 2977 | GDBRemoteCommunicationClient::SendGDBStoppointTypePacket (GDBStoppointType type, bool insert, addr_t addr, uint32_t length) |
| 2978 | { |
Todd Fiala | 616b827 | 2014-10-09 00:55:04 +0000 | [diff] [blame] | 2979 | Log *log (GetLogIfAnyCategoriesSet (LIBLLDB_LOG_BREAKPOINTS)); |
| 2980 | if (log) |
| 2981 | log->Printf ("GDBRemoteCommunicationClient::%s() %s at addr = 0x%" PRIx64, |
| 2982 | __FUNCTION__, insert ? "add" : "remove", addr); |
| 2983 | |
Deepak Panickal | b98a2bb | 2014-02-24 11:50:46 +0000 | [diff] [blame] | 2984 | // Check if the stub is known not to support this breakpoint type |
| 2985 | if (!SupportsGDBStoppointPacket(type)) |
| 2986 | return UINT8_MAX; |
| 2987 | // Construct the breakpoint packet |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 2988 | char packet[64]; |
| 2989 | const int packet_len = ::snprintf (packet, |
| 2990 | sizeof(packet), |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 2991 | "%c%i,%" PRIx64 ",%x", |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 2992 | insert ? 'Z' : 'z', |
| 2993 | type, |
| 2994 | addr, |
| 2995 | length); |
Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 2996 | // Check we haven't overwritten the end of the packet buffer |
Andy Gibbs | a297a97 | 2013-06-19 19:04:53 +0000 | [diff] [blame] | 2997 | assert (packet_len + 1 < (int)sizeof(packet)); |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 2998 | StringExtractorGDBRemote response; |
Deepak Panickal | b98a2bb | 2014-02-24 11:50:46 +0000 | [diff] [blame] | 2999 | // Try to send the breakpoint packet, and check that it was correctly sent |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 3000 | if (SendPacketAndWaitForResponse(packet, packet_len, response, true) == PacketResult::Success) |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 3001 | { |
Deepak Panickal | b98a2bb | 2014-02-24 11:50:46 +0000 | [diff] [blame] | 3002 | // Receive and OK packet when the breakpoint successfully placed |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 3003 | if (response.IsOKResponse()) |
| 3004 | return 0; |
Deepak Panickal | b98a2bb | 2014-02-24 11:50:46 +0000 | [diff] [blame] | 3005 | |
| 3006 | // Error while setting breakpoint, send back specific error |
| 3007 | if (response.IsErrorResponse()) |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 3008 | return response.GetError(); |
Deepak Panickal | b98a2bb | 2014-02-24 11:50:46 +0000 | [diff] [blame] | 3009 | |
| 3010 | // Empty packet informs us that breakpoint is not supported |
| 3011 | if (response.IsUnsupportedResponse()) |
Greg Clayton | 17a0cb6 | 2011-05-15 23:46:54 +0000 | [diff] [blame] | 3012 | { |
Deepak Panickal | b98a2bb | 2014-02-24 11:50:46 +0000 | [diff] [blame] | 3013 | // Disable this breakpoint type since it is unsupported |
| 3014 | switch (type) |
| 3015 | { |
Greg Clayton | 17a0cb6 | 2011-05-15 23:46:54 +0000 | [diff] [blame] | 3016 | case eBreakpointSoftware: m_supports_z0 = false; break; |
| 3017 | case eBreakpointHardware: m_supports_z1 = false; break; |
| 3018 | case eWatchpointWrite: m_supports_z2 = false; break; |
| 3019 | case eWatchpointRead: m_supports_z3 = false; break; |
| 3020 | case eWatchpointReadWrite: m_supports_z4 = false; break; |
Chaoren Lin | 0be9ebb | 2015-02-03 01:51:50 +0000 | [diff] [blame^] | 3021 | case eStoppointInvalid: return UINT8_MAX; |
Deepak Panickal | b98a2bb | 2014-02-24 11:50:46 +0000 | [diff] [blame] | 3022 | } |
Greg Clayton | 17a0cb6 | 2011-05-15 23:46:54 +0000 | [diff] [blame] | 3023 | } |
| 3024 | } |
Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 3025 | // Signal generic failure |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 3026 | return UINT8_MAX; |
| 3027 | } |
Greg Clayton | adc00cb | 2011-05-20 23:38:13 +0000 | [diff] [blame] | 3028 | |
| 3029 | size_t |
| 3030 | GDBRemoteCommunicationClient::GetCurrentThreadIDs (std::vector<lldb::tid_t> &thread_ids, |
| 3031 | bool &sequence_mutex_unavailable) |
| 3032 | { |
| 3033 | Mutex::Locker locker; |
| 3034 | thread_ids.clear(); |
| 3035 | |
Jim Ingham | 4ceb928 | 2012-06-08 22:50:40 +0000 | [diff] [blame] | 3036 | 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] | 3037 | { |
| 3038 | sequence_mutex_unavailable = false; |
| 3039 | StringExtractorGDBRemote response; |
| 3040 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 3041 | PacketResult packet_result; |
| 3042 | for (packet_result = SendPacketAndWaitForResponseNoLock ("qfThreadInfo", strlen("qfThreadInfo"), response); |
| 3043 | packet_result == PacketResult::Success && response.IsNormalResponse(); |
| 3044 | packet_result = SendPacketAndWaitForResponseNoLock ("qsThreadInfo", strlen("qsThreadInfo"), response)) |
Greg Clayton | adc00cb | 2011-05-20 23:38:13 +0000 | [diff] [blame] | 3045 | { |
| 3046 | char ch = response.GetChar(); |
| 3047 | if (ch == 'l') |
| 3048 | break; |
| 3049 | if (ch == 'm') |
| 3050 | { |
| 3051 | do |
| 3052 | { |
Jason Molenda | e9ca4af | 2013-02-23 02:04:45 +0000 | [diff] [blame] | 3053 | tid_t tid = response.GetHexMaxU64(false, LLDB_INVALID_THREAD_ID); |
Greg Clayton | adc00cb | 2011-05-20 23:38:13 +0000 | [diff] [blame] | 3054 | |
| 3055 | if (tid != LLDB_INVALID_THREAD_ID) |
| 3056 | { |
| 3057 | thread_ids.push_back (tid); |
| 3058 | } |
| 3059 | ch = response.GetChar(); // Skip the command separator |
| 3060 | } while (ch == ','); // Make sure we got a comma separator |
| 3061 | } |
| 3062 | } |
| 3063 | } |
| 3064 | else |
| 3065 | { |
Jim Ingham | 4ceb928 | 2012-06-08 22:50:40 +0000 | [diff] [blame] | 3066 | #if defined (LLDB_CONFIGURATION_DEBUG) |
| 3067 | // assert(!"ProcessGDBRemote::UpdateThreadList() failed due to not getting the sequence mutex"); |
| 3068 | #else |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3069 | Log *log (ProcessGDBRemoteLog::GetLogIfAnyCategoryIsSet (GDBR_LOG_PROCESS | GDBR_LOG_PACKETS)); |
Greg Clayton | c3c0b0e | 2012-04-12 19:04:34 +0000 | [diff] [blame] | 3070 | if (log) |
| 3071 | 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] | 3072 | #endif |
Greg Clayton | adc00cb | 2011-05-20 23:38:13 +0000 | [diff] [blame] | 3073 | sequence_mutex_unavailable = true; |
| 3074 | } |
| 3075 | return thread_ids.size(); |
| 3076 | } |
Greg Clayton | 37a0a24 | 2012-04-11 00:24:49 +0000 | [diff] [blame] | 3077 | |
| 3078 | lldb::addr_t |
| 3079 | GDBRemoteCommunicationClient::GetShlibInfoAddr() |
| 3080 | { |
| 3081 | if (!IsRunning()) |
| 3082 | { |
| 3083 | StringExtractorGDBRemote response; |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 3084 | if (SendPacketAndWaitForResponse("qShlibInfoAddr", ::strlen ("qShlibInfoAddr"), response, false) == PacketResult::Success) |
Greg Clayton | 37a0a24 | 2012-04-11 00:24:49 +0000 | [diff] [blame] | 3085 | { |
| 3086 | if (response.IsNormalResponse()) |
| 3087 | return response.GetHexMaxU64(false, LLDB_INVALID_ADDRESS); |
| 3088 | } |
| 3089 | } |
| 3090 | return LLDB_INVALID_ADDRESS; |
| 3091 | } |
| 3092 | |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 3093 | lldb_private::Error |
| 3094 | GDBRemoteCommunicationClient::RunShellCommand (const char *command, // Shouldn't be NULL |
| 3095 | const char *working_dir, // Pass NULL to use the current working directory |
| 3096 | int *status_ptr, // Pass NULL if you don't want the process exit status |
| 3097 | int *signo_ptr, // Pass NULL if you don't want the signal that caused the process to exit |
| 3098 | std::string *command_output, // Pass NULL if you don't want the command output |
| 3099 | uint32_t timeout_sec) // Timeout in seconds to wait for shell program to finish |
| 3100 | { |
| 3101 | lldb_private::StreamString stream; |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 3102 | stream.PutCString("qPlatform_shell:"); |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 3103 | stream.PutBytesAsRawHex8(command, strlen(command)); |
| 3104 | stream.PutChar(','); |
| 3105 | stream.PutHex32(timeout_sec); |
| 3106 | if (working_dir && *working_dir) |
| 3107 | { |
| 3108 | stream.PutChar(','); |
| 3109 | stream.PutBytesAsRawHex8(working_dir, strlen(working_dir)); |
| 3110 | } |
| 3111 | const char *packet = stream.GetData(); |
| 3112 | int packet_len = stream.GetSize(); |
| 3113 | StringExtractorGDBRemote response; |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 3114 | if (SendPacketAndWaitForResponse(packet, packet_len, response, false) == PacketResult::Success) |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 3115 | { |
| 3116 | if (response.GetChar() != 'F') |
| 3117 | return Error("malformed reply"); |
| 3118 | if (response.GetChar() != ',') |
| 3119 | return Error("malformed reply"); |
| 3120 | uint32_t exitcode = response.GetHexMaxU32(false, UINT32_MAX); |
| 3121 | if (exitcode == UINT32_MAX) |
| 3122 | return Error("unable to run remote process"); |
| 3123 | else if (status_ptr) |
| 3124 | *status_ptr = exitcode; |
| 3125 | if (response.GetChar() != ',') |
| 3126 | return Error("malformed reply"); |
| 3127 | uint32_t signo = response.GetHexMaxU32(false, UINT32_MAX); |
| 3128 | if (signo_ptr) |
| 3129 | *signo_ptr = signo; |
| 3130 | if (response.GetChar() != ',') |
| 3131 | return Error("malformed reply"); |
| 3132 | std::string output; |
| 3133 | response.GetEscapedBinaryData(output); |
| 3134 | if (command_output) |
| 3135 | command_output->assign(output); |
| 3136 | return Error(); |
| 3137 | } |
| 3138 | return Error("unable to send packet"); |
| 3139 | } |
| 3140 | |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 3141 | Error |
| 3142 | GDBRemoteCommunicationClient::MakeDirectory (const char *path, |
| 3143 | uint32_t file_permissions) |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 3144 | { |
| 3145 | lldb_private::StreamString stream; |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 3146 | stream.PutCString("qPlatform_mkdir:"); |
| 3147 | stream.PutHex32(file_permissions); |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 3148 | stream.PutChar(','); |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 3149 | stream.PutBytesAsRawHex8(path, strlen(path)); |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 3150 | const char *packet = stream.GetData(); |
| 3151 | int packet_len = stream.GetSize(); |
| 3152 | StringExtractorGDBRemote response; |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 3153 | if (SendPacketAndWaitForResponse(packet, packet_len, response, false) == PacketResult::Success) |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 3154 | { |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 3155 | return Error(response.GetHexMaxU32(false, UINT32_MAX), eErrorTypePOSIX); |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 3156 | } |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 3157 | return Error(); |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 3158 | |
| 3159 | } |
| 3160 | |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 3161 | Error |
| 3162 | GDBRemoteCommunicationClient::SetFilePermissions (const char *path, |
| 3163 | uint32_t file_permissions) |
| 3164 | { |
| 3165 | lldb_private::StreamString stream; |
| 3166 | stream.PutCString("qPlatform_chmod:"); |
| 3167 | stream.PutHex32(file_permissions); |
| 3168 | stream.PutChar(','); |
| 3169 | stream.PutBytesAsRawHex8(path, strlen(path)); |
| 3170 | const char *packet = stream.GetData(); |
| 3171 | int packet_len = stream.GetSize(); |
| 3172 | StringExtractorGDBRemote response; |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 3173 | if (SendPacketAndWaitForResponse(packet, packet_len, response, false) == PacketResult::Success) |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 3174 | { |
| 3175 | return Error(response.GetHexMaxU32(false, UINT32_MAX), eErrorTypePOSIX); |
| 3176 | } |
| 3177 | return Error(); |
| 3178 | |
| 3179 | } |
| 3180 | |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 3181 | static uint64_t |
| 3182 | ParseHostIOPacketResponse (StringExtractorGDBRemote &response, |
| 3183 | uint64_t fail_result, |
| 3184 | Error &error) |
| 3185 | { |
| 3186 | response.SetFilePos(0); |
| 3187 | if (response.GetChar() != 'F') |
| 3188 | return fail_result; |
| 3189 | int32_t result = response.GetS32 (-2); |
| 3190 | if (result == -2) |
| 3191 | return fail_result; |
| 3192 | if (response.GetChar() == ',') |
| 3193 | { |
| 3194 | int result_errno = response.GetS32 (-2); |
| 3195 | if (result_errno != -2) |
| 3196 | error.SetError(result_errno, eErrorTypePOSIX); |
| 3197 | else |
| 3198 | error.SetError(-1, eErrorTypeGeneric); |
| 3199 | } |
| 3200 | else |
| 3201 | error.Clear(); |
| 3202 | return result; |
| 3203 | } |
| 3204 | lldb::user_id_t |
| 3205 | GDBRemoteCommunicationClient::OpenFile (const lldb_private::FileSpec& file_spec, |
| 3206 | uint32_t flags, |
| 3207 | mode_t mode, |
| 3208 | Error &error) |
| 3209 | { |
| 3210 | lldb_private::StreamString stream; |
| 3211 | stream.PutCString("vFile:open:"); |
| 3212 | std::string path (file_spec.GetPath()); |
| 3213 | if (path.empty()) |
| 3214 | return UINT64_MAX; |
| 3215 | stream.PutCStringAsRawHex8(path.c_str()); |
| 3216 | stream.PutChar(','); |
| 3217 | const uint32_t posix_open_flags = File::ConvertOpenOptionsForPOSIXOpen(flags); |
| 3218 | stream.PutHex32(posix_open_flags); |
| 3219 | stream.PutChar(','); |
| 3220 | stream.PutHex32(mode); |
| 3221 | const char* packet = stream.GetData(); |
| 3222 | int packet_len = stream.GetSize(); |
| 3223 | StringExtractorGDBRemote response; |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 3224 | if (SendPacketAndWaitForResponse(packet, packet_len, response, false) == PacketResult::Success) |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 3225 | { |
| 3226 | return ParseHostIOPacketResponse (response, UINT64_MAX, error); |
| 3227 | } |
| 3228 | return UINT64_MAX; |
| 3229 | } |
| 3230 | |
| 3231 | bool |
| 3232 | GDBRemoteCommunicationClient::CloseFile (lldb::user_id_t fd, |
| 3233 | Error &error) |
| 3234 | { |
| 3235 | lldb_private::StreamString stream; |
| 3236 | stream.Printf("vFile:close:%i", (int)fd); |
| 3237 | const char* packet = stream.GetData(); |
| 3238 | int packet_len = stream.GetSize(); |
| 3239 | StringExtractorGDBRemote response; |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 3240 | if (SendPacketAndWaitForResponse(packet, packet_len, response, false) == PacketResult::Success) |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 3241 | { |
| 3242 | return ParseHostIOPacketResponse (response, -1, error) == 0; |
| 3243 | } |
Deepak Panickal | d66b50c | 2013-10-22 12:27:43 +0000 | [diff] [blame] | 3244 | return false; |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 3245 | } |
| 3246 | |
| 3247 | // Extension of host I/O packets to get the file size. |
| 3248 | lldb::user_id_t |
| 3249 | GDBRemoteCommunicationClient::GetFileSize (const lldb_private::FileSpec& file_spec) |
| 3250 | { |
| 3251 | lldb_private::StreamString stream; |
| 3252 | stream.PutCString("vFile:size:"); |
| 3253 | std::string path (file_spec.GetPath()); |
| 3254 | stream.PutCStringAsRawHex8(path.c_str()); |
| 3255 | const char* packet = stream.GetData(); |
| 3256 | int packet_len = stream.GetSize(); |
| 3257 | StringExtractorGDBRemote response; |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 3258 | if (SendPacketAndWaitForResponse(packet, packet_len, response, false) == PacketResult::Success) |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 3259 | { |
| 3260 | if (response.GetChar() != 'F') |
| 3261 | return UINT64_MAX; |
| 3262 | uint32_t retcode = response.GetHexMaxU64(false, UINT64_MAX); |
| 3263 | return retcode; |
| 3264 | } |
| 3265 | return UINT64_MAX; |
| 3266 | } |
| 3267 | |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 3268 | Error |
| 3269 | GDBRemoteCommunicationClient::GetFilePermissions(const char *path, uint32_t &file_permissions) |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 3270 | { |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 3271 | Error error; |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 3272 | lldb_private::StreamString stream; |
| 3273 | stream.PutCString("vFile:mode:"); |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 3274 | stream.PutCStringAsRawHex8(path); |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 3275 | const char* packet = stream.GetData(); |
| 3276 | int packet_len = stream.GetSize(); |
| 3277 | StringExtractorGDBRemote response; |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 3278 | if (SendPacketAndWaitForResponse(packet, packet_len, response, false) == PacketResult::Success) |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 3279 | { |
| 3280 | if (response.GetChar() != 'F') |
| 3281 | { |
| 3282 | error.SetErrorStringWithFormat ("invalid response to '%s' packet", packet); |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 3283 | } |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 3284 | else |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 3285 | { |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 3286 | const uint32_t mode = response.GetS32(-1); |
Saleem Abdulrasool | 3985c8c | 2014-04-02 03:51:35 +0000 | [diff] [blame] | 3287 | if (static_cast<int32_t>(mode) == -1) |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 3288 | { |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 3289 | if (response.GetChar() == ',') |
| 3290 | { |
| 3291 | int response_errno = response.GetS32(-1); |
| 3292 | if (response_errno > 0) |
| 3293 | error.SetError(response_errno, lldb::eErrorTypePOSIX); |
| 3294 | else |
| 3295 | error.SetErrorToGenericError(); |
| 3296 | } |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 3297 | else |
| 3298 | error.SetErrorToGenericError(); |
| 3299 | } |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 3300 | else |
| 3301 | { |
| 3302 | file_permissions = mode & (S_IRWXU|S_IRWXG|S_IRWXO); |
| 3303 | } |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 3304 | } |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 3305 | } |
| 3306 | else |
| 3307 | { |
| 3308 | error.SetErrorStringWithFormat ("failed to send '%s' packet", packet); |
| 3309 | } |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 3310 | return error; |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 3311 | } |
| 3312 | |
| 3313 | uint64_t |
| 3314 | GDBRemoteCommunicationClient::ReadFile (lldb::user_id_t fd, |
| 3315 | uint64_t offset, |
| 3316 | void *dst, |
| 3317 | uint64_t dst_len, |
| 3318 | Error &error) |
| 3319 | { |
| 3320 | lldb_private::StreamString stream; |
| 3321 | stream.Printf("vFile:pread:%i,%" PRId64 ",%" PRId64, (int)fd, dst_len, offset); |
| 3322 | const char* packet = stream.GetData(); |
| 3323 | int packet_len = stream.GetSize(); |
| 3324 | StringExtractorGDBRemote response; |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 3325 | if (SendPacketAndWaitForResponse(packet, packet_len, response, false) == PacketResult::Success) |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 3326 | { |
| 3327 | if (response.GetChar() != 'F') |
| 3328 | return 0; |
| 3329 | uint32_t retcode = response.GetHexMaxU32(false, UINT32_MAX); |
| 3330 | if (retcode == UINT32_MAX) |
| 3331 | return retcode; |
| 3332 | const char next = (response.Peek() ? *response.Peek() : 0); |
| 3333 | if (next == ',') |
| 3334 | return 0; |
| 3335 | if (next == ';') |
| 3336 | { |
| 3337 | response.GetChar(); // skip the semicolon |
| 3338 | std::string buffer; |
| 3339 | if (response.GetEscapedBinaryData(buffer)) |
| 3340 | { |
| 3341 | const uint64_t data_to_write = std::min<uint64_t>(dst_len, buffer.size()); |
| 3342 | if (data_to_write > 0) |
| 3343 | memcpy(dst, &buffer[0], data_to_write); |
| 3344 | return data_to_write; |
| 3345 | } |
| 3346 | } |
| 3347 | } |
| 3348 | return 0; |
| 3349 | } |
| 3350 | |
| 3351 | uint64_t |
| 3352 | GDBRemoteCommunicationClient::WriteFile (lldb::user_id_t fd, |
| 3353 | uint64_t offset, |
| 3354 | const void* src, |
| 3355 | uint64_t src_len, |
| 3356 | Error &error) |
| 3357 | { |
| 3358 | lldb_private::StreamGDBRemote stream; |
| 3359 | stream.Printf("vFile:pwrite:%i,%" PRId64 ",", (int)fd, offset); |
| 3360 | stream.PutEscapedBytes(src, src_len); |
| 3361 | const char* packet = stream.GetData(); |
| 3362 | int packet_len = stream.GetSize(); |
| 3363 | StringExtractorGDBRemote response; |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 3364 | if (SendPacketAndWaitForResponse(packet, packet_len, response, false) == PacketResult::Success) |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 3365 | { |
| 3366 | if (response.GetChar() != 'F') |
| 3367 | { |
| 3368 | error.SetErrorStringWithFormat("write file failed"); |
| 3369 | return 0; |
| 3370 | } |
| 3371 | uint64_t bytes_written = response.GetU64(UINT64_MAX); |
| 3372 | if (bytes_written == UINT64_MAX) |
| 3373 | { |
| 3374 | error.SetErrorToGenericError(); |
| 3375 | if (response.GetChar() == ',') |
| 3376 | { |
| 3377 | int response_errno = response.GetS32(-1); |
| 3378 | if (response_errno > 0) |
| 3379 | error.SetError(response_errno, lldb::eErrorTypePOSIX); |
| 3380 | } |
| 3381 | return 0; |
| 3382 | } |
| 3383 | return bytes_written; |
| 3384 | } |
| 3385 | else |
| 3386 | { |
| 3387 | error.SetErrorString ("failed to send vFile:pwrite packet"); |
| 3388 | } |
| 3389 | return 0; |
| 3390 | } |
| 3391 | |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 3392 | Error |
| 3393 | GDBRemoteCommunicationClient::CreateSymlink (const char *src, const char *dst) |
| 3394 | { |
| 3395 | Error error; |
| 3396 | lldb_private::StreamGDBRemote stream; |
| 3397 | stream.PutCString("vFile:symlink:"); |
| 3398 | // the unix symlink() command reverses its parameters where the dst if first, |
| 3399 | // so we follow suit here |
| 3400 | stream.PutCStringAsRawHex8(dst); |
| 3401 | stream.PutChar(','); |
| 3402 | stream.PutCStringAsRawHex8(src); |
| 3403 | const char* packet = stream.GetData(); |
| 3404 | int packet_len = stream.GetSize(); |
| 3405 | StringExtractorGDBRemote response; |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 3406 | if (SendPacketAndWaitForResponse(packet, packet_len, response, false) == PacketResult::Success) |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 3407 | { |
| 3408 | if (response.GetChar() == 'F') |
| 3409 | { |
| 3410 | uint32_t result = response.GetU32(UINT32_MAX); |
| 3411 | if (result != 0) |
| 3412 | { |
| 3413 | error.SetErrorToGenericError(); |
| 3414 | if (response.GetChar() == ',') |
| 3415 | { |
| 3416 | int response_errno = response.GetS32(-1); |
| 3417 | if (response_errno > 0) |
| 3418 | error.SetError(response_errno, lldb::eErrorTypePOSIX); |
| 3419 | } |
| 3420 | } |
| 3421 | } |
| 3422 | else |
| 3423 | { |
| 3424 | // Should have returned with 'F<result>[,<errno>]' |
| 3425 | error.SetErrorStringWithFormat("symlink failed"); |
| 3426 | } |
| 3427 | } |
| 3428 | else |
| 3429 | { |
| 3430 | error.SetErrorString ("failed to send vFile:symlink packet"); |
| 3431 | } |
| 3432 | return error; |
| 3433 | } |
| 3434 | |
| 3435 | Error |
| 3436 | GDBRemoteCommunicationClient::Unlink (const char *path) |
| 3437 | { |
| 3438 | Error error; |
| 3439 | lldb_private::StreamGDBRemote stream; |
| 3440 | stream.PutCString("vFile:unlink:"); |
| 3441 | // the unix symlink() command reverses its parameters where the dst if first, |
| 3442 | // so we follow suit here |
| 3443 | stream.PutCStringAsRawHex8(path); |
| 3444 | const char* packet = stream.GetData(); |
| 3445 | int packet_len = stream.GetSize(); |
| 3446 | StringExtractorGDBRemote response; |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 3447 | if (SendPacketAndWaitForResponse(packet, packet_len, response, false) == PacketResult::Success) |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 3448 | { |
| 3449 | if (response.GetChar() == 'F') |
| 3450 | { |
| 3451 | uint32_t result = response.GetU32(UINT32_MAX); |
| 3452 | if (result != 0) |
| 3453 | { |
| 3454 | error.SetErrorToGenericError(); |
| 3455 | if (response.GetChar() == ',') |
| 3456 | { |
| 3457 | int response_errno = response.GetS32(-1); |
| 3458 | if (response_errno > 0) |
| 3459 | error.SetError(response_errno, lldb::eErrorTypePOSIX); |
| 3460 | } |
| 3461 | } |
| 3462 | } |
| 3463 | else |
| 3464 | { |
| 3465 | // Should have returned with 'F<result>[,<errno>]' |
| 3466 | error.SetErrorStringWithFormat("unlink failed"); |
| 3467 | } |
| 3468 | } |
| 3469 | else |
| 3470 | { |
| 3471 | error.SetErrorString ("failed to send vFile:unlink packet"); |
| 3472 | } |
| 3473 | return error; |
| 3474 | } |
| 3475 | |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 3476 | // Extension of host I/O packets to get whether a file exists. |
| 3477 | bool |
| 3478 | GDBRemoteCommunicationClient::GetFileExists (const lldb_private::FileSpec& file_spec) |
| 3479 | { |
| 3480 | lldb_private::StreamString stream; |
| 3481 | stream.PutCString("vFile:exists:"); |
| 3482 | std::string path (file_spec.GetPath()); |
| 3483 | stream.PutCStringAsRawHex8(path.c_str()); |
| 3484 | const char* packet = stream.GetData(); |
| 3485 | int packet_len = stream.GetSize(); |
| 3486 | StringExtractorGDBRemote response; |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 3487 | if (SendPacketAndWaitForResponse(packet, packet_len, response, false) == PacketResult::Success) |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 3488 | { |
| 3489 | if (response.GetChar() != 'F') |
| 3490 | return false; |
| 3491 | if (response.GetChar() != ',') |
| 3492 | return false; |
| 3493 | bool retcode = (response.GetChar() != '0'); |
| 3494 | return retcode; |
| 3495 | } |
| 3496 | return false; |
| 3497 | } |
| 3498 | |
| 3499 | bool |
| 3500 | GDBRemoteCommunicationClient::CalculateMD5 (const lldb_private::FileSpec& file_spec, |
| 3501 | uint64_t &high, |
| 3502 | uint64_t &low) |
| 3503 | { |
| 3504 | lldb_private::StreamString stream; |
| 3505 | stream.PutCString("vFile:MD5:"); |
| 3506 | std::string path (file_spec.GetPath()); |
| 3507 | stream.PutCStringAsRawHex8(path.c_str()); |
| 3508 | const char* packet = stream.GetData(); |
| 3509 | int packet_len = stream.GetSize(); |
| 3510 | StringExtractorGDBRemote response; |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 3511 | if (SendPacketAndWaitForResponse(packet, packet_len, response, false) == PacketResult::Success) |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 3512 | { |
| 3513 | if (response.GetChar() != 'F') |
| 3514 | return false; |
| 3515 | if (response.GetChar() != ',') |
| 3516 | return false; |
| 3517 | if (response.Peek() && *response.Peek() == 'x') |
| 3518 | return false; |
| 3519 | low = response.GetHexMaxU64(false, UINT64_MAX); |
| 3520 | high = response.GetHexMaxU64(false, UINT64_MAX); |
| 3521 | return true; |
| 3522 | } |
| 3523 | return false; |
| 3524 | } |
Greg Clayton | f74cf86 | 2013-11-13 23:28:31 +0000 | [diff] [blame] | 3525 | |
| 3526 | bool |
Jason Molenda | a332978 | 2014-03-29 18:54:20 +0000 | [diff] [blame] | 3527 | GDBRemoteCommunicationClient::AvoidGPackets (ProcessGDBRemote *process) |
| 3528 | { |
| 3529 | // Some targets have issues with g/G packets and we need to avoid using them |
| 3530 | if (m_avoid_g_packets == eLazyBoolCalculate) |
| 3531 | { |
| 3532 | if (process) |
| 3533 | { |
| 3534 | m_avoid_g_packets = eLazyBoolNo; |
| 3535 | const ArchSpec &arch = process->GetTarget().GetArchitecture(); |
| 3536 | if (arch.IsValid() |
| 3537 | && arch.GetTriple().getVendor() == llvm::Triple::Apple |
| 3538 | && arch.GetTriple().getOS() == llvm::Triple::IOS |
Todd Fiala | d8eaa17 | 2014-07-23 14:37:35 +0000 | [diff] [blame] | 3539 | && arch.GetTriple().getArch() == llvm::Triple::aarch64) |
Jason Molenda | a332978 | 2014-03-29 18:54:20 +0000 | [diff] [blame] | 3540 | { |
| 3541 | m_avoid_g_packets = eLazyBoolYes; |
| 3542 | uint32_t gdb_server_version = GetGDBServerProgramVersion(); |
| 3543 | if (gdb_server_version != 0) |
| 3544 | { |
| 3545 | const char *gdb_server_name = GetGDBServerProgramName(); |
| 3546 | if (gdb_server_name && strcmp(gdb_server_name, "debugserver") == 0) |
| 3547 | { |
| 3548 | if (gdb_server_version >= 310) |
| 3549 | m_avoid_g_packets = eLazyBoolNo; |
| 3550 | } |
| 3551 | } |
| 3552 | } |
| 3553 | } |
| 3554 | } |
| 3555 | return m_avoid_g_packets == eLazyBoolYes; |
| 3556 | } |
| 3557 | |
| 3558 | bool |
Greg Clayton | f74cf86 | 2013-11-13 23:28:31 +0000 | [diff] [blame] | 3559 | GDBRemoteCommunicationClient::ReadRegister(lldb::tid_t tid, uint32_t reg, StringExtractorGDBRemote &response) |
| 3560 | { |
| 3561 | Mutex::Locker locker; |
| 3562 | if (GetSequenceMutex (locker, "Didn't get sequence mutex for p packet.")) |
| 3563 | { |
| 3564 | const bool thread_suffix_supported = GetThreadSuffixSupported(); |
| 3565 | |
| 3566 | if (thread_suffix_supported || SetCurrentThread(tid)) |
| 3567 | { |
| 3568 | char packet[64]; |
| 3569 | int packet_len = 0; |
| 3570 | if (thread_suffix_supported) |
| 3571 | packet_len = ::snprintf (packet, sizeof(packet), "p%x;thread:%4.4" PRIx64 ";", reg, tid); |
| 3572 | else |
| 3573 | packet_len = ::snprintf (packet, sizeof(packet), "p%x", reg); |
| 3574 | assert (packet_len < ((int)sizeof(packet) - 1)); |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 3575 | return SendPacketAndWaitForResponse(packet, response, false) == PacketResult::Success; |
Greg Clayton | f74cf86 | 2013-11-13 23:28:31 +0000 | [diff] [blame] | 3576 | } |
| 3577 | } |
| 3578 | return false; |
| 3579 | |
| 3580 | } |
| 3581 | |
| 3582 | |
| 3583 | bool |
| 3584 | GDBRemoteCommunicationClient::ReadAllRegisters (lldb::tid_t tid, StringExtractorGDBRemote &response) |
| 3585 | { |
| 3586 | Mutex::Locker locker; |
| 3587 | if (GetSequenceMutex (locker, "Didn't get sequence mutex for g packet.")) |
| 3588 | { |
| 3589 | const bool thread_suffix_supported = GetThreadSuffixSupported(); |
| 3590 | |
| 3591 | if (thread_suffix_supported || SetCurrentThread(tid)) |
| 3592 | { |
| 3593 | char packet[64]; |
| 3594 | int packet_len = 0; |
| 3595 | // Get all registers in one packet |
| 3596 | if (thread_suffix_supported) |
| 3597 | packet_len = ::snprintf (packet, sizeof(packet), "g;thread:%4.4" PRIx64 ";", tid); |
| 3598 | else |
| 3599 | packet_len = ::snprintf (packet, sizeof(packet), "g"); |
| 3600 | assert (packet_len < ((int)sizeof(packet) - 1)); |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 3601 | return SendPacketAndWaitForResponse(packet, response, false) == PacketResult::Success; |
Greg Clayton | f74cf86 | 2013-11-13 23:28:31 +0000 | [diff] [blame] | 3602 | } |
| 3603 | } |
| 3604 | return false; |
| 3605 | } |
| 3606 | bool |
| 3607 | GDBRemoteCommunicationClient::SaveRegisterState (lldb::tid_t tid, uint32_t &save_id) |
| 3608 | { |
| 3609 | save_id = 0; // Set to invalid save ID |
| 3610 | if (m_supports_QSaveRegisterState == eLazyBoolNo) |
| 3611 | return false; |
| 3612 | |
| 3613 | m_supports_QSaveRegisterState = eLazyBoolYes; |
| 3614 | Mutex::Locker locker; |
| 3615 | if (GetSequenceMutex (locker, "Didn't get sequence mutex for QSaveRegisterState.")) |
| 3616 | { |
| 3617 | const bool thread_suffix_supported = GetThreadSuffixSupported(); |
| 3618 | if (thread_suffix_supported || SetCurrentThread(tid)) |
| 3619 | { |
| 3620 | char packet[256]; |
| 3621 | if (thread_suffix_supported) |
| 3622 | ::snprintf (packet, sizeof(packet), "QSaveRegisterState;thread:%4.4" PRIx64 ";", tid); |
| 3623 | else |
| 3624 | ::strncpy (packet, "QSaveRegisterState", sizeof(packet)); |
| 3625 | |
| 3626 | StringExtractorGDBRemote response; |
| 3627 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 3628 | if (SendPacketAndWaitForResponse(packet, response, false) == PacketResult::Success) |
Greg Clayton | f74cf86 | 2013-11-13 23:28:31 +0000 | [diff] [blame] | 3629 | { |
| 3630 | if (response.IsUnsupportedResponse()) |
| 3631 | { |
| 3632 | // This packet isn't supported, don't try calling it again |
| 3633 | m_supports_QSaveRegisterState = eLazyBoolNo; |
| 3634 | } |
| 3635 | |
| 3636 | const uint32_t response_save_id = response.GetU32(0); |
| 3637 | if (response_save_id != 0) |
| 3638 | { |
| 3639 | save_id = response_save_id; |
| 3640 | return true; |
| 3641 | } |
| 3642 | } |
| 3643 | } |
| 3644 | } |
| 3645 | return false; |
| 3646 | } |
| 3647 | |
| 3648 | bool |
| 3649 | GDBRemoteCommunicationClient::RestoreRegisterState (lldb::tid_t tid, uint32_t save_id) |
| 3650 | { |
Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 3651 | // We use the "m_supports_QSaveRegisterState" variable here because the |
Greg Clayton | f74cf86 | 2013-11-13 23:28:31 +0000 | [diff] [blame] | 3652 | // QSaveRegisterState and QRestoreRegisterState packets must both be supported in |
| 3653 | // order to be useful |
| 3654 | if (m_supports_QSaveRegisterState == eLazyBoolNo) |
| 3655 | return false; |
| 3656 | |
| 3657 | Mutex::Locker locker; |
| 3658 | if (GetSequenceMutex (locker, "Didn't get sequence mutex for QRestoreRegisterState.")) |
| 3659 | { |
| 3660 | const bool thread_suffix_supported = GetThreadSuffixSupported(); |
| 3661 | if (thread_suffix_supported || SetCurrentThread(tid)) |
| 3662 | { |
| 3663 | char packet[256]; |
| 3664 | if (thread_suffix_supported) |
| 3665 | ::snprintf (packet, sizeof(packet), "QRestoreRegisterState:%u;thread:%4.4" PRIx64 ";", save_id, tid); |
| 3666 | else |
| 3667 | ::snprintf (packet, sizeof(packet), "QRestoreRegisterState:%u" PRIx64 ";", save_id); |
| 3668 | |
| 3669 | StringExtractorGDBRemote response; |
| 3670 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 3671 | if (SendPacketAndWaitForResponse(packet, response, false) == PacketResult::Success) |
Greg Clayton | f74cf86 | 2013-11-13 23:28:31 +0000 | [diff] [blame] | 3672 | { |
| 3673 | if (response.IsOKResponse()) |
| 3674 | { |
| 3675 | return true; |
| 3676 | } |
| 3677 | else if (response.IsUnsupportedResponse()) |
| 3678 | { |
| 3679 | // This packet isn't supported, don't try calling this packet or |
| 3680 | // QSaveRegisterState again... |
| 3681 | m_supports_QSaveRegisterState = eLazyBoolNo; |
| 3682 | } |
| 3683 | } |
| 3684 | } |
| 3685 | } |
| 3686 | return false; |
| 3687 | } |