blob: 6cbb44dad990cb19a22800f5018162cbdc923c01 [file] [log] [blame]
Greg Clayton576d8832011-03-22 04:00:09 +00001//===-- GDBRemoteCommunicationClient.h --------------------------*- C++ -*-===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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
Greg Clayton576d8832011-03-22 04:00:09 +00006//
7//===----------------------------------------------------------------------===//
8
9#ifndef liblldb_GDBRemoteCommunicationClient_h_
10#define liblldb_GDBRemoteCommunicationClient_h_
11
Pavel Labathb42b48e2016-08-19 12:31:49 +000012#include "GDBRemoteClientBase.h"
13
Pavel Labath8c1b6bd2016-08-09 12:04:46 +000014#include <chrono>
Eugene Zelenkoedb35d92015-10-24 01:08:35 +000015#include <map>
Saleem Abdulrasool16ff8602016-05-18 01:59:10 +000016#include <mutex>
Eugene Zelenkoedb35d92015-10-24 01:08:35 +000017#include <string>
Greg Claytonadc00cb2011-05-20 23:38:13 +000018#include <vector>
19
Greg Clayton46fb5582011-11-18 07:03:08 +000020#include "lldb/Target/Process.h"
Pavel Labath5f19b902017-11-13 16:16:33 +000021#include "lldb/Utility/ArchSpec.h"
Ravitheja Addepallye714c4f2017-05-26 11:46:27 +000022#include "lldb/Utility/StreamGDBRemote.h"
Pavel Labathf2a8bcc2017-06-27 10:45:31 +000023#include "lldb/Utility/StructuredData.h"
Greg Clayton576d8832011-03-22 04:00:09 +000024
Pavel Labath2f1fbae2016-09-08 10:07:04 +000025#include "llvm/ADT/Optional.h"
26
Tamas Berghammerdb264a62015-03-31 09:52:22 +000027namespace lldb_private {
28namespace process_gdb_remote {
29
Kate Stoneb9c1b512016-09-06 20:57:50 +000030class GDBRemoteCommunicationClient : public GDBRemoteClientBase {
Greg Clayton576d8832011-03-22 04:00:09 +000031public:
Kate Stoneb9c1b512016-09-06 20:57:50 +000032 GDBRemoteCommunicationClient();
Greg Clayton576d8832011-03-22 04:00:09 +000033
Kate Stoneb9c1b512016-09-06 20:57:50 +000034 ~GDBRemoteCommunicationClient() override;
Greg Clayton576d8832011-03-22 04:00:09 +000035
Kate Stoneb9c1b512016-09-06 20:57:50 +000036 //------------------------------------------------------------------
37 // After connecting, send the handshake to the server to make sure
38 // we are communicating with it.
39 //------------------------------------------------------------------
Zachary Turner97206d52017-05-12 04:51:55 +000040 bool HandshakeWithServer(Status *error_ptr);
Greg Clayton1cb64962011-03-24 04:28:38 +000041
Kate Stoneb9c1b512016-09-06 20:57:50 +000042 // For packets which specify a range of output to be returned,
43 // return all of the output via a series of request packets of the form
44 // <prefix>0,<size>
45 // <prefix><size>,<size>
46 // <prefix><size>*2,<size>
47 // <prefix><size>*3,<size>
48 // ...
49 // until a "$l..." packet is received, indicating the end.
50 // (size is in hex; this format is used by a standard gdbserver to
51 // return the given portion of the output specified by <prefix>;
52 // for example, "qXfer:libraries-svr4:read::fff,1000" means
53 // "return a chunk of the xml description file for shared
54 // library load addresses, where the chunk starts at offset 0xfff
55 // and continues for 0x1000 bytes").
56 // Concatenate the resulting server response packets together and
57 // return in response_string. If any packet fails, the return value
58 // indicates that failure and the returned string value is undefined.
59 PacketResult
60 SendPacketsAndConcatenateResponses(const char *send_payload_prefix,
61 std::string &response_string);
Steve Pucci5ae54ae2014-01-25 05:46:51 +000062
Kate Stoneb9c1b512016-09-06 20:57:50 +000063 bool GetThreadSuffixSupported();
Greg Clayton576d8832011-03-22 04:00:09 +000064
Kate Stoneb9c1b512016-09-06 20:57:50 +000065 // This packet is usually sent first and the boolean return value
66 // indicates if the packet was send and any response was received
67 // even in the response is UNIMPLEMENTED. If the packet failed to
68 // get a response, then false is returned. This quickly tells us
69 // if we were able to connect and communicate with the remote GDB
70 // server
71 bool QueryNoAckModeSupported();
Greg Clayton576d8832011-03-22 04:00:09 +000072
Kate Stoneb9c1b512016-09-06 20:57:50 +000073 void GetListThreadsInStopReplySupported();
Greg Clayton44633992012-04-10 03:22:03 +000074
Kate Stoneb9c1b512016-09-06 20:57:50 +000075 lldb::pid_t GetCurrentProcessID(bool allow_lazy = true);
Greg Clayton576d8832011-03-22 04:00:09 +000076
Kate Stoneb9c1b512016-09-06 20:57:50 +000077 bool GetLaunchSuccess(std::string &error_str);
Greg Clayton576d8832011-03-22 04:00:09 +000078
Kate Stoneb9c1b512016-09-06 20:57:50 +000079 bool LaunchGDBServer(const char *remote_accept_hostname, lldb::pid_t &pid,
80 uint16_t &port, std::string &socket_name);
Tamas Berghammerccd6cff2015-12-08 14:08:19 +000081
Kate Stoneb9c1b512016-09-06 20:57:50 +000082 size_t QueryGDBServer(
83 std::vector<std::pair<uint16_t, std::string>> &connection_urls);
Tamas Berghammerccd6cff2015-12-08 14:08:19 +000084
Kate Stoneb9c1b512016-09-06 20:57:50 +000085 bool KillSpawnedProcess(lldb::pid_t pid);
Greg Clayton8b82f082011-04-12 05:54:46 +000086
Kate Stoneb9c1b512016-09-06 20:57:50 +000087 //------------------------------------------------------------------
88 /// Sends a GDB remote protocol 'A' packet that delivers program
89 /// arguments to the remote server.
90 ///
Adrian Prantlf05b42e2019-03-11 17:09:29 +000091 /// \param[in] argv
Kate Stoneb9c1b512016-09-06 20:57:50 +000092 /// A NULL terminated array of const C strings to use as the
93 /// arguments.
94 ///
Adrian Prantlf05b42e2019-03-11 17:09:29 +000095 /// \return
Kate Stoneb9c1b512016-09-06 20:57:50 +000096 /// Zero if the response was "OK", a positive value if the
97 /// the response was "Exx" where xx are two hex digits, or
98 /// -1 if the call is unsupported or any other unexpected
99 /// response was received.
100 //------------------------------------------------------------------
101 int SendArgumentsPacket(const ProcessLaunchInfo &launch_info);
Greg Clayton576d8832011-03-22 04:00:09 +0000102
Kate Stoneb9c1b512016-09-06 20:57:50 +0000103 //------------------------------------------------------------------
104 /// Sends a "QEnvironment:NAME=VALUE" packet that will build up the
105 /// environment that will get used when launching an application
106 /// in conjunction with the 'A' packet. This function can be called
107 /// multiple times in a row in order to pass on the desired
108 /// environment that the inferior should be launched with.
109 ///
Adrian Prantlf05b42e2019-03-11 17:09:29 +0000110 /// \param[in] name_equal_value
Kate Stoneb9c1b512016-09-06 20:57:50 +0000111 /// A NULL terminated C string that contains a single environment
112 /// in the format "NAME=VALUE".
113 ///
Adrian Prantlf05b42e2019-03-11 17:09:29 +0000114 /// \return
Kate Stoneb9c1b512016-09-06 20:57:50 +0000115 /// Zero if the response was "OK", a positive value if the
116 /// the response was "Exx" where xx are two hex digits, or
117 /// -1 if the call is unsupported or any other unexpected
118 /// response was received.
119 //------------------------------------------------------------------
120 int SendEnvironmentPacket(char const *name_equal_value);
Pavel Labath62930e52018-01-10 11:57:31 +0000121 int SendEnvironment(const Environment &env);
Greg Clayton576d8832011-03-22 04:00:09 +0000122
Kate Stoneb9c1b512016-09-06 20:57:50 +0000123 int SendLaunchArchPacket(const char *arch);
Greg Clayton576d8832011-03-22 04:00:09 +0000124
Kate Stoneb9c1b512016-09-06 20:57:50 +0000125 int SendLaunchEventDataPacket(const char *data,
126 bool *was_supported = nullptr);
Vince Harrone0be4252015-02-06 18:32:57 +0000127
Kate Stoneb9c1b512016-09-06 20:57:50 +0000128 //------------------------------------------------------------------
129 /// Sends a "vAttach:PID" where PID is in hex.
130 ///
Adrian Prantlf05b42e2019-03-11 17:09:29 +0000131 /// \param[in] pid
Kate Stoneb9c1b512016-09-06 20:57:50 +0000132 /// A process ID for the remote gdb server to attach to.
133 ///
Adrian Prantlf05b42e2019-03-11 17:09:29 +0000134 /// \param[out] response
Kate Stoneb9c1b512016-09-06 20:57:50 +0000135 /// The response received from the gdb server. If the return
136 /// value is zero, \a response will contain a stop reply
137 /// packet.
138 ///
Adrian Prantlf05b42e2019-03-11 17:09:29 +0000139 /// \return
Kate Stoneb9c1b512016-09-06 20:57:50 +0000140 /// Zero if the attach was successful, or an error indicating
141 /// an error code.
142 //------------------------------------------------------------------
143 int SendAttach(lldb::pid_t pid, StringExtractorGDBRemote &response);
Greg Clayton576d8832011-03-22 04:00:09 +0000144
Kate Stoneb9c1b512016-09-06 20:57:50 +0000145 //------------------------------------------------------------------
146 /// Sends a GDB remote protocol 'I' packet that delivers stdin
147 /// data to the remote process.
148 ///
Adrian Prantlf05b42e2019-03-11 17:09:29 +0000149 /// \param[in] data
Kate Stoneb9c1b512016-09-06 20:57:50 +0000150 /// A pointer to stdin data.
151 ///
Adrian Prantlf05b42e2019-03-11 17:09:29 +0000152 /// \param[in] data_len
Kate Stoneb9c1b512016-09-06 20:57:50 +0000153 /// The number of bytes available at \a data.
154 ///
Adrian Prantlf05b42e2019-03-11 17:09:29 +0000155 /// \return
Kate Stoneb9c1b512016-09-06 20:57:50 +0000156 /// Zero if the attach was successful, or an error indicating
157 /// an error code.
158 //------------------------------------------------------------------
159 int SendStdinNotification(const char *data, size_t data_len);
Greg Clayton576d8832011-03-22 04:00:09 +0000160
Kate Stoneb9c1b512016-09-06 20:57:50 +0000161 //------------------------------------------------------------------
162 /// Sets the path to use for stdin/out/err for a process
163 /// that will be launched with the 'A' packet.
164 ///
Adrian Prantlf05b42e2019-03-11 17:09:29 +0000165 /// \param[in] path
Kate Stoneb9c1b512016-09-06 20:57:50 +0000166 /// The path to use for stdin/out/err
167 ///
Adrian Prantlf05b42e2019-03-11 17:09:29 +0000168 /// \return
Kate Stoneb9c1b512016-09-06 20:57:50 +0000169 /// Zero if the for success, or an error code for failure.
170 //------------------------------------------------------------------
171 int SetSTDIN(const FileSpec &file_spec);
172 int SetSTDOUT(const FileSpec &file_spec);
173 int SetSTDERR(const FileSpec &file_spec);
Greg Clayton576d8832011-03-22 04:00:09 +0000174
Kate Stoneb9c1b512016-09-06 20:57:50 +0000175 //------------------------------------------------------------------
176 /// Sets the disable ASLR flag to \a enable for a process that will
177 /// be launched with the 'A' packet.
178 ///
Adrian Prantlf05b42e2019-03-11 17:09:29 +0000179 /// \param[in] enable
Kate Stoneb9c1b512016-09-06 20:57:50 +0000180 /// A boolean value indicating whether to disable ASLR or not.
181 ///
Adrian Prantlf05b42e2019-03-11 17:09:29 +0000182 /// \return
Kate Stoneb9c1b512016-09-06 20:57:50 +0000183 /// Zero if the for success, or an error code for failure.
184 //------------------------------------------------------------------
185 int SetDisableASLR(bool enable);
Greg Claytonfbb76342013-11-20 21:07:01 +0000186
Kate Stoneb9c1b512016-09-06 20:57:50 +0000187 //------------------------------------------------------------------
188 /// Sets the DetachOnError flag to \a enable for the process controlled by the
189 /// stub.
190 ///
Adrian Prantlf05b42e2019-03-11 17:09:29 +0000191 /// \param[in] enable
Kate Stoneb9c1b512016-09-06 20:57:50 +0000192 /// A boolean value indicating whether to detach on error or not.
193 ///
Adrian Prantlf05b42e2019-03-11 17:09:29 +0000194 /// \return
Kate Stoneb9c1b512016-09-06 20:57:50 +0000195 /// Zero if the for success, or an error code for failure.
196 //------------------------------------------------------------------
197 int SetDetachOnError(bool enable);
Greg Clayton576d8832011-03-22 04:00:09 +0000198
Kate Stoneb9c1b512016-09-06 20:57:50 +0000199 //------------------------------------------------------------------
200 /// Sets the working directory to \a path for a process that will
201 /// be launched with the 'A' packet for non platform based
202 /// connections. If this packet is sent to a GDB server that
203 /// implements the platform, it will change the current working
204 /// directory for the platform process.
205 ///
Adrian Prantlf05b42e2019-03-11 17:09:29 +0000206 /// \param[in] working_dir
Kate Stoneb9c1b512016-09-06 20:57:50 +0000207 /// The path to a directory to use when launching our process
208 ///
Adrian Prantlf05b42e2019-03-11 17:09:29 +0000209 /// \return
Kate Stoneb9c1b512016-09-06 20:57:50 +0000210 /// Zero if the for success, or an error code for failure.
211 //------------------------------------------------------------------
212 int SetWorkingDir(const FileSpec &working_dir);
Greg Clayton576d8832011-03-22 04:00:09 +0000213
Kate Stoneb9c1b512016-09-06 20:57:50 +0000214 //------------------------------------------------------------------
215 /// Gets the current working directory of a remote platform GDB
216 /// server.
217 ///
Adrian Prantlf05b42e2019-03-11 17:09:29 +0000218 /// \param[out] working_dir
Kate Stoneb9c1b512016-09-06 20:57:50 +0000219 /// The current working directory on the remote platform.
220 ///
Adrian Prantlf05b42e2019-03-11 17:09:29 +0000221 /// \return
Kate Stoneb9c1b512016-09-06 20:57:50 +0000222 /// Boolean for success
223 //------------------------------------------------------------------
224 bool GetWorkingDir(FileSpec &working_dir);
Greg Clayton37a0a242012-04-11 00:24:49 +0000225
Kate Stoneb9c1b512016-09-06 20:57:50 +0000226 lldb::addr_t AllocateMemory(size_t size, uint32_t permissions);
Greg Clayton46fb5582011-11-18 07:03:08 +0000227
Kate Stoneb9c1b512016-09-06 20:57:50 +0000228 bool DeallocateMemory(lldb::addr_t addr);
Johnny Chen64637202012-05-23 21:09:52 +0000229
Zachary Turner97206d52017-05-12 04:51:55 +0000230 Status Detach(bool keep_stopped);
Enrico Granataf04a2192012-07-13 23:18:48 +0000231
Zachary Turner97206d52017-05-12 04:51:55 +0000232 Status GetMemoryRegionInfo(lldb::addr_t addr, MemoryRegionInfo &range_info);
Jason Molendaf17b5ac2012-12-19 02:54:03 +0000233
Zachary Turner97206d52017-05-12 04:51:55 +0000234 Status GetWatchpointSupportInfo(uint32_t &num);
Jason Molendaf17b5ac2012-12-19 02:54:03 +0000235
Zachary Turner97206d52017-05-12 04:51:55 +0000236 Status GetWatchpointSupportInfo(uint32_t &num, bool &after,
237 const ArchSpec &arch);
Steve Pucci5ae54ae2014-01-25 05:46:51 +0000238
Zachary Turner97206d52017-05-12 04:51:55 +0000239 Status GetWatchpointsTriggerAfterInstruction(bool &after,
240 const ArchSpec &arch);
Greg Clayton576d8832011-03-22 04:00:09 +0000241
Kate Stoneb9c1b512016-09-06 20:57:50 +0000242 const ArchSpec &GetHostArchitecture();
Hafiz Abid Qadeer9a78cdf2013-08-29 09:09:45 +0000243
Pavel Labath3aa04912016-10-31 17:19:42 +0000244 std::chrono::seconds GetHostDefaultPacketTimeout();
Jason Molendabdc4f122014-05-06 02:59:39 +0000245
Kate Stoneb9c1b512016-09-06 20:57:50 +0000246 const ArchSpec &GetProcessArchitecture();
Greg Clayton576d8832011-03-22 04:00:09 +0000247
Kate Stoneb9c1b512016-09-06 20:57:50 +0000248 void GetRemoteQSupported();
Ewan Crawford78baa192015-05-13 09:18:18 +0000249
Kate Stoneb9c1b512016-09-06 20:57:50 +0000250 bool GetVContSupported(char flavor);
Greg Clayton1cb64962011-03-24 04:28:38 +0000251
Kate Stoneb9c1b512016-09-06 20:57:50 +0000252 bool GetpPacketSupported(lldb::tid_t tid);
Greg Clayton1cb64962011-03-24 04:28:38 +0000253
Kate Stoneb9c1b512016-09-06 20:57:50 +0000254 bool GetxPacketSupported();
Greg Clayton1cb64962011-03-24 04:28:38 +0000255
Kate Stoneb9c1b512016-09-06 20:57:50 +0000256 bool GetVAttachOrWaitSupported();
Greg Clayton1cb64962011-03-24 04:28:38 +0000257
Kate Stoneb9c1b512016-09-06 20:57:50 +0000258 bool GetSyncThreadStateSupported();
Greg Clayton37a0a242012-04-11 00:24:49 +0000259
Kate Stoneb9c1b512016-09-06 20:57:50 +0000260 void ResetDiscoverableSettings(bool did_exec);
Greg Clayton576d8832011-03-22 04:00:09 +0000261
Kate Stoneb9c1b512016-09-06 20:57:50 +0000262 bool GetHostInfo(bool force = false);
Greg Clayton32e0a752011-03-30 18:16:51 +0000263
Kate Stoneb9c1b512016-09-06 20:57:50 +0000264 bool GetDefaultThreadId(lldb::tid_t &tid);
Greg Clayton32e0a752011-03-30 18:16:51 +0000265
Pavel Labath2272c482018-06-18 15:02:23 +0000266 llvm::VersionTuple GetOSVersion();
Greg Clayton32e0a752011-03-30 18:16:51 +0000267
Kate Stoneb9c1b512016-09-06 20:57:50 +0000268 bool GetOSBuildString(std::string &s);
269
270 bool GetOSKernelDescription(std::string &s);
271
272 ArchSpec GetSystemArchitecture();
273
274 bool GetHostname(std::string &s);
275
276 lldb::addr_t GetShlibInfoAddr();
277
278 bool GetSupportsThreadSuffix();
279
280 bool GetProcessInfo(lldb::pid_t pid, ProcessInstanceInfo &process_info);
281
282 uint32_t FindProcesses(const ProcessInstanceInfoMatch &process_match_info,
283 ProcessInstanceInfoList &process_infos);
284
285 bool GetUserName(uint32_t uid, std::string &name);
286
287 bool GetGroupName(uint32_t gid, std::string &name);
288
289 bool HasFullVContSupport() { return GetVContSupported('A'); }
290
291 bool HasAnyVContSupport() { return GetVContSupported('a'); }
292
293 bool GetStopReply(StringExtractorGDBRemote &response);
294
295 bool GetThreadStopInfo(lldb::tid_t tid, StringExtractorGDBRemote &response);
296
297 bool SupportsGDBStoppointPacket(GDBStoppointType type) {
298 switch (type) {
299 case eBreakpointSoftware:
300 return m_supports_z0;
301 case eBreakpointHardware:
302 return m_supports_z1;
303 case eWatchpointWrite:
304 return m_supports_z2;
305 case eWatchpointRead:
306 return m_supports_z3;
307 case eWatchpointReadWrite:
308 return m_supports_z4;
309 default:
310 return false;
Greg Clayton576d8832011-03-22 04:00:09 +0000311 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000312 }
Greg Clayton576d8832011-03-22 04:00:09 +0000313
Kate Stoneb9c1b512016-09-06 20:57:50 +0000314 uint8_t SendGDBStoppointTypePacket(
315 GDBStoppointType type, // Type of breakpoint or watchpoint
316 bool insert, // Insert or remove?
317 lldb::addr_t addr, // Address of breakpoint or watchpoint
318 uint32_t length); // Byte Size of breakpoint or watchpoint
Greg Clayton8b82f082011-04-12 05:54:46 +0000319
Kate Stoneb9c1b512016-09-06 20:57:50 +0000320 bool SetNonStopMode(const bool enable);
Greg Clayton8b82f082011-04-12 05:54:46 +0000321
Kate Stoneb9c1b512016-09-06 20:57:50 +0000322 void TestPacketSpeed(const uint32_t num_packets, uint32_t max_send,
Pavel Labath2fd9a1e2016-11-04 11:49:06 +0000323 uint32_t max_recv, uint64_t recv_amount, bool json,
324 Stream &strm);
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000325
Kate Stoneb9c1b512016-09-06 20:57:50 +0000326 // This packet is for testing the speed of the interface only. Both
327 // the client and server need to support it, but this allows us to
328 // measure the packet speed without any other work being done on the
329 // other end and avoids any of that work affecting the packet send
330 // and response times.
331 bool SendSpeedTestPacket(uint32_t send_size, uint32_t recv_size);
Greg Clayton8b82f082011-04-12 05:54:46 +0000332
Kate Stoneb9c1b512016-09-06 20:57:50 +0000333 bool SetCurrentThread(uint64_t tid);
Ewan Crawford78baa192015-05-13 09:18:18 +0000334
Kate Stoneb9c1b512016-09-06 20:57:50 +0000335 bool SetCurrentThreadForRun(uint64_t tid);
Greg Clayton9b1e1cd2011-04-04 18:18:57 +0000336
Kate Stoneb9c1b512016-09-06 20:57:50 +0000337 bool GetQXferAuxvReadSupported();
Greg Clayton8b82f082011-04-12 05:54:46 +0000338
Ravitheja Addepallydab1d5f2017-07-12 11:15:34 +0000339 void EnableErrorStringInPacket();
340
Kate Stoneb9c1b512016-09-06 20:57:50 +0000341 bool GetQXferLibrariesReadSupported();
Steve Pucci03904ac2014-03-04 23:18:46 +0000342
Kate Stoneb9c1b512016-09-06 20:57:50 +0000343 bool GetQXferLibrariesSVR4ReadSupported();
Steve Pucci5ae54ae2014-01-25 05:46:51 +0000344
Kate Stoneb9c1b512016-09-06 20:57:50 +0000345 uint64_t GetRemoteMaxPacketSize();
Steve Pucci5ae54ae2014-01-25 05:46:51 +0000346
Kate Stoneb9c1b512016-09-06 20:57:50 +0000347 bool GetEchoSupported();
Steve Pucci5ae54ae2014-01-25 05:46:51 +0000348
Eugene Zemtsov7993cc52017-03-07 21:34:40 +0000349 bool GetQPassSignalsSupported();
350
Kate Stoneb9c1b512016-09-06 20:57:50 +0000351 bool GetAugmentedLibrariesSVR4ReadSupported();
Greg Claytonb30c50c2015-05-29 00:01:55 +0000352
Kate Stoneb9c1b512016-09-06 20:57:50 +0000353 bool GetQXferFeaturesReadSupported();
Steve Pucci5ae54ae2014-01-25 05:46:51 +0000354
Pavel Labath16064d32018-03-20 11:56:24 +0000355 bool GetQXferMemoryMapReadSupported();
356
Kate Stoneb9c1b512016-09-06 20:57:50 +0000357 LazyBool SupportsAllocDeallocMemory() // const
358 {
359 // Uncomment this to have lldb pretend the debug server doesn't respond to
360 // alloc/dealloc memory packets.
361 // m_supports_alloc_dealloc_memory = lldb_private::eLazyBoolNo;
362 return m_supports_alloc_dealloc_memory;
363 }
Colin Rileyc3c95b22015-04-16 15:51:33 +0000364
Kate Stoneb9c1b512016-09-06 20:57:50 +0000365 size_t GetCurrentThreadIDs(std::vector<lldb::tid_t> &thread_ids,
366 bool &sequence_mutex_unavailable);
Greg Clayton2a48f522011-05-14 01:50:35 +0000367
Kate Stoneb9c1b512016-09-06 20:57:50 +0000368 lldb::user_id_t OpenFile(const FileSpec &file_spec, uint32_t flags,
Zachary Turner97206d52017-05-12 04:51:55 +0000369 mode_t mode, Status &error);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000370
Zachary Turner97206d52017-05-12 04:51:55 +0000371 bool CloseFile(lldb::user_id_t fd, Status &error);
Greg Claytonfbb76342013-11-20 21:07:01 +0000372
Kate Stoneb9c1b512016-09-06 20:57:50 +0000373 lldb::user_id_t GetFileSize(const FileSpec &file_spec);
Greg Claytonfbb76342013-11-20 21:07:01 +0000374
Zachary Turner97206d52017-05-12 04:51:55 +0000375 Status GetFilePermissions(const FileSpec &file_spec,
376 uint32_t &file_permissions);
Chaoren Lind3173f32015-05-29 19:52:29 +0000377
Zachary Turner97206d52017-05-12 04:51:55 +0000378 Status SetFilePermissions(const FileSpec &file_spec,
379 uint32_t file_permissions);
Chaoren Lind3173f32015-05-29 19:52:29 +0000380
Kate Stoneb9c1b512016-09-06 20:57:50 +0000381 uint64_t ReadFile(lldb::user_id_t fd, uint64_t offset, void *dst,
Zachary Turner97206d52017-05-12 04:51:55 +0000382 uint64_t dst_len, Status &error);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000383
Kate Stoneb9c1b512016-09-06 20:57:50 +0000384 uint64_t WriteFile(lldb::user_id_t fd, uint64_t offset, const void *src,
Zachary Turner97206d52017-05-12 04:51:55 +0000385 uint64_t src_len, Status &error);
Greg Claytonf74cf862013-11-13 23:28:31 +0000386
Zachary Turner97206d52017-05-12 04:51:55 +0000387 Status CreateSymlink(const FileSpec &src, const FileSpec &dst);
Greg Claytonf74cf862013-11-13 23:28:31 +0000388
Zachary Turner97206d52017-05-12 04:51:55 +0000389 Status Unlink(const FileSpec &file_spec);
Pavel Labath56d72622016-08-17 08:53:31 +0000390
Zachary Turner97206d52017-05-12 04:51:55 +0000391 Status MakeDirectory(const FileSpec &file_spec, uint32_t mode);
Pavel Labath56d72622016-08-17 08:53:31 +0000392
Kate Stoneb9c1b512016-09-06 20:57:50 +0000393 bool GetFileExists(const FileSpec &file_spec);
Pavel Labath56d72622016-08-17 08:53:31 +0000394
Zachary Turner97206d52017-05-12 04:51:55 +0000395 Status RunShellCommand(
Kate Stoneb9c1b512016-09-06 20:57:50 +0000396 const char *command, // Shouldn't be nullptr
397 const FileSpec &working_dir, // Pass empty FileSpec to use the current
398 // working directory
399 int *status_ptr, // Pass nullptr if you don't want the process exit status
400 int *signo_ptr, // Pass nullptr if you don't want the signal that caused
401 // the process to exit
402 std::string
403 *command_output, // Pass nullptr if you don't want the command output
Pavel Labath19dd1a02018-05-10 10:46:03 +0000404 const Timeout<std::micro> &timeout);
Jason Molendaa3329782014-03-29 18:54:20 +0000405
Kate Stoneb9c1b512016-09-06 20:57:50 +0000406 bool CalculateMD5(const FileSpec &file_spec, uint64_t &high, uint64_t &low);
Pavel Labath27402d22016-08-18 12:32:41 +0000407
Kate Stoneb9c1b512016-09-06 20:57:50 +0000408 lldb::DataBufferSP ReadRegister(
409 lldb::tid_t tid,
410 uint32_t
411 reg_num); // Must be the eRegisterKindProcessPlugin register number
Jason Molendaa3329782014-03-29 18:54:20 +0000412
Kate Stoneb9c1b512016-09-06 20:57:50 +0000413 lldb::DataBufferSP ReadAllRegisters(lldb::tid_t tid);
Jason Molendaa3329782014-03-29 18:54:20 +0000414
Kate Stoneb9c1b512016-09-06 20:57:50 +0000415 bool
416 WriteRegister(lldb::tid_t tid,
417 uint32_t reg_num, // eRegisterKindProcessPlugin register number
418 llvm::ArrayRef<uint8_t> data);
Greg Clayton358cf1e2015-06-25 21:46:34 +0000419
Kate Stoneb9c1b512016-09-06 20:57:50 +0000420 bool WriteAllRegisters(lldb::tid_t tid, llvm::ArrayRef<uint8_t> data);
Jason Molenda705b1802014-06-13 02:37:02 +0000421
Kate Stoneb9c1b512016-09-06 20:57:50 +0000422 bool SaveRegisterState(lldb::tid_t tid, uint32_t &save_id);
Jason Molenda20ee21b2015-07-10 23:15:22 +0000423
Kate Stoneb9c1b512016-09-06 20:57:50 +0000424 bool RestoreRegisterState(lldb::tid_t tid, uint32_t save_id);
Jason Molenda37397352016-07-22 00:17:55 +0000425
Kate Stoneb9c1b512016-09-06 20:57:50 +0000426 bool SyncThreadState(lldb::tid_t tid);
Oleksiy Vyalov6801be32015-02-25 22:15:44 +0000427
Kate Stoneb9c1b512016-09-06 20:57:50 +0000428 const char *GetGDBServerProgramName();
Colin Rileyc3c95b22015-04-16 15:51:33 +0000429
Kate Stoneb9c1b512016-09-06 20:57:50 +0000430 uint32_t GetGDBServerProgramVersion();
Greg Clayton0b90be12015-06-23 21:27:50 +0000431
Kate Stoneb9c1b512016-09-06 20:57:50 +0000432 bool AvoidGPackets(ProcessGDBRemote *process);
Todd Fiala75930012016-08-19 04:21:48 +0000433
Kate Stoneb9c1b512016-09-06 20:57:50 +0000434 StructuredData::ObjectSP GetThreadsInfo();
Todd Fiala75930012016-08-19 04:21:48 +0000435
Kate Stoneb9c1b512016-09-06 20:57:50 +0000436 bool GetThreadExtendedInfoSupported();
437
438 bool GetLoadedDynamicLibrariesInfosSupported();
439
440 bool GetSharedCacheInfoSupported();
441
442 bool GetModuleInfo(const FileSpec &module_file_spec,
443 const ArchSpec &arch_spec, ModuleSpec &module_spec);
444
Pavel Labath2f1fbae2016-09-08 10:07:04 +0000445 llvm::Optional<std::vector<ModuleSpec>>
446 GetModulesInfo(llvm::ArrayRef<FileSpec> module_file_specs,
447 const llvm::Triple &triple);
448
Kate Stoneb9c1b512016-09-06 20:57:50 +0000449 bool ReadExtFeature(const lldb_private::ConstString object,
450 const lldb_private::ConstString annex, std::string &out,
Zachary Turner97206d52017-05-12 04:51:55 +0000451 lldb_private::Status &err);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000452
453 void ServeSymbolLookups(lldb_private::Process *process);
454
Eugene Zemtsov7993cc52017-03-07 21:34:40 +0000455 // Sends QPassSignals packet to the server with given signals to ignore.
Zachary Turner97206d52017-05-12 04:51:55 +0000456 Status SendSignalsToIgnore(llvm::ArrayRef<int32_t> signals);
Eugene Zemtsov7993cc52017-03-07 21:34:40 +0000457
Kate Stoneb9c1b512016-09-06 20:57:50 +0000458 //------------------------------------------------------------------
459 /// Return the feature set supported by the gdb-remote server.
460 ///
461 /// This method returns the remote side's response to the qSupported
462 /// packet. The response is the complete string payload returned
463 /// to the client.
464 ///
Adrian Prantlf05b42e2019-03-11 17:09:29 +0000465 /// \return
Kate Stoneb9c1b512016-09-06 20:57:50 +0000466 /// The string returned by the server to the qSupported query.
467 //------------------------------------------------------------------
468 const std::string &GetServerSupportedFeatures() const {
469 return m_qSupported_response;
470 }
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 ///
Adrian Prantlf05b42e2019-03-11 17:09:29 +0000488 /// \return
Kate Stoneb9c1b512016-09-06 20:57:50 +0000489 /// The string returned by the server to the qSupported query.
490 //------------------------------------------------------------------
491 lldb_private::StructuredData::Array *GetSupportedStructuredDataPlugins();
492
493 //------------------------------------------------------------------
494 /// Configure a StructuredData feature on the remote end.
495 ///
Adrian Prantlf05b42e2019-03-11 17:09:29 +0000496 /// \see \b Process::ConfigureStructuredData(...) for details.
Kate Stoneb9c1b512016-09-06 20:57:50 +0000497 //------------------------------------------------------------------
Zachary Turner97206d52017-05-12 04:51:55 +0000498 Status
Adrian Prantl0e4c4822019-03-06 21:22:25 +0000499 ConfigureRemoteStructuredData(ConstString type_name,
Kate Stoneb9c1b512016-09-06 20:57:50 +0000500 const StructuredData::ObjectSP &config_sp);
Todd Fiala75930012016-08-19 04:21:48 +0000501
Ravitheja Addepallye714c4f2017-05-26 11:46:27 +0000502 lldb::user_id_t SendStartTracePacket(const TraceOptions &options,
503 Status &error);
504
505 Status SendStopTracePacket(lldb::user_id_t uid, lldb::tid_t thread_id);
506
507 Status SendGetDataPacket(lldb::user_id_t uid, lldb::tid_t thread_id,
508 llvm::MutableArrayRef<uint8_t> &buffer,
509 size_t offset = 0);
510
511 Status SendGetMetaDataPacket(lldb::user_id_t uid, lldb::tid_t thread_id,
512 llvm::MutableArrayRef<uint8_t> &buffer,
513 size_t offset = 0);
514
515 Status SendGetTraceConfigPacket(lldb::user_id_t uid, TraceOptions &options);
516
Greg Clayton576d8832011-03-22 04:00:09 +0000517protected:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000518 LazyBool m_supports_not_sending_acks;
519 LazyBool m_supports_thread_suffix;
520 LazyBool m_supports_threads_in_stop_reply;
521 LazyBool m_supports_vCont_all;
522 LazyBool m_supports_vCont_any;
523 LazyBool m_supports_vCont_c;
524 LazyBool m_supports_vCont_C;
525 LazyBool m_supports_vCont_s;
526 LazyBool m_supports_vCont_S;
527 LazyBool m_qHostInfo_is_valid;
528 LazyBool m_curr_pid_is_valid;
529 LazyBool m_qProcessInfo_is_valid;
530 LazyBool m_qGDBServerVersion_is_valid;
531 LazyBool m_supports_alloc_dealloc_memory;
532 LazyBool m_supports_memory_region_info;
533 LazyBool m_supports_watchpoint_support_info;
534 LazyBool m_supports_detach_stay_stopped;
535 LazyBool m_watchpoints_trigger_after_instruction;
536 LazyBool m_attach_or_wait_reply;
537 LazyBool m_prepare_for_reg_writing_reply;
538 LazyBool m_supports_p;
539 LazyBool m_supports_x;
540 LazyBool m_avoid_g_packets;
541 LazyBool m_supports_QSaveRegisterState;
542 LazyBool m_supports_qXfer_auxv_read;
543 LazyBool m_supports_qXfer_libraries_read;
544 LazyBool m_supports_qXfer_libraries_svr4_read;
545 LazyBool m_supports_qXfer_features_read;
Pavel Labath16064d32018-03-20 11:56:24 +0000546 LazyBool m_supports_qXfer_memory_map_read;
Kate Stoneb9c1b512016-09-06 20:57:50 +0000547 LazyBool m_supports_augmented_libraries_svr4_read;
548 LazyBool m_supports_jThreadExtendedInfo;
549 LazyBool m_supports_jLoadedDynamicLibrariesInfos;
550 LazyBool m_supports_jGetSharedCacheInfo;
Eugene Zemtsov7993cc52017-03-07 21:34:40 +0000551 LazyBool m_supports_QPassSignals;
Ravitheja Addepallydab1d5f2017-07-12 11:15:34 +0000552 LazyBool m_supports_error_string_reply;
Steve Pucci5ae54ae2014-01-25 05:46:51 +0000553
Kate Stoneb9c1b512016-09-06 20:57:50 +0000554 bool m_supports_qProcessInfoPID : 1, m_supports_qfProcessInfo : 1,
555 m_supports_qUserName : 1, m_supports_qGroupName : 1,
556 m_supports_qThreadStopInfo : 1, m_supports_z0 : 1, m_supports_z1 : 1,
557 m_supports_z2 : 1, m_supports_z3 : 1, m_supports_z4 : 1,
558 m_supports_QEnvironment : 1, m_supports_QEnvironmentHexEncoded : 1,
559 m_supports_qSymbol : 1, m_qSymbol_requests_done : 1,
Pavel Labath2f1fbae2016-09-08 10:07:04 +0000560 m_supports_qModuleInfo : 1, m_supports_jThreadsInfo : 1,
561 m_supports_jModulesInfo : 1;
Greg Clayton8b82f082011-04-12 05:54:46 +0000562
Kate Stoneb9c1b512016-09-06 20:57:50 +0000563 lldb::pid_t m_curr_pid;
564 lldb::tid_t m_curr_tid; // Current gdb remote protocol thread index for all
565 // other operations
566 lldb::tid_t m_curr_tid_run; // Current gdb remote protocol thread index for
567 // continue, step, etc
Johnny Chen64637202012-05-23 21:09:52 +0000568
Kate Stoneb9c1b512016-09-06 20:57:50 +0000569 uint32_t m_num_supported_hardware_watchpoints;
Todd Fiala75930012016-08-19 04:21:48 +0000570
Kate Stoneb9c1b512016-09-06 20:57:50 +0000571 ArchSpec m_host_arch;
572 ArchSpec m_process_arch;
Pavel Labath2272c482018-06-18 15:02:23 +0000573 llvm::VersionTuple m_os_version;
Kate Stoneb9c1b512016-09-06 20:57:50 +0000574 std::string m_os_build;
575 std::string m_os_kernel;
576 std::string m_hostname;
577 std::string m_gdb_server_name; // from reply to qGDBServerVersion, empty if
578 // qGDBServerVersion is not supported
579 uint32_t m_gdb_server_version; // from reply to qGDBServerVersion, zero if
580 // qGDBServerVersion is not supported
Pavel Labath3aa04912016-10-31 17:19:42 +0000581 std::chrono::seconds m_default_packet_timeout;
Kate Stoneb9c1b512016-09-06 20:57:50 +0000582 uint64_t m_max_packet_size; // as returned by qSupported
583 std::string m_qSupported_response; // the complete response to qSupported
Jason Molenda91ffe0a2015-06-18 21:46:06 +0000584
Kate Stoneb9c1b512016-09-06 20:57:50 +0000585 bool m_supported_async_json_packets_is_valid;
586 lldb_private::StructuredData::ObjectSP m_supported_async_json_packets_sp;
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000587
Pavel Labath16064d32018-03-20 11:56:24 +0000588 std::vector<MemoryRegionInfo> m_qXfer_memory_map;
589 bool m_qXfer_memory_map_loaded;
590
Kate Stoneb9c1b512016-09-06 20:57:50 +0000591 bool GetCurrentProcessInfo(bool allow_lazy_pid = true);
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000592
Kate Stoneb9c1b512016-09-06 20:57:50 +0000593 bool GetGDBServerVersion();
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000594
Kate Stoneb9c1b512016-09-06 20:57:50 +0000595 // Given the list of compression types that the remote debug stub can support,
596 // possibly enable compression if we find an encoding we can handle.
597 void MaybeEnableCompression(std::vector<std::string> supported_compressions);
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000598
Kate Stoneb9c1b512016-09-06 20:57:50 +0000599 bool DecodeProcessInfoResponse(StringExtractorGDBRemote &response,
600 ProcessInstanceInfo &process_info);
Pavel Labath8c1b6bd2016-08-09 12:04:46 +0000601
Kate Stoneb9c1b512016-09-06 20:57:50 +0000602 void OnRunPacketSent(bool first) override;
603
604 PacketResult SendThreadSpecificPacketAndWaitForResponse(
605 lldb::tid_t tid, StreamString &&payload,
606 StringExtractorGDBRemote &response, bool send_async);
Pavel Labath4b6f9592016-08-18 08:30:03 +0000607
Ravitheja Addepallye714c4f2017-05-26 11:46:27 +0000608 Status SendGetTraceDataPacket(StreamGDBRemote &packet, lldb::user_id_t uid,
609 lldb::tid_t thread_id,
610 llvm::MutableArrayRef<uint8_t> &buffer,
611 size_t offset);
612
Pavel Labath16064d32018-03-20 11:56:24 +0000613 Status LoadQXferMemoryMap();
614
615 Status GetQXferMemoryMapRegionInfo(lldb::addr_t addr,
616 MemoryRegionInfo &region);
617
Greg Clayton576d8832011-03-22 04:00:09 +0000618private:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000619 DISALLOW_COPY_AND_ASSIGN(GDBRemoteCommunicationClient);
Greg Clayton576d8832011-03-22 04:00:09 +0000620};
621
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000622} // namespace process_gdb_remote
623} // namespace lldb_private
624
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000625#endif // liblldb_GDBRemoteCommunicationClient_h_