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