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