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