1 //===-- GDBRemoteCommunicationClient.h --------------------------*- C++ -*-===// 2 // 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 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef LLDB_SOURCE_PLUGINS_PROCESS_GDB_REMOTE_GDBREMOTECOMMUNICATIONCLIENT_H 10 #define LLDB_SOURCE_PLUGINS_PROCESS_GDB_REMOTE_GDBREMOTECOMMUNICATIONCLIENT_H 11 12 #include "GDBRemoteClientBase.h" 13 14 #include <chrono> 15 #include <map> 16 #include <mutex> 17 #include <string> 18 #include <vector> 19 20 #include "lldb/Host/File.h" 21 #include "lldb/Utility/ArchSpec.h" 22 #include "lldb/Utility/GDBRemote.h" 23 #include "lldb/Utility/ProcessInfo.h" 24 #include "lldb/Utility/StructuredData.h" 25 #include "lldb/Utility/TraceGDBRemotePackets.h" 26 #if defined(_WIN32) 27 #include "lldb/Host/windows/PosixApi.h" 28 #endif 29 30 #include "llvm/ADT/Optional.h" 31 #include "llvm/Support/VersionTuple.h" 32 33 namespace lldb_private { 34 namespace process_gdb_remote { 35 36 /// The offsets used by the target when relocating the executable. Decoded from 37 /// qOffsets packet response. 38 struct QOffsets { 39 /// If true, the offsets field describes segments. Otherwise, it describes 40 /// sections. 41 bool segments; 42 43 /// The individual offsets. Section offsets have two or three members. 44 /// Segment offsets have either one of two. 45 std::vector<uint64_t> offsets; 46 }; 47 inline bool operator==(const QOffsets &a, const QOffsets &b) { 48 return a.segments == b.segments && a.offsets == b.offsets; 49 } 50 llvm::raw_ostream &operator<<(llvm::raw_ostream &os, const QOffsets &offsets); 51 52 // A trivial struct used to return a pair of PID and TID. 53 struct PidTid { 54 uint64_t pid; 55 uint64_t tid; 56 }; 57 58 class GDBRemoteCommunicationClient : public GDBRemoteClientBase { 59 public: 60 GDBRemoteCommunicationClient(); 61 62 ~GDBRemoteCommunicationClient() override; 63 64 // After connecting, send the handshake to the server to make sure 65 // we are communicating with it. 66 bool HandshakeWithServer(Status *error_ptr); 67 68 // For packets which specify a range of output to be returned, 69 // return all of the output via a series of request packets of the form 70 // <prefix>0,<size> 71 // <prefix><size>,<size> 72 // <prefix><size>*2,<size> 73 // <prefix><size>*3,<size> 74 // ... 75 // until a "$l..." packet is received, indicating the end. 76 // (size is in hex; this format is used by a standard gdbserver to 77 // return the given portion of the output specified by <prefix>; 78 // for example, "qXfer:libraries-svr4:read::fff,1000" means 79 // "return a chunk of the xml description file for shared 80 // library load addresses, where the chunk starts at offset 0xfff 81 // and continues for 0x1000 bytes"). 82 // Concatenate the resulting server response packets together and 83 // return in response_string. If any packet fails, the return value 84 // indicates that failure and the returned string value is undefined. 85 PacketResult 86 SendPacketsAndConcatenateResponses(const char *send_payload_prefix, 87 std::string &response_string); 88 89 bool GetThreadSuffixSupported(); 90 91 // This packet is usually sent first and the boolean return value 92 // indicates if the packet was send and any response was received 93 // even in the response is UNIMPLEMENTED. If the packet failed to 94 // get a response, then false is returned. This quickly tells us 95 // if we were able to connect and communicate with the remote GDB 96 // server 97 bool QueryNoAckModeSupported(); 98 99 void GetListThreadsInStopReplySupported(); 100 101 lldb::pid_t GetCurrentProcessID(bool allow_lazy = true); 102 103 bool GetLaunchSuccess(std::string &error_str); 104 105 bool LaunchGDBServer(const char *remote_accept_hostname, lldb::pid_t &pid, 106 uint16_t &port, std::string &socket_name); 107 108 size_t QueryGDBServer( 109 std::vector<std::pair<uint16_t, std::string>> &connection_urls); 110 111 bool KillSpawnedProcess(lldb::pid_t pid); 112 113 /// Sends a GDB remote protocol 'A' packet that delivers program 114 /// arguments to the remote server. 115 /// 116 /// \param[in] launch_info 117 /// A NULL terminated array of const C strings to use as the 118 /// arguments. 119 /// 120 /// \return 121 /// Zero if the response was "OK", a positive value if the 122 /// the response was "Exx" where xx are two hex digits, or 123 /// -1 if the call is unsupported or any other unexpected 124 /// response was received. 125 int SendArgumentsPacket(const ProcessLaunchInfo &launch_info); 126 127 /// Sends a "QEnvironment:NAME=VALUE" packet that will build up the 128 /// environment that will get used when launching an application 129 /// in conjunction with the 'A' packet. This function can be called 130 /// multiple times in a row in order to pass on the desired 131 /// environment that the inferior should be launched with. 132 /// 133 /// \param[in] name_equal_value 134 /// A NULL terminated C string that contains a single environment 135 /// in the format "NAME=VALUE". 136 /// 137 /// \return 138 /// Zero if the response was "OK", a positive value if the 139 /// the response was "Exx" where xx are two hex digits, or 140 /// -1 if the call is unsupported or any other unexpected 141 /// response was received. 142 int SendEnvironmentPacket(char const *name_equal_value); 143 int SendEnvironment(const Environment &env); 144 145 int SendLaunchArchPacket(const char *arch); 146 147 int SendLaunchEventDataPacket(const char *data, 148 bool *was_supported = nullptr); 149 150 /// Sends a GDB remote protocol 'I' packet that delivers stdin 151 /// data to the remote process. 152 /// 153 /// \param[in] data 154 /// A pointer to stdin data. 155 /// 156 /// \param[in] data_len 157 /// The number of bytes available at \a data. 158 /// 159 /// \return 160 /// Zero if the attach was successful, or an error indicating 161 /// an error code. 162 int SendStdinNotification(const char *data, size_t data_len); 163 164 /// Sets the path to use for stdin/out/err for a process 165 /// that will be launched with the 'A' packet. 166 /// 167 /// \param[in] file_spec 168 /// The path to use for stdin/out/err 169 /// 170 /// \return 171 /// Zero if the for success, or an error code for failure. 172 int SetSTDIN(const FileSpec &file_spec); 173 int SetSTDOUT(const FileSpec &file_spec); 174 int SetSTDERR(const FileSpec &file_spec); 175 176 /// Sets the disable ASLR flag to \a enable for a process that will 177 /// be launched with the 'A' packet. 178 /// 179 /// \param[in] enable 180 /// A boolean value indicating whether to disable ASLR or not. 181 /// 182 /// \return 183 /// Zero if the for success, or an error code for failure. 184 int SetDisableASLR(bool enable); 185 186 /// Sets the DetachOnError flag to \a enable for the process controlled by the 187 /// stub. 188 /// 189 /// \param[in] enable 190 /// A boolean value indicating whether to detach on error or not. 191 /// 192 /// \return 193 /// Zero if the for success, or an error code for failure. 194 int SetDetachOnError(bool enable); 195 196 /// Sets the working directory to \a path for a process that will 197 /// be launched with the 'A' packet for non platform based 198 /// connections. If this packet is sent to a GDB server that 199 /// implements the platform, it will change the current working 200 /// directory for the platform process. 201 /// 202 /// \param[in] working_dir 203 /// The path to a directory to use when launching our process 204 /// 205 /// \return 206 /// Zero if the for success, or an error code for failure. 207 int SetWorkingDir(const FileSpec &working_dir); 208 209 /// Gets the current working directory of a remote platform GDB 210 /// server. 211 /// 212 /// \param[out] working_dir 213 /// The current working directory on the remote platform. 214 /// 215 /// \return 216 /// Boolean for success 217 bool GetWorkingDir(FileSpec &working_dir); 218 219 lldb::addr_t AllocateMemory(size_t size, uint32_t permissions); 220 221 bool DeallocateMemory(lldb::addr_t addr); 222 223 Status Detach(bool keep_stopped, lldb::pid_t pid = LLDB_INVALID_PROCESS_ID); 224 225 Status GetMemoryRegionInfo(lldb::addr_t addr, MemoryRegionInfo &range_info); 226 227 Status GetWatchpointSupportInfo(uint32_t &num); 228 229 Status GetWatchpointSupportInfo(uint32_t &num, bool &after, 230 const ArchSpec &arch); 231 232 Status GetWatchpointsTriggerAfterInstruction(bool &after, 233 const ArchSpec &arch); 234 235 const ArchSpec &GetHostArchitecture(); 236 237 std::chrono::seconds GetHostDefaultPacketTimeout(); 238 239 const ArchSpec &GetProcessArchitecture(); 240 241 void GetRemoteQSupported(); 242 243 bool GetVContSupported(char flavor); 244 245 bool GetpPacketSupported(lldb::tid_t tid); 246 247 bool GetxPacketSupported(); 248 249 bool GetVAttachOrWaitSupported(); 250 251 bool GetSyncThreadStateSupported(); 252 253 void ResetDiscoverableSettings(bool did_exec); 254 255 bool GetHostInfo(bool force = false); 256 257 bool GetDefaultThreadId(lldb::tid_t &tid); 258 259 llvm::VersionTuple GetOSVersion(); 260 261 llvm::VersionTuple GetMacCatalystVersion(); 262 263 bool GetOSBuildString(std::string &s); 264 265 bool GetOSKernelDescription(std::string &s); 266 267 ArchSpec GetSystemArchitecture(); 268 269 uint32_t GetAddressingBits(); 270 271 bool GetHostname(std::string &s); 272 273 lldb::addr_t GetShlibInfoAddr(); 274 275 bool GetSupportsThreadSuffix(); 276 277 bool GetProcessInfo(lldb::pid_t pid, ProcessInstanceInfo &process_info); 278 279 uint32_t FindProcesses(const ProcessInstanceInfoMatch &process_match_info, 280 ProcessInstanceInfoList &process_infos); 281 282 bool GetUserName(uint32_t uid, std::string &name); 283 284 bool GetGroupName(uint32_t gid, std::string &name); 285 286 bool HasFullVContSupport() { return GetVContSupported('A'); } 287 288 bool HasAnyVContSupport() { return GetVContSupported('a'); } 289 290 bool GetStopReply(StringExtractorGDBRemote &response); 291 292 bool GetThreadStopInfo(lldb::tid_t tid, StringExtractorGDBRemote &response); 293 294 bool SupportsGDBStoppointPacket(GDBStoppointType type) { 295 switch (type) { 296 case eBreakpointSoftware: 297 return m_supports_z0; 298 case eBreakpointHardware: 299 return m_supports_z1; 300 case eWatchpointWrite: 301 return m_supports_z2; 302 case eWatchpointRead: 303 return m_supports_z3; 304 case eWatchpointReadWrite: 305 return m_supports_z4; 306 default: 307 return false; 308 } 309 } 310 311 uint8_t SendGDBStoppointTypePacket( 312 GDBStoppointType type, // Type of breakpoint or watchpoint 313 bool insert, // Insert or remove? 314 lldb::addr_t addr, // Address of breakpoint or watchpoint 315 uint32_t length, // Byte Size of breakpoint or watchpoint 316 std::chrono::seconds interrupt_timeout); // Time to wait for an interrupt 317 318 bool SetNonStopMode(const bool enable); 319 320 void TestPacketSpeed(const uint32_t num_packets, uint32_t max_send, 321 uint32_t max_recv, uint64_t recv_amount, bool json, 322 Stream &strm); 323 324 // This packet is for testing the speed of the interface only. Both 325 // the client and server need to support it, but this allows us to 326 // measure the packet speed without any other work being done on the 327 // other end and avoids any of that work affecting the packet send 328 // and response times. 329 bool SendSpeedTestPacket(uint32_t send_size, uint32_t recv_size); 330 331 llvm::Optional<PidTid> 332 SendSetCurrentThreadPacket(uint64_t tid, uint64_t pid, char op); 333 334 bool SetCurrentThread(uint64_t tid, 335 lldb::pid_t pid = LLDB_INVALID_PROCESS_ID); 336 337 bool SetCurrentThreadForRun(uint64_t tid, 338 lldb::pid_t pid = LLDB_INVALID_PROCESS_ID); 339 340 bool GetQXferAuxvReadSupported(); 341 342 void EnableErrorStringInPacket(); 343 344 bool GetQXferLibrariesReadSupported(); 345 346 bool GetQXferLibrariesSVR4ReadSupported(); 347 348 uint64_t GetRemoteMaxPacketSize(); 349 350 bool GetEchoSupported(); 351 352 bool GetQPassSignalsSupported(); 353 354 bool GetAugmentedLibrariesSVR4ReadSupported(); 355 356 bool GetQXferFeaturesReadSupported(); 357 358 bool GetQXferMemoryMapReadSupported(); 359 360 LazyBool SupportsAllocDeallocMemory() // const 361 { 362 // Uncomment this to have lldb pretend the debug server doesn't respond to 363 // alloc/dealloc memory packets. 364 // m_supports_alloc_dealloc_memory = lldb_private::eLazyBoolNo; 365 return m_supports_alloc_dealloc_memory; 366 } 367 368 std::vector<std::pair<lldb::pid_t, lldb::tid_t>> 369 GetCurrentProcessAndThreadIDs(bool &sequence_mutex_unavailable); 370 371 size_t GetCurrentThreadIDs(std::vector<lldb::tid_t> &thread_ids, 372 bool &sequence_mutex_unavailable); 373 374 lldb::user_id_t OpenFile(const FileSpec &file_spec, File::OpenOptions flags, 375 mode_t mode, Status &error); 376 377 bool CloseFile(lldb::user_id_t fd, Status &error); 378 379 llvm::Optional<GDBRemoteFStatData> FStat(lldb::user_id_t fd); 380 381 // NB: this is just a convenience wrapper over open() + fstat(). It does not 382 // work if the file cannot be opened. 383 llvm::Optional<GDBRemoteFStatData> Stat(const FileSpec &file_spec); 384 385 lldb::user_id_t GetFileSize(const FileSpec &file_spec); 386 387 void AutoCompleteDiskFileOrDirectory(CompletionRequest &request, 388 bool only_dir); 389 390 Status GetFilePermissions(const FileSpec &file_spec, 391 uint32_t &file_permissions); 392 393 Status SetFilePermissions(const FileSpec &file_spec, 394 uint32_t file_permissions); 395 396 uint64_t ReadFile(lldb::user_id_t fd, uint64_t offset, void *dst, 397 uint64_t dst_len, Status &error); 398 399 uint64_t WriteFile(lldb::user_id_t fd, uint64_t offset, const void *src, 400 uint64_t src_len, Status &error); 401 402 Status CreateSymlink(const FileSpec &src, const FileSpec &dst); 403 404 Status Unlink(const FileSpec &file_spec); 405 406 Status MakeDirectory(const FileSpec &file_spec, uint32_t mode); 407 408 bool GetFileExists(const FileSpec &file_spec); 409 410 Status RunShellCommand( 411 llvm::StringRef command, 412 const FileSpec &working_dir, // Pass empty FileSpec to use the current 413 // working directory 414 int *status_ptr, // Pass nullptr if you don't want the process exit status 415 int *signo_ptr, // Pass nullptr if you don't want the signal that caused 416 // the process to exit 417 std::string 418 *command_output, // Pass nullptr if you don't want the command output 419 const Timeout<std::micro> &timeout); 420 421 bool CalculateMD5(const FileSpec &file_spec, uint64_t &high, uint64_t &low); 422 423 lldb::DataBufferSP ReadRegister( 424 lldb::tid_t tid, 425 uint32_t 426 reg_num); // Must be the eRegisterKindProcessPlugin register number 427 428 lldb::DataBufferSP ReadAllRegisters(lldb::tid_t tid); 429 430 bool 431 WriteRegister(lldb::tid_t tid, 432 uint32_t reg_num, // eRegisterKindProcessPlugin register number 433 llvm::ArrayRef<uint8_t> data); 434 435 bool WriteAllRegisters(lldb::tid_t tid, llvm::ArrayRef<uint8_t> data); 436 437 bool SaveRegisterState(lldb::tid_t tid, uint32_t &save_id); 438 439 bool RestoreRegisterState(lldb::tid_t tid, uint32_t save_id); 440 441 bool SyncThreadState(lldb::tid_t tid); 442 443 const char *GetGDBServerProgramName(); 444 445 uint32_t GetGDBServerProgramVersion(); 446 447 bool AvoidGPackets(ProcessGDBRemote *process); 448 449 StructuredData::ObjectSP GetThreadsInfo(); 450 451 bool GetThreadExtendedInfoSupported(); 452 453 bool GetLoadedDynamicLibrariesInfosSupported(); 454 455 bool GetSharedCacheInfoSupported(); 456 457 bool GetMemoryTaggingSupported(); 458 459 lldb::DataBufferSP ReadMemoryTags(lldb::addr_t addr, size_t len, 460 int32_t type); 461 462 Status WriteMemoryTags(lldb::addr_t addr, size_t len, int32_t type, 463 const std::vector<uint8_t> &tags); 464 465 /// Use qOffsets to query the offset used when relocating the target 466 /// executable. If successful, the returned structure will contain at least 467 /// one value in the offsets field. 468 llvm::Optional<QOffsets> GetQOffsets(); 469 470 bool GetModuleInfo(const FileSpec &module_file_spec, 471 const ArchSpec &arch_spec, ModuleSpec &module_spec); 472 473 llvm::Optional<std::vector<ModuleSpec>> 474 GetModulesInfo(llvm::ArrayRef<FileSpec> module_file_specs, 475 const llvm::Triple &triple); 476 477 bool ReadExtFeature(const lldb_private::ConstString object, 478 const lldb_private::ConstString annex, std::string &out, 479 lldb_private::Status &err); 480 481 void ServeSymbolLookups(lldb_private::Process *process); 482 483 // Sends QPassSignals packet to the server with given signals to ignore. 484 Status SendSignalsToIgnore(llvm::ArrayRef<int32_t> signals); 485 486 /// Return the feature set supported by the gdb-remote server. 487 /// 488 /// This method returns the remote side's response to the qSupported 489 /// packet. The response is the complete string payload returned 490 /// to the client. 491 /// 492 /// \return 493 /// The string returned by the server to the qSupported query. 494 const std::string &GetServerSupportedFeatures() const { 495 return m_qSupported_response; 496 } 497 498 /// Return the array of async JSON packet types supported by the remote. 499 /// 500 /// This method returns the remote side's array of supported JSON 501 /// packet types as a list of type names. Each of the results are 502 /// expected to have an Enable{type_name} command to enable and configure 503 /// the related feature. Each type_name for an enabled feature will 504 /// possibly send async-style packets that contain a payload of a 505 /// binhex-encoded JSON dictionary. The dictionary will have a 506 /// string field named 'type', that contains the type_name of the 507 /// supported packet type. 508 /// 509 /// There is a Plugin category called structured-data plugins. 510 /// A plugin indicates whether it knows how to handle a type_name. 511 /// If so, it can be used to process the async JSON packet. 512 /// 513 /// \return 514 /// The string returned by the server to the qSupported query. 515 lldb_private::StructuredData::Array *GetSupportedStructuredDataPlugins(); 516 517 /// Configure a StructuredData feature on the remote end. 518 /// 519 /// \see \b Process::ConfigureStructuredData(...) for details. 520 Status 521 ConfigureRemoteStructuredData(ConstString type_name, 522 const StructuredData::ObjectSP &config_sp); 523 524 llvm::Expected<TraceSupportedResponse> 525 SendTraceSupported(std::chrono::seconds interrupt_timeout); 526 527 llvm::Error SendTraceStart(const llvm::json::Value &request, 528 std::chrono::seconds interrupt_timeout); 529 530 llvm::Error SendTraceStop(const TraceStopRequest &request, 531 std::chrono::seconds interrupt_timeout); 532 533 llvm::Expected<std::string> 534 SendTraceGetState(llvm::StringRef type, 535 std::chrono::seconds interrupt_timeout); 536 537 llvm::Expected<std::vector<uint8_t>> 538 SendTraceGetBinaryData(const TraceGetBinaryDataRequest &request, 539 std::chrono::seconds interrupt_timeout); 540 541 bool GetSaveCoreSupported() const; 542 543 protected: 544 LazyBool m_supports_not_sending_acks = eLazyBoolCalculate; 545 LazyBool m_supports_thread_suffix = eLazyBoolCalculate; 546 LazyBool m_supports_threads_in_stop_reply = eLazyBoolCalculate; 547 LazyBool m_supports_vCont_all = eLazyBoolCalculate; 548 LazyBool m_supports_vCont_any = eLazyBoolCalculate; 549 LazyBool m_supports_vCont_c = eLazyBoolCalculate; 550 LazyBool m_supports_vCont_C = eLazyBoolCalculate; 551 LazyBool m_supports_vCont_s = eLazyBoolCalculate; 552 LazyBool m_supports_vCont_S = eLazyBoolCalculate; 553 LazyBool m_qHostInfo_is_valid = eLazyBoolCalculate; 554 LazyBool m_curr_pid_is_valid = eLazyBoolCalculate; 555 LazyBool m_qProcessInfo_is_valid = eLazyBoolCalculate; 556 LazyBool m_qGDBServerVersion_is_valid = eLazyBoolCalculate; 557 LazyBool m_supports_alloc_dealloc_memory = eLazyBoolCalculate; 558 LazyBool m_supports_memory_region_info = eLazyBoolCalculate; 559 LazyBool m_supports_watchpoint_support_info = eLazyBoolCalculate; 560 LazyBool m_supports_detach_stay_stopped = eLazyBoolCalculate; 561 LazyBool m_watchpoints_trigger_after_instruction = eLazyBoolCalculate; 562 LazyBool m_attach_or_wait_reply = eLazyBoolCalculate; 563 LazyBool m_prepare_for_reg_writing_reply = eLazyBoolCalculate; 564 LazyBool m_supports_p = eLazyBoolCalculate; 565 LazyBool m_supports_x = eLazyBoolCalculate; 566 LazyBool m_avoid_g_packets = eLazyBoolCalculate; 567 LazyBool m_supports_QSaveRegisterState = eLazyBoolCalculate; 568 LazyBool m_supports_qXfer_auxv_read = eLazyBoolCalculate; 569 LazyBool m_supports_qXfer_libraries_read = eLazyBoolCalculate; 570 LazyBool m_supports_qXfer_libraries_svr4_read = eLazyBoolCalculate; 571 LazyBool m_supports_qXfer_features_read = eLazyBoolCalculate; 572 LazyBool m_supports_qXfer_memory_map_read = eLazyBoolCalculate; 573 LazyBool m_supports_augmented_libraries_svr4_read = eLazyBoolCalculate; 574 LazyBool m_supports_jThreadExtendedInfo = eLazyBoolCalculate; 575 LazyBool m_supports_jLoadedDynamicLibrariesInfos = eLazyBoolCalculate; 576 LazyBool m_supports_jGetSharedCacheInfo = eLazyBoolCalculate; 577 LazyBool m_supports_QPassSignals = eLazyBoolCalculate; 578 LazyBool m_supports_error_string_reply = eLazyBoolCalculate; 579 LazyBool m_supports_multiprocess = eLazyBoolCalculate; 580 LazyBool m_supports_memory_tagging = eLazyBoolCalculate; 581 LazyBool m_supports_qSaveCore = eLazyBoolCalculate; 582 583 bool m_supports_qProcessInfoPID : 1, m_supports_qfProcessInfo : 1, 584 m_supports_qUserName : 1, m_supports_qGroupName : 1, 585 m_supports_qThreadStopInfo : 1, m_supports_z0 : 1, m_supports_z1 : 1, 586 m_supports_z2 : 1, m_supports_z3 : 1, m_supports_z4 : 1, 587 m_supports_QEnvironment : 1, m_supports_QEnvironmentHexEncoded : 1, 588 m_supports_qSymbol : 1, m_qSymbol_requests_done : 1, 589 m_supports_qModuleInfo : 1, m_supports_jThreadsInfo : 1, 590 m_supports_jModulesInfo : 1, m_supports_vFileSize : 1, 591 m_supports_vFileMode : 1, m_supports_vFileExists : 1, 592 m_supports_vRun : 1; 593 594 /// Current gdb remote protocol process identifier for all other operations 595 lldb::pid_t m_curr_pid = LLDB_INVALID_PROCESS_ID; 596 /// Current gdb remote protocol process identifier for continue, step, etc 597 lldb::pid_t m_curr_pid_run = LLDB_INVALID_PROCESS_ID; 598 /// Current gdb remote protocol thread identifier for all other operations 599 lldb::tid_t m_curr_tid = LLDB_INVALID_THREAD_ID; 600 /// Current gdb remote protocol thread identifier for continue, step, etc 601 lldb::tid_t m_curr_tid_run = LLDB_INVALID_THREAD_ID; 602 603 uint32_t m_num_supported_hardware_watchpoints = 0; 604 uint32_t m_addressing_bits = 0; 605 606 ArchSpec m_host_arch; 607 ArchSpec m_process_arch; 608 llvm::VersionTuple m_os_version; 609 llvm::VersionTuple m_maccatalyst_version; 610 std::string m_os_build; 611 std::string m_os_kernel; 612 std::string m_hostname; 613 std::string m_gdb_server_name; // from reply to qGDBServerVersion, empty if 614 // qGDBServerVersion is not supported 615 uint32_t m_gdb_server_version = 616 UINT32_MAX; // from reply to qGDBServerVersion, zero if 617 // qGDBServerVersion is not supported 618 std::chrono::seconds m_default_packet_timeout; 619 int m_target_vm_page_size = 0; // target system VM page size; 0 unspecified 620 uint64_t m_max_packet_size = 0; // as returned by qSupported 621 std::string m_qSupported_response; // the complete response to qSupported 622 623 bool m_supported_async_json_packets_is_valid = false; 624 lldb_private::StructuredData::ObjectSP m_supported_async_json_packets_sp; 625 626 std::vector<MemoryRegionInfo> m_qXfer_memory_map; 627 bool m_qXfer_memory_map_loaded = false; 628 629 bool GetCurrentProcessInfo(bool allow_lazy_pid = true); 630 631 bool GetGDBServerVersion(); 632 633 // Given the list of compression types that the remote debug stub can support, 634 // possibly enable compression if we find an encoding we can handle. 635 void MaybeEnableCompression( 636 llvm::ArrayRef<llvm::StringRef> supported_compressions); 637 638 bool DecodeProcessInfoResponse(StringExtractorGDBRemote &response, 639 ProcessInstanceInfo &process_info); 640 641 void OnRunPacketSent(bool first) override; 642 643 PacketResult SendThreadSpecificPacketAndWaitForResponse( 644 lldb::tid_t tid, StreamString &&payload, 645 StringExtractorGDBRemote &response); 646 647 Status SendGetTraceDataPacket(StreamGDBRemote &packet, lldb::user_id_t uid, 648 lldb::tid_t thread_id, 649 llvm::MutableArrayRef<uint8_t> &buffer, 650 size_t offset); 651 652 Status LoadQXferMemoryMap(); 653 654 Status GetQXferMemoryMapRegionInfo(lldb::addr_t addr, 655 MemoryRegionInfo ®ion); 656 657 LazyBool GetThreadPacketSupported(lldb::tid_t tid, llvm::StringRef packetStr); 658 659 private: 660 GDBRemoteCommunicationClient(const GDBRemoteCommunicationClient &) = delete; 661 const GDBRemoteCommunicationClient & 662 operator=(const GDBRemoteCommunicationClient &) = delete; 663 }; 664 665 } // namespace process_gdb_remote 666 } // namespace lldb_private 667 668 #endif // LLDB_SOURCE_PLUGINS_PROCESS_GDB_REMOTE_GDBREMOTECOMMUNICATIONCLIENT_H 669