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