GDBRemoteCommunicationClient.h revision 314564
1254721Semaste//===-- GDBRemoteCommunicationClient.h --------------------------*- C++ -*-===//
2254721Semaste//
3254721Semaste//                     The LLVM Compiler Infrastructure
4254721Semaste//
5254721Semaste// This file is distributed under the University of Illinois Open Source
6254721Semaste// License. See LICENSE.TXT for details.
7254721Semaste//
8254721Semaste//===----------------------------------------------------------------------===//
9254721Semaste
10254721Semaste#ifndef liblldb_GDBRemoteCommunicationClient_h_
11254721Semaste#define liblldb_GDBRemoteCommunicationClient_h_
12254721Semaste
13314564Sdim#include "GDBRemoteClientBase.h"
14314564Sdim
15254721Semaste// C Includes
16254721Semaste// C++ Includes
17314564Sdim#include <chrono>
18296417Sdim#include <map>
19309124Sdim#include <mutex>
20296417Sdim#include <string>
21254721Semaste#include <vector>
22254721Semaste
23254721Semaste// Other libraries and framework includes
24254721Semaste// Project includes
25254721Semaste#include "lldb/Core/ArchSpec.h"
26288943Sdim#include "lldb/Core/StructuredData.h"
27254721Semaste#include "lldb/Target/Process.h"
28254721Semaste
29314564Sdim#include "llvm/ADT/Optional.h"
30254721Semaste
31288943Sdimnamespace lldb_private {
32288943Sdimnamespace process_gdb_remote {
33254721Semaste
34314564Sdimclass GDBRemoteCommunicationClient : public GDBRemoteClientBase {
35254721Semastepublic:
36314564Sdim  GDBRemoteCommunicationClient();
37254721Semaste
38314564Sdim  ~GDBRemoteCommunicationClient() override;
39254721Semaste
40314564Sdim  //------------------------------------------------------------------
41314564Sdim  // After connecting, send the handshake to the server to make sure
42314564Sdim  // we are communicating with it.
43314564Sdim  //------------------------------------------------------------------
44314564Sdim  bool HandshakeWithServer(Error *error_ptr);
45254721Semaste
46314564Sdim  // For packets which specify a range of output to be returned,
47314564Sdim  // return all of the output via a series of request packets of the form
48314564Sdim  // <prefix>0,<size>
49314564Sdim  // <prefix><size>,<size>
50314564Sdim  // <prefix><size>*2,<size>
51314564Sdim  // <prefix><size>*3,<size>
52314564Sdim  // ...
53314564Sdim  // until a "$l..." packet is received, indicating the end.
54314564Sdim  // (size is in hex; this format is used by a standard gdbserver to
55314564Sdim  // return the given portion of the output specified by <prefix>;
56314564Sdim  // for example, "qXfer:libraries-svr4:read::fff,1000" means
57314564Sdim  // "return a chunk of the xml description file for shared
58314564Sdim  // library load addresses, where the chunk starts at offset 0xfff
59314564Sdim  // and continues for 0x1000 bytes").
60314564Sdim  // Concatenate the resulting server response packets together and
61314564Sdim  // return in response_string.  If any packet fails, the return value
62314564Sdim  // indicates that failure and the returned string value is undefined.
63314564Sdim  PacketResult
64314564Sdim  SendPacketsAndConcatenateResponses(const char *send_payload_prefix,
65314564Sdim                                     std::string &response_string);
66254721Semaste
67314564Sdim  bool GetThreadSuffixSupported();
68254721Semaste
69314564Sdim  // This packet is usually sent first and the boolean return value
70314564Sdim  // indicates if the packet was send and any response was received
71314564Sdim  // even in the response is UNIMPLEMENTED. If the packet failed to
72314564Sdim  // get a response, then false is returned. This quickly tells us
73314564Sdim  // if we were able to connect and communicate with the remote GDB
74314564Sdim  // server
75314564Sdim  bool QueryNoAckModeSupported();
76262528Semaste
77314564Sdim  void GetListThreadsInStopReplySupported();
78296417Sdim
79314564Sdim  lldb::pid_t GetCurrentProcessID(bool allow_lazy = true);
80254721Semaste
81314564Sdim  bool GetLaunchSuccess(std::string &error_str);
82254721Semaste
83314564Sdim  bool LaunchGDBServer(const char *remote_accept_hostname, lldb::pid_t &pid,
84314564Sdim                       uint16_t &port, std::string &socket_name);
85254721Semaste
86314564Sdim  size_t QueryGDBServer(
87314564Sdim      std::vector<std::pair<uint16_t, std::string>> &connection_urls);
88254721Semaste
89314564Sdim  bool KillSpawnedProcess(lldb::pid_t pid);
90254721Semaste
91314564Sdim  //------------------------------------------------------------------
92314564Sdim  /// Sends a GDB remote protocol 'A' packet that delivers program
93314564Sdim  /// arguments to the remote server.
94314564Sdim  ///
95314564Sdim  /// @param[in] argv
96314564Sdim  ///     A NULL terminated array of const C strings to use as the
97314564Sdim  ///     arguments.
98314564Sdim  ///
99314564Sdim  /// @return
100314564Sdim  ///     Zero if the response was "OK", a positive value if the
101314564Sdim  ///     the response was "Exx" where xx are two hex digits, or
102314564Sdim  ///     -1 if the call is unsupported or any other unexpected
103314564Sdim  ///     response was received.
104314564Sdim  //------------------------------------------------------------------
105314564Sdim  int SendArgumentsPacket(const ProcessLaunchInfo &launch_info);
106254721Semaste
107314564Sdim  //------------------------------------------------------------------
108314564Sdim  /// Sends a "QEnvironment:NAME=VALUE" packet that will build up the
109314564Sdim  /// environment that will get used when launching an application
110314564Sdim  /// in conjunction with the 'A' packet. This function can be called
111314564Sdim  /// multiple times in a row in order to pass on the desired
112314564Sdim  /// environment that the inferior should be launched with.
113314564Sdim  ///
114314564Sdim  /// @param[in] name_equal_value
115314564Sdim  ///     A NULL terminated C string that contains a single environment
116314564Sdim  ///     in the format "NAME=VALUE".
117314564Sdim  ///
118314564Sdim  /// @return
119314564Sdim  ///     Zero if the response was "OK", a positive value if the
120314564Sdim  ///     the response was "Exx" where xx are two hex digits, or
121314564Sdim  ///     -1 if the call is unsupported or any other unexpected
122314564Sdim  ///     response was received.
123314564Sdim  //------------------------------------------------------------------
124314564Sdim  int SendEnvironmentPacket(char const *name_equal_value);
125254721Semaste
126314564Sdim  int SendLaunchArchPacket(const char *arch);
127254721Semaste
128314564Sdim  int SendLaunchEventDataPacket(const char *data,
129314564Sdim                                bool *was_supported = nullptr);
130296417Sdim
131314564Sdim  //------------------------------------------------------------------
132314564Sdim  /// Sends a "vAttach:PID" where PID is in hex.
133314564Sdim  ///
134314564Sdim  /// @param[in] pid
135314564Sdim  ///     A process ID for the remote gdb server to attach to.
136314564Sdim  ///
137314564Sdim  /// @param[out] response
138314564Sdim  ///     The response received from the gdb server. If the return
139314564Sdim  ///     value is zero, \a response will contain a stop reply
140314564Sdim  ///     packet.
141314564Sdim  ///
142314564Sdim  /// @return
143314564Sdim  ///     Zero if the attach was successful, or an error indicating
144314564Sdim  ///     an error code.
145314564Sdim  //------------------------------------------------------------------
146314564Sdim  int SendAttach(lldb::pid_t pid, StringExtractorGDBRemote &response);
147296417Sdim
148314564Sdim  //------------------------------------------------------------------
149314564Sdim  /// Sends a GDB remote protocol 'I' packet that delivers stdin
150314564Sdim  /// data to the remote process.
151314564Sdim  ///
152314564Sdim  /// @param[in] data
153314564Sdim  ///     A pointer to stdin data.
154314564Sdim  ///
155314564Sdim  /// @param[in] data_len
156314564Sdim  ///     The number of bytes available at \a data.
157314564Sdim  ///
158314564Sdim  /// @return
159314564Sdim  ///     Zero if the attach was successful, or an error indicating
160314564Sdim  ///     an error code.
161314564Sdim  //------------------------------------------------------------------
162314564Sdim  int SendStdinNotification(const char *data, size_t data_len);
163254721Semaste
164314564Sdim  //------------------------------------------------------------------
165314564Sdim  /// Sets the path to use for stdin/out/err for a process
166314564Sdim  /// that will be launched with the 'A' packet.
167314564Sdim  ///
168314564Sdim  /// @param[in] path
169314564Sdim  ///     The path to use for stdin/out/err
170314564Sdim  ///
171314564Sdim  /// @return
172314564Sdim  ///     Zero if the for success, or an error code for failure.
173314564Sdim  //------------------------------------------------------------------
174314564Sdim  int SetSTDIN(const FileSpec &file_spec);
175314564Sdim  int SetSTDOUT(const FileSpec &file_spec);
176314564Sdim  int SetSTDERR(const FileSpec &file_spec);
177254721Semaste
178314564Sdim  //------------------------------------------------------------------
179314564Sdim  /// Sets the disable ASLR flag to \a enable for a process that will
180314564Sdim  /// be launched with the 'A' packet.
181314564Sdim  ///
182314564Sdim  /// @param[in] enable
183314564Sdim  ///     A boolean value indicating whether to disable ASLR or not.
184314564Sdim  ///
185314564Sdim  /// @return
186314564Sdim  ///     Zero if the for success, or an error code for failure.
187314564Sdim  //------------------------------------------------------------------
188314564Sdim  int SetDisableASLR(bool enable);
189254721Semaste
190314564Sdim  //------------------------------------------------------------------
191314564Sdim  /// Sets the DetachOnError flag to \a enable for the process controlled by the
192314564Sdim  /// stub.
193314564Sdim  ///
194314564Sdim  /// @param[in] enable
195314564Sdim  ///     A boolean value indicating whether to detach on error or not.
196314564Sdim  ///
197314564Sdim  /// @return
198314564Sdim  ///     Zero if the for success, or an error code for failure.
199314564Sdim  //------------------------------------------------------------------
200314564Sdim  int SetDetachOnError(bool enable);
201254721Semaste
202314564Sdim  //------------------------------------------------------------------
203314564Sdim  /// Sets the working directory to \a path for a process that will
204314564Sdim  /// be launched with the 'A' packet for non platform based
205314564Sdim  /// connections. If this packet is sent to a GDB server that
206314564Sdim  /// implements the platform, it will change the current working
207314564Sdim  /// directory for the platform process.
208314564Sdim  ///
209314564Sdim  /// @param[in] working_dir
210314564Sdim  ///     The path to a directory to use when launching our process
211314564Sdim  ///
212314564Sdim  /// @return
213314564Sdim  ///     Zero if the for success, or an error code for failure.
214314564Sdim  //------------------------------------------------------------------
215314564Sdim  int SetWorkingDir(const FileSpec &working_dir);
216288943Sdim
217314564Sdim  //------------------------------------------------------------------
218314564Sdim  /// Gets the current working directory of a remote platform GDB
219314564Sdim  /// server.
220314564Sdim  ///
221314564Sdim  /// @param[out] working_dir
222314564Sdim  ///     The current working directory on the remote platform.
223314564Sdim  ///
224314564Sdim  /// @return
225314564Sdim  ///     Boolean for success
226314564Sdim  //------------------------------------------------------------------
227314564Sdim  bool GetWorkingDir(FileSpec &working_dir);
228254721Semaste
229314564Sdim  lldb::addr_t AllocateMemory(size_t size, uint32_t permissions);
230254721Semaste
231314564Sdim  bool DeallocateMemory(lldb::addr_t addr);
232254721Semaste
233314564Sdim  Error Detach(bool keep_stopped);
234258884Semaste
235314564Sdim  Error GetMemoryRegionInfo(lldb::addr_t addr, MemoryRegionInfo &range_info);
236254721Semaste
237314564Sdim  Error GetWatchpointSupportInfo(uint32_t &num);
238254721Semaste
239314564Sdim  Error GetWatchpointSupportInfo(uint32_t &num, bool &after,
240314564Sdim                                 const ArchSpec &arch);
241254721Semaste
242314564Sdim  Error GetWatchpointsTriggerAfterInstruction(bool &after,
243314564Sdim                                              const ArchSpec &arch);
244254721Semaste
245314564Sdim  const ArchSpec &GetHostArchitecture();
246254721Semaste
247314564Sdim  std::chrono::seconds GetHostDefaultPacketTimeout();
248254721Semaste
249314564Sdim  const ArchSpec &GetProcessArchitecture();
250254721Semaste
251314564Sdim  void GetRemoteQSupported();
252254721Semaste
253314564Sdim  bool GetVContSupported(char flavor);
254262528Semaste
255314564Sdim  bool GetpPacketSupported(lldb::tid_t tid);
256254721Semaste
257314564Sdim  bool GetxPacketSupported();
258258054Semaste
259314564Sdim  bool GetVAttachOrWaitSupported();
260276479Sdim
261314564Sdim  bool GetSyncThreadStateSupported();
262254721Semaste
263314564Sdim  void ResetDiscoverableSettings(bool did_exec);
264288943Sdim
265314564Sdim  bool GetHostInfo(bool force = false);
266254721Semaste
267314564Sdim  bool GetDefaultThreadId(lldb::tid_t &tid);
268254721Semaste
269314564Sdim  bool GetOSVersion(uint32_t &major, uint32_t &minor, uint32_t &update);
270254721Semaste
271314564Sdim  bool GetOSBuildString(std::string &s);
272254721Semaste
273314564Sdim  bool GetOSKernelDescription(std::string &s);
274254721Semaste
275314564Sdim  ArchSpec GetSystemArchitecture();
276254721Semaste
277314564Sdim  bool GetHostname(std::string &s);
278254721Semaste
279314564Sdim  lldb::addr_t GetShlibInfoAddr();
280254721Semaste
281314564Sdim  bool GetSupportsThreadSuffix();
282254721Semaste
283314564Sdim  bool GetProcessInfo(lldb::pid_t pid, ProcessInstanceInfo &process_info);
284254721Semaste
285314564Sdim  uint32_t FindProcesses(const ProcessInstanceInfoMatch &process_match_info,
286314564Sdim                         ProcessInstanceInfoList &process_infos);
287254721Semaste
288314564Sdim  bool GetUserName(uint32_t uid, std::string &name);
289254721Semaste
290314564Sdim  bool GetGroupName(uint32_t gid, std::string &name);
291314564Sdim
292314564Sdim  bool HasFullVContSupport() { return GetVContSupported('A'); }
293314564Sdim
294314564Sdim  bool HasAnyVContSupport() { return GetVContSupported('a'); }
295314564Sdim
296314564Sdim  bool GetStopReply(StringExtractorGDBRemote &response);
297314564Sdim
298314564Sdim  bool GetThreadStopInfo(lldb::tid_t tid, StringExtractorGDBRemote &response);
299314564Sdim
300314564Sdim  bool SupportsGDBStoppointPacket(GDBStoppointType type) {
301314564Sdim    switch (type) {
302314564Sdim    case eBreakpointSoftware:
303314564Sdim      return m_supports_z0;
304314564Sdim    case eBreakpointHardware:
305314564Sdim      return m_supports_z1;
306314564Sdim    case eWatchpointWrite:
307314564Sdim      return m_supports_z2;
308314564Sdim    case eWatchpointRead:
309314564Sdim      return m_supports_z3;
310314564Sdim    case eWatchpointReadWrite:
311314564Sdim      return m_supports_z4;
312314564Sdim    default:
313314564Sdim      return false;
314254721Semaste    }
315314564Sdim  }
316296417Sdim
317314564Sdim  uint8_t SendGDBStoppointTypePacket(
318314564Sdim      GDBStoppointType type, // Type of breakpoint or watchpoint
319314564Sdim      bool insert,           // Insert or remove?
320314564Sdim      lldb::addr_t addr,     // Address of breakpoint or watchpoint
321314564Sdim      uint32_t length);      // Byte Size of breakpoint or watchpoint
322254721Semaste
323314564Sdim  bool SetNonStopMode(const bool enable);
324288943Sdim
325314564Sdim  void TestPacketSpeed(const uint32_t num_packets, uint32_t max_send,
326314564Sdim                       uint32_t max_recv, uint64_t recv_amount, bool json,
327314564Sdim                       Stream &strm);
328254721Semaste
329314564Sdim  // This packet is for testing the speed of the interface only. Both
330314564Sdim  // the client and server need to support it, but this allows us to
331314564Sdim  // measure the packet speed without any other work being done on the
332314564Sdim  // other end and avoids any of that work affecting the packet send
333314564Sdim  // and response times.
334314564Sdim  bool SendSpeedTestPacket(uint32_t send_size, uint32_t recv_size);
335254721Semaste
336314564Sdim  bool SetCurrentThread(uint64_t tid);
337276479Sdim
338314564Sdim  bool SetCurrentThreadForRun(uint64_t tid);
339262528Semaste
340314564Sdim  bool GetQXferAuxvReadSupported();
341262528Semaste
342314564Sdim  bool GetQXferLibrariesReadSupported();
343262528Semaste
344314564Sdim  bool GetQXferLibrariesSVR4ReadSupported();
345288943Sdim
346314564Sdim  uint64_t GetRemoteMaxPacketSize();
347262528Semaste
348314564Sdim  bool GetEchoSupported();
349288943Sdim
350314564Sdim  bool GetAugmentedLibrariesSVR4ReadSupported();
351254721Semaste
352314564Sdim  bool GetQXferFeaturesReadSupported();
353258054Semaste
354314564Sdim  LazyBool SupportsAllocDeallocMemory() // const
355314564Sdim  {
356314564Sdim    // Uncomment this to have lldb pretend the debug server doesn't respond to
357314564Sdim    // alloc/dealloc memory packets.
358314564Sdim    // m_supports_alloc_dealloc_memory = lldb_private::eLazyBoolNo;
359314564Sdim    return m_supports_alloc_dealloc_memory;
360314564Sdim  }
361258884Semaste
362314564Sdim  size_t GetCurrentThreadIDs(std::vector<lldb::tid_t> &thread_ids,
363314564Sdim                             bool &sequence_mutex_unavailable);
364258884Semaste
365314564Sdim  lldb::user_id_t OpenFile(const FileSpec &file_spec, uint32_t flags,
366314564Sdim                           mode_t mode, Error &error);
367288943Sdim
368314564Sdim  bool CloseFile(lldb::user_id_t fd, Error &error);
369288943Sdim
370314564Sdim  lldb::user_id_t GetFileSize(const FileSpec &file_spec);
371258054Semaste
372314564Sdim  Error GetFilePermissions(const FileSpec &file_spec,
373314564Sdim                           uint32_t &file_permissions);
374258884Semaste
375314564Sdim  Error SetFilePermissions(const FileSpec &file_spec,
376314564Sdim                           uint32_t file_permissions);
377258884Semaste
378314564Sdim  uint64_t ReadFile(lldb::user_id_t fd, uint64_t offset, void *dst,
379314564Sdim                    uint64_t dst_len, Error &error);
380276479Sdim
381314564Sdim  uint64_t WriteFile(lldb::user_id_t fd, uint64_t offset, const void *src,
382314564Sdim                     uint64_t src_len, Error &error);
383276479Sdim
384314564Sdim  Error CreateSymlink(const FileSpec &src, const FileSpec &dst);
385276479Sdim
386314564Sdim  Error Unlink(const FileSpec &file_spec);
387288943Sdim
388314564Sdim  Error MakeDirectory(const FileSpec &file_spec, uint32_t mode);
389276479Sdim
390314564Sdim  bool GetFileExists(const FileSpec &file_spec);
391288943Sdim
392314564Sdim  Error RunShellCommand(
393314564Sdim      const char *command,         // Shouldn't be nullptr
394314564Sdim      const FileSpec &working_dir, // Pass empty FileSpec to use the current
395314564Sdim                                   // working directory
396314564Sdim      int *status_ptr, // Pass nullptr if you don't want the process exit status
397314564Sdim      int *signo_ptr,  // Pass nullptr if you don't want the signal that caused
398314564Sdim                       // the process to exit
399314564Sdim      std::string
400314564Sdim          *command_output, // Pass nullptr if you don't want the command output
401314564Sdim      uint32_t timeout_sec); // Timeout in seconds to wait for shell program to
402314564Sdim                             // finish
403288943Sdim
404314564Sdim  bool CalculateMD5(const FileSpec &file_spec, uint64_t &high, uint64_t &low);
405288943Sdim
406314564Sdim  lldb::DataBufferSP ReadRegister(
407314564Sdim      lldb::tid_t tid,
408314564Sdim      uint32_t
409314564Sdim          reg_num); // Must be the eRegisterKindProcessPlugin register number
410288943Sdim
411314564Sdim  lldb::DataBufferSP ReadAllRegisters(lldb::tid_t tid);
412314564Sdim
413314564Sdim  bool
414314564Sdim  WriteRegister(lldb::tid_t tid,
415314564Sdim                uint32_t reg_num, // eRegisterKindProcessPlugin register number
416314564Sdim                llvm::ArrayRef<uint8_t> data);
417314564Sdim
418314564Sdim  bool WriteAllRegisters(lldb::tid_t tid, llvm::ArrayRef<uint8_t> data);
419314564Sdim
420314564Sdim  bool SaveRegisterState(lldb::tid_t tid, uint32_t &save_id);
421314564Sdim
422314564Sdim  bool RestoreRegisterState(lldb::tid_t tid, uint32_t save_id);
423314564Sdim
424314564Sdim  bool SyncThreadState(lldb::tid_t tid);
425314564Sdim
426314564Sdim  const char *GetGDBServerProgramName();
427314564Sdim
428314564Sdim  uint32_t GetGDBServerProgramVersion();
429314564Sdim
430314564Sdim  bool AvoidGPackets(ProcessGDBRemote *process);
431314564Sdim
432314564Sdim  StructuredData::ObjectSP GetThreadsInfo();
433314564Sdim
434314564Sdim  bool GetThreadExtendedInfoSupported();
435314564Sdim
436314564Sdim  bool GetLoadedDynamicLibrariesInfosSupported();
437314564Sdim
438314564Sdim  bool GetSharedCacheInfoSupported();
439314564Sdim
440314564Sdim  bool GetModuleInfo(const FileSpec &module_file_spec,
441314564Sdim                     const ArchSpec &arch_spec, ModuleSpec &module_spec);
442314564Sdim
443314564Sdim  llvm::Optional<std::vector<ModuleSpec>>
444314564Sdim  GetModulesInfo(llvm::ArrayRef<FileSpec> module_file_specs,
445314564Sdim                 const llvm::Triple &triple);
446314564Sdim
447314564Sdim  bool ReadExtFeature(const lldb_private::ConstString object,
448314564Sdim                      const lldb_private::ConstString annex, std::string &out,
449314564Sdim                      lldb_private::Error &err);
450314564Sdim
451314564Sdim  void ServeSymbolLookups(lldb_private::Process *process);
452314564Sdim
453314564Sdim  //------------------------------------------------------------------
454314564Sdim  /// Return the feature set supported by the gdb-remote server.
455314564Sdim  ///
456314564Sdim  /// This method returns the remote side's response to the qSupported
457314564Sdim  /// packet.  The response is the complete string payload returned
458314564Sdim  /// to the client.
459314564Sdim  ///
460314564Sdim  /// @return
461314564Sdim  ///     The string returned by the server to the qSupported query.
462314564Sdim  //------------------------------------------------------------------
463314564Sdim  const std::string &GetServerSupportedFeatures() const {
464314564Sdim    return m_qSupported_response;
465314564Sdim  }
466314564Sdim
467314564Sdim  //------------------------------------------------------------------
468314564Sdim  /// Return the array of async JSON packet types supported by the remote.
469314564Sdim  ///
470314564Sdim  /// This method returns the remote side's array of supported JSON
471314564Sdim  /// packet types as a list of type names.  Each of the results are
472314564Sdim  /// expected to have an Enable{type_name} command to enable and configure
473314564Sdim  /// the related feature.  Each type_name for an enabled feature will
474314564Sdim  /// possibly send async-style packets that contain a payload of a
475314564Sdim  /// binhex-encoded JSON dictionary.  The dictionary will have a
476314564Sdim  /// string field named 'type', that contains the type_name of the
477314564Sdim  /// supported packet type.
478314564Sdim  ///
479314564Sdim  /// There is a Plugin category called structured-data plugins.
480314564Sdim  /// A plugin indicates whether it knows how to handle a type_name.
481314564Sdim  /// If so, it can be used to process the async JSON packet.
482314564Sdim  ///
483314564Sdim  /// @return
484314564Sdim  ///     The string returned by the server to the qSupported query.
485314564Sdim  //------------------------------------------------------------------
486314564Sdim  lldb_private::StructuredData::Array *GetSupportedStructuredDataPlugins();
487314564Sdim
488314564Sdim  //------------------------------------------------------------------
489314564Sdim  /// Configure a StructuredData feature on the remote end.
490314564Sdim  ///
491314564Sdim  /// @see \b Process::ConfigureStructuredData(...) for details.
492314564Sdim  //------------------------------------------------------------------
493314564Sdim  Error
494314564Sdim  ConfigureRemoteStructuredData(const ConstString &type_name,
495314564Sdim                                const StructuredData::ObjectSP &config_sp);
496314564Sdim
497254721Semasteprotected:
498314564Sdim  LazyBool m_supports_not_sending_acks;
499314564Sdim  LazyBool m_supports_thread_suffix;
500314564Sdim  LazyBool m_supports_threads_in_stop_reply;
501314564Sdim  LazyBool m_supports_vCont_all;
502314564Sdim  LazyBool m_supports_vCont_any;
503314564Sdim  LazyBool m_supports_vCont_c;
504314564Sdim  LazyBool m_supports_vCont_C;
505314564Sdim  LazyBool m_supports_vCont_s;
506314564Sdim  LazyBool m_supports_vCont_S;
507314564Sdim  LazyBool m_qHostInfo_is_valid;
508314564Sdim  LazyBool m_curr_pid_is_valid;
509314564Sdim  LazyBool m_qProcessInfo_is_valid;
510314564Sdim  LazyBool m_qGDBServerVersion_is_valid;
511314564Sdim  LazyBool m_supports_alloc_dealloc_memory;
512314564Sdim  LazyBool m_supports_memory_region_info;
513314564Sdim  LazyBool m_supports_watchpoint_support_info;
514314564Sdim  LazyBool m_supports_detach_stay_stopped;
515314564Sdim  LazyBool m_watchpoints_trigger_after_instruction;
516314564Sdim  LazyBool m_attach_or_wait_reply;
517314564Sdim  LazyBool m_prepare_for_reg_writing_reply;
518314564Sdim  LazyBool m_supports_p;
519314564Sdim  LazyBool m_supports_x;
520314564Sdim  LazyBool m_avoid_g_packets;
521314564Sdim  LazyBool m_supports_QSaveRegisterState;
522314564Sdim  LazyBool m_supports_qXfer_auxv_read;
523314564Sdim  LazyBool m_supports_qXfer_libraries_read;
524314564Sdim  LazyBool m_supports_qXfer_libraries_svr4_read;
525314564Sdim  LazyBool m_supports_qXfer_features_read;
526314564Sdim  LazyBool m_supports_augmented_libraries_svr4_read;
527314564Sdim  LazyBool m_supports_jThreadExtendedInfo;
528314564Sdim  LazyBool m_supports_jLoadedDynamicLibrariesInfos;
529314564Sdim  LazyBool m_supports_jGetSharedCacheInfo;
530262528Semaste
531314564Sdim  bool m_supports_qProcessInfoPID : 1, m_supports_qfProcessInfo : 1,
532314564Sdim      m_supports_qUserName : 1, m_supports_qGroupName : 1,
533314564Sdim      m_supports_qThreadStopInfo : 1, m_supports_z0 : 1, m_supports_z1 : 1,
534314564Sdim      m_supports_z2 : 1, m_supports_z3 : 1, m_supports_z4 : 1,
535314564Sdim      m_supports_QEnvironment : 1, m_supports_QEnvironmentHexEncoded : 1,
536314564Sdim      m_supports_qSymbol : 1, m_qSymbol_requests_done : 1,
537314564Sdim      m_supports_qModuleInfo : 1, m_supports_jThreadsInfo : 1,
538314564Sdim      m_supports_jModulesInfo : 1;
539254721Semaste
540314564Sdim  lldb::pid_t m_curr_pid;
541314564Sdim  lldb::tid_t m_curr_tid; // Current gdb remote protocol thread index for all
542314564Sdim                          // other operations
543314564Sdim  lldb::tid_t m_curr_tid_run; // Current gdb remote protocol thread index for
544314564Sdim                              // continue, step, etc
545254721Semaste
546314564Sdim  uint32_t m_num_supported_hardware_watchpoints;
547288943Sdim
548314564Sdim  ArchSpec m_host_arch;
549314564Sdim  ArchSpec m_process_arch;
550314564Sdim  uint32_t m_os_version_major;
551314564Sdim  uint32_t m_os_version_minor;
552314564Sdim  uint32_t m_os_version_update;
553314564Sdim  std::string m_os_build;
554314564Sdim  std::string m_os_kernel;
555314564Sdim  std::string m_hostname;
556314564Sdim  std::string m_gdb_server_name; // from reply to qGDBServerVersion, empty if
557314564Sdim                                 // qGDBServerVersion is not supported
558314564Sdim  uint32_t m_gdb_server_version; // from reply to qGDBServerVersion, zero if
559314564Sdim                                 // qGDBServerVersion is not supported
560314564Sdim  std::chrono::seconds m_default_packet_timeout;
561314564Sdim  uint64_t m_max_packet_size;        // as returned by qSupported
562314564Sdim  std::string m_qSupported_response; // the complete response to qSupported
563296417Sdim
564314564Sdim  bool m_supported_async_json_packets_is_valid;
565314564Sdim  lldb_private::StructuredData::ObjectSP m_supported_async_json_packets_sp;
566296417Sdim
567314564Sdim  bool GetCurrentProcessInfo(bool allow_lazy_pid = true);
568296417Sdim
569314564Sdim  bool GetGDBServerVersion();
570296417Sdim
571314564Sdim  // Given the list of compression types that the remote debug stub can support,
572314564Sdim  // possibly enable compression if we find an encoding we can handle.
573314564Sdim  void MaybeEnableCompression(std::vector<std::string> supported_compressions);
574296417Sdim
575314564Sdim  bool DecodeProcessInfoResponse(StringExtractorGDBRemote &response,
576314564Sdim                                 ProcessInstanceInfo &process_info);
577314564Sdim
578314564Sdim  void OnRunPacketSent(bool first) override;
579314564Sdim
580314564Sdim  PacketResult SendThreadSpecificPacketAndWaitForResponse(
581314564Sdim      lldb::tid_t tid, StreamString &&payload,
582314564Sdim      StringExtractorGDBRemote &response, bool send_async);
583314564Sdim
584254721Semasteprivate:
585314564Sdim  DISALLOW_COPY_AND_ASSIGN(GDBRemoteCommunicationClient);
586254721Semaste};
587254721Semaste
588288943Sdim} // namespace process_gdb_remote
589288943Sdim} // namespace lldb_private
590288943Sdim
591296417Sdim#endif // liblldb_GDBRemoteCommunicationClient_h_
592