blob: e40c08cc68102187d0bc8c76c0beb0d1842cd8f9 [file] [log] [blame]
Greg Clayton576d8832011-03-22 04:00:09 +00001//===-- GDBRemoteCommunicationClient.h --------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef liblldb_GDBRemoteCommunicationClient_h_
11#define liblldb_GDBRemoteCommunicationClient_h_
12
Pavel Labathb42b48e2016-08-19 12:31:49 +000013#include "GDBRemoteClientBase.h"
14
Greg Clayton576d8832011-03-22 04:00:09 +000015// C Includes
16// C++ Includes
Pavel Labath8c1b6bd2016-08-09 12:04:46 +000017#include <chrono>
Eugene Zelenkoedb35d92015-10-24 01:08:35 +000018#include <map>
Saleem Abdulrasool16ff8602016-05-18 01:59:10 +000019#include <mutex>
Eugene Zelenkoedb35d92015-10-24 01:08:35 +000020#include <string>
Greg Claytonadc00cb2011-05-20 23:38:13 +000021#include <vector>
22
Greg Clayton576d8832011-03-22 04:00:09 +000023// Other libraries and framework includes
24// Project includes
25#include "lldb/Core/ArchSpec.h"
Greg Clayton358cf1e2015-06-25 21:46:34 +000026#include "lldb/Core/StructuredData.h"
Greg Clayton46fb5582011-11-18 07:03:08 +000027#include "lldb/Target/Process.h"
Greg Clayton576d8832011-03-22 04:00:09 +000028
Tamas Berghammerdb264a62015-03-31 09:52:22 +000029namespace lldb_private {
30namespace process_gdb_remote {
31
Kate Stoneb9c1b512016-09-06 20:57:50 +000032class GDBRemoteCommunicationClient : public GDBRemoteClientBase {
Greg Clayton576d8832011-03-22 04:00:09 +000033public:
Kate Stoneb9c1b512016-09-06 20:57:50 +000034 GDBRemoteCommunicationClient();
Greg Clayton576d8832011-03-22 04:00:09 +000035
Kate Stoneb9c1b512016-09-06 20:57:50 +000036 ~GDBRemoteCommunicationClient() override;
Greg Clayton576d8832011-03-22 04:00:09 +000037
Kate Stoneb9c1b512016-09-06 20:57:50 +000038 //------------------------------------------------------------------
39 // After connecting, send the handshake to the server to make sure
40 // we are communicating with it.
41 //------------------------------------------------------------------
42 bool HandshakeWithServer(Error *error_ptr);
Greg Clayton1cb64962011-03-24 04:28:38 +000043
Kate Stoneb9c1b512016-09-06 20:57:50 +000044 // For packets which specify a range of output to be returned,
45 // return all of the output via a series of request packets of the form
46 // <prefix>0,<size>
47 // <prefix><size>,<size>
48 // <prefix><size>*2,<size>
49 // <prefix><size>*3,<size>
50 // ...
51 // until a "$l..." packet is received, indicating the end.
52 // (size is in hex; this format is used by a standard gdbserver to
53 // return the given portion of the output specified by <prefix>;
54 // for example, "qXfer:libraries-svr4:read::fff,1000" means
55 // "return a chunk of the xml description file for shared
56 // library load addresses, where the chunk starts at offset 0xfff
57 // and continues for 0x1000 bytes").
58 // Concatenate the resulting server response packets together and
59 // return in response_string. If any packet fails, the return value
60 // indicates that failure and the returned string value is undefined.
61 PacketResult
62 SendPacketsAndConcatenateResponses(const char *send_payload_prefix,
63 std::string &response_string);
Steve Pucci5ae54ae2014-01-25 05:46:51 +000064
Kate Stoneb9c1b512016-09-06 20:57:50 +000065 bool GetThreadSuffixSupported();
Greg Clayton576d8832011-03-22 04:00:09 +000066
Kate Stoneb9c1b512016-09-06 20:57:50 +000067 // This packet is usually sent first and the boolean return value
68 // indicates if the packet was send and any response was received
69 // even in the response is UNIMPLEMENTED. If the packet failed to
70 // get a response, then false is returned. This quickly tells us
71 // if we were able to connect and communicate with the remote GDB
72 // server
73 bool QueryNoAckModeSupported();
Greg Clayton576d8832011-03-22 04:00:09 +000074
Kate Stoneb9c1b512016-09-06 20:57:50 +000075 void GetListThreadsInStopReplySupported();
Greg Clayton44633992012-04-10 03:22:03 +000076
Kate Stoneb9c1b512016-09-06 20:57:50 +000077 lldb::pid_t GetCurrentProcessID(bool allow_lazy = true);
Greg Clayton576d8832011-03-22 04:00:09 +000078
Kate Stoneb9c1b512016-09-06 20:57:50 +000079 bool GetLaunchSuccess(std::string &error_str);
Greg Clayton576d8832011-03-22 04:00:09 +000080
Kate Stoneb9c1b512016-09-06 20:57:50 +000081 bool LaunchGDBServer(const char *remote_accept_hostname, lldb::pid_t &pid,
82 uint16_t &port, std::string &socket_name);
Tamas Berghammerccd6cff2015-12-08 14:08:19 +000083
Kate Stoneb9c1b512016-09-06 20:57:50 +000084 size_t QueryGDBServer(
85 std::vector<std::pair<uint16_t, std::string>> &connection_urls);
Tamas Berghammerccd6cff2015-12-08 14:08:19 +000086
Kate Stoneb9c1b512016-09-06 20:57:50 +000087 bool KillSpawnedProcess(lldb::pid_t pid);
Greg Clayton8b82f082011-04-12 05:54:46 +000088
Kate Stoneb9c1b512016-09-06 20:57:50 +000089 //------------------------------------------------------------------
90 /// Sends a GDB remote protocol 'A' packet that delivers program
91 /// arguments to the remote server.
92 ///
93 /// @param[in] argv
94 /// A NULL terminated array of const C strings to use as the
95 /// arguments.
96 ///
97 /// @return
98 /// Zero if the response was "OK", a positive value if the
99 /// the response was "Exx" where xx are two hex digits, or
100 /// -1 if the call is unsupported or any other unexpected
101 /// response was received.
102 //------------------------------------------------------------------
103 int SendArgumentsPacket(const ProcessLaunchInfo &launch_info);
Greg Clayton576d8832011-03-22 04:00:09 +0000104
Kate Stoneb9c1b512016-09-06 20:57:50 +0000105 //------------------------------------------------------------------
106 /// Sends a "QEnvironment:NAME=VALUE" packet that will build up the
107 /// environment that will get used when launching an application
108 /// in conjunction with the 'A' packet. This function can be called
109 /// multiple times in a row in order to pass on the desired
110 /// environment that the inferior should be launched with.
111 ///
112 /// @param[in] name_equal_value
113 /// A NULL terminated C string that contains a single environment
114 /// in the format "NAME=VALUE".
115 ///
116 /// @return
117 /// Zero if the response was "OK", a positive value if the
118 /// the response was "Exx" where xx are two hex digits, or
119 /// -1 if the call is unsupported or any other unexpected
120 /// response was received.
121 //------------------------------------------------------------------
122 int SendEnvironmentPacket(char const *name_equal_value);
Greg Clayton576d8832011-03-22 04:00:09 +0000123
Kate Stoneb9c1b512016-09-06 20:57:50 +0000124 int SendLaunchArchPacket(const char *arch);
Greg Clayton576d8832011-03-22 04:00:09 +0000125
Kate Stoneb9c1b512016-09-06 20:57:50 +0000126 int SendLaunchEventDataPacket(const char *data,
127 bool *was_supported = nullptr);
Vince Harrone0be4252015-02-06 18:32:57 +0000128
Kate Stoneb9c1b512016-09-06 20:57:50 +0000129 //------------------------------------------------------------------
130 /// Sends a "vAttach:PID" where PID is in hex.
131 ///
132 /// @param[in] pid
133 /// A process ID for the remote gdb server to attach to.
134 ///
135 /// @param[out] response
136 /// The response received from the gdb server. If the return
137 /// value is zero, \a response will contain a stop reply
138 /// packet.
139 ///
140 /// @return
141 /// Zero if the attach was successful, or an error indicating
142 /// an error code.
143 //------------------------------------------------------------------
144 int SendAttach(lldb::pid_t pid, StringExtractorGDBRemote &response);
Greg Clayton576d8832011-03-22 04:00:09 +0000145
Kate Stoneb9c1b512016-09-06 20:57:50 +0000146 //------------------------------------------------------------------
147 /// Sends a GDB remote protocol 'I' packet that delivers stdin
148 /// data to the remote process.
149 ///
150 /// @param[in] data
151 /// A pointer to stdin data.
152 ///
153 /// @param[in] data_len
154 /// The number of bytes available at \a data.
155 ///
156 /// @return
157 /// Zero if the attach was successful, or an error indicating
158 /// an error code.
159 //------------------------------------------------------------------
160 int SendStdinNotification(const char *data, size_t data_len);
Greg Clayton576d8832011-03-22 04:00:09 +0000161
Kate Stoneb9c1b512016-09-06 20:57:50 +0000162 //------------------------------------------------------------------
163 /// Sets the path to use for stdin/out/err for a process
164 /// that will be launched with the 'A' packet.
165 ///
166 /// @param[in] path
167 /// The path to use for stdin/out/err
168 ///
169 /// @return
170 /// Zero if the for success, or an error code for failure.
171 //------------------------------------------------------------------
172 int SetSTDIN(const FileSpec &file_spec);
173 int SetSTDOUT(const FileSpec &file_spec);
174 int SetSTDERR(const FileSpec &file_spec);
Greg Clayton576d8832011-03-22 04:00:09 +0000175
Kate Stoneb9c1b512016-09-06 20:57:50 +0000176 //------------------------------------------------------------------
177 /// Sets the disable ASLR flag to \a enable for a process that will
178 /// be launched with the 'A' packet.
179 ///
180 /// @param[in] enable
181 /// A boolean value indicating whether to disable ASLR or not.
182 ///
183 /// @return
184 /// Zero if the for success, or an error code for failure.
185 //------------------------------------------------------------------
186 int SetDisableASLR(bool enable);
Greg Claytonfbb76342013-11-20 21:07:01 +0000187
Kate Stoneb9c1b512016-09-06 20:57:50 +0000188 //------------------------------------------------------------------
189 /// Sets the DetachOnError flag to \a enable for the process controlled by the
190 /// stub.
191 ///
192 /// @param[in] enable
193 /// A boolean value indicating whether to detach on error or not.
194 ///
195 /// @return
196 /// Zero if the for success, or an error code for failure.
197 //------------------------------------------------------------------
198 int SetDetachOnError(bool enable);
Greg Clayton576d8832011-03-22 04:00:09 +0000199
Kate Stoneb9c1b512016-09-06 20:57:50 +0000200 //------------------------------------------------------------------
201 /// Sets the working directory to \a path for a process that will
202 /// be launched with the 'A' packet for non platform based
203 /// connections. If this packet is sent to a GDB server that
204 /// implements the platform, it will change the current working
205 /// directory for the platform process.
206 ///
207 /// @param[in] working_dir
208 /// The path to a directory to use when launching our process
209 ///
210 /// @return
211 /// Zero if the for success, or an error code for failure.
212 //------------------------------------------------------------------
213 int SetWorkingDir(const FileSpec &working_dir);
Greg Clayton576d8832011-03-22 04:00:09 +0000214
Kate Stoneb9c1b512016-09-06 20:57:50 +0000215 //------------------------------------------------------------------
216 /// Gets the current working directory of a remote platform GDB
217 /// server.
218 ///
219 /// @param[out] working_dir
220 /// The current working directory on the remote platform.
221 ///
222 /// @return
223 /// Boolean for success
224 //------------------------------------------------------------------
225 bool GetWorkingDir(FileSpec &working_dir);
Greg Clayton37a0a242012-04-11 00:24:49 +0000226
Kate Stoneb9c1b512016-09-06 20:57:50 +0000227 lldb::addr_t AllocateMemory(size_t size, uint32_t permissions);
Greg Clayton46fb5582011-11-18 07:03:08 +0000228
Kate Stoneb9c1b512016-09-06 20:57:50 +0000229 bool DeallocateMemory(lldb::addr_t addr);
Johnny Chen64637202012-05-23 21:09:52 +0000230
Kate Stoneb9c1b512016-09-06 20:57:50 +0000231 Error Detach(bool keep_stopped);
Enrico Granataf04a2192012-07-13 23:18:48 +0000232
Kate Stoneb9c1b512016-09-06 20:57:50 +0000233 Error GetMemoryRegionInfo(lldb::addr_t addr, MemoryRegionInfo &range_info);
Jason Molendaf17b5ac2012-12-19 02:54:03 +0000234
Kate Stoneb9c1b512016-09-06 20:57:50 +0000235 Error GetWatchpointSupportInfo(uint32_t &num);
Jason Molendaf17b5ac2012-12-19 02:54:03 +0000236
Kate Stoneb9c1b512016-09-06 20:57:50 +0000237 Error GetWatchpointSupportInfo(uint32_t &num, bool &after,
238 const ArchSpec &arch);
Steve Pucci5ae54ae2014-01-25 05:46:51 +0000239
Kate Stoneb9c1b512016-09-06 20:57:50 +0000240 Error GetWatchpointsTriggerAfterInstruction(bool &after,
241 const ArchSpec &arch);
Greg Clayton576d8832011-03-22 04:00:09 +0000242
Kate Stoneb9c1b512016-09-06 20:57:50 +0000243 const ArchSpec &GetHostArchitecture();
Hafiz Abid Qadeer9a78cdf2013-08-29 09:09:45 +0000244
Kate Stoneb9c1b512016-09-06 20:57:50 +0000245 uint32_t GetHostDefaultPacketTimeout();
Jason Molendabdc4f122014-05-06 02:59:39 +0000246
Kate Stoneb9c1b512016-09-06 20:57:50 +0000247 const ArchSpec &GetProcessArchitecture();
Greg Clayton576d8832011-03-22 04:00:09 +0000248
Kate Stoneb9c1b512016-09-06 20:57:50 +0000249 void GetRemoteQSupported();
Ewan Crawford78baa192015-05-13 09:18:18 +0000250
Kate Stoneb9c1b512016-09-06 20:57:50 +0000251 bool GetVContSupported(char flavor);
Greg Clayton1cb64962011-03-24 04:28:38 +0000252
Kate Stoneb9c1b512016-09-06 20:57:50 +0000253 bool GetpPacketSupported(lldb::tid_t tid);
Greg Clayton1cb64962011-03-24 04:28:38 +0000254
Kate Stoneb9c1b512016-09-06 20:57:50 +0000255 bool GetxPacketSupported();
Greg Clayton1cb64962011-03-24 04:28:38 +0000256
Kate Stoneb9c1b512016-09-06 20:57:50 +0000257 bool GetVAttachOrWaitSupported();
Greg Clayton1cb64962011-03-24 04:28:38 +0000258
Kate Stoneb9c1b512016-09-06 20:57:50 +0000259 bool GetSyncThreadStateSupported();
Greg Clayton37a0a242012-04-11 00:24:49 +0000260
Kate Stoneb9c1b512016-09-06 20:57:50 +0000261 void ResetDiscoverableSettings(bool did_exec);
Greg Clayton576d8832011-03-22 04:00:09 +0000262
Kate Stoneb9c1b512016-09-06 20:57:50 +0000263 bool GetHostInfo(bool force = false);
Greg Clayton32e0a752011-03-30 18:16:51 +0000264
Kate Stoneb9c1b512016-09-06 20:57:50 +0000265 bool GetDefaultThreadId(lldb::tid_t &tid);
Greg Clayton32e0a752011-03-30 18:16:51 +0000266
Kate Stoneb9c1b512016-09-06 20:57:50 +0000267 bool GetOSVersion(uint32_t &major, uint32_t &minor, uint32_t &update);
Greg Clayton32e0a752011-03-30 18:16:51 +0000268
Kate Stoneb9c1b512016-09-06 20:57:50 +0000269 bool GetOSBuildString(std::string &s);
270
271 bool GetOSKernelDescription(std::string &s);
272
273 ArchSpec GetSystemArchitecture();
274
275 bool GetHostname(std::string &s);
276
277 lldb::addr_t GetShlibInfoAddr();
278
279 bool GetSupportsThreadSuffix();
280
281 bool GetProcessInfo(lldb::pid_t pid, ProcessInstanceInfo &process_info);
282
283 uint32_t FindProcesses(const ProcessInstanceInfoMatch &process_match_info,
284 ProcessInstanceInfoList &process_infos);
285
286 bool GetUserName(uint32_t uid, std::string &name);
287
288 bool GetGroupName(uint32_t gid, std::string &name);
289
290 bool HasFullVContSupport() { return GetVContSupported('A'); }
291
292 bool HasAnyVContSupport() { return GetVContSupported('a'); }
293
294 bool GetStopReply(StringExtractorGDBRemote &response);
295
296 bool GetThreadStopInfo(lldb::tid_t tid, StringExtractorGDBRemote &response);
297
298 bool SupportsGDBStoppointPacket(GDBStoppointType type) {
299 switch (type) {
300 case eBreakpointSoftware:
301 return m_supports_z0;
302 case eBreakpointHardware:
303 return m_supports_z1;
304 case eWatchpointWrite:
305 return m_supports_z2;
306 case eWatchpointRead:
307 return m_supports_z3;
308 case eWatchpointReadWrite:
309 return m_supports_z4;
310 default:
311 return false;
Greg Clayton576d8832011-03-22 04:00:09 +0000312 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000313 }
Greg Clayton576d8832011-03-22 04:00:09 +0000314
Kate Stoneb9c1b512016-09-06 20:57:50 +0000315 uint8_t SendGDBStoppointTypePacket(
316 GDBStoppointType type, // Type of breakpoint or watchpoint
317 bool insert, // Insert or remove?
318 lldb::addr_t addr, // Address of breakpoint or watchpoint
319 uint32_t length); // Byte Size of breakpoint or watchpoint
Greg Clayton8b82f082011-04-12 05:54:46 +0000320
Kate Stoneb9c1b512016-09-06 20:57:50 +0000321 bool SetNonStopMode(const bool enable);
Greg Clayton8b82f082011-04-12 05:54:46 +0000322
Kate Stoneb9c1b512016-09-06 20:57:50 +0000323 void TestPacketSpeed(const uint32_t num_packets, uint32_t max_send,
324 uint32_t max_recv, bool json, 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
Kate Stoneb9c1b512016-09-06 20:57:50 +0000339 bool GetQXferLibrariesReadSupported();
Steve Pucci03904ac2014-03-04 23:18:46 +0000340
Kate Stoneb9c1b512016-09-06 20:57:50 +0000341 bool GetQXferLibrariesSVR4ReadSupported();
Steve Pucci5ae54ae2014-01-25 05:46:51 +0000342
Kate Stoneb9c1b512016-09-06 20:57:50 +0000343 uint64_t GetRemoteMaxPacketSize();
Steve Pucci5ae54ae2014-01-25 05:46:51 +0000344
Kate Stoneb9c1b512016-09-06 20:57:50 +0000345 bool GetEchoSupported();
Steve Pucci5ae54ae2014-01-25 05:46:51 +0000346
Kate Stoneb9c1b512016-09-06 20:57:50 +0000347 bool GetAugmentedLibrariesSVR4ReadSupported();
Greg Claytonb30c50c2015-05-29 00:01:55 +0000348
Kate Stoneb9c1b512016-09-06 20:57:50 +0000349 bool GetQXferFeaturesReadSupported();
Steve Pucci5ae54ae2014-01-25 05:46:51 +0000350
Kate Stoneb9c1b512016-09-06 20:57:50 +0000351 LazyBool SupportsAllocDeallocMemory() // const
352 {
353 // Uncomment this to have lldb pretend the debug server doesn't respond to
354 // alloc/dealloc memory packets.
355 // m_supports_alloc_dealloc_memory = lldb_private::eLazyBoolNo;
356 return m_supports_alloc_dealloc_memory;
357 }
Colin Rileyc3c95b22015-04-16 15:51:33 +0000358
Kate Stoneb9c1b512016-09-06 20:57:50 +0000359 size_t GetCurrentThreadIDs(std::vector<lldb::tid_t> &thread_ids,
360 bool &sequence_mutex_unavailable);
Greg Clayton2a48f522011-05-14 01:50:35 +0000361
Kate Stoneb9c1b512016-09-06 20:57:50 +0000362 lldb::user_id_t OpenFile(const FileSpec &file_spec, uint32_t flags,
363 mode_t mode, Error &error);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000364
Kate Stoneb9c1b512016-09-06 20:57:50 +0000365 bool CloseFile(lldb::user_id_t fd, Error &error);
Greg Claytonfbb76342013-11-20 21:07:01 +0000366
Kate Stoneb9c1b512016-09-06 20:57:50 +0000367 lldb::user_id_t GetFileSize(const FileSpec &file_spec);
Greg Claytonfbb76342013-11-20 21:07:01 +0000368
Kate Stoneb9c1b512016-09-06 20:57:50 +0000369 Error GetFilePermissions(const FileSpec &file_spec,
370 uint32_t &file_permissions);
Chaoren Lind3173f32015-05-29 19:52:29 +0000371
Kate Stoneb9c1b512016-09-06 20:57:50 +0000372 Error SetFilePermissions(const FileSpec &file_spec,
373 uint32_t file_permissions);
Chaoren Lind3173f32015-05-29 19:52:29 +0000374
Kate Stoneb9c1b512016-09-06 20:57:50 +0000375 uint64_t ReadFile(lldb::user_id_t fd, uint64_t offset, void *dst,
376 uint64_t dst_len, Error &error);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000377
Kate Stoneb9c1b512016-09-06 20:57:50 +0000378 uint64_t WriteFile(lldb::user_id_t fd, uint64_t offset, const void *src,
379 uint64_t src_len, Error &error);
Greg Claytonf74cf862013-11-13 23:28:31 +0000380
Kate Stoneb9c1b512016-09-06 20:57:50 +0000381 Error CreateSymlink(const FileSpec &src, const FileSpec &dst);
Greg Claytonf74cf862013-11-13 23:28:31 +0000382
Kate Stoneb9c1b512016-09-06 20:57:50 +0000383 Error Unlink(const FileSpec &file_spec);
Pavel Labath56d72622016-08-17 08:53:31 +0000384
Kate Stoneb9c1b512016-09-06 20:57:50 +0000385 Error MakeDirectory(const FileSpec &file_spec, uint32_t mode);
Pavel Labath56d72622016-08-17 08:53:31 +0000386
Kate Stoneb9c1b512016-09-06 20:57:50 +0000387 bool GetFileExists(const FileSpec &file_spec);
Pavel Labath56d72622016-08-17 08:53:31 +0000388
Kate Stoneb9c1b512016-09-06 20:57:50 +0000389 Error RunShellCommand(
390 const char *command, // Shouldn't be nullptr
391 const FileSpec &working_dir, // Pass empty FileSpec to use the current
392 // working directory
393 int *status_ptr, // Pass nullptr if you don't want the process exit status
394 int *signo_ptr, // Pass nullptr if you don't want the signal that caused
395 // the process to exit
396 std::string
397 *command_output, // Pass nullptr if you don't want the command output
398 uint32_t timeout_sec); // Timeout in seconds to wait for shell program to
399 // finish
Jason Molendaa3329782014-03-29 18:54:20 +0000400
Kate Stoneb9c1b512016-09-06 20:57:50 +0000401 bool CalculateMD5(const FileSpec &file_spec, uint64_t &high, uint64_t &low);
Pavel Labath27402d22016-08-18 12:32:41 +0000402
Kate Stoneb9c1b512016-09-06 20:57:50 +0000403 lldb::DataBufferSP ReadRegister(
404 lldb::tid_t tid,
405 uint32_t
406 reg_num); // Must be the eRegisterKindProcessPlugin register number
Jason Molendaa3329782014-03-29 18:54:20 +0000407
Kate Stoneb9c1b512016-09-06 20:57:50 +0000408 lldb::DataBufferSP ReadAllRegisters(lldb::tid_t tid);
Jason Molendaa3329782014-03-29 18:54:20 +0000409
Kate Stoneb9c1b512016-09-06 20:57:50 +0000410 bool
411 WriteRegister(lldb::tid_t tid,
412 uint32_t reg_num, // eRegisterKindProcessPlugin register number
413 llvm::ArrayRef<uint8_t> data);
Greg Clayton358cf1e2015-06-25 21:46:34 +0000414
Kate Stoneb9c1b512016-09-06 20:57:50 +0000415 bool WriteAllRegisters(lldb::tid_t tid, llvm::ArrayRef<uint8_t> data);
Jason Molenda705b1802014-06-13 02:37:02 +0000416
Kate Stoneb9c1b512016-09-06 20:57:50 +0000417 bool SaveRegisterState(lldb::tid_t tid, uint32_t &save_id);
Jason Molenda20ee21b2015-07-10 23:15:22 +0000418
Kate Stoneb9c1b512016-09-06 20:57:50 +0000419 bool RestoreRegisterState(lldb::tid_t tid, uint32_t save_id);
Jason Molenda37397352016-07-22 00:17:55 +0000420
Kate Stoneb9c1b512016-09-06 20:57:50 +0000421 bool SyncThreadState(lldb::tid_t tid);
Oleksiy Vyalov6801be32015-02-25 22:15:44 +0000422
Kate Stoneb9c1b512016-09-06 20:57:50 +0000423 const char *GetGDBServerProgramName();
Colin Rileyc3c95b22015-04-16 15:51:33 +0000424
Kate Stoneb9c1b512016-09-06 20:57:50 +0000425 uint32_t GetGDBServerProgramVersion();
Greg Clayton0b90be12015-06-23 21:27:50 +0000426
Kate Stoneb9c1b512016-09-06 20:57:50 +0000427 bool AvoidGPackets(ProcessGDBRemote *process);
Todd Fiala75930012016-08-19 04:21:48 +0000428
Kate Stoneb9c1b512016-09-06 20:57:50 +0000429 StructuredData::ObjectSP GetThreadsInfo();
Todd Fiala75930012016-08-19 04:21:48 +0000430
Kate Stoneb9c1b512016-09-06 20:57:50 +0000431 bool GetThreadExtendedInfoSupported();
432
433 bool GetLoadedDynamicLibrariesInfosSupported();
434
435 bool GetSharedCacheInfoSupported();
436
437 bool GetModuleInfo(const FileSpec &module_file_spec,
438 const ArchSpec &arch_spec, ModuleSpec &module_spec);
439
440 bool ReadExtFeature(const lldb_private::ConstString object,
441 const lldb_private::ConstString annex, std::string &out,
442 lldb_private::Error &err);
443
444 void ServeSymbolLookups(lldb_private::Process *process);
445
446 //------------------------------------------------------------------
447 /// Return the feature set supported by the gdb-remote server.
448 ///
449 /// This method returns the remote side's response to the qSupported
450 /// packet. The response is the complete string payload returned
451 /// to the client.
452 ///
453 /// @return
454 /// The string returned by the server to the qSupported query.
455 //------------------------------------------------------------------
456 const std::string &GetServerSupportedFeatures() const {
457 return m_qSupported_response;
458 }
459
460 //------------------------------------------------------------------
461 /// Return the array of async JSON packet types supported by the remote.
462 ///
463 /// This method returns the remote side's array of supported JSON
464 /// packet types as a list of type names. Each of the results are
465 /// expected to have an Enable{type_name} command to enable and configure
466 /// the related feature. Each type_name for an enabled feature will
467 /// possibly send async-style packets that contain a payload of a
468 /// binhex-encoded JSON dictionary. The dictionary will have a
469 /// string field named 'type', that contains the type_name of the
470 /// supported packet type.
471 ///
472 /// There is a Plugin category called structured-data plugins.
473 /// A plugin indicates whether it knows how to handle a type_name.
474 /// If so, it can be used to process the async JSON packet.
475 ///
476 /// @return
477 /// The string returned by the server to the qSupported query.
478 //------------------------------------------------------------------
479 lldb_private::StructuredData::Array *GetSupportedStructuredDataPlugins();
480
481 //------------------------------------------------------------------
482 /// Configure a StructuredData feature on the remote end.
483 ///
484 /// @see \b Process::ConfigureStructuredData(...) for details.
485 //------------------------------------------------------------------
486 Error
487 ConfigureRemoteStructuredData(const ConstString &type_name,
488 const StructuredData::ObjectSP &config_sp);
Todd Fiala75930012016-08-19 04:21:48 +0000489
Greg Clayton576d8832011-03-22 04:00:09 +0000490protected:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000491 LazyBool m_supports_not_sending_acks;
492 LazyBool m_supports_thread_suffix;
493 LazyBool m_supports_threads_in_stop_reply;
494 LazyBool m_supports_vCont_all;
495 LazyBool m_supports_vCont_any;
496 LazyBool m_supports_vCont_c;
497 LazyBool m_supports_vCont_C;
498 LazyBool m_supports_vCont_s;
499 LazyBool m_supports_vCont_S;
500 LazyBool m_qHostInfo_is_valid;
501 LazyBool m_curr_pid_is_valid;
502 LazyBool m_qProcessInfo_is_valid;
503 LazyBool m_qGDBServerVersion_is_valid;
504 LazyBool m_supports_alloc_dealloc_memory;
505 LazyBool m_supports_memory_region_info;
506 LazyBool m_supports_watchpoint_support_info;
507 LazyBool m_supports_detach_stay_stopped;
508 LazyBool m_watchpoints_trigger_after_instruction;
509 LazyBool m_attach_or_wait_reply;
510 LazyBool m_prepare_for_reg_writing_reply;
511 LazyBool m_supports_p;
512 LazyBool m_supports_x;
513 LazyBool m_avoid_g_packets;
514 LazyBool m_supports_QSaveRegisterState;
515 LazyBool m_supports_qXfer_auxv_read;
516 LazyBool m_supports_qXfer_libraries_read;
517 LazyBool m_supports_qXfer_libraries_svr4_read;
518 LazyBool m_supports_qXfer_features_read;
519 LazyBool m_supports_augmented_libraries_svr4_read;
520 LazyBool m_supports_jThreadExtendedInfo;
521 LazyBool m_supports_jLoadedDynamicLibrariesInfos;
522 LazyBool m_supports_jGetSharedCacheInfo;
Steve Pucci5ae54ae2014-01-25 05:46:51 +0000523
Kate Stoneb9c1b512016-09-06 20:57:50 +0000524 bool m_supports_qProcessInfoPID : 1, m_supports_qfProcessInfo : 1,
525 m_supports_qUserName : 1, m_supports_qGroupName : 1,
526 m_supports_qThreadStopInfo : 1, m_supports_z0 : 1, m_supports_z1 : 1,
527 m_supports_z2 : 1, m_supports_z3 : 1, m_supports_z4 : 1,
528 m_supports_QEnvironment : 1, m_supports_QEnvironmentHexEncoded : 1,
529 m_supports_qSymbol : 1, m_qSymbol_requests_done : 1,
530 m_supports_qModuleInfo : 1, m_supports_jThreadsInfo : 1;
Greg Clayton8b82f082011-04-12 05:54:46 +0000531
Kate Stoneb9c1b512016-09-06 20:57:50 +0000532 lldb::pid_t m_curr_pid;
533 lldb::tid_t m_curr_tid; // Current gdb remote protocol thread index for all
534 // other operations
535 lldb::tid_t m_curr_tid_run; // Current gdb remote protocol thread index for
536 // continue, step, etc
Johnny Chen64637202012-05-23 21:09:52 +0000537
Kate Stoneb9c1b512016-09-06 20:57:50 +0000538 uint32_t m_num_supported_hardware_watchpoints;
Todd Fiala75930012016-08-19 04:21:48 +0000539
Kate Stoneb9c1b512016-09-06 20:57:50 +0000540 ArchSpec m_host_arch;
541 ArchSpec m_process_arch;
542 uint32_t m_os_version_major;
543 uint32_t m_os_version_minor;
544 uint32_t m_os_version_update;
545 std::string m_os_build;
546 std::string m_os_kernel;
547 std::string m_hostname;
548 std::string m_gdb_server_name; // from reply to qGDBServerVersion, empty if
549 // qGDBServerVersion is not supported
550 uint32_t m_gdb_server_version; // from reply to qGDBServerVersion, zero if
551 // qGDBServerVersion is not supported
552 uint32_t m_default_packet_timeout;
553 uint64_t m_max_packet_size; // as returned by qSupported
554 std::string m_qSupported_response; // the complete response to qSupported
Jason Molenda91ffe0a2015-06-18 21:46:06 +0000555
Kate Stoneb9c1b512016-09-06 20:57:50 +0000556 bool m_supported_async_json_packets_is_valid;
557 lldb_private::StructuredData::ObjectSP m_supported_async_json_packets_sp;
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000558
Kate Stoneb9c1b512016-09-06 20:57:50 +0000559 bool GetCurrentProcessInfo(bool allow_lazy_pid = true);
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000560
Kate Stoneb9c1b512016-09-06 20:57:50 +0000561 bool GetGDBServerVersion();
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000562
Kate Stoneb9c1b512016-09-06 20:57:50 +0000563 // Given the list of compression types that the remote debug stub can support,
564 // possibly enable compression if we find an encoding we can handle.
565 void MaybeEnableCompression(std::vector<std::string> supported_compressions);
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000566
Kate Stoneb9c1b512016-09-06 20:57:50 +0000567 bool DecodeProcessInfoResponse(StringExtractorGDBRemote &response,
568 ProcessInstanceInfo &process_info);
Pavel Labath8c1b6bd2016-08-09 12:04:46 +0000569
Kate Stoneb9c1b512016-09-06 20:57:50 +0000570 void OnRunPacketSent(bool first) override;
571
572 PacketResult SendThreadSpecificPacketAndWaitForResponse(
573 lldb::tid_t tid, StreamString &&payload,
574 StringExtractorGDBRemote &response, bool send_async);
Pavel Labath4b6f9592016-08-18 08:30:03 +0000575
Greg Clayton576d8832011-03-22 04:00:09 +0000576private:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000577 DISALLOW_COPY_AND_ASSIGN(GDBRemoteCommunicationClient);
Greg Clayton576d8832011-03-22 04:00:09 +0000578};
579
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000580} // namespace process_gdb_remote
581} // namespace lldb_private
582
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000583#endif // liblldb_GDBRemoteCommunicationClient_h_