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