Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 1 | //===-- GDBRemoteCommunicationServerCommon.cpp ------------------*- C++ -*-===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #include "GDBRemoteCommunicationServerCommon.h" |
| 10 | |
| 11 | #include <errno.h> |
| 12 | |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 13 | #ifdef __APPLE__ |
| 14 | #include <TargetConditionals.h> |
| 15 | #endif |
| 16 | |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 17 | #include <chrono> |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 18 | #include <cstring> |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 19 | |
Oleksiy Vyalov | 6801be3 | 2015-02-25 22:15:44 +0000 | [diff] [blame] | 20 | #include "lldb/Core/ModuleSpec.h" |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 21 | #include "lldb/Host/Config.h" |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 22 | #include "lldb/Host/File.h" |
Pavel Labath | eef758e | 2019-02-04 14:28:08 +0000 | [diff] [blame] | 23 | #include "lldb/Host/FileAction.h" |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 24 | #include "lldb/Host/FileSystem.h" |
| 25 | #include "lldb/Host/Host.h" |
| 26 | #include "lldb/Host/HostInfo.h" |
Pavel Labath | 7704473 | 2018-09-12 12:26:05 +0000 | [diff] [blame] | 27 | #include "lldb/Host/SafeMachO.h" |
Pavel Labath | 47cbf4a | 2018-04-10 09:03:59 +0000 | [diff] [blame] | 28 | #include "lldb/Interpreter/OptionArgParser.h" |
Oleksiy Vyalov | 6801be3 | 2015-02-25 22:15:44 +0000 | [diff] [blame] | 29 | #include "lldb/Symbol/ObjectFile.h" |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 30 | #include "lldb/Target/Platform.h" |
Zachary Turner | 01c3243 | 2017-02-14 19:06:07 +0000 | [diff] [blame] | 31 | #include "lldb/Utility/Endian.h" |
Pavel Labath | 2f1fbae | 2016-09-08 10:07:04 +0000 | [diff] [blame] | 32 | #include "lldb/Utility/JSON.h" |
Zachary Turner | 6f9e690 | 2017-03-03 20:56:28 +0000 | [diff] [blame] | 33 | #include "lldb/Utility/Log.h" |
Zachary Turner | fb1a0a0 | 2017-03-06 18:34:25 +0000 | [diff] [blame] | 34 | #include "lldb/Utility/StreamGDBRemote.h" |
Zachary Turner | bf9a773 | 2017-02-02 21:39:50 +0000 | [diff] [blame] | 35 | #include "lldb/Utility/StreamString.h" |
Saleem Abdulrasool | bd689b9 | 2019-05-02 18:15:03 +0000 | [diff] [blame] | 36 | #include "lldb/Utility/StructuredData.h" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 37 | #include "llvm/ADT/Triple.h" |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 38 | |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 39 | #include "ProcessGDBRemoteLog.h" |
Pavel Labath | 9af71b3 | 2018-03-20 16:14:00 +0000 | [diff] [blame] | 40 | #include "lldb/Utility/StringExtractorGDBRemote.h" |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 41 | |
Tamas Berghammer | dad4db7 | 2015-03-13 11:16:08 +0000 | [diff] [blame] | 42 | #ifdef __ANDROID__ |
| 43 | #include "lldb/Host/android/HostInfoAndroid.h" |
| 44 | #endif |
| 45 | |
Zachary Turner | 54695a3 | 2016-08-29 19:58:14 +0000 | [diff] [blame] | 46 | #include "llvm/ADT/StringSwitch.h" |
| 47 | |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 48 | using namespace lldb; |
| 49 | using namespace lldb_private; |
Tamas Berghammer | db264a6 | 2015-03-31 09:52:22 +0000 | [diff] [blame] | 50 | using namespace lldb_private::process_gdb_remote; |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 51 | |
Tamas Berghammer | 2d52afd | 2015-02-26 11:37:21 +0000 | [diff] [blame] | 52 | #ifdef __ANDROID__ |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 53 | const static uint32_t g_default_packet_timeout_sec = 20; // seconds |
Tamas Berghammer | 2d52afd | 2015-02-26 11:37:21 +0000 | [diff] [blame] | 54 | #else |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 55 | const static uint32_t g_default_packet_timeout_sec = 0; // not specified |
Tamas Berghammer | 2d52afd | 2015-02-26 11:37:21 +0000 | [diff] [blame] | 56 | #endif |
| 57 | |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 58 | // GDBRemoteCommunicationServerCommon constructor |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 59 | GDBRemoteCommunicationServerCommon::GDBRemoteCommunicationServerCommon( |
| 60 | const char *comm_name, const char *listener_name) |
| 61 | : GDBRemoteCommunicationServer(comm_name, listener_name), |
| 62 | m_process_launch_info(), m_process_launch_error(), m_proc_infos(), |
| 63 | m_proc_infos_index(0), m_thread_suffix_supported(false), |
| 64 | m_list_threads_in_stop_reply(false) { |
| 65 | RegisterMemberFunctionHandler(StringExtractorGDBRemote::eServerPacketType_A, |
| 66 | &GDBRemoteCommunicationServerCommon::Handle_A); |
| 67 | RegisterMemberFunctionHandler( |
| 68 | StringExtractorGDBRemote::eServerPacketType_QEnvironment, |
| 69 | &GDBRemoteCommunicationServerCommon::Handle_QEnvironment); |
| 70 | RegisterMemberFunctionHandler( |
| 71 | StringExtractorGDBRemote::eServerPacketType_QEnvironmentHexEncoded, |
| 72 | &GDBRemoteCommunicationServerCommon::Handle_QEnvironmentHexEncoded); |
| 73 | RegisterMemberFunctionHandler( |
| 74 | StringExtractorGDBRemote::eServerPacketType_qfProcessInfo, |
| 75 | &GDBRemoteCommunicationServerCommon::Handle_qfProcessInfo); |
| 76 | RegisterMemberFunctionHandler( |
| 77 | StringExtractorGDBRemote::eServerPacketType_qGroupName, |
| 78 | &GDBRemoteCommunicationServerCommon::Handle_qGroupName); |
| 79 | RegisterMemberFunctionHandler( |
| 80 | StringExtractorGDBRemote::eServerPacketType_qHostInfo, |
| 81 | &GDBRemoteCommunicationServerCommon::Handle_qHostInfo); |
| 82 | RegisterMemberFunctionHandler( |
| 83 | StringExtractorGDBRemote::eServerPacketType_QLaunchArch, |
| 84 | &GDBRemoteCommunicationServerCommon::Handle_QLaunchArch); |
| 85 | RegisterMemberFunctionHandler( |
| 86 | StringExtractorGDBRemote::eServerPacketType_qLaunchSuccess, |
| 87 | &GDBRemoteCommunicationServerCommon::Handle_qLaunchSuccess); |
| 88 | RegisterMemberFunctionHandler( |
| 89 | StringExtractorGDBRemote::eServerPacketType_QListThreadsInStopReply, |
| 90 | &GDBRemoteCommunicationServerCommon::Handle_QListThreadsInStopReply); |
| 91 | RegisterMemberFunctionHandler( |
| 92 | StringExtractorGDBRemote::eServerPacketType_qEcho, |
| 93 | &GDBRemoteCommunicationServerCommon::Handle_qEcho); |
| 94 | RegisterMemberFunctionHandler( |
| 95 | StringExtractorGDBRemote::eServerPacketType_qModuleInfo, |
| 96 | &GDBRemoteCommunicationServerCommon::Handle_qModuleInfo); |
| 97 | RegisterMemberFunctionHandler( |
Pavel Labath | 2f1fbae | 2016-09-08 10:07:04 +0000 | [diff] [blame] | 98 | StringExtractorGDBRemote::eServerPacketType_jModulesInfo, |
| 99 | &GDBRemoteCommunicationServerCommon::Handle_jModulesInfo); |
| 100 | RegisterMemberFunctionHandler( |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 101 | StringExtractorGDBRemote::eServerPacketType_qPlatform_chmod, |
| 102 | &GDBRemoteCommunicationServerCommon::Handle_qPlatform_chmod); |
| 103 | RegisterMemberFunctionHandler( |
| 104 | StringExtractorGDBRemote::eServerPacketType_qPlatform_mkdir, |
| 105 | &GDBRemoteCommunicationServerCommon::Handle_qPlatform_mkdir); |
| 106 | RegisterMemberFunctionHandler( |
| 107 | StringExtractorGDBRemote::eServerPacketType_qPlatform_shell, |
| 108 | &GDBRemoteCommunicationServerCommon::Handle_qPlatform_shell); |
| 109 | RegisterMemberFunctionHandler( |
| 110 | StringExtractorGDBRemote::eServerPacketType_qProcessInfoPID, |
| 111 | &GDBRemoteCommunicationServerCommon::Handle_qProcessInfoPID); |
| 112 | RegisterMemberFunctionHandler( |
| 113 | StringExtractorGDBRemote::eServerPacketType_QSetDetachOnError, |
| 114 | &GDBRemoteCommunicationServerCommon::Handle_QSetDetachOnError); |
| 115 | RegisterMemberFunctionHandler( |
| 116 | StringExtractorGDBRemote::eServerPacketType_QSetSTDERR, |
| 117 | &GDBRemoteCommunicationServerCommon::Handle_QSetSTDERR); |
| 118 | RegisterMemberFunctionHandler( |
| 119 | StringExtractorGDBRemote::eServerPacketType_QSetSTDIN, |
| 120 | &GDBRemoteCommunicationServerCommon::Handle_QSetSTDIN); |
| 121 | RegisterMemberFunctionHandler( |
| 122 | StringExtractorGDBRemote::eServerPacketType_QSetSTDOUT, |
| 123 | &GDBRemoteCommunicationServerCommon::Handle_QSetSTDOUT); |
| 124 | RegisterMemberFunctionHandler( |
| 125 | StringExtractorGDBRemote::eServerPacketType_qSpeedTest, |
| 126 | &GDBRemoteCommunicationServerCommon::Handle_qSpeedTest); |
| 127 | RegisterMemberFunctionHandler( |
| 128 | StringExtractorGDBRemote::eServerPacketType_qsProcessInfo, |
| 129 | &GDBRemoteCommunicationServerCommon::Handle_qsProcessInfo); |
| 130 | RegisterMemberFunctionHandler( |
| 131 | StringExtractorGDBRemote::eServerPacketType_QStartNoAckMode, |
| 132 | &GDBRemoteCommunicationServerCommon::Handle_QStartNoAckMode); |
| 133 | RegisterMemberFunctionHandler( |
| 134 | StringExtractorGDBRemote::eServerPacketType_qSupported, |
| 135 | &GDBRemoteCommunicationServerCommon::Handle_qSupported); |
| 136 | RegisterMemberFunctionHandler( |
| 137 | StringExtractorGDBRemote::eServerPacketType_QThreadSuffixSupported, |
| 138 | &GDBRemoteCommunicationServerCommon::Handle_QThreadSuffixSupported); |
| 139 | RegisterMemberFunctionHandler( |
| 140 | StringExtractorGDBRemote::eServerPacketType_qUserName, |
| 141 | &GDBRemoteCommunicationServerCommon::Handle_qUserName); |
| 142 | RegisterMemberFunctionHandler( |
| 143 | StringExtractorGDBRemote::eServerPacketType_vFile_close, |
| 144 | &GDBRemoteCommunicationServerCommon::Handle_vFile_Close); |
| 145 | RegisterMemberFunctionHandler( |
| 146 | StringExtractorGDBRemote::eServerPacketType_vFile_exists, |
| 147 | &GDBRemoteCommunicationServerCommon::Handle_vFile_Exists); |
| 148 | RegisterMemberFunctionHandler( |
| 149 | StringExtractorGDBRemote::eServerPacketType_vFile_md5, |
| 150 | &GDBRemoteCommunicationServerCommon::Handle_vFile_MD5); |
| 151 | RegisterMemberFunctionHandler( |
| 152 | StringExtractorGDBRemote::eServerPacketType_vFile_mode, |
| 153 | &GDBRemoteCommunicationServerCommon::Handle_vFile_Mode); |
| 154 | RegisterMemberFunctionHandler( |
| 155 | StringExtractorGDBRemote::eServerPacketType_vFile_open, |
| 156 | &GDBRemoteCommunicationServerCommon::Handle_vFile_Open); |
| 157 | RegisterMemberFunctionHandler( |
| 158 | StringExtractorGDBRemote::eServerPacketType_vFile_pread, |
| 159 | &GDBRemoteCommunicationServerCommon::Handle_vFile_pRead); |
| 160 | RegisterMemberFunctionHandler( |
| 161 | StringExtractorGDBRemote::eServerPacketType_vFile_pwrite, |
| 162 | &GDBRemoteCommunicationServerCommon::Handle_vFile_pWrite); |
| 163 | RegisterMemberFunctionHandler( |
| 164 | StringExtractorGDBRemote::eServerPacketType_vFile_size, |
| 165 | &GDBRemoteCommunicationServerCommon::Handle_vFile_Size); |
| 166 | RegisterMemberFunctionHandler( |
| 167 | StringExtractorGDBRemote::eServerPacketType_vFile_stat, |
| 168 | &GDBRemoteCommunicationServerCommon::Handle_vFile_Stat); |
| 169 | RegisterMemberFunctionHandler( |
| 170 | StringExtractorGDBRemote::eServerPacketType_vFile_symlink, |
| 171 | &GDBRemoteCommunicationServerCommon::Handle_vFile_symlink); |
| 172 | RegisterMemberFunctionHandler( |
| 173 | StringExtractorGDBRemote::eServerPacketType_vFile_unlink, |
| 174 | &GDBRemoteCommunicationServerCommon::Handle_vFile_unlink); |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 175 | } |
| 176 | |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 177 | // Destructor |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 178 | GDBRemoteCommunicationServerCommon::~GDBRemoteCommunicationServerCommon() {} |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 179 | |
| 180 | GDBRemoteCommunication::PacketResult |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 181 | GDBRemoteCommunicationServerCommon::Handle_qHostInfo( |
| 182 | StringExtractorGDBRemote &packet) { |
| 183 | StreamString response; |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 184 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 185 | // $cputype:16777223;cpusubtype:3;ostype:Darwin;vendor:apple;endian:little;ptrsize:8;#00 |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 186 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 187 | ArchSpec host_arch(HostInfo::GetArchitecture()); |
| 188 | const llvm::Triple &host_triple = host_arch.GetTriple(); |
| 189 | response.PutCString("triple:"); |
Pavel Labath | 7f815a9 | 2019-02-12 14:28:55 +0000 | [diff] [blame] | 190 | response.PutStringAsRawHex8(host_triple.getTriple()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 191 | response.Printf(";ptrsize:%u;", host_arch.GetAddressByteSize()); |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 192 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 193 | const char *distribution_id = host_arch.GetDistributionId().AsCString(); |
| 194 | if (distribution_id) { |
| 195 | response.PutCString("distribution_id:"); |
Pavel Labath | 7f815a9 | 2019-02-12 14:28:55 +0000 | [diff] [blame] | 196 | response.PutStringAsRawHex8(distribution_id); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 197 | response.PutCString(";"); |
| 198 | } |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 199 | |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 200 | #if defined(__APPLE__) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 201 | // For parity with debugserver, we'll include the vendor key. |
| 202 | response.PutCString("vendor:apple;"); |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 203 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 204 | // Send out MachO info. |
| 205 | uint32_t cpu = host_arch.GetMachOCPUType(); |
| 206 | uint32_t sub = host_arch.GetMachOCPUSubType(); |
| 207 | if (cpu != LLDB_INVALID_CPUTYPE) |
| 208 | response.Printf("cputype:%u;", cpu); |
| 209 | if (sub != LLDB_INVALID_CPUTYPE) |
| 210 | response.Printf("cpusubtype:%u;", sub); |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 211 | |
Aaron Smith | 3a14249 | 2019-02-07 18:46:25 +0000 | [diff] [blame] | 212 | if (cpu == llvm::MachO::CPU_TYPE_ARM || cpu == llvm::MachO::CPU_TYPE_ARM64) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 213 | // Indicate the OS type. |
| 214 | #if defined(TARGET_OS_TV) && TARGET_OS_TV == 1 |
| 215 | response.PutCString("ostype:tvos;"); |
| 216 | #elif defined(TARGET_OS_WATCH) && TARGET_OS_WATCH == 1 |
| 217 | response.PutCString("ostype:watchos;"); |
Jason Molenda | 8c0d106 | 2018-02-05 23:10:51 +0000 | [diff] [blame] | 218 | #elif defined(TARGET_OS_BRIDGE) && TARGET_OS_BRIDGE == 1 |
| 219 | response.PutCString("ostype:bridgeos;"); |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 220 | #else |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 221 | response.PutCString("ostype:ios;"); |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 222 | #endif |
| 223 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 224 | // On arm, we use "synchronous" watchpoints which means the exception is |
| 225 | // delivered before the instruction executes. |
| 226 | response.PutCString("watchpoint_exceptions_received:before;"); |
| 227 | } else { |
| 228 | response.PutCString("ostype:macosx;"); |
| 229 | response.Printf("watchpoint_exceptions_received:after;"); |
| 230 | } |
Todd Fiala | e77fce0 | 2016-09-04 00:18:56 +0000 | [diff] [blame] | 231 | |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 232 | #else |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 233 | if (host_arch.GetMachine() == llvm::Triple::aarch64 || |
| 234 | host_arch.GetMachine() == llvm::Triple::aarch64_be || |
| 235 | host_arch.GetMachine() == llvm::Triple::arm || |
Fangrui Song | ddb93b6 | 2019-05-16 08:37:32 +0000 | [diff] [blame] | 236 | host_arch.GetMachine() == llvm::Triple::armeb || host_arch.IsMIPS()) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 237 | response.Printf("watchpoint_exceptions_received:before;"); |
| 238 | else |
| 239 | response.Printf("watchpoint_exceptions_received:after;"); |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 240 | #endif |
| 241 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 242 | switch (endian::InlHostByteOrder()) { |
| 243 | case eByteOrderBig: |
| 244 | response.PutCString("endian:big;"); |
| 245 | break; |
| 246 | case eByteOrderLittle: |
| 247 | response.PutCString("endian:little;"); |
| 248 | break; |
| 249 | case eByteOrderPDP: |
| 250 | response.PutCString("endian:pdp;"); |
| 251 | break; |
| 252 | default: |
| 253 | response.PutCString("endian:unknown;"); |
| 254 | break; |
| 255 | } |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 256 | |
Pavel Labath | 2272c48 | 2018-06-18 15:02:23 +0000 | [diff] [blame] | 257 | llvm::VersionTuple version = HostInfo::GetOSVersion(); |
| 258 | if (!version.empty()) { |
| 259 | response.Format("os_version:{0}", version.getAsString()); |
| 260 | response.PutChar(';'); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 261 | } |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 262 | |
Adrian Prantl | 2461061 | 2019-09-04 17:23:15 +0000 | [diff] [blame^] | 263 | #if defined(__APPLE__) |
| 264 | llvm::VersionTuple maccatalyst_version = HostInfo::GetMacCatalystVersion(); |
| 265 | if (!maccatalyst_version.empty()) { |
| 266 | response.Format("maccatalyst_version:{0}", |
| 267 | maccatalyst_version.getAsString()); |
| 268 | response.PutChar(';'); |
| 269 | } |
| 270 | #endif |
| 271 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 272 | std::string s; |
| 273 | if (HostInfo::GetOSBuildString(s)) { |
| 274 | response.PutCString("os_build:"); |
Pavel Labath | 7f815a9 | 2019-02-12 14:28:55 +0000 | [diff] [blame] | 275 | response.PutStringAsRawHex8(s); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 276 | response.PutChar(';'); |
| 277 | } |
| 278 | if (HostInfo::GetOSKernelDescription(s)) { |
| 279 | response.PutCString("os_kernel:"); |
Pavel Labath | 7f815a9 | 2019-02-12 14:28:55 +0000 | [diff] [blame] | 280 | response.PutStringAsRawHex8(s); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 281 | response.PutChar(';'); |
| 282 | } |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 283 | |
| 284 | #if defined(__APPLE__) |
| 285 | |
| 286 | #if defined(__arm__) || defined(__arm64__) || defined(__aarch64__) |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 287 | // For iOS devices, we are connected through a USB Mux so we never pretend to |
| 288 | // actually have a hostname as far as the remote lldb that is connecting to |
| 289 | // this lldb-platform is concerned |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 290 | response.PutCString("hostname:"); |
Pavel Labath | 7f815a9 | 2019-02-12 14:28:55 +0000 | [diff] [blame] | 291 | response.PutStringAsRawHex8("127.0.0.1"); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 292 | response.PutChar(';'); |
| 293 | #else // #if defined(__arm__) || defined(__arm64__) || defined(__aarch64__) |
| 294 | if (HostInfo::GetHostname(s)) { |
| 295 | response.PutCString("hostname:"); |
Pavel Labath | 7f815a9 | 2019-02-12 14:28:55 +0000 | [diff] [blame] | 296 | response.PutStringAsRawHex8(s); |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 297 | response.PutChar(';'); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 298 | } |
| 299 | #endif // #if defined(__arm__) || defined(__arm64__) || defined(__aarch64__) |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 300 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 301 | #else // #if defined(__APPLE__) |
| 302 | if (HostInfo::GetHostname(s)) { |
| 303 | response.PutCString("hostname:"); |
Pavel Labath | 7f815a9 | 2019-02-12 14:28:55 +0000 | [diff] [blame] | 304 | response.PutStringAsRawHex8(s); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 305 | response.PutChar(';'); |
| 306 | } |
| 307 | #endif // #if defined(__APPLE__) |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 308 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 309 | if (g_default_packet_timeout_sec > 0) |
| 310 | response.Printf("default_packet_timeout:%u;", g_default_packet_timeout_sec); |
Tamas Berghammer | 2d52afd | 2015-02-26 11:37:21 +0000 | [diff] [blame] | 311 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 312 | return SendPacketNoLock(response.GetString()); |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | GDBRemoteCommunication::PacketResult |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 316 | GDBRemoteCommunicationServerCommon::Handle_qProcessInfoPID( |
| 317 | StringExtractorGDBRemote &packet) { |
| 318 | // Packet format: "qProcessInfoPID:%i" where %i is the pid |
| 319 | packet.SetFilePos(::strlen("qProcessInfoPID:")); |
| 320 | lldb::pid_t pid = packet.GetU32(LLDB_INVALID_PROCESS_ID); |
| 321 | if (pid != LLDB_INVALID_PROCESS_ID) { |
| 322 | ProcessInstanceInfo proc_info; |
| 323 | if (Host::GetProcessInfo(pid, proc_info)) { |
| 324 | StreamString response; |
| 325 | CreateProcessInfoResponse(proc_info, response); |
| 326 | return SendPacketNoLock(response.GetString()); |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 327 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 328 | } |
| 329 | return SendErrorResponse(1); |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | GDBRemoteCommunication::PacketResult |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 333 | GDBRemoteCommunicationServerCommon::Handle_qfProcessInfo( |
| 334 | StringExtractorGDBRemote &packet) { |
| 335 | m_proc_infos_index = 0; |
| 336 | m_proc_infos.Clear(); |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 337 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 338 | ProcessInstanceInfoMatch match_info; |
| 339 | packet.SetFilePos(::strlen("qfProcessInfo")); |
| 340 | if (packet.GetChar() == ':') { |
Zachary Turner | 54695a3 | 2016-08-29 19:58:14 +0000 | [diff] [blame] | 341 | llvm::StringRef key; |
| 342 | llvm::StringRef value; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 343 | while (packet.GetNameColonValue(key, value)) { |
| 344 | bool success = true; |
| 345 | if (key.equals("name")) { |
| 346 | StringExtractor extractor(value); |
| 347 | std::string file; |
| 348 | extractor.GetHexByteString(file); |
Jonas Devlieghere | 937348c | 2018-06-13 22:08:14 +0000 | [diff] [blame] | 349 | match_info.GetProcessInfo().GetExecutableFile().SetFile( |
Jonas Devlieghere | 8f3be7a | 2018-11-01 21:05:36 +0000 | [diff] [blame] | 350 | file, FileSpec::Style::native); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 351 | } else if (key.equals("name_match")) { |
Pavel Labath | c4a3395 | 2017-02-20 11:35:33 +0000 | [diff] [blame] | 352 | NameMatch name_match = llvm::StringSwitch<NameMatch>(value) |
| 353 | .Case("equals", NameMatch::Equals) |
| 354 | .Case("starts_with", NameMatch::StartsWith) |
| 355 | .Case("ends_with", NameMatch::EndsWith) |
| 356 | .Case("contains", NameMatch::Contains) |
| 357 | .Case("regex", NameMatch::RegularExpression) |
| 358 | .Default(NameMatch::Ignore); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 359 | match_info.SetNameMatchType(name_match); |
Pavel Labath | c4a3395 | 2017-02-20 11:35:33 +0000 | [diff] [blame] | 360 | if (name_match == NameMatch::Ignore) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 361 | return SendErrorResponse(2); |
| 362 | } else if (key.equals("pid")) { |
| 363 | lldb::pid_t pid = LLDB_INVALID_PROCESS_ID; |
| 364 | if (value.getAsInteger(0, pid)) |
| 365 | return SendErrorResponse(2); |
| 366 | match_info.GetProcessInfo().SetProcessID(pid); |
| 367 | } else if (key.equals("parent_pid")) { |
| 368 | lldb::pid_t pid = LLDB_INVALID_PROCESS_ID; |
| 369 | if (value.getAsInteger(0, pid)) |
| 370 | return SendErrorResponse(2); |
| 371 | match_info.GetProcessInfo().SetParentProcessID(pid); |
| 372 | } else if (key.equals("uid")) { |
| 373 | uint32_t uid = UINT32_MAX; |
| 374 | if (value.getAsInteger(0, uid)) |
| 375 | return SendErrorResponse(2); |
| 376 | match_info.GetProcessInfo().SetUserID(uid); |
| 377 | } else if (key.equals("gid")) { |
| 378 | uint32_t gid = UINT32_MAX; |
| 379 | if (value.getAsInteger(0, gid)) |
| 380 | return SendErrorResponse(2); |
| 381 | match_info.GetProcessInfo().SetGroupID(gid); |
| 382 | } else if (key.equals("euid")) { |
| 383 | uint32_t uid = UINT32_MAX; |
| 384 | if (value.getAsInteger(0, uid)) |
| 385 | return SendErrorResponse(2); |
| 386 | match_info.GetProcessInfo().SetEffectiveUserID(uid); |
| 387 | } else if (key.equals("egid")) { |
| 388 | uint32_t gid = UINT32_MAX; |
| 389 | if (value.getAsInteger(0, gid)) |
| 390 | return SendErrorResponse(2); |
| 391 | match_info.GetProcessInfo().SetEffectiveGroupID(gid); |
| 392 | } else if (key.equals("all_users")) { |
| 393 | match_info.SetMatchAllUsers( |
Pavel Labath | 47cbf4a | 2018-04-10 09:03:59 +0000 | [diff] [blame] | 394 | OptionArgParser::ToBoolean(value, false, &success)); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 395 | } else if (key.equals("triple")) { |
Pavel Labath | 7263f1b | 2017-10-31 10:56:03 +0000 | [diff] [blame] | 396 | match_info.GetProcessInfo().GetArchitecture() = |
| 397 | HostInfo::GetAugmentedArchSpec(value); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 398 | } else { |
| 399 | success = false; |
| 400 | } |
| 401 | |
| 402 | if (!success) |
| 403 | return SendErrorResponse(2); |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 404 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 405 | } |
| 406 | |
| 407 | if (Host::FindProcesses(match_info, m_proc_infos)) { |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 408 | // We found something, return the first item by calling the get subsequent |
| 409 | // process info packet handler... |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 410 | return Handle_qsProcessInfo(packet); |
| 411 | } |
| 412 | return SendErrorResponse(3); |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 413 | } |
| 414 | |
| 415 | GDBRemoteCommunication::PacketResult |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 416 | GDBRemoteCommunicationServerCommon::Handle_qsProcessInfo( |
| 417 | StringExtractorGDBRemote &packet) { |
| 418 | if (m_proc_infos_index < m_proc_infos.GetSize()) { |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 419 | StreamString response; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 420 | CreateProcessInfoResponse( |
| 421 | m_proc_infos.GetProcessInfoAtIndex(m_proc_infos_index), response); |
| 422 | ++m_proc_infos_index; |
Zachary Turner | 26709df | 2016-08-27 15:52:29 +0000 | [diff] [blame] | 423 | return SendPacketNoLock(response.GetString()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 424 | } |
| 425 | return SendErrorResponse(4); |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | GDBRemoteCommunication::PacketResult |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 429 | GDBRemoteCommunicationServerCommon::Handle_qUserName( |
| 430 | StringExtractorGDBRemote &packet) { |
| 431 | #if !defined(LLDB_DISABLE_POSIX) |
| 432 | Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS)); |
Jonas Devlieghere | 63e5fb7 | 2019-07-24 17:56:10 +0000 | [diff] [blame] | 433 | LLDB_LOGF(log, "GDBRemoteCommunicationServerCommon::%s begin", __FUNCTION__); |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 434 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 435 | // Packet format: "qUserName:%i" where %i is the uid |
| 436 | packet.SetFilePos(::strlen("qUserName:")); |
| 437 | uint32_t uid = packet.GetU32(UINT32_MAX); |
| 438 | if (uid != UINT32_MAX) { |
Pavel Labath | aa51e6a | 2019-03-04 18:48:00 +0000 | [diff] [blame] | 439 | if (llvm::Optional<llvm::StringRef> name = |
| 440 | HostInfo::GetUserIDResolver().GetUserName(uid)) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 441 | StreamString response; |
Pavel Labath | aa51e6a | 2019-03-04 18:48:00 +0000 | [diff] [blame] | 442 | response.PutStringAsRawHex8(*name); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 443 | return SendPacketNoLock(response.GetString()); |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 444 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 445 | } |
Jonas Devlieghere | 63e5fb7 | 2019-07-24 17:56:10 +0000 | [diff] [blame] | 446 | LLDB_LOGF(log, "GDBRemoteCommunicationServerCommon::%s end", __FUNCTION__); |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 447 | #endif |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 448 | return SendErrorResponse(5); |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 449 | } |
| 450 | |
| 451 | GDBRemoteCommunication::PacketResult |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 452 | GDBRemoteCommunicationServerCommon::Handle_qGroupName( |
| 453 | StringExtractorGDBRemote &packet) { |
| 454 | #if !defined(LLDB_DISABLE_POSIX) |
| 455 | // Packet format: "qGroupName:%i" where %i is the gid |
| 456 | packet.SetFilePos(::strlen("qGroupName:")); |
| 457 | uint32_t gid = packet.GetU32(UINT32_MAX); |
| 458 | if (gid != UINT32_MAX) { |
Pavel Labath | aa51e6a | 2019-03-04 18:48:00 +0000 | [diff] [blame] | 459 | if (llvm::Optional<llvm::StringRef> name = |
| 460 | HostInfo::GetUserIDResolver().GetGroupName(gid)) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 461 | StreamString response; |
Pavel Labath | aa51e6a | 2019-03-04 18:48:00 +0000 | [diff] [blame] | 462 | response.PutStringAsRawHex8(*name); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 463 | return SendPacketNoLock(response.GetString()); |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 464 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 465 | } |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 466 | #endif |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 467 | return SendErrorResponse(6); |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 468 | } |
| 469 | |
| 470 | GDBRemoteCommunication::PacketResult |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 471 | GDBRemoteCommunicationServerCommon::Handle_qSpeedTest( |
| 472 | StringExtractorGDBRemote &packet) { |
| 473 | packet.SetFilePos(::strlen("qSpeedTest:")); |
| 474 | |
| 475 | llvm::StringRef key; |
| 476 | llvm::StringRef value; |
| 477 | bool success = packet.GetNameColonValue(key, value); |
| 478 | if (success && key.equals("response_size")) { |
| 479 | uint32_t response_size = 0; |
| 480 | if (!value.getAsInteger(0, response_size)) { |
| 481 | if (response_size == 0) |
| 482 | return SendOKResponse(); |
| 483 | StreamString response; |
| 484 | uint32_t bytes_left = response_size; |
| 485 | response.PutCString("data:"); |
| 486 | while (bytes_left > 0) { |
| 487 | if (bytes_left >= 26) { |
| 488 | response.PutCString("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); |
| 489 | bytes_left -= 26; |
| 490 | } else { |
| 491 | response.Printf("%*.*s;", bytes_left, bytes_left, |
| 492 | "ABCDEFGHIJKLMNOPQRSTUVWXYZ"); |
| 493 | bytes_left = 0; |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 494 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 495 | } |
| 496 | return SendPacketNoLock(response.GetString()); |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 497 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 498 | } |
| 499 | return SendErrorResponse(7); |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 500 | } |
| 501 | |
| 502 | GDBRemoteCommunication::PacketResult |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 503 | GDBRemoteCommunicationServerCommon::Handle_vFile_Open( |
| 504 | StringExtractorGDBRemote &packet) { |
| 505 | packet.SetFilePos(::strlen("vFile:open:")); |
| 506 | std::string path; |
| 507 | packet.GetHexByteStringTerminatedBy(path, ','); |
| 508 | if (!path.empty()) { |
| 509 | if (packet.GetChar() == ',') { |
Aaron Smith | 3a14249 | 2019-02-07 18:46:25 +0000 | [diff] [blame] | 510 | uint32_t flags = packet.GetHexMaxU32(false, 0); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 511 | if (packet.GetChar() == ',') { |
| 512 | mode_t mode = packet.GetHexMaxU32(false, 0600); |
Jonas Devlieghere | 8f3be7a | 2018-11-01 21:05:36 +0000 | [diff] [blame] | 513 | FileSpec path_spec(path); |
| 514 | FileSystem::Instance().Resolve(path_spec); |
Aaron Smith | 3a14249 | 2019-02-07 18:46:25 +0000 | [diff] [blame] | 515 | File file; |
| 516 | // Do not close fd. |
| 517 | Status error = |
| 518 | FileSystem::Instance().Open(file, path_spec, flags, mode, false); |
| 519 | const int save_errno = error.GetError(); |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 520 | StreamString response; |
| 521 | response.PutChar('F'); |
Aaron Smith | 3a14249 | 2019-02-07 18:46:25 +0000 | [diff] [blame] | 522 | response.Printf("%i", file.GetDescriptor()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 523 | if (save_errno) |
| 524 | response.Printf(",%i", save_errno); |
Zachary Turner | 26709df | 2016-08-27 15:52:29 +0000 | [diff] [blame] | 525 | return SendPacketNoLock(response.GetString()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 526 | } |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 527 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 528 | } |
| 529 | return SendErrorResponse(18); |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 530 | } |
| 531 | |
| 532 | GDBRemoteCommunication::PacketResult |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 533 | GDBRemoteCommunicationServerCommon::Handle_vFile_Close( |
| 534 | StringExtractorGDBRemote &packet) { |
| 535 | packet.SetFilePos(::strlen("vFile:close:")); |
| 536 | int fd = packet.GetS32(-1); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 537 | int err = -1; |
| 538 | int save_errno = 0; |
| 539 | if (fd >= 0) { |
Aaron Smith | 3a14249 | 2019-02-07 18:46:25 +0000 | [diff] [blame] | 540 | File file(fd, true); |
| 541 | Status error = file.Close(); |
| 542 | err = 0; |
| 543 | save_errno = error.GetError(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 544 | } else { |
| 545 | save_errno = EINVAL; |
| 546 | } |
| 547 | StreamString response; |
| 548 | response.PutChar('F'); |
| 549 | response.Printf("%i", err); |
| 550 | if (save_errno) |
| 551 | response.Printf(",%i", save_errno); |
| 552 | return SendPacketNoLock(response.GetString()); |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 553 | } |
| 554 | |
| 555 | GDBRemoteCommunication::PacketResult |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 556 | GDBRemoteCommunicationServerCommon::Handle_vFile_pRead( |
| 557 | StringExtractorGDBRemote &packet) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 558 | StreamGDBRemote response; |
| 559 | packet.SetFilePos(::strlen("vFile:pread:")); |
| 560 | int fd = packet.GetS32(-1); |
| 561 | if (packet.GetChar() == ',') { |
Pavel Labath | 341df3f | 2019-08-26 13:56:33 +0000 | [diff] [blame] | 562 | size_t count = packet.GetU64(SIZE_MAX); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 563 | if (packet.GetChar() == ',') { |
Aaron Smith | 3a14249 | 2019-02-07 18:46:25 +0000 | [diff] [blame] | 564 | off_t offset = packet.GetU64(UINT32_MAX); |
Pavel Labath | 341df3f | 2019-08-26 13:56:33 +0000 | [diff] [blame] | 565 | if (count == SIZE_MAX) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 566 | response.Printf("F-1:%i", EINVAL); |
Zachary Turner | 26709df | 2016-08-27 15:52:29 +0000 | [diff] [blame] | 567 | return SendPacketNoLock(response.GetString()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 568 | } |
| 569 | |
| 570 | std::string buffer(count, 0); |
Aaron Smith | 3a14249 | 2019-02-07 18:46:25 +0000 | [diff] [blame] | 571 | File file(fd, false); |
| 572 | Status error = file.Read(static_cast<void *>(&buffer[0]), count, offset); |
| 573 | const ssize_t bytes_read = error.Success() ? count : -1; |
| 574 | const int save_errno = error.GetError(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 575 | response.PutChar('F'); |
| 576 | response.Printf("%zi", bytes_read); |
| 577 | if (save_errno) |
| 578 | response.Printf(",%i", save_errno); |
| 579 | else { |
| 580 | response.PutChar(';'); |
| 581 | response.PutEscapedBytes(&buffer[0], bytes_read); |
| 582 | } |
| 583 | return SendPacketNoLock(response.GetString()); |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 584 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 585 | } |
| 586 | return SendErrorResponse(21); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 587 | } |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 588 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 589 | GDBRemoteCommunication::PacketResult |
| 590 | GDBRemoteCommunicationServerCommon::Handle_vFile_pWrite( |
| 591 | StringExtractorGDBRemote &packet) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 592 | packet.SetFilePos(::strlen("vFile:pwrite:")); |
| 593 | |
| 594 | StreamGDBRemote response; |
| 595 | response.PutChar('F'); |
| 596 | |
| 597 | int fd = packet.GetU32(UINT32_MAX); |
| 598 | if (packet.GetChar() == ',') { |
| 599 | off_t offset = packet.GetU64(UINT32_MAX); |
| 600 | if (packet.GetChar() == ',') { |
| 601 | std::string buffer; |
| 602 | if (packet.GetEscapedBinaryData(buffer)) { |
Aaron Smith | 3a14249 | 2019-02-07 18:46:25 +0000 | [diff] [blame] | 603 | File file(fd, false); |
| 604 | size_t count = buffer.size(); |
| 605 | Status error = |
| 606 | file.Write(static_cast<const void *>(&buffer[0]), count, offset); |
| 607 | const ssize_t bytes_written = error.Success() ? count : -1; |
| 608 | const int save_errno = error.GetError(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 609 | response.Printf("%zi", bytes_written); |
| 610 | if (save_errno) |
| 611 | response.Printf(",%i", save_errno); |
| 612 | } else { |
| 613 | response.Printf("-1,%i", EINVAL); |
| 614 | } |
| 615 | return SendPacketNoLock(response.GetString()); |
| 616 | } |
| 617 | } |
| 618 | return SendErrorResponse(27); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 619 | } |
| 620 | |
| 621 | GDBRemoteCommunication::PacketResult |
| 622 | GDBRemoteCommunicationServerCommon::Handle_vFile_Size( |
| 623 | StringExtractorGDBRemote &packet) { |
| 624 | packet.SetFilePos(::strlen("vFile:size:")); |
| 625 | std::string path; |
| 626 | packet.GetHexByteString(path); |
| 627 | if (!path.empty()) { |
Zachary Turner | 07db3f7 | 2017-03-21 05:47:57 +0000 | [diff] [blame] | 628 | uint64_t Size; |
| 629 | if (llvm::sys::fs::file_size(path, Size)) |
| 630 | return SendErrorResponse(5); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 631 | StreamString response; |
| 632 | response.PutChar('F'); |
Zachary Turner | 07db3f7 | 2017-03-21 05:47:57 +0000 | [diff] [blame] | 633 | response.PutHex64(Size); |
| 634 | if (Size == UINT64_MAX) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 635 | response.PutChar(','); |
Zachary Turner | 07db3f7 | 2017-03-21 05:47:57 +0000 | [diff] [blame] | 636 | response.PutHex64(Size); // TODO: replace with Host::GetSyswideErrorCode() |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 637 | } |
Zachary Turner | 26709df | 2016-08-27 15:52:29 +0000 | [diff] [blame] | 638 | return SendPacketNoLock(response.GetString()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 639 | } |
| 640 | return SendErrorResponse(22); |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 641 | } |
| 642 | |
| 643 | GDBRemoteCommunication::PacketResult |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 644 | GDBRemoteCommunicationServerCommon::Handle_vFile_Mode( |
| 645 | StringExtractorGDBRemote &packet) { |
| 646 | packet.SetFilePos(::strlen("vFile:mode:")); |
| 647 | std::string path; |
| 648 | packet.GetHexByteString(path); |
| 649 | if (!path.empty()) { |
Jonas Devlieghere | 8f3be7a | 2018-11-01 21:05:36 +0000 | [diff] [blame] | 650 | FileSpec file_spec(path); |
| 651 | FileSystem::Instance().Resolve(file_spec); |
Jonas Devlieghere | 73ed607 | 2018-11-01 22:46:49 +0000 | [diff] [blame] | 652 | std::error_code ec; |
| 653 | const uint32_t mode = FileSystem::Instance().GetPermissions(file_spec, ec); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 654 | StreamString response; |
| 655 | response.Printf("F%u", mode); |
Jonas Devlieghere | 73ed607 | 2018-11-01 22:46:49 +0000 | [diff] [blame] | 656 | if (mode == 0 || ec) |
| 657 | response.Printf(",%i", (int)Status(ec).GetError()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 658 | return SendPacketNoLock(response.GetString()); |
| 659 | } |
| 660 | return SendErrorResponse(23); |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 661 | } |
| 662 | |
| 663 | GDBRemoteCommunication::PacketResult |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 664 | GDBRemoteCommunicationServerCommon::Handle_vFile_Exists( |
| 665 | StringExtractorGDBRemote &packet) { |
| 666 | packet.SetFilePos(::strlen("vFile:exists:")); |
| 667 | std::string path; |
| 668 | packet.GetHexByteString(path); |
| 669 | if (!path.empty()) { |
Zachary Turner | 07db3f7 | 2017-03-21 05:47:57 +0000 | [diff] [blame] | 670 | bool retcode = llvm::sys::fs::exists(path); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 671 | StreamString response; |
| 672 | response.PutChar('F'); |
| 673 | response.PutChar(','); |
| 674 | if (retcode) |
| 675 | response.PutChar('1'); |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 676 | else |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 677 | response.PutChar('0'); |
| 678 | return SendPacketNoLock(response.GetString()); |
| 679 | } |
| 680 | return SendErrorResponse(24); |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 681 | } |
| 682 | |
| 683 | GDBRemoteCommunication::PacketResult |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 684 | GDBRemoteCommunicationServerCommon::Handle_vFile_symlink( |
| 685 | StringExtractorGDBRemote &packet) { |
| 686 | packet.SetFilePos(::strlen("vFile:symlink:")); |
| 687 | std::string dst, src; |
| 688 | packet.GetHexByteStringTerminatedBy(dst, ','); |
| 689 | packet.GetChar(); // Skip ',' char |
| 690 | packet.GetHexByteString(src); |
Jonas Devlieghere | 8f3be7a | 2018-11-01 21:05:36 +0000 | [diff] [blame] | 691 | |
| 692 | FileSpec src_spec(src); |
| 693 | FileSystem::Instance().Resolve(src_spec); |
| 694 | Status error = FileSystem::Instance().Symlink(src_spec, FileSpec(dst)); |
| 695 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 696 | StreamString response; |
| 697 | response.Printf("F%u,%u", error.GetError(), error.GetError()); |
| 698 | return SendPacketNoLock(response.GetString()); |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 699 | } |
| 700 | |
| 701 | GDBRemoteCommunication::PacketResult |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 702 | GDBRemoteCommunicationServerCommon::Handle_vFile_unlink( |
| 703 | StringExtractorGDBRemote &packet) { |
| 704 | packet.SetFilePos(::strlen("vFile:unlink:")); |
| 705 | std::string path; |
| 706 | packet.GetHexByteString(path); |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 707 | Status error(llvm::sys::fs::remove(path)); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 708 | StreamString response; |
| 709 | response.Printf("F%u,%u", error.GetError(), error.GetError()); |
| 710 | return SendPacketNoLock(response.GetString()); |
| 711 | } |
| 712 | |
| 713 | GDBRemoteCommunication::PacketResult |
| 714 | GDBRemoteCommunicationServerCommon::Handle_qPlatform_shell( |
| 715 | StringExtractorGDBRemote &packet) { |
| 716 | packet.SetFilePos(::strlen("qPlatform_shell:")); |
| 717 | std::string path; |
| 718 | std::string working_dir; |
| 719 | packet.GetHexByteStringTerminatedBy(path, ','); |
| 720 | if (!path.empty()) { |
| 721 | if (packet.GetChar() == ',') { |
| 722 | // FIXME: add timeout to qPlatform_shell packet |
| 723 | // uint32_t timeout = packet.GetHexMaxU32(false, 32); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 724 | if (packet.GetChar() == ',') |
| 725 | packet.GetHexByteString(working_dir); |
| 726 | int status, signo; |
| 727 | std::string output; |
Jonas Devlieghere | 8f3be7a | 2018-11-01 21:05:36 +0000 | [diff] [blame] | 728 | FileSpec working_spec(working_dir); |
| 729 | FileSystem::Instance().Resolve(working_spec); |
| 730 | Status err = |
| 731 | Host::RunShellCommand(path.c_str(), working_spec, &status, &signo, |
| 732 | &output, std::chrono::seconds(10)); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 733 | StreamGDBRemote response; |
| 734 | if (err.Fail()) { |
| 735 | response.PutCString("F,"); |
| 736 | response.PutHex32(UINT32_MAX); |
| 737 | } else { |
| 738 | response.PutCString("F,"); |
| 739 | response.PutHex32(status); |
| 740 | response.PutChar(','); |
| 741 | response.PutHex32(signo); |
| 742 | response.PutChar(','); |
| 743 | response.PutEscapedBytes(output.c_str(), output.size()); |
| 744 | } |
| 745 | return SendPacketNoLock(response.GetString()); |
| 746 | } |
| 747 | } |
| 748 | return SendErrorResponse(24); |
| 749 | } |
| 750 | |
| 751 | GDBRemoteCommunication::PacketResult |
| 752 | GDBRemoteCommunicationServerCommon::Handle_vFile_Stat( |
| 753 | StringExtractorGDBRemote &packet) { |
| 754 | return SendUnimplementedResponse( |
| 755 | "GDBRemoteCommunicationServerCommon::Handle_vFile_Stat() unimplemented"); |
| 756 | } |
| 757 | |
| 758 | GDBRemoteCommunication::PacketResult |
| 759 | GDBRemoteCommunicationServerCommon::Handle_vFile_MD5( |
| 760 | StringExtractorGDBRemote &packet) { |
| 761 | packet.SetFilePos(::strlen("vFile:MD5:")); |
| 762 | std::string path; |
| 763 | packet.GetHexByteString(path); |
| 764 | if (!path.empty()) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 765 | StreamGDBRemote response; |
Zachary Turner | 076a259 | 2017-03-20 23:54:54 +0000 | [diff] [blame] | 766 | auto Result = llvm::sys::fs::md5_contents(path); |
| 767 | if (!Result) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 768 | response.PutCString("F,"); |
| 769 | response.PutCString("x"); |
| 770 | } else { |
| 771 | response.PutCString("F,"); |
Zachary Turner | 076a259 | 2017-03-20 23:54:54 +0000 | [diff] [blame] | 772 | response.PutHex64(Result->low()); |
| 773 | response.PutHex64(Result->high()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 774 | } |
| 775 | return SendPacketNoLock(response.GetString()); |
| 776 | } |
| 777 | return SendErrorResponse(25); |
| 778 | } |
| 779 | |
| 780 | GDBRemoteCommunication::PacketResult |
| 781 | GDBRemoteCommunicationServerCommon::Handle_qPlatform_mkdir( |
| 782 | StringExtractorGDBRemote &packet) { |
| 783 | packet.SetFilePos(::strlen("qPlatform_mkdir:")); |
| 784 | mode_t mode = packet.GetHexMaxU32(false, UINT32_MAX); |
| 785 | if (packet.GetChar() == ',') { |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 786 | std::string path; |
| 787 | packet.GetHexByteString(path); |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 788 | Status error(llvm::sys::fs::create_directory(path, mode)); |
Oleksiy Vyalov | 6801be3 | 2015-02-25 22:15:44 +0000 | [diff] [blame] | 789 | |
| 790 | StreamGDBRemote response; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 791 | response.Printf("F%u", error.GetError()); |
Oleksiy Vyalov | 6801be3 | 2015-02-25 22:15:44 +0000 | [diff] [blame] | 792 | |
Zachary Turner | 26709df | 2016-08-27 15:52:29 +0000 | [diff] [blame] | 793 | return SendPacketNoLock(response.GetString()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 794 | } |
| 795 | return SendErrorResponse(20); |
Oleksiy Vyalov | 6801be3 | 2015-02-25 22:15:44 +0000 | [diff] [blame] | 796 | } |
| 797 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 798 | GDBRemoteCommunication::PacketResult |
| 799 | GDBRemoteCommunicationServerCommon::Handle_qPlatform_chmod( |
| 800 | StringExtractorGDBRemote &packet) { |
| 801 | packet.SetFilePos(::strlen("qPlatform_chmod:")); |
| 802 | |
Zachary Turner | 6934e0a | 2017-03-19 05:49:43 +0000 | [diff] [blame] | 803 | auto perms = |
| 804 | static_cast<llvm::sys::fs::perms>(packet.GetHexMaxU32(false, UINT32_MAX)); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 805 | if (packet.GetChar() == ',') { |
| 806 | std::string path; |
| 807 | packet.GetHexByteString(path); |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 808 | Status error(llvm::sys::fs::setPermissions(path, perms)); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 809 | |
| 810 | StreamGDBRemote response; |
| 811 | response.Printf("F%u", error.GetError()); |
| 812 | |
| 813 | return SendPacketNoLock(response.GetString()); |
| 814 | } |
| 815 | return SendErrorResponse(19); |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 816 | } |
| 817 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 818 | GDBRemoteCommunication::PacketResult |
| 819 | GDBRemoteCommunicationServerCommon::Handle_qSupported( |
| 820 | StringExtractorGDBRemote &packet) { |
| 821 | StreamGDBRemote response; |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 822 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 823 | // Features common to lldb-platform and llgs. |
| 824 | uint32_t max_packet_size = 128 * 1024; // 128KBytes is a reasonable max packet |
| 825 | // size--debugger can always use less |
| 826 | response.Printf("PacketSize=%x", max_packet_size); |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 827 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 828 | response.PutCString(";QStartNoAckMode+"); |
| 829 | response.PutCString(";QThreadSuffixSupported+"); |
| 830 | response.PutCString(";QListThreadsInStopReply+"); |
| 831 | response.PutCString(";qEcho+"); |
Kamil Rytarowski | c93408a | 2017-03-21 17:27:59 +0000 | [diff] [blame] | 832 | #if defined(__linux__) || defined(__NetBSD__) |
Pavel Labath | 4a705e7 | 2017-02-24 09:29:14 +0000 | [diff] [blame] | 833 | response.PutCString(";QPassSignals+"); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 834 | response.PutCString(";qXfer:auxv:read+"); |
Antonio Afonso | 05e32ba | 2019-07-23 20:40:30 +0000 | [diff] [blame] | 835 | response.PutCString(";qXfer:libraries-svr4:read+"); |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 836 | #endif |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 837 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 838 | return SendPacketNoLock(response.GetString()); |
Tamas Berghammer | e13c273 | 2015-02-11 10:29:30 +0000 | [diff] [blame] | 839 | } |
Tamas Berghammer | 7cb18bf | 2015-03-24 11:15:23 +0000 | [diff] [blame] | 840 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 841 | GDBRemoteCommunication::PacketResult |
| 842 | GDBRemoteCommunicationServerCommon::Handle_QThreadSuffixSupported( |
| 843 | StringExtractorGDBRemote &packet) { |
| 844 | m_thread_suffix_supported = true; |
| 845 | return SendOKResponse(); |
| 846 | } |
| 847 | |
| 848 | GDBRemoteCommunication::PacketResult |
| 849 | GDBRemoteCommunicationServerCommon::Handle_QListThreadsInStopReply( |
| 850 | StringExtractorGDBRemote &packet) { |
| 851 | m_list_threads_in_stop_reply = true; |
| 852 | return SendOKResponse(); |
| 853 | } |
| 854 | |
| 855 | GDBRemoteCommunication::PacketResult |
| 856 | GDBRemoteCommunicationServerCommon::Handle_QSetDetachOnError( |
| 857 | StringExtractorGDBRemote &packet) { |
| 858 | packet.SetFilePos(::strlen("QSetDetachOnError:")); |
| 859 | if (packet.GetU32(0)) |
| 860 | m_process_launch_info.GetFlags().Set(eLaunchFlagDetachOnError); |
| 861 | else |
| 862 | m_process_launch_info.GetFlags().Clear(eLaunchFlagDetachOnError); |
| 863 | return SendOKResponse(); |
| 864 | } |
| 865 | |
| 866 | GDBRemoteCommunication::PacketResult |
| 867 | GDBRemoteCommunicationServerCommon::Handle_QStartNoAckMode( |
| 868 | StringExtractorGDBRemote &packet) { |
| 869 | // Send response first before changing m_send_acks to we ack this packet |
| 870 | PacketResult packet_result = SendOKResponse(); |
| 871 | m_send_acks = false; |
| 872 | return packet_result; |
| 873 | } |
| 874 | |
| 875 | GDBRemoteCommunication::PacketResult |
| 876 | GDBRemoteCommunicationServerCommon::Handle_QSetSTDIN( |
| 877 | StringExtractorGDBRemote &packet) { |
| 878 | packet.SetFilePos(::strlen("QSetSTDIN:")); |
| 879 | FileAction file_action; |
| 880 | std::string path; |
| 881 | packet.GetHexByteString(path); |
| 882 | const bool read = true; |
| 883 | const bool write = false; |
Jonas Devlieghere | 8f3be7a | 2018-11-01 21:05:36 +0000 | [diff] [blame] | 884 | if (file_action.Open(STDIN_FILENO, FileSpec(path), read, write)) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 885 | m_process_launch_info.AppendFileAction(file_action); |
| 886 | return SendOKResponse(); |
| 887 | } |
| 888 | return SendErrorResponse(15); |
| 889 | } |
| 890 | |
| 891 | GDBRemoteCommunication::PacketResult |
| 892 | GDBRemoteCommunicationServerCommon::Handle_QSetSTDOUT( |
| 893 | StringExtractorGDBRemote &packet) { |
| 894 | packet.SetFilePos(::strlen("QSetSTDOUT:")); |
| 895 | FileAction file_action; |
| 896 | std::string path; |
| 897 | packet.GetHexByteString(path); |
| 898 | const bool read = false; |
| 899 | const bool write = true; |
Jonas Devlieghere | 8f3be7a | 2018-11-01 21:05:36 +0000 | [diff] [blame] | 900 | if (file_action.Open(STDOUT_FILENO, FileSpec(path), read, write)) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 901 | m_process_launch_info.AppendFileAction(file_action); |
| 902 | return SendOKResponse(); |
| 903 | } |
| 904 | return SendErrorResponse(16); |
| 905 | } |
| 906 | |
| 907 | GDBRemoteCommunication::PacketResult |
| 908 | GDBRemoteCommunicationServerCommon::Handle_QSetSTDERR( |
| 909 | StringExtractorGDBRemote &packet) { |
| 910 | packet.SetFilePos(::strlen("QSetSTDERR:")); |
| 911 | FileAction file_action; |
| 912 | std::string path; |
| 913 | packet.GetHexByteString(path); |
| 914 | const bool read = false; |
| 915 | const bool write = true; |
Jonas Devlieghere | 8f3be7a | 2018-11-01 21:05:36 +0000 | [diff] [blame] | 916 | if (file_action.Open(STDERR_FILENO, FileSpec(path), read, write)) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 917 | m_process_launch_info.AppendFileAction(file_action); |
| 918 | return SendOKResponse(); |
| 919 | } |
| 920 | return SendErrorResponse(17); |
| 921 | } |
| 922 | |
| 923 | GDBRemoteCommunication::PacketResult |
| 924 | GDBRemoteCommunicationServerCommon::Handle_qLaunchSuccess( |
| 925 | StringExtractorGDBRemote &packet) { |
| 926 | if (m_process_launch_error.Success()) |
| 927 | return SendOKResponse(); |
| 928 | StreamString response; |
| 929 | response.PutChar('E'); |
| 930 | response.PutCString(m_process_launch_error.AsCString("<unknown error>")); |
| 931 | return SendPacketNoLock(response.GetString()); |
| 932 | } |
| 933 | |
| 934 | GDBRemoteCommunication::PacketResult |
| 935 | GDBRemoteCommunicationServerCommon::Handle_QEnvironment( |
| 936 | StringExtractorGDBRemote &packet) { |
| 937 | packet.SetFilePos(::strlen("QEnvironment:")); |
| 938 | const uint32_t bytes_left = packet.GetBytesLeft(); |
| 939 | if (bytes_left > 0) { |
Pavel Labath | 62930e5 | 2018-01-10 11:57:31 +0000 | [diff] [blame] | 940 | m_process_launch_info.GetEnvironment().insert(packet.Peek()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 941 | return SendOKResponse(); |
| 942 | } |
| 943 | return SendErrorResponse(12); |
| 944 | } |
| 945 | |
| 946 | GDBRemoteCommunication::PacketResult |
| 947 | GDBRemoteCommunicationServerCommon::Handle_QEnvironmentHexEncoded( |
| 948 | StringExtractorGDBRemote &packet) { |
| 949 | packet.SetFilePos(::strlen("QEnvironmentHexEncoded:")); |
| 950 | const uint32_t bytes_left = packet.GetBytesLeft(); |
| 951 | if (bytes_left > 0) { |
| 952 | std::string str; |
| 953 | packet.GetHexByteString(str); |
Pavel Labath | 62930e5 | 2018-01-10 11:57:31 +0000 | [diff] [blame] | 954 | m_process_launch_info.GetEnvironment().insert(str); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 955 | return SendOKResponse(); |
| 956 | } |
| 957 | return SendErrorResponse(12); |
| 958 | } |
| 959 | |
| 960 | GDBRemoteCommunication::PacketResult |
| 961 | GDBRemoteCommunicationServerCommon::Handle_QLaunchArch( |
| 962 | StringExtractorGDBRemote &packet) { |
| 963 | packet.SetFilePos(::strlen("QLaunchArch:")); |
| 964 | const uint32_t bytes_left = packet.GetBytesLeft(); |
| 965 | if (bytes_left > 0) { |
| 966 | const char *arch_triple = packet.Peek(); |
Aaron Smith | 3a14249 | 2019-02-07 18:46:25 +0000 | [diff] [blame] | 967 | m_process_launch_info.SetArchitecture( |
| 968 | HostInfo::GetAugmentedArchSpec(arch_triple)); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 969 | return SendOKResponse(); |
| 970 | } |
| 971 | return SendErrorResponse(13); |
| 972 | } |
| 973 | |
| 974 | GDBRemoteCommunication::PacketResult |
| 975 | GDBRemoteCommunicationServerCommon::Handle_A(StringExtractorGDBRemote &packet) { |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 976 | // The 'A' packet is the most over designed packet ever here with redundant |
| 977 | // argument indexes, redundant argument lengths and needed hex encoded |
| 978 | // argument string values. Really all that is needed is a comma separated hex |
| 979 | // encoded argument value list, but we will stay true to the documented |
| 980 | // version of the 'A' packet here... |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 981 | |
| 982 | Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS)); |
| 983 | int actual_arg_index = 0; |
| 984 | |
| 985 | packet.SetFilePos(1); // Skip the 'A' |
| 986 | bool success = true; |
| 987 | while (success && packet.GetBytesLeft() > 0) { |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 988 | // Decode the decimal argument string length. This length is the number of |
| 989 | // hex nibbles in the argument string value. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 990 | const uint32_t arg_len = packet.GetU32(UINT32_MAX); |
| 991 | if (arg_len == UINT32_MAX) |
| 992 | success = false; |
| 993 | else { |
| 994 | // Make sure the argument hex string length is followed by a comma |
| 995 | if (packet.GetChar() != ',') |
| 996 | success = false; |
| 997 | else { |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 998 | // Decode the argument index. We ignore this really because who would |
| 999 | // really send down the arguments in a random order??? |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1000 | const uint32_t arg_idx = packet.GetU32(UINT32_MAX); |
| 1001 | if (arg_idx == UINT32_MAX) |
| 1002 | success = false; |
| 1003 | else { |
| 1004 | // Make sure the argument index is followed by a comma |
| 1005 | if (packet.GetChar() != ',') |
| 1006 | success = false; |
| 1007 | else { |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1008 | // Decode the argument string value from hex bytes back into a UTF8 |
| 1009 | // string and make sure the length matches the one supplied in the |
| 1010 | // packet |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1011 | std::string arg; |
| 1012 | if (packet.GetHexByteStringFixedLength(arg, arg_len) != |
| 1013 | (arg_len / 2)) |
| 1014 | success = false; |
| 1015 | else { |
| 1016 | // If there are any bytes left |
| 1017 | if (packet.GetBytesLeft()) { |
| 1018 | if (packet.GetChar() != ',') |
| 1019 | success = false; |
| 1020 | } |
| 1021 | |
| 1022 | if (success) { |
| 1023 | if (arg_idx == 0) |
Jonas Devlieghere | 937348c | 2018-06-13 22:08:14 +0000 | [diff] [blame] | 1024 | m_process_launch_info.GetExecutableFile().SetFile( |
Jonas Devlieghere | 8f3be7a | 2018-11-01 21:05:36 +0000 | [diff] [blame] | 1025 | arg, FileSpec::Style::native); |
Zachary Turner | ecbb0bb | 2016-09-19 17:54:06 +0000 | [diff] [blame] | 1026 | m_process_launch_info.GetArguments().AppendArgument(arg); |
Jonas Devlieghere | 63e5fb7 | 2019-07-24 17:56:10 +0000 | [diff] [blame] | 1027 | LLDB_LOGF(log, "LLGSPacketHandler::%s added arg %d: \"%s\"", |
| 1028 | __FUNCTION__, actual_arg_index, arg.c_str()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1029 | ++actual_arg_index; |
| 1030 | } |
| 1031 | } |
| 1032 | } |
| 1033 | } |
| 1034 | } |
| 1035 | } |
| 1036 | } |
| 1037 | |
| 1038 | if (success) { |
| 1039 | m_process_launch_error = LaunchProcess(); |
Pavel Labath | 96e600f | 2017-07-07 11:02:19 +0000 | [diff] [blame] | 1040 | if (m_process_launch_error.Success()) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1041 | return SendOKResponse(); |
Pavel Labath | 96e600f | 2017-07-07 11:02:19 +0000 | [diff] [blame] | 1042 | LLDB_LOG(log, "failed to launch exe: {0}", m_process_launch_error); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1043 | } |
| 1044 | return SendErrorResponse(8); |
| 1045 | } |
| 1046 | |
| 1047 | GDBRemoteCommunication::PacketResult |
| 1048 | GDBRemoteCommunicationServerCommon::Handle_qEcho( |
| 1049 | StringExtractorGDBRemote &packet) { |
| 1050 | // Just echo back the exact same packet for qEcho... |
| 1051 | return SendPacketNoLock(packet.GetStringRef()); |
| 1052 | } |
| 1053 | |
| 1054 | GDBRemoteCommunication::PacketResult |
| 1055 | GDBRemoteCommunicationServerCommon::Handle_qModuleInfo( |
| 1056 | StringExtractorGDBRemote &packet) { |
| 1057 | packet.SetFilePos(::strlen("qModuleInfo:")); |
| 1058 | |
| 1059 | std::string module_path; |
| 1060 | packet.GetHexByteStringTerminatedBy(module_path, ';'); |
| 1061 | if (module_path.empty()) |
| 1062 | return SendErrorResponse(1); |
| 1063 | |
| 1064 | if (packet.GetChar() != ';') |
| 1065 | return SendErrorResponse(2); |
| 1066 | |
| 1067 | std::string triple; |
| 1068 | packet.GetHexByteString(triple); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1069 | |
Pavel Labath | 2f1fbae | 2016-09-08 10:07:04 +0000 | [diff] [blame] | 1070 | ModuleSpec matched_module_spec = GetModuleInfo(module_path, triple); |
| 1071 | if (!matched_module_spec.GetFileSpec()) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1072 | return SendErrorResponse(3); |
| 1073 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1074 | const auto file_offset = matched_module_spec.GetObjectOffset(); |
| 1075 | const auto file_size = matched_module_spec.GetObjectSize(); |
| 1076 | const auto uuid_str = matched_module_spec.GetUUID().GetAsString(""); |
| 1077 | |
| 1078 | StreamGDBRemote response; |
| 1079 | |
| 1080 | if (uuid_str.empty()) { |
Aaron Smith | 3a14249 | 2019-02-07 18:46:25 +0000 | [diff] [blame] | 1081 | auto Result = llvm::sys::fs::md5_contents( |
| 1082 | matched_module_spec.GetFileSpec().GetPath()); |
Zachary Turner | 076a259 | 2017-03-20 23:54:54 +0000 | [diff] [blame] | 1083 | if (!Result) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1084 | return SendErrorResponse(5); |
| 1085 | response.PutCString("md5:"); |
Pavel Labath | 7f815a9 | 2019-02-12 14:28:55 +0000 | [diff] [blame] | 1086 | response.PutStringAsRawHex8(Result->digest()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1087 | } else { |
| 1088 | response.PutCString("uuid:"); |
Pavel Labath | 7f815a9 | 2019-02-12 14:28:55 +0000 | [diff] [blame] | 1089 | response.PutStringAsRawHex8(uuid_str); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1090 | } |
| 1091 | response.PutChar(';'); |
| 1092 | |
| 1093 | const auto &module_arch = matched_module_spec.GetArchitecture(); |
| 1094 | response.PutCString("triple:"); |
Pavel Labath | 7f815a9 | 2019-02-12 14:28:55 +0000 | [diff] [blame] | 1095 | response.PutStringAsRawHex8(module_arch.GetTriple().getTriple()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1096 | response.PutChar(';'); |
| 1097 | |
| 1098 | response.PutCString("file_path:"); |
Pavel Labath | 7f815a9 | 2019-02-12 14:28:55 +0000 | [diff] [blame] | 1099 | response.PutStringAsRawHex8(matched_module_spec.GetFileSpec().GetCString()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1100 | response.PutChar(';'); |
| 1101 | response.PutCString("file_offset:"); |
| 1102 | response.PutHex64(file_offset); |
| 1103 | response.PutChar(';'); |
| 1104 | response.PutCString("file_size:"); |
| 1105 | response.PutHex64(file_size); |
| 1106 | response.PutChar(';'); |
| 1107 | |
| 1108 | return SendPacketNoLock(response.GetString()); |
| 1109 | } |
| 1110 | |
Pavel Labath | 2f1fbae | 2016-09-08 10:07:04 +0000 | [diff] [blame] | 1111 | GDBRemoteCommunication::PacketResult |
| 1112 | GDBRemoteCommunicationServerCommon::Handle_jModulesInfo( |
| 1113 | StringExtractorGDBRemote &packet) { |
| 1114 | packet.SetFilePos(::strlen("jModulesInfo:")); |
| 1115 | |
| 1116 | StructuredData::ObjectSP object_sp = StructuredData::ParseJSON(packet.Peek()); |
| 1117 | if (!object_sp) |
| 1118 | return SendErrorResponse(1); |
| 1119 | |
| 1120 | StructuredData::Array *packet_array = object_sp->GetAsArray(); |
| 1121 | if (!packet_array) |
| 1122 | return SendErrorResponse(2); |
| 1123 | |
| 1124 | JSONArray::SP response_array_sp = std::make_shared<JSONArray>(); |
| 1125 | for (size_t i = 0; i < packet_array->GetSize(); ++i) { |
| 1126 | StructuredData::Dictionary *query = |
| 1127 | packet_array->GetItemAtIndex(i)->GetAsDictionary(); |
| 1128 | if (!query) |
| 1129 | continue; |
Zachary Turner | 2833321 | 2017-05-12 05:49:54 +0000 | [diff] [blame] | 1130 | llvm::StringRef file, triple; |
Pavel Labath | 2f1fbae | 2016-09-08 10:07:04 +0000 | [diff] [blame] | 1131 | if (!query->GetValueForKeyAsString("file", file) || |
| 1132 | !query->GetValueForKeyAsString("triple", triple)) |
| 1133 | continue; |
| 1134 | |
| 1135 | ModuleSpec matched_module_spec = GetModuleInfo(file, triple); |
| 1136 | if (!matched_module_spec.GetFileSpec()) |
| 1137 | continue; |
| 1138 | |
| 1139 | const auto file_offset = matched_module_spec.GetObjectOffset(); |
| 1140 | const auto file_size = matched_module_spec.GetObjectSize(); |
| 1141 | const auto uuid_str = matched_module_spec.GetUUID().GetAsString(""); |
| 1142 | |
| 1143 | if (uuid_str.empty()) |
| 1144 | continue; |
| 1145 | |
| 1146 | JSONObject::SP response = std::make_shared<JSONObject>(); |
| 1147 | response_array_sp->AppendObject(response); |
| 1148 | response->SetObject("uuid", std::make_shared<JSONString>(uuid_str)); |
| 1149 | response->SetObject( |
| 1150 | "triple", |
| 1151 | std::make_shared<JSONString>( |
| 1152 | matched_module_spec.GetArchitecture().GetTriple().getTriple())); |
| 1153 | response->SetObject("file_path", |
| 1154 | std::make_shared<JSONString>( |
| 1155 | matched_module_spec.GetFileSpec().GetPath())); |
| 1156 | response->SetObject("file_offset", |
| 1157 | std::make_shared<JSONNumber>(file_offset)); |
| 1158 | response->SetObject("file_size", std::make_shared<JSONNumber>(file_size)); |
| 1159 | } |
| 1160 | |
| 1161 | StreamString response; |
| 1162 | response_array_sp->Write(response); |
| 1163 | StreamGDBRemote escaped_response; |
Zachary Turner | c156427 | 2016-11-16 21:15:24 +0000 | [diff] [blame] | 1164 | escaped_response.PutEscapedBytes(response.GetString().data(), |
| 1165 | response.GetSize()); |
Pavel Labath | 2f1fbae | 2016-09-08 10:07:04 +0000 | [diff] [blame] | 1166 | return SendPacketNoLock(escaped_response.GetString()); |
| 1167 | } |
| 1168 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1169 | void GDBRemoteCommunicationServerCommon::CreateProcessInfoResponse( |
| 1170 | const ProcessInstanceInfo &proc_info, StreamString &response) { |
| 1171 | response.Printf( |
| 1172 | "pid:%" PRIu64 ";ppid:%" PRIu64 ";uid:%i;gid:%i;euid:%i;egid:%i;", |
| 1173 | proc_info.GetProcessID(), proc_info.GetParentProcessID(), |
| 1174 | proc_info.GetUserID(), proc_info.GetGroupID(), |
| 1175 | proc_info.GetEffectiveUserID(), proc_info.GetEffectiveGroupID()); |
| 1176 | response.PutCString("name:"); |
Pavel Labath | 7f815a9 | 2019-02-12 14:28:55 +0000 | [diff] [blame] | 1177 | response.PutStringAsRawHex8(proc_info.GetExecutableFile().GetCString()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1178 | response.PutChar(';'); |
| 1179 | const ArchSpec &proc_arch = proc_info.GetArchitecture(); |
| 1180 | if (proc_arch.IsValid()) { |
| 1181 | const llvm::Triple &proc_triple = proc_arch.GetTriple(); |
| 1182 | response.PutCString("triple:"); |
Pavel Labath | 7f815a9 | 2019-02-12 14:28:55 +0000 | [diff] [blame] | 1183 | response.PutStringAsRawHex8(proc_triple.getTriple()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1184 | response.PutChar(';'); |
| 1185 | } |
| 1186 | } |
| 1187 | |
| 1188 | void GDBRemoteCommunicationServerCommon:: |
| 1189 | CreateProcessInfoResponse_DebugServerStyle( |
| 1190 | const ProcessInstanceInfo &proc_info, StreamString &response) { |
| 1191 | response.Printf("pid:%" PRIx64 ";parent-pid:%" PRIx64 |
| 1192 | ";real-uid:%x;real-gid:%x;effective-uid:%x;effective-gid:%x;", |
| 1193 | proc_info.GetProcessID(), proc_info.GetParentProcessID(), |
| 1194 | proc_info.GetUserID(), proc_info.GetGroupID(), |
| 1195 | proc_info.GetEffectiveUserID(), |
| 1196 | proc_info.GetEffectiveGroupID()); |
| 1197 | |
| 1198 | const ArchSpec &proc_arch = proc_info.GetArchitecture(); |
| 1199 | if (proc_arch.IsValid()) { |
| 1200 | const llvm::Triple &proc_triple = proc_arch.GetTriple(); |
| 1201 | #if defined(__APPLE__) |
| 1202 | // We'll send cputype/cpusubtype. |
| 1203 | const uint32_t cpu_type = proc_arch.GetMachOCPUType(); |
| 1204 | if (cpu_type != 0) |
| 1205 | response.Printf("cputype:%" PRIx32 ";", cpu_type); |
| 1206 | |
| 1207 | const uint32_t cpu_subtype = proc_arch.GetMachOCPUSubType(); |
| 1208 | if (cpu_subtype != 0) |
| 1209 | response.Printf("cpusubtype:%" PRIx32 ";", cpu_subtype); |
| 1210 | |
| 1211 | const std::string vendor = proc_triple.getVendorName(); |
| 1212 | if (!vendor.empty()) |
| 1213 | response.Printf("vendor:%s;", vendor.c_str()); |
Tamas Berghammer | 7cb18bf | 2015-03-24 11:15:23 +0000 | [diff] [blame] | 1214 | #else |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1215 | // We'll send the triple. |
| 1216 | response.PutCString("triple:"); |
Pavel Labath | 7f815a9 | 2019-02-12 14:28:55 +0000 | [diff] [blame] | 1217 | response.PutStringAsRawHex8(proc_triple.getTriple()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1218 | response.PutChar(';'); |
| 1219 | #endif |
| 1220 | std::string ostype = proc_triple.getOSName(); |
| 1221 | // Adjust so ostype reports ios for Apple/ARM and Apple/ARM64. |
| 1222 | if (proc_triple.getVendor() == llvm::Triple::Apple) { |
| 1223 | switch (proc_triple.getArch()) { |
| 1224 | case llvm::Triple::arm: |
| 1225 | case llvm::Triple::thumb: |
| 1226 | case llvm::Triple::aarch64: |
| 1227 | ostype = "ios"; |
| 1228 | break; |
| 1229 | default: |
| 1230 | // No change. |
| 1231 | break; |
| 1232 | } |
| 1233 | } |
| 1234 | response.Printf("ostype:%s;", ostype.c_str()); |
| 1235 | |
| 1236 | switch (proc_arch.GetByteOrder()) { |
| 1237 | case lldb::eByteOrderLittle: |
| 1238 | response.PutCString("endian:little;"); |
| 1239 | break; |
| 1240 | case lldb::eByteOrderBig: |
| 1241 | response.PutCString("endian:big;"); |
| 1242 | break; |
| 1243 | case lldb::eByteOrderPDP: |
| 1244 | response.PutCString("endian:pdp;"); |
| 1245 | break; |
| 1246 | default: |
| 1247 | // Nothing. |
| 1248 | break; |
| 1249 | } |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1250 | // In case of MIPS64, pointer size is depend on ELF ABI For N32 the pointer |
| 1251 | // size is 4 and for N64 it is 8 |
Nitesh Jain | 8999edf | 2016-10-12 10:21:09 +0000 | [diff] [blame] | 1252 | std::string abi = proc_arch.GetTargetABI(); |
| 1253 | if (!abi.empty()) |
| 1254 | response.Printf("elf_abi:%s;", abi.c_str()); |
| 1255 | response.Printf("ptrsize:%d;", proc_arch.GetAddressByteSize()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1256 | } |
| 1257 | } |
| 1258 | |
| 1259 | FileSpec GDBRemoteCommunicationServerCommon::FindModuleFile( |
| 1260 | const std::string &module_path, const ArchSpec &arch) { |
| 1261 | #ifdef __ANDROID__ |
| 1262 | return HostInfoAndroid::ResolveLibraryPath(module_path, arch); |
| 1263 | #else |
Jonas Devlieghere | 8f3be7a | 2018-11-01 21:05:36 +0000 | [diff] [blame] | 1264 | FileSpec file_spec(module_path); |
| 1265 | FileSystem::Instance().Resolve(file_spec); |
| 1266 | return file_spec; |
Tamas Berghammer | 7cb18bf | 2015-03-24 11:15:23 +0000 | [diff] [blame] | 1267 | #endif |
| 1268 | } |
Pavel Labath | 2f1fbae | 2016-09-08 10:07:04 +0000 | [diff] [blame] | 1269 | |
Zachary Turner | 2833321 | 2017-05-12 05:49:54 +0000 | [diff] [blame] | 1270 | ModuleSpec |
| 1271 | GDBRemoteCommunicationServerCommon::GetModuleInfo(llvm::StringRef module_path, |
| 1272 | llvm::StringRef triple) { |
| 1273 | ArchSpec arch(triple); |
Pavel Labath | 2f1fbae | 2016-09-08 10:07:04 +0000 | [diff] [blame] | 1274 | |
Jonas Devlieghere | 8f3be7a | 2018-11-01 21:05:36 +0000 | [diff] [blame] | 1275 | FileSpec req_module_path_spec(module_path); |
| 1276 | FileSystem::Instance().Resolve(req_module_path_spec); |
| 1277 | |
Pavel Labath | 2f1fbae | 2016-09-08 10:07:04 +0000 | [diff] [blame] | 1278 | const FileSpec module_path_spec = |
| 1279 | FindModuleFile(req_module_path_spec.GetPath(), arch); |
| 1280 | const ModuleSpec module_spec(module_path_spec, arch); |
| 1281 | |
| 1282 | ModuleSpecList module_specs; |
| 1283 | if (!ObjectFile::GetModuleSpecifications(module_path_spec, 0, 0, |
| 1284 | module_specs)) |
| 1285 | return ModuleSpec(); |
| 1286 | |
| 1287 | ModuleSpec matched_module_spec; |
| 1288 | if (!module_specs.FindMatchingModuleSpec(module_spec, matched_module_spec)) |
| 1289 | return ModuleSpec(); |
| 1290 | |
| 1291 | return matched_module_spec; |
| 1292 | } |