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 void TestPacketSpeed(const uint32_t num_packets, uint32_t max_send, 319 uint32_t max_recv, uint64_t recv_amount, bool json, 320 Stream &strm); 321 322 // This packet is for testing the speed of the interface only. Both 323 // the client and server need to support it, but this allows us to 324 // measure the packet speed without any other work being done on the 325 // other end and avoids any of that work affecting the packet send 326 // and response times. 327 bool SendSpeedTestPacket(uint32_t send_size, uint32_t recv_size); 328 329 llvm::Optional<PidTid> 330 SendSetCurrentThreadPacket(uint64_t tid, uint64_t pid, char op); 331 332 bool SetCurrentThread(uint64_t tid, 333 lldb::pid_t pid = LLDB_INVALID_PROCESS_ID); 334 335 bool SetCurrentThreadForRun(uint64_t tid, 336 lldb::pid_t pid = LLDB_INVALID_PROCESS_ID); 337 338 bool GetQXferAuxvReadSupported(); 339 340 void EnableErrorStringInPacket(); 341 342 bool GetQXferLibrariesReadSupported(); 343 344 bool GetQXferLibrariesSVR4ReadSupported(); 345 346 uint64_t GetRemoteMaxPacketSize(); 347 348 bool GetEchoSupported(); 349 350 bool GetQPassSignalsSupported(); 351 352 bool GetAugmentedLibrariesSVR4ReadSupported(); 353 354 bool GetQXferFeaturesReadSupported(); 355 356 bool GetQXferMemoryMapReadSupported(); 357 358 LazyBool SupportsAllocDeallocMemory() // const 359 { 360 // Uncomment this to have lldb pretend the debug server doesn't respond to 361 // alloc/dealloc memory packets. 362 // m_supports_alloc_dealloc_memory = lldb_private::eLazyBoolNo; 363 return m_supports_alloc_dealloc_memory; 364 } 365 366 std::vector<std::pair<lldb::pid_t, lldb::tid_t>> 367 GetCurrentProcessAndThreadIDs(bool &sequence_mutex_unavailable); 368 369 size_t GetCurrentThreadIDs(std::vector<lldb::tid_t> &thread_ids, 370 bool &sequence_mutex_unavailable); 371 372 lldb::user_id_t OpenFile(const FileSpec &file_spec, File::OpenOptions flags, 373 mode_t mode, Status &error); 374 375 bool CloseFile(lldb::user_id_t fd, Status &error); 376 377 llvm::Optional<GDBRemoteFStatData> FStat(lldb::user_id_t fd); 378 379 // NB: this is just a convenience wrapper over open() + fstat(). It does not 380 // work if the file cannot be opened. 381 llvm::Optional<GDBRemoteFStatData> Stat(const FileSpec &file_spec); 382 383 lldb::user_id_t GetFileSize(const FileSpec &file_spec); 384 385 void AutoCompleteDiskFileOrDirectory(CompletionRequest &request, 386 bool only_dir); 387 388 Status GetFilePermissions(const FileSpec &file_spec, 389 uint32_t &file_permissions); 390 391 Status SetFilePermissions(const FileSpec &file_spec, 392 uint32_t file_permissions); 393 394 uint64_t ReadFile(lldb::user_id_t fd, uint64_t offset, void *dst, 395 uint64_t dst_len, Status &error); 396 397 uint64_t WriteFile(lldb::user_id_t fd, uint64_t offset, const void *src, 398 uint64_t src_len, Status &error); 399 400 Status CreateSymlink(const FileSpec &src, const FileSpec &dst); 401 402 Status Unlink(const FileSpec &file_spec); 403 404 Status MakeDirectory(const FileSpec &file_spec, uint32_t mode); 405 406 bool GetFileExists(const FileSpec &file_spec); 407 408 Status RunShellCommand( 409 llvm::StringRef command, 410 const FileSpec &working_dir, // Pass empty FileSpec to use the current 411 // working directory 412 int *status_ptr, // Pass nullptr if you don't want the process exit status 413 int *signo_ptr, // Pass nullptr if you don't want the signal that caused 414 // the process to exit 415 std::string 416 *command_output, // Pass nullptr if you don't want the command output 417 const Timeout<std::micro> &timeout); 418 419 bool CalculateMD5(const FileSpec &file_spec, uint64_t &high, uint64_t &low); 420 421 lldb::DataBufferSP ReadRegister( 422 lldb::tid_t tid, 423 uint32_t 424 reg_num); // Must be the eRegisterKindProcessPlugin register number 425 426 lldb::DataBufferSP ReadAllRegisters(lldb::tid_t tid); 427 428 bool 429 WriteRegister(lldb::tid_t tid, 430 uint32_t reg_num, // eRegisterKindProcessPlugin register number 431 llvm::ArrayRef<uint8_t> data); 432 433 bool WriteAllRegisters(lldb::tid_t tid, llvm::ArrayRef<uint8_t> data); 434 435 bool SaveRegisterState(lldb::tid_t tid, uint32_t &save_id); 436 437 bool RestoreRegisterState(lldb::tid_t tid, uint32_t save_id); 438 439 bool SyncThreadState(lldb::tid_t tid); 440 441 const char *GetGDBServerProgramName(); 442 443 uint32_t GetGDBServerProgramVersion(); 444 445 bool AvoidGPackets(ProcessGDBRemote *process); 446 447 StructuredData::ObjectSP GetThreadsInfo(); 448 449 bool GetThreadExtendedInfoSupported(); 450 451 bool GetLoadedDynamicLibrariesInfosSupported(); 452 453 bool GetSharedCacheInfoSupported(); 454 455 bool GetMemoryTaggingSupported(); 456 457 lldb::DataBufferSP ReadMemoryTags(lldb::addr_t addr, size_t len, 458 int32_t type); 459 460 Status WriteMemoryTags(lldb::addr_t addr, size_t len, int32_t type, 461 const std::vector<uint8_t> &tags); 462 463 /// Use qOffsets to query the offset used when relocating the target 464 /// executable. If successful, the returned structure will contain at least 465 /// one value in the offsets field. 466 llvm::Optional<QOffsets> GetQOffsets(); 467 468 bool GetModuleInfo(const FileSpec &module_file_spec, 469 const ArchSpec &arch_spec, ModuleSpec &module_spec); 470 471 llvm::Optional<std::vector<ModuleSpec>> 472 GetModulesInfo(llvm::ArrayRef<FileSpec> module_file_specs, 473 const llvm::Triple &triple); 474 475 bool ReadExtFeature(const lldb_private::ConstString object, 476 const lldb_private::ConstString annex, std::string &out, 477 lldb_private::Status &err); 478 479 void ServeSymbolLookups(lldb_private::Process *process); 480 481 // Sends QPassSignals packet to the server with given signals to ignore. 482 Status SendSignalsToIgnore(llvm::ArrayRef<int32_t> signals); 483 484 /// Return the feature set supported by the gdb-remote server. 485 /// 486 /// This method returns the remote side's response to the qSupported 487 /// packet. The response is the complete string payload returned 488 /// to the client. 489 /// 490 /// \return 491 /// The string returned by the server to the qSupported query. 492 const std::string &GetServerSupportedFeatures() const { 493 return m_qSupported_response; 494 } 495 496 /// Return the array of async JSON packet types supported by the remote. 497 /// 498 /// This method returns the remote side's array of supported JSON 499 /// packet types as a list of type names. Each of the results are 500 /// expected to have an Enable{type_name} command to enable and configure 501 /// the related feature. Each type_name for an enabled feature will 502 /// possibly send async-style packets that contain a payload of a 503 /// binhex-encoded JSON dictionary. The dictionary will have a 504 /// string field named 'type', that contains the type_name of the 505 /// supported packet type. 506 /// 507 /// There is a Plugin category called structured-data plugins. 508 /// A plugin indicates whether it knows how to handle a type_name. 509 /// If so, it can be used to process the async JSON packet. 510 /// 511 /// \return 512 /// The string returned by the server to the qSupported query. 513 lldb_private::StructuredData::Array *GetSupportedStructuredDataPlugins(); 514 515 /// Configure a StructuredData feature on the remote end. 516 /// 517 /// \see \b Process::ConfigureStructuredData(...) for details. 518 Status 519 ConfigureRemoteStructuredData(ConstString type_name, 520 const StructuredData::ObjectSP &config_sp); 521 522 llvm::Expected<TraceSupportedResponse> 523 SendTraceSupported(std::chrono::seconds interrupt_timeout); 524 525 llvm::Error SendTraceStart(const llvm::json::Value &request, 526 std::chrono::seconds interrupt_timeout); 527 528 llvm::Error SendTraceStop(const TraceStopRequest &request, 529 std::chrono::seconds interrupt_timeout); 530 531 llvm::Expected<std::string> 532 SendTraceGetState(llvm::StringRef type, 533 std::chrono::seconds interrupt_timeout); 534 535 llvm::Expected<std::vector<uint8_t>> 536 SendTraceGetBinaryData(const TraceGetBinaryDataRequest &request, 537 std::chrono::seconds interrupt_timeout); 538 539 bool GetSaveCoreSupported() const; 540 541 protected: 542 LazyBool m_supports_not_sending_acks = eLazyBoolCalculate; 543 LazyBool m_supports_thread_suffix = eLazyBoolCalculate; 544 LazyBool m_supports_threads_in_stop_reply = eLazyBoolCalculate; 545 LazyBool m_supports_vCont_all = eLazyBoolCalculate; 546 LazyBool m_supports_vCont_any = eLazyBoolCalculate; 547 LazyBool m_supports_vCont_c = eLazyBoolCalculate; 548 LazyBool m_supports_vCont_C = eLazyBoolCalculate; 549 LazyBool m_supports_vCont_s = eLazyBoolCalculate; 550 LazyBool m_supports_vCont_S = eLazyBoolCalculate; 551 LazyBool m_qHostInfo_is_valid = eLazyBoolCalculate; 552 LazyBool m_curr_pid_is_valid = eLazyBoolCalculate; 553 LazyBool m_qProcessInfo_is_valid = eLazyBoolCalculate; 554 LazyBool m_qGDBServerVersion_is_valid = eLazyBoolCalculate; 555 LazyBool m_supports_alloc_dealloc_memory = eLazyBoolCalculate; 556 LazyBool m_supports_memory_region_info = eLazyBoolCalculate; 557 LazyBool m_supports_watchpoint_support_info = eLazyBoolCalculate; 558 LazyBool m_supports_detach_stay_stopped = eLazyBoolCalculate; 559 LazyBool m_watchpoints_trigger_after_instruction = eLazyBoolCalculate; 560 LazyBool m_attach_or_wait_reply = eLazyBoolCalculate; 561 LazyBool m_prepare_for_reg_writing_reply = eLazyBoolCalculate; 562 LazyBool m_supports_p = eLazyBoolCalculate; 563 LazyBool m_supports_x = eLazyBoolCalculate; 564 LazyBool m_avoid_g_packets = eLazyBoolCalculate; 565 LazyBool m_supports_QSaveRegisterState = eLazyBoolCalculate; 566 LazyBool m_supports_qXfer_auxv_read = eLazyBoolCalculate; 567 LazyBool m_supports_qXfer_libraries_read = eLazyBoolCalculate; 568 LazyBool m_supports_qXfer_libraries_svr4_read = eLazyBoolCalculate; 569 LazyBool m_supports_qXfer_features_read = eLazyBoolCalculate; 570 LazyBool m_supports_qXfer_memory_map_read = eLazyBoolCalculate; 571 LazyBool m_supports_augmented_libraries_svr4_read = eLazyBoolCalculate; 572 LazyBool m_supports_jThreadExtendedInfo = eLazyBoolCalculate; 573 LazyBool m_supports_jLoadedDynamicLibrariesInfos = eLazyBoolCalculate; 574 LazyBool m_supports_jGetSharedCacheInfo = eLazyBoolCalculate; 575 LazyBool m_supports_QPassSignals = eLazyBoolCalculate; 576 LazyBool m_supports_error_string_reply = eLazyBoolCalculate; 577 LazyBool m_supports_multiprocess = eLazyBoolCalculate; 578 LazyBool m_supports_memory_tagging = eLazyBoolCalculate; 579 LazyBool m_supports_qSaveCore = eLazyBoolCalculate; 580 581 bool m_supports_qProcessInfoPID : 1, m_supports_qfProcessInfo : 1, 582 m_supports_qUserName : 1, m_supports_qGroupName : 1, 583 m_supports_qThreadStopInfo : 1, m_supports_z0 : 1, m_supports_z1 : 1, 584 m_supports_z2 : 1, m_supports_z3 : 1, m_supports_z4 : 1, 585 m_supports_QEnvironment : 1, m_supports_QEnvironmentHexEncoded : 1, 586 m_supports_qSymbol : 1, m_qSymbol_requests_done : 1, 587 m_supports_qModuleInfo : 1, m_supports_jThreadsInfo : 1, 588 m_supports_jModulesInfo : 1, m_supports_vFileSize : 1, 589 m_supports_vFileMode : 1, m_supports_vFileExists : 1, 590 m_supports_vRun : 1; 591 592 /// Current gdb remote protocol process identifier for all other operations 593 lldb::pid_t m_curr_pid = LLDB_INVALID_PROCESS_ID; 594 /// Current gdb remote protocol process identifier for continue, step, etc 595 lldb::pid_t m_curr_pid_run = LLDB_INVALID_PROCESS_ID; 596 /// Current gdb remote protocol thread identifier for all other operations 597 lldb::tid_t m_curr_tid = LLDB_INVALID_THREAD_ID; 598 /// Current gdb remote protocol thread identifier for continue, step, etc 599 lldb::tid_t m_curr_tid_run = LLDB_INVALID_THREAD_ID; 600 601 uint32_t m_num_supported_hardware_watchpoints = 0; 602 uint32_t m_addressing_bits = 0; 603 604 ArchSpec m_host_arch; 605 ArchSpec m_process_arch; 606 llvm::VersionTuple m_os_version; 607 llvm::VersionTuple m_maccatalyst_version; 608 std::string m_os_build; 609 std::string m_os_kernel; 610 std::string m_hostname; 611 std::string m_gdb_server_name; // from reply to qGDBServerVersion, empty if 612 // qGDBServerVersion is not supported 613 uint32_t m_gdb_server_version = 614 UINT32_MAX; // from reply to qGDBServerVersion, zero if 615 // qGDBServerVersion is not supported 616 std::chrono::seconds m_default_packet_timeout; 617 int m_target_vm_page_size = 0; // target system VM page size; 0 unspecified 618 uint64_t m_max_packet_size = 0; // as returned by qSupported 619 std::string m_qSupported_response; // the complete response to qSupported 620 621 bool m_supported_async_json_packets_is_valid = false; 622 lldb_private::StructuredData::ObjectSP m_supported_async_json_packets_sp; 623 624 std::vector<MemoryRegionInfo> m_qXfer_memory_map; 625 bool m_qXfer_memory_map_loaded = false; 626 627 bool GetCurrentProcessInfo(bool allow_lazy_pid = true); 628 629 bool GetGDBServerVersion(); 630 631 // Given the list of compression types that the remote debug stub can support, 632 // possibly enable compression if we find an encoding we can handle. 633 void MaybeEnableCompression( 634 llvm::ArrayRef<llvm::StringRef> supported_compressions); 635 636 bool DecodeProcessInfoResponse(StringExtractorGDBRemote &response, 637 ProcessInstanceInfo &process_info); 638 639 void OnRunPacketSent(bool first) override; 640 641 PacketResult SendThreadSpecificPacketAndWaitForResponse( 642 lldb::tid_t tid, StreamString &&payload, 643 StringExtractorGDBRemote &response); 644 645 Status SendGetTraceDataPacket(StreamGDBRemote &packet, lldb::user_id_t uid, 646 lldb::tid_t thread_id, 647 llvm::MutableArrayRef<uint8_t> &buffer, 648 size_t offset); 649 650 Status LoadQXferMemoryMap(); 651 652 Status GetQXferMemoryMapRegionInfo(lldb::addr_t addr, 653 MemoryRegionInfo ®ion); 654 655 LazyBool GetThreadPacketSupported(lldb::tid_t tid, llvm::StringRef packetStr); 656 657 private: 658 GDBRemoteCommunicationClient(const GDBRemoteCommunicationClient &) = delete; 659 const GDBRemoteCommunicationClient & 660 operator=(const GDBRemoteCommunicationClient &) = delete; 661 }; 662 663 } // namespace process_gdb_remote 664 } // namespace lldb_private 665 666 #endif // LLDB_SOURCE_PLUGINS_PROCESS_GDB_REMOTE_GDBREMOTECOMMUNICATIONCLIENT_H 667