xref: /openbsd-src/gnu/llvm/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h (revision f84b1df5a16cdd762c93854218de246e79975d3b)
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 "vAttach:PID" where PID is in hex.
151   ///
152   /// \param[in] pid
153   ///     A process ID for the remote gdb server to attach to.
154   ///
155   /// \param[out] response
156   ///     The response received from the gdb server. If the return
157   ///     value is zero, \a response will contain a stop reply
158   ///     packet.
159   ///
160   /// \return
161   ///     Zero if the attach was successful, or an error indicating
162   ///     an error code.
163   int SendAttach(lldb::pid_t pid, StringExtractorGDBRemote &response);
164 
165   /// Sends a GDB remote protocol 'I' packet that delivers stdin
166   /// data to the remote process.
167   ///
168   /// \param[in] data
169   ///     A pointer to stdin data.
170   ///
171   /// \param[in] data_len
172   ///     The number of bytes available at \a data.
173   ///
174   /// \return
175   ///     Zero if the attach was successful, or an error indicating
176   ///     an error code.
177   int SendStdinNotification(const char *data, size_t data_len);
178 
179   /// Sets the path to use for stdin/out/err for a process
180   /// that will be launched with the 'A' packet.
181   ///
182   /// \param[in] file_spec
183   ///     The path to use for stdin/out/err
184   ///
185   /// \return
186   ///     Zero if the for success, or an error code for failure.
187   int SetSTDIN(const FileSpec &file_spec);
188   int SetSTDOUT(const FileSpec &file_spec);
189   int SetSTDERR(const FileSpec &file_spec);
190 
191   /// Sets the disable ASLR flag to \a enable for a process that will
192   /// be launched with the 'A' packet.
193   ///
194   /// \param[in] enable
195   ///     A boolean value indicating whether to disable ASLR or not.
196   ///
197   /// \return
198   ///     Zero if the for success, or an error code for failure.
199   int SetDisableASLR(bool enable);
200 
201   /// Sets the DetachOnError flag to \a enable for the process controlled by the
202   /// stub.
203   ///
204   /// \param[in] enable
205   ///     A boolean value indicating whether to detach on error or not.
206   ///
207   /// \return
208   ///     Zero if the for success, or an error code for failure.
209   int SetDetachOnError(bool enable);
210 
211   /// Sets the working directory to \a path for a process that will
212   /// be launched with the 'A' packet for non platform based
213   /// connections. If this packet is sent to a GDB server that
214   /// implements the platform, it will change the current working
215   /// directory for the platform process.
216   ///
217   /// \param[in] working_dir
218   ///     The path to a directory to use when launching our process
219   ///
220   /// \return
221   ///     Zero if the for success, or an error code for failure.
222   int SetWorkingDir(const FileSpec &working_dir);
223 
224   /// Gets the current working directory of a remote platform GDB
225   /// server.
226   ///
227   /// \param[out] working_dir
228   ///     The current working directory on the remote platform.
229   ///
230   /// \return
231   ///     Boolean for success
232   bool GetWorkingDir(FileSpec &working_dir);
233 
234   lldb::addr_t AllocateMemory(size_t size, uint32_t permissions);
235 
236   bool DeallocateMemory(lldb::addr_t addr);
237 
238   Status Detach(bool keep_stopped);
239 
240   Status GetMemoryRegionInfo(lldb::addr_t addr, MemoryRegionInfo &range_info);
241 
242   Status GetWatchpointSupportInfo(uint32_t &num);
243 
244   Status GetWatchpointSupportInfo(uint32_t &num, bool &after,
245                                   const ArchSpec &arch);
246 
247   Status GetWatchpointsTriggerAfterInstruction(bool &after,
248                                                const ArchSpec &arch);
249 
250   const ArchSpec &GetHostArchitecture();
251 
252   std::chrono::seconds GetHostDefaultPacketTimeout();
253 
254   const ArchSpec &GetProcessArchitecture();
255 
256   void GetRemoteQSupported();
257 
258   bool GetVContSupported(char flavor);
259 
260   bool GetpPacketSupported(lldb::tid_t tid);
261 
262   bool GetxPacketSupported();
263 
264   bool GetVAttachOrWaitSupported();
265 
266   bool GetSyncThreadStateSupported();
267 
268   void ResetDiscoverableSettings(bool did_exec);
269 
270   bool GetHostInfo(bool force = false);
271 
272   bool GetDefaultThreadId(lldb::tid_t &tid);
273 
274   llvm::VersionTuple GetOSVersion();
275 
276   llvm::VersionTuple GetMacCatalystVersion();
277 
278   bool GetOSBuildString(std::string &s);
279 
280   bool GetOSKernelDescription(std::string &s);
281 
282   ArchSpec GetSystemArchitecture();
283 
284   uint32_t GetAddressingBits();
285 
286   bool GetHostname(std::string &s);
287 
288   lldb::addr_t GetShlibInfoAddr();
289 
290   bool GetSupportsThreadSuffix();
291 
292   bool GetProcessInfo(lldb::pid_t pid, ProcessInstanceInfo &process_info);
293 
294   uint32_t FindProcesses(const ProcessInstanceInfoMatch &process_match_info,
295                          ProcessInstanceInfoList &process_infos);
296 
297   bool GetUserName(uint32_t uid, std::string &name);
298 
299   bool GetGroupName(uint32_t gid, std::string &name);
300 
301   bool HasFullVContSupport() { return GetVContSupported('A'); }
302 
303   bool HasAnyVContSupport() { return GetVContSupported('a'); }
304 
305   bool GetStopReply(StringExtractorGDBRemote &response);
306 
307   bool GetThreadStopInfo(lldb::tid_t tid, StringExtractorGDBRemote &response);
308 
309   bool SupportsGDBStoppointPacket(GDBStoppointType type) {
310     switch (type) {
311     case eBreakpointSoftware:
312       return m_supports_z0;
313     case eBreakpointHardware:
314       return m_supports_z1;
315     case eWatchpointWrite:
316       return m_supports_z2;
317     case eWatchpointRead:
318       return m_supports_z3;
319     case eWatchpointReadWrite:
320       return m_supports_z4;
321     default:
322       return false;
323     }
324   }
325 
326   uint8_t SendGDBStoppointTypePacket(
327       GDBStoppointType type, // Type of breakpoint or watchpoint
328       bool insert,           // Insert or remove?
329       lldb::addr_t addr,     // Address of breakpoint or watchpoint
330       uint32_t length,       // Byte Size of breakpoint or watchpoint
331       std::chrono::seconds interrupt_timeout); // Time to wait for an interrupt
332 
333   bool SetNonStopMode(const bool enable);
334 
335   void TestPacketSpeed(const uint32_t num_packets, uint32_t max_send,
336                        uint32_t max_recv, uint64_t recv_amount, bool json,
337                        Stream &strm);
338 
339   // This packet is for testing the speed of the interface only. Both
340   // the client and server need to support it, but this allows us to
341   // measure the packet speed without any other work being done on the
342   // other end and avoids any of that work affecting the packet send
343   // and response times.
344   bool SendSpeedTestPacket(uint32_t send_size, uint32_t recv_size);
345 
346   llvm::Optional<PidTid>
347   SendSetCurrentThreadPacket(uint64_t tid, uint64_t pid, char op);
348 
349   bool SetCurrentThread(uint64_t tid,
350                         lldb::pid_t pid = LLDB_INVALID_PROCESS_ID);
351 
352   bool SetCurrentThreadForRun(uint64_t tid,
353                               lldb::pid_t pid = LLDB_INVALID_PROCESS_ID);
354 
355   bool GetQXferAuxvReadSupported();
356 
357   void EnableErrorStringInPacket();
358 
359   bool GetQXferLibrariesReadSupported();
360 
361   bool GetQXferLibrariesSVR4ReadSupported();
362 
363   uint64_t GetRemoteMaxPacketSize();
364 
365   bool GetEchoSupported();
366 
367   bool GetQPassSignalsSupported();
368 
369   bool GetAugmentedLibrariesSVR4ReadSupported();
370 
371   bool GetQXferFeaturesReadSupported();
372 
373   bool GetQXferMemoryMapReadSupported();
374 
375   LazyBool SupportsAllocDeallocMemory() // const
376   {
377     // Uncomment this to have lldb pretend the debug server doesn't respond to
378     // alloc/dealloc memory packets.
379     // m_supports_alloc_dealloc_memory = lldb_private::eLazyBoolNo;
380     return m_supports_alloc_dealloc_memory;
381   }
382 
383   std::vector<std::pair<lldb::pid_t, lldb::tid_t>>
384   GetCurrentProcessAndThreadIDs(bool &sequence_mutex_unavailable);
385 
386   size_t GetCurrentThreadIDs(std::vector<lldb::tid_t> &thread_ids,
387                              bool &sequence_mutex_unavailable);
388 
389   lldb::user_id_t OpenFile(const FileSpec &file_spec, File::OpenOptions flags,
390                            mode_t mode, Status &error);
391 
392   bool CloseFile(lldb::user_id_t fd, Status &error);
393 
394   lldb::user_id_t GetFileSize(const FileSpec &file_spec);
395 
396   void AutoCompleteDiskFileOrDirectory(CompletionRequest &request,
397                                        bool only_dir);
398 
399   Status GetFilePermissions(const FileSpec &file_spec,
400                             uint32_t &file_permissions);
401 
402   Status SetFilePermissions(const FileSpec &file_spec,
403                             uint32_t file_permissions);
404 
405   uint64_t ReadFile(lldb::user_id_t fd, uint64_t offset, void *dst,
406                     uint64_t dst_len, Status &error);
407 
408   uint64_t WriteFile(lldb::user_id_t fd, uint64_t offset, const void *src,
409                      uint64_t src_len, Status &error);
410 
411   Status CreateSymlink(const FileSpec &src, const FileSpec &dst);
412 
413   Status Unlink(const FileSpec &file_spec);
414 
415   Status MakeDirectory(const FileSpec &file_spec, uint32_t mode);
416 
417   bool GetFileExists(const FileSpec &file_spec);
418 
419   Status RunShellCommand(
420       llvm::StringRef command,
421       const FileSpec &working_dir, // Pass empty FileSpec to use the current
422                                    // working directory
423       int *status_ptr, // Pass nullptr if you don't want the process exit status
424       int *signo_ptr,  // Pass nullptr if you don't want the signal that caused
425                        // the process to exit
426       std::string
427           *command_output, // Pass nullptr if you don't want the command output
428       const Timeout<std::micro> &timeout);
429 
430   bool CalculateMD5(const FileSpec &file_spec, uint64_t &high, uint64_t &low);
431 
432   lldb::DataBufferSP ReadRegister(
433       lldb::tid_t tid,
434       uint32_t
435           reg_num); // Must be the eRegisterKindProcessPlugin register number
436 
437   lldb::DataBufferSP ReadAllRegisters(lldb::tid_t tid);
438 
439   bool
440   WriteRegister(lldb::tid_t tid,
441                 uint32_t reg_num, // eRegisterKindProcessPlugin register number
442                 llvm::ArrayRef<uint8_t> data);
443 
444   bool WriteAllRegisters(lldb::tid_t tid, llvm::ArrayRef<uint8_t> data);
445 
446   bool SaveRegisterState(lldb::tid_t tid, uint32_t &save_id);
447 
448   bool RestoreRegisterState(lldb::tid_t tid, uint32_t save_id);
449 
450   bool SyncThreadState(lldb::tid_t tid);
451 
452   const char *GetGDBServerProgramName();
453 
454   uint32_t GetGDBServerProgramVersion();
455 
456   bool AvoidGPackets(ProcessGDBRemote *process);
457 
458   StructuredData::ObjectSP GetThreadsInfo();
459 
460   bool GetThreadExtendedInfoSupported();
461 
462   bool GetLoadedDynamicLibrariesInfosSupported();
463 
464   bool GetSharedCacheInfoSupported();
465 
466   bool GetMemoryTaggingSupported();
467 
468   lldb::DataBufferSP ReadMemoryTags(lldb::addr_t addr, size_t len,
469                                     int32_t type);
470 
471   Status WriteMemoryTags(lldb::addr_t addr, size_t len, int32_t type,
472                          const std::vector<uint8_t> &tags);
473 
474   /// Use qOffsets to query the offset used when relocating the target
475   /// executable. If successful, the returned structure will contain at least
476   /// one value in the offsets field.
477   llvm::Optional<QOffsets> GetQOffsets();
478 
479   bool GetModuleInfo(const FileSpec &module_file_spec,
480                      const ArchSpec &arch_spec, ModuleSpec &module_spec);
481 
482   llvm::Optional<std::vector<ModuleSpec>>
483   GetModulesInfo(llvm::ArrayRef<FileSpec> module_file_specs,
484                  const llvm::Triple &triple);
485 
486   bool ReadExtFeature(const lldb_private::ConstString object,
487                       const lldb_private::ConstString annex, std::string &out,
488                       lldb_private::Status &err);
489 
490   void ServeSymbolLookups(lldb_private::Process *process);
491 
492   // Sends QPassSignals packet to the server with given signals to ignore.
493   Status SendSignalsToIgnore(llvm::ArrayRef<int32_t> signals);
494 
495   /// Return the feature set supported by the gdb-remote server.
496   ///
497   /// This method returns the remote side's response to the qSupported
498   /// packet.  The response is the complete string payload returned
499   /// to the client.
500   ///
501   /// \return
502   ///     The string returned by the server to the qSupported query.
503   const std::string &GetServerSupportedFeatures() const {
504     return m_qSupported_response;
505   }
506 
507   /// Return the array of async JSON packet types supported by the remote.
508   ///
509   /// This method returns the remote side's array of supported JSON
510   /// packet types as a list of type names.  Each of the results are
511   /// expected to have an Enable{type_name} command to enable and configure
512   /// the related feature.  Each type_name for an enabled feature will
513   /// possibly send async-style packets that contain a payload of a
514   /// binhex-encoded JSON dictionary.  The dictionary will have a
515   /// string field named 'type', that contains the type_name of the
516   /// supported packet type.
517   ///
518   /// There is a Plugin category called structured-data plugins.
519   /// A plugin indicates whether it knows how to handle a type_name.
520   /// If so, it can be used to process the async JSON packet.
521   ///
522   /// \return
523   ///     The string returned by the server to the qSupported query.
524   lldb_private::StructuredData::Array *GetSupportedStructuredDataPlugins();
525 
526   /// Configure a StructuredData feature on the remote end.
527   ///
528   /// \see \b Process::ConfigureStructuredData(...) for details.
529   Status
530   ConfigureRemoteStructuredData(ConstString type_name,
531                                 const StructuredData::ObjectSP &config_sp);
532 
533   llvm::Expected<TraceSupportedResponse>
534   SendTraceSupported(std::chrono::seconds interrupt_timeout);
535 
536   llvm::Error SendTraceStart(const llvm::json::Value &request,
537                              std::chrono::seconds interrupt_timeout);
538 
539   llvm::Error SendTraceStop(const TraceStopRequest &request,
540                             std::chrono::seconds interrupt_timeout);
541 
542   llvm::Expected<std::string>
543   SendTraceGetState(llvm::StringRef type,
544                     std::chrono::seconds interrupt_timeout);
545 
546   llvm::Expected<std::vector<uint8_t>>
547   SendTraceGetBinaryData(const TraceGetBinaryDataRequest &request,
548                          std::chrono::seconds interrupt_timeout);
549 
550 protected:
551   LazyBool m_supports_not_sending_acks = eLazyBoolCalculate;
552   LazyBool m_supports_thread_suffix = eLazyBoolCalculate;
553   LazyBool m_supports_threads_in_stop_reply = eLazyBoolCalculate;
554   LazyBool m_supports_vCont_all = eLazyBoolCalculate;
555   LazyBool m_supports_vCont_any = eLazyBoolCalculate;
556   LazyBool m_supports_vCont_c = eLazyBoolCalculate;
557   LazyBool m_supports_vCont_C = eLazyBoolCalculate;
558   LazyBool m_supports_vCont_s = eLazyBoolCalculate;
559   LazyBool m_supports_vCont_S = eLazyBoolCalculate;
560   LazyBool m_qHostInfo_is_valid = eLazyBoolCalculate;
561   LazyBool m_curr_pid_is_valid = eLazyBoolCalculate;
562   LazyBool m_qProcessInfo_is_valid = eLazyBoolCalculate;
563   LazyBool m_qGDBServerVersion_is_valid = eLazyBoolCalculate;
564   LazyBool m_supports_alloc_dealloc_memory = eLazyBoolCalculate;
565   LazyBool m_supports_memory_region_info = eLazyBoolCalculate;
566   LazyBool m_supports_watchpoint_support_info = eLazyBoolCalculate;
567   LazyBool m_supports_detach_stay_stopped = eLazyBoolCalculate;
568   LazyBool m_watchpoints_trigger_after_instruction = eLazyBoolCalculate;
569   LazyBool m_attach_or_wait_reply = eLazyBoolCalculate;
570   LazyBool m_prepare_for_reg_writing_reply = eLazyBoolCalculate;
571   LazyBool m_supports_p = eLazyBoolCalculate;
572   LazyBool m_supports_x = eLazyBoolCalculate;
573   LazyBool m_avoid_g_packets = eLazyBoolCalculate;
574   LazyBool m_supports_QSaveRegisterState = eLazyBoolCalculate;
575   LazyBool m_supports_qXfer_auxv_read = eLazyBoolCalculate;
576   LazyBool m_supports_qXfer_libraries_read = eLazyBoolCalculate;
577   LazyBool m_supports_qXfer_libraries_svr4_read = eLazyBoolCalculate;
578   LazyBool m_supports_qXfer_features_read = eLazyBoolCalculate;
579   LazyBool m_supports_qXfer_memory_map_read = eLazyBoolCalculate;
580   LazyBool m_supports_augmented_libraries_svr4_read = eLazyBoolCalculate;
581   LazyBool m_supports_jThreadExtendedInfo = eLazyBoolCalculate;
582   LazyBool m_supports_jLoadedDynamicLibrariesInfos = eLazyBoolCalculate;
583   LazyBool m_supports_jGetSharedCacheInfo = eLazyBoolCalculate;
584   LazyBool m_supports_QPassSignals = eLazyBoolCalculate;
585   LazyBool m_supports_error_string_reply = eLazyBoolCalculate;
586   LazyBool m_supports_multiprocess = eLazyBoolCalculate;
587   LazyBool m_supports_memory_tagging = eLazyBoolCalculate;
588 
589   bool m_supports_qProcessInfoPID : 1, m_supports_qfProcessInfo : 1,
590       m_supports_qUserName : 1, m_supports_qGroupName : 1,
591       m_supports_qThreadStopInfo : 1, m_supports_z0 : 1, m_supports_z1 : 1,
592       m_supports_z2 : 1, m_supports_z3 : 1, m_supports_z4 : 1,
593       m_supports_QEnvironment : 1, m_supports_QEnvironmentHexEncoded : 1,
594       m_supports_qSymbol : 1, m_qSymbol_requests_done : 1,
595       m_supports_qModuleInfo : 1, m_supports_jThreadsInfo : 1,
596       m_supports_jModulesInfo : 1;
597 
598   /// Current gdb remote protocol process identifier for all other operations
599   lldb::pid_t m_curr_pid = LLDB_INVALID_PROCESS_ID;
600   /// Current gdb remote protocol process identifier for continue, step, etc
601   lldb::pid_t m_curr_pid_run = LLDB_INVALID_PROCESS_ID;
602   /// Current gdb remote protocol thread identifier for all other operations
603   lldb::tid_t m_curr_tid = LLDB_INVALID_THREAD_ID;
604   /// Current gdb remote protocol thread identifier for continue, step, etc
605   lldb::tid_t m_curr_tid_run = LLDB_INVALID_THREAD_ID;
606 
607   uint32_t m_num_supported_hardware_watchpoints = 0;
608   uint32_t m_addressing_bits = 0;
609 
610   ArchSpec m_host_arch;
611   ArchSpec m_process_arch;
612   llvm::VersionTuple m_os_version;
613   llvm::VersionTuple m_maccatalyst_version;
614   std::string m_os_build;
615   std::string m_os_kernel;
616   std::string m_hostname;
617   std::string m_gdb_server_name; // from reply to qGDBServerVersion, empty if
618                                  // qGDBServerVersion is not supported
619   uint32_t m_gdb_server_version =
620       UINT32_MAX; // from reply to qGDBServerVersion, zero if
621                   // qGDBServerVersion is not supported
622   std::chrono::seconds m_default_packet_timeout;
623   int m_target_vm_page_size = 0; // target system VM page size; 0 unspecified
624   uint64_t m_max_packet_size = 0;    // as returned by qSupported
625   std::string m_qSupported_response; // the complete response to qSupported
626 
627   bool m_supported_async_json_packets_is_valid = false;
628   lldb_private::StructuredData::ObjectSP m_supported_async_json_packets_sp;
629 
630   std::vector<MemoryRegionInfo> m_qXfer_memory_map;
631   bool m_qXfer_memory_map_loaded = false;
632 
633   bool GetCurrentProcessInfo(bool allow_lazy_pid = true);
634 
635   bool GetGDBServerVersion();
636 
637   // Given the list of compression types that the remote debug stub can support,
638   // possibly enable compression if we find an encoding we can handle.
639   void MaybeEnableCompression(
640       llvm::ArrayRef<llvm::StringRef> supported_compressions);
641 
642   bool DecodeProcessInfoResponse(StringExtractorGDBRemote &response,
643                                  ProcessInstanceInfo &process_info);
644 
645   void OnRunPacketSent(bool first) override;
646 
647   PacketResult SendThreadSpecificPacketAndWaitForResponse(
648       lldb::tid_t tid, StreamString &&payload,
649       StringExtractorGDBRemote &response);
650 
651   Status SendGetTraceDataPacket(StreamGDBRemote &packet, lldb::user_id_t uid,
652                                 lldb::tid_t thread_id,
653                                 llvm::MutableArrayRef<uint8_t> &buffer,
654                                 size_t offset);
655 
656   Status LoadQXferMemoryMap();
657 
658   Status GetQXferMemoryMapRegionInfo(lldb::addr_t addr,
659                                      MemoryRegionInfo &region);
660 
661   LazyBool GetThreadPacketSupported(lldb::tid_t tid, llvm::StringRef packetStr);
662 
663 private:
664   GDBRemoteCommunicationClient(const GDBRemoteCommunicationClient &) = delete;
665   const GDBRemoteCommunicationClient &
666   operator=(const GDBRemoteCommunicationClient &) = delete;
667 };
668 
669 } // namespace process_gdb_remote
670 } // namespace lldb_private
671 
672 #endif // LLDB_SOURCE_PLUGINS_PROCESS_GDB_REMOTE_GDBREMOTECOMMUNICATIONCLIENT_H
673