blob: a714b403babb981a836465d8a2fd3688ec4ac227 [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
Pavel Labath8c1b6bd2016-08-09 12:04:46 +000032class GDBRemoteCommunicationClient : public GDBRemoteClientBase
Greg Clayton576d8832011-03-22 04:00:09 +000033{
34public:
Tamas Berghammere13c2732015-02-11 10:29:30 +000035 GDBRemoteCommunicationClient();
Greg Clayton576d8832011-03-22 04:00:09 +000036
Eugene Zelenkoedb35d92015-10-24 01:08:35 +000037 ~GDBRemoteCommunicationClient() override;
Greg Clayton576d8832011-03-22 04:00:09 +000038
Greg Clayton1cb64962011-03-24 04:28:38 +000039 //------------------------------------------------------------------
40 // After connecting, send the handshake to the server to make sure
41 // we are communicating with it.
42 //------------------------------------------------------------------
43 bool
Tamas Berghammerdb264a62015-03-31 09:52:22 +000044 HandshakeWithServer (Error *error_ptr);
Greg Clayton1cb64962011-03-24 04:28:38 +000045
Steve Pucci5ae54ae2014-01-25 05:46:51 +000046 // For packets which specify a range of output to be returned,
47 // return all of the output via a series of request packets of the form
48 // <prefix>0,<size>
49 // <prefix><size>,<size>
50 // <prefix><size>*2,<size>
51 // <prefix><size>*3,<size>
52 // ...
53 // until a "$l..." packet is received, indicating the end.
54 // (size is in hex; this format is used by a standard gdbserver to
55 // return the given portion of the output specified by <prefix>;
56 // for example, "qXfer:libraries-svr4:read::fff,1000" means
57 // "return a chunk of the xml description file for shared
58 // library load addresses, where the chunk starts at offset 0xfff
59 // and continues for 0x1000 bytes").
60 // Concatenate the resulting server response packets together and
61 // return in response_string. If any packet fails, the return value
62 // indicates that failure and the returned string value is undefined.
63 PacketResult
64 SendPacketsAndConcatenateResponses (const char *send_payload_prefix,
65 std::string &response_string);
66
Pavel Labath0faf3732016-08-25 08:34:57 +000067 void
68 ComputeThreadSuffixSupport();
69
Greg Claytonfbb76342013-11-20 21:07:01 +000070 bool
Pavel Labath5a123c42016-08-16 09:36:29 +000071 GetThreadSuffixSupported();
Greg Clayton576d8832011-03-22 04:00:09 +000072
Greg Claytonfb909312013-11-23 01:58:15 +000073 // This packet is usually sent first and the boolean return value
74 // indicates if the packet was send and any response was received
75 // even in the response is UNIMPLEMENTED. If the packet failed to
76 // get a response, then false is returned. This quickly tells us
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +000077 // if we were able to connect and communicate with the remote GDB
Greg Claytonfb909312013-11-23 01:58:15 +000078 // server
79 bool
Greg Clayton1cb64962011-03-24 04:28:38 +000080 QueryNoAckModeSupported ();
Greg Clayton576d8832011-03-22 04:00:09 +000081
Greg Clayton44633992012-04-10 03:22:03 +000082 void
83 GetListThreadsInStopReplySupported ();
84
Greg Clayton576d8832011-03-22 04:00:09 +000085 lldb::pid_t
Oleksiy Vyalov1ef7b2c2015-02-04 23:19:15 +000086 GetCurrentProcessID (bool allow_lazy = true);
Greg Clayton576d8832011-03-22 04:00:09 +000087
88 bool
89 GetLaunchSuccess (std::string &error_str);
90
Oleksiy Vyalov9fe526c2015-10-21 19:34:26 +000091 bool
92 LaunchGDBServer (const char *remote_accept_hostname,
93 lldb::pid_t &pid,
94 uint16_t &port,
95 std::string &socket_name);
Tamas Berghammerccd6cff2015-12-08 14:08:19 +000096
97 size_t
98 QueryGDBServer (std::vector<std::pair<uint16_t, std::string>>& connection_urls);
99
Daniel Maleae0f8f572013-08-26 23:57:52 +0000100 bool
101 KillSpawnedProcess (lldb::pid_t pid);
Greg Clayton8b82f082011-04-12 05:54:46 +0000102
Greg Clayton576d8832011-03-22 04:00:09 +0000103 //------------------------------------------------------------------
104 /// Sends a GDB remote protocol 'A' packet that delivers program
105 /// arguments to the remote server.
106 ///
107 /// @param[in] argv
108 /// A NULL terminated array of const C strings to use as the
109 /// arguments.
110 ///
111 /// @return
112 /// Zero if the response was "OK", a positive value if the
113 /// the response was "Exx" where xx are two hex digits, or
114 /// -1 if the call is unsupported or any other unexpected
115 /// response was received.
116 //------------------------------------------------------------------
117 int
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000118 SendArgumentsPacket (const ProcessLaunchInfo &launch_info);
Greg Clayton576d8832011-03-22 04:00:09 +0000119
120 //------------------------------------------------------------------
121 /// Sends a "QEnvironment:NAME=VALUE" packet that will build up the
122 /// environment that will get used when launching an application
123 /// in conjunction with the 'A' packet. This function can be called
124 /// multiple times in a row in order to pass on the desired
125 /// environment that the inferior should be launched with.
126 ///
127 /// @param[in] name_equal_value
128 /// A NULL terminated C string that contains a single environment
129 /// in the format "NAME=VALUE".
130 ///
131 /// @return
132 /// Zero if the response was "OK", a positive value if the
133 /// the response was "Exx" where xx are two hex digits, or
134 /// -1 if the call is unsupported or any other unexpected
135 /// response was received.
136 //------------------------------------------------------------------
137 int
138 SendEnvironmentPacket (char const *name_equal_value);
139
Greg Claytonc4103b32011-05-08 04:53:50 +0000140 int
141 SendLaunchArchPacket (const char *arch);
Jason Molendaa3329782014-03-29 18:54:20 +0000142
143 int
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000144 SendLaunchEventDataPacket(const char *data, bool *was_supported = nullptr);
Jason Molendaa3329782014-03-29 18:54:20 +0000145
Greg Clayton576d8832011-03-22 04:00:09 +0000146 //------------------------------------------------------------------
147 /// Sends a "vAttach:PID" where PID is in hex.
148 ///
149 /// @param[in] pid
150 /// A process ID for the remote gdb server to attach to.
151 ///
152 /// @param[out] response
153 /// The response received from the gdb server. If the return
154 /// value is zero, \a response will contain a stop reply
155 /// packet.
156 ///
157 /// @return
158 /// Zero if the attach was successful, or an error indicating
159 /// an error code.
160 //------------------------------------------------------------------
161 int
162 SendAttach (lldb::pid_t pid,
163 StringExtractorGDBRemote& response);
164
Greg Clayton576d8832011-03-22 04:00:09 +0000165 //------------------------------------------------------------------
Vince Harrone0be4252015-02-06 18:32:57 +0000166 /// Sends a GDB remote protocol 'I' packet that delivers stdin
167 /// data to the remote process.
168 ///
169 /// @param[in] data
170 /// A pointer to stdin data.
171 ///
172 /// @param[in] data_len
173 /// The number of bytes available at \a data.
174 ///
175 /// @return
176 /// Zero if the attach was successful, or an error indicating
177 /// an error code.
178 //------------------------------------------------------------------
179 int
180 SendStdinNotification(const char* data, size_t data_len);
181
182 //------------------------------------------------------------------
Greg Clayton576d8832011-03-22 04:00:09 +0000183 /// Sets the path to use for stdin/out/err for a process
184 /// that will be launched with the 'A' packet.
185 ///
186 /// @param[in] path
187 /// The path to use for stdin/out/err
188 ///
189 /// @return
190 /// Zero if the for success, or an error code for failure.
191 //------------------------------------------------------------------
192 int
Chaoren Lind3173f32015-05-29 19:52:29 +0000193 SetSTDIN(const FileSpec &file_spec);
Greg Clayton576d8832011-03-22 04:00:09 +0000194 int
Chaoren Lind3173f32015-05-29 19:52:29 +0000195 SetSTDOUT(const FileSpec &file_spec);
Greg Clayton576d8832011-03-22 04:00:09 +0000196 int
Chaoren Lind3173f32015-05-29 19:52:29 +0000197 SetSTDERR(const FileSpec &file_spec);
Greg Clayton576d8832011-03-22 04:00:09 +0000198
199 //------------------------------------------------------------------
200 /// Sets the disable ASLR flag to \a enable for a process that will
201 /// be launched with the 'A' packet.
202 ///
203 /// @param[in] enable
Jim Ingham106d0282014-06-25 02:32:56 +0000204 /// A boolean value indicating whether to disable ASLR or not.
Greg Clayton576d8832011-03-22 04:00:09 +0000205 ///
206 /// @return
207 /// Zero if the for success, or an error code for failure.
208 //------------------------------------------------------------------
209 int
210 SetDisableASLR (bool enable);
Jim Ingham106d0282014-06-25 02:32:56 +0000211
212 //------------------------------------------------------------------
213 /// Sets the DetachOnError flag to \a enable for the process controlled by the stub.
214 ///
215 /// @param[in] enable
216 /// A boolean value indicating whether to detach on error or not.
217 ///
218 /// @return
219 /// Zero if the for success, or an error code for failure.
220 //------------------------------------------------------------------
221 int
222 SetDetachOnError (bool enable);
Greg Clayton576d8832011-03-22 04:00:09 +0000223
224 //------------------------------------------------------------------
225 /// Sets the working directory to \a path for a process that will
Greg Claytonfbb76342013-11-20 21:07:01 +0000226 /// be launched with the 'A' packet for non platform based
227 /// connections. If this packet is sent to a GDB server that
228 /// implements the platform, it will change the current working
229 /// directory for the platform process.
Greg Clayton576d8832011-03-22 04:00:09 +0000230 ///
Chaoren Lind3173f32015-05-29 19:52:29 +0000231 /// @param[in] working_dir
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +0000232 /// The path to a directory to use when launching our process
Greg Clayton576d8832011-03-22 04:00:09 +0000233 ///
234 /// @return
235 /// Zero if the for success, or an error code for failure.
236 //------------------------------------------------------------------
237 int
Chaoren Lind3173f32015-05-29 19:52:29 +0000238 SetWorkingDir(const FileSpec &working_dir);
Greg Clayton576d8832011-03-22 04:00:09 +0000239
Greg Claytonfbb76342013-11-20 21:07:01 +0000240 //------------------------------------------------------------------
241 /// Gets the current working directory of a remote platform GDB
242 /// server.
243 ///
Chaoren Lind3173f32015-05-29 19:52:29 +0000244 /// @param[out] working_dir
Greg Claytonfbb76342013-11-20 21:07:01 +0000245 /// The current working directory on the remote platform.
246 ///
247 /// @return
248 /// Boolean for success
249 //------------------------------------------------------------------
250 bool
Chaoren Lind3173f32015-05-29 19:52:29 +0000251 GetWorkingDir(FileSpec &working_dir);
Greg Claytonfbb76342013-11-20 21:07:01 +0000252
Greg Clayton576d8832011-03-22 04:00:09 +0000253 lldb::addr_t
254 AllocateMemory (size_t size, uint32_t permissions);
255
256 bool
257 DeallocateMemory (lldb::addr_t addr);
258
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000259 Error
Jim Inghamacff8952013-05-02 00:27:30 +0000260 Detach (bool keep_stopped);
Greg Clayton37a0a242012-04-11 00:24:49 +0000261
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000262 Error
263 GetMemoryRegionInfo (lldb::addr_t addr, MemoryRegionInfo &range_info);
Greg Clayton46fb5582011-11-18 07:03:08 +0000264
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000265 Error
Johnny Chen64637202012-05-23 21:09:52 +0000266 GetWatchpointSupportInfo (uint32_t &num);
267
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000268 Error
Jaydeep Patil725666c2015-08-13 03:46:01 +0000269 GetWatchpointSupportInfo (uint32_t &num, bool& after, const ArchSpec &arch);
Enrico Granataf04a2192012-07-13 23:18:48 +0000270
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000271 Error
Jaydeep Patil725666c2015-08-13 03:46:01 +0000272 GetWatchpointsTriggerAfterInstruction (bool &after, const ArchSpec &arch);
Enrico Granataf04a2192012-07-13 23:18:48 +0000273
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000274 const ArchSpec &
Greg Clayton576d8832011-03-22 04:00:09 +0000275 GetHostArchitecture ();
Greg Clayton9ac6d2d2013-10-25 18:13:17 +0000276
277 uint32_t
278 GetHostDefaultPacketTimeout();
Jason Molendaf17b5ac2012-12-19 02:54:03 +0000279
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000280 const ArchSpec &
Jason Molendaf17b5ac2012-12-19 02:54:03 +0000281 GetProcessArchitecture ();
282
Steve Pucci5ae54ae2014-01-25 05:46:51 +0000283 void
284 GetRemoteQSupported();
285
Greg Clayton576d8832011-03-22 04:00:09 +0000286 bool
287 GetVContSupported (char flavor);
288
Jim Inghamcd16df92012-07-20 21:37:13 +0000289 bool
Sean Callananb1de1142013-09-04 23:24:15 +0000290 GetpPacketSupported (lldb::tid_t tid);
Hafiz Abid Qadeer9a78cdf2013-08-29 09:09:45 +0000291
292 bool
Jason Molendabdc4f122014-05-06 02:59:39 +0000293 GetxPacketSupported ();
294
295 bool
Jim Inghamcd16df92012-07-20 21:37:13 +0000296 GetVAttachOrWaitSupported ();
297
Jim Ingham279ceec2012-07-25 21:12:43 +0000298 bool
299 GetSyncThreadStateSupported();
300
Greg Clayton576d8832011-03-22 04:00:09 +0000301 void
Greg Clayton2e59d4f2015-06-29 20:08:51 +0000302 ResetDiscoverableSettings (bool did_exec);
Greg Clayton576d8832011-03-22 04:00:09 +0000303
304 bool
Greg Clayton9b1e1cd2011-04-04 18:18:57 +0000305 GetHostInfo (bool force = false);
Ewan Crawford78baa192015-05-13 09:18:18 +0000306
307 bool
308 GetDefaultThreadId (lldb::tid_t &tid);
Greg Clayton576d8832011-03-22 04:00:09 +0000309
310 bool
Greg Clayton1cb64962011-03-24 04:28:38 +0000311 GetOSVersion (uint32_t &major,
312 uint32_t &minor,
313 uint32_t &update);
314
315 bool
316 GetOSBuildString (std::string &s);
317
318 bool
319 GetOSKernelDescription (std::string &s);
320
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000321 ArchSpec
Greg Clayton1cb64962011-03-24 04:28:38 +0000322 GetSystemArchitecture ();
323
324 bool
325 GetHostname (std::string &s);
326
Greg Clayton37a0a242012-04-11 00:24:49 +0000327 lldb::addr_t
328 GetShlibInfoAddr();
329
Greg Clayton1cb64962011-03-24 04:28:38 +0000330 bool
Greg Clayton576d8832011-03-22 04:00:09 +0000331 GetSupportsThreadSuffix ();
332
333 bool
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000334 GetProcessInfo (lldb::pid_t pid, ProcessInstanceInfo &process_info);
Greg Clayton32e0a752011-03-30 18:16:51 +0000335
336 uint32_t
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000337 FindProcesses (const ProcessInstanceInfoMatch &process_match_info,
338 ProcessInstanceInfoList &process_infos);
Greg Clayton32e0a752011-03-30 18:16:51 +0000339
340 bool
341 GetUserName (uint32_t uid, std::string &name);
342
343 bool
344 GetGroupName (uint32_t gid, std::string &name);
345
346 bool
Greg Clayton576d8832011-03-22 04:00:09 +0000347 HasFullVContSupport ()
348 {
349 return GetVContSupported ('A');
350 }
351
352 bool
353 HasAnyVContSupport ()
354 {
355 return GetVContSupported ('a');
356 }
357
Greg Clayton8b82f082011-04-12 05:54:46 +0000358 bool
359 GetStopReply (StringExtractorGDBRemote &response);
360
361 bool
Greg Claytonf402f782012-10-13 02:11:55 +0000362 GetThreadStopInfo (lldb::tid_t tid,
Greg Clayton8b82f082011-04-12 05:54:46 +0000363 StringExtractorGDBRemote &response);
364
365 bool
366 SupportsGDBStoppointPacket (GDBStoppointType type)
367 {
368 switch (type)
369 {
370 case eBreakpointSoftware: return m_supports_z0;
371 case eBreakpointHardware: return m_supports_z1;
372 case eWatchpointWrite: return m_supports_z2;
373 case eWatchpointRead: return m_supports_z3;
374 case eWatchpointReadWrite: return m_supports_z4;
Zachary Turner568b0de2015-02-18 18:44:03 +0000375 default: return false;
Greg Clayton8b82f082011-04-12 05:54:46 +0000376 }
Greg Clayton8b82f082011-04-12 05:54:46 +0000377 }
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000378
Greg Clayton8b82f082011-04-12 05:54:46 +0000379 uint8_t
380 SendGDBStoppointTypePacket (GDBStoppointType type, // Type of breakpoint or watchpoint
381 bool insert, // Insert or remove?
382 lldb::addr_t addr, // Address of breakpoint or watchpoint
383 uint32_t length); // Byte Size of breakpoint or watchpoint
384
Ewan Crawford78baa192015-05-13 09:18:18 +0000385 bool
386 SetNonStopMode (const bool enable);
387
Greg Clayton9b1e1cd2011-04-04 18:18:57 +0000388 void
Greg Claytone034a042015-05-21 20:52:06 +0000389 TestPacketSpeed (const uint32_t num_packets, uint32_t max_send, uint32_t max_recv, bool json, Stream &strm);
Greg Clayton9b1e1cd2011-04-04 18:18:57 +0000390
391 // This packet is for testing the speed of the interface only. Both
392 // the client and server need to support it, but this allows us to
393 // measure the packet speed without any other work being done on the
394 // other end and avoids any of that work affecting the packet send
395 // and response times.
396 bool
397 SendSpeedTestPacket (uint32_t send_size,
398 uint32_t recv_size);
Greg Clayton8b82f082011-04-12 05:54:46 +0000399
400 bool
Jason Molendae9ca4af2013-02-23 02:04:45 +0000401 SetCurrentThreadForRun (uint64_t tid);
Greg Clayton8b82f082011-04-12 05:54:46 +0000402
Steve Pucci5ae54ae2014-01-25 05:46:51 +0000403 bool
Steve Pucci03904ac2014-03-04 23:18:46 +0000404 GetQXferAuxvReadSupported ();
405
406 bool
Steve Pucci5ae54ae2014-01-25 05:46:51 +0000407 GetQXferLibrariesReadSupported ();
408
409 bool
410 GetQXferLibrariesSVR4ReadSupported ();
411
412 uint64_t
413 GetRemoteMaxPacketSize();
414
415 bool
Greg Claytonb30c50c2015-05-29 00:01:55 +0000416 GetEchoSupported ();
417
418 bool
Steve Pucci5ae54ae2014-01-25 05:46:51 +0000419 GetAugmentedLibrariesSVR4ReadSupported ();
420
Colin Rileyc3c95b22015-04-16 15:51:33 +0000421 bool
422 GetQXferFeaturesReadSupported ();
423
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000424 LazyBool
Jim Ingham372787f2012-04-07 00:00:41 +0000425 SupportsAllocDeallocMemory () // const
Greg Clayton2a48f522011-05-14 01:50:35 +0000426 {
Jim Ingham372787f2012-04-07 00:00:41 +0000427 // Uncomment this to have lldb pretend the debug server doesn't respond to alloc/dealloc memory packets.
428 // m_supports_alloc_dealloc_memory = lldb_private::eLazyBoolNo;
Greg Clayton70b57652011-05-15 01:25:55 +0000429 return m_supports_alloc_dealloc_memory;
Greg Clayton2a48f522011-05-14 01:50:35 +0000430 }
431
Greg Claytonadc00cb2011-05-20 23:38:13 +0000432 size_t
433 GetCurrentThreadIDs (std::vector<lldb::tid_t> &thread_ids,
434 bool &sequence_mutex_unavailable);
435
Greg Claytonfbb76342013-11-20 21:07:01 +0000436 lldb::user_id_t
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000437 OpenFile (const FileSpec& file_spec, uint32_t flags, mode_t mode, Error &error);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000438
Greg Claytonfbb76342013-11-20 21:07:01 +0000439 bool
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000440 CloseFile (lldb::user_id_t fd, Error &error);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000441
Greg Claytonfbb76342013-11-20 21:07:01 +0000442 lldb::user_id_t
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000443 GetFileSize (const FileSpec& file_spec);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000444
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000445 Error
Chaoren Lind3173f32015-05-29 19:52:29 +0000446 GetFilePermissions(const FileSpec &file_spec, uint32_t &file_permissions);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000447
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000448 Error
Chaoren Lind3173f32015-05-29 19:52:29 +0000449 SetFilePermissions(const FileSpec &file_spec, uint32_t file_permissions);
Greg Claytonfbb76342013-11-20 21:07:01 +0000450
451 uint64_t
Daniel Maleae0f8f572013-08-26 23:57:52 +0000452 ReadFile (lldb::user_id_t fd,
453 uint64_t offset,
454 void *dst,
455 uint64_t dst_len,
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000456 Error &error);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000457
Greg Claytonfbb76342013-11-20 21:07:01 +0000458 uint64_t
Daniel Maleae0f8f572013-08-26 23:57:52 +0000459 WriteFile (lldb::user_id_t fd,
460 uint64_t offset,
461 const void* src,
462 uint64_t src_len,
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000463 Error &error);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000464
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000465 Error
Chaoren Lind3173f32015-05-29 19:52:29 +0000466 CreateSymlink(const FileSpec &src,
467 const FileSpec &dst);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000468
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000469 Error
Chaoren Lind3173f32015-05-29 19:52:29 +0000470 Unlink(const FileSpec &file_spec);
Greg Claytonfbb76342013-11-20 21:07:01 +0000471
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000472 Error
Chaoren Lind3173f32015-05-29 19:52:29 +0000473 MakeDirectory(const FileSpec &file_spec, uint32_t mode);
474
Greg Claytonfbb76342013-11-20 21:07:01 +0000475 bool
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000476 GetFileExists (const FileSpec& file_spec);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000477
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000478 Error
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000479 RunShellCommand(const char *command, // Shouldn't be nullptr
Chaoren Lind3173f32015-05-29 19:52:29 +0000480 const FileSpec &working_dir, // Pass empty FileSpec to use the current working directory
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000481 int *status_ptr, // Pass nullptr if you don't want the process exit status
482 int *signo_ptr, // Pass nullptr if you don't want the signal that caused the process to exit
483 std::string *command_output, // Pass nullptr if you don't want the command output
Chaoren Lind3173f32015-05-29 19:52:29 +0000484 uint32_t timeout_sec); // Timeout in seconds to wait for shell program to finish
485
Greg Claytonfbb76342013-11-20 21:07:01 +0000486 bool
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000487 CalculateMD5 (const FileSpec& file_spec, uint64_t &high, uint64_t &low);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000488
Pavel Labathb42b48e2016-08-19 12:31:49 +0000489 lldb::DataBufferSP
Greg Claytonf74cf862013-11-13 23:28:31 +0000490 ReadRegister(lldb::tid_t tid,
Pavel Labath0faf3732016-08-25 08:34:57 +0000491 uint32_t reg_num, // Must be the eRegisterKindProcessPlugin register number
492 const Lock &lock);
Greg Claytonf74cf862013-11-13 23:28:31 +0000493
Pavel Labathb42b48e2016-08-19 12:31:49 +0000494 lldb::DataBufferSP
Pavel Labath0faf3732016-08-25 08:34:57 +0000495 ReadAllRegisters(lldb::tid_t tid, const Lock &lock);
Greg Claytonf74cf862013-11-13 23:28:31 +0000496
497 bool
Pavel Labath56d72622016-08-17 08:53:31 +0000498 WriteRegister(lldb::tid_t tid, uint32_t reg_num, // eRegisterKindProcessPlugin register number
Pavel Labath0faf3732016-08-25 08:34:57 +0000499 llvm::ArrayRef<uint8_t> data, const Lock &lock);
Pavel Labath56d72622016-08-17 08:53:31 +0000500
501 bool
Pavel Labath0faf3732016-08-25 08:34:57 +0000502 WriteAllRegisters(lldb::tid_t tid, llvm::ArrayRef<uint8_t> data, const Lock &lock);
Pavel Labath56d72622016-08-17 08:53:31 +0000503
504 bool
505 SaveRegisterState(lldb::tid_t tid, uint32_t &save_id);
506
Greg Claytonf74cf862013-11-13 23:28:31 +0000507 bool
508 RestoreRegisterState (lldb::tid_t tid, uint32_t save_id);
Jason Molendaa3329782014-03-29 18:54:20 +0000509
Pavel Labath27402d22016-08-18 12:32:41 +0000510 bool
511 SyncThreadState(lldb::tid_t tid);
512
Jason Molendaa3329782014-03-29 18:54:20 +0000513 const char *
514 GetGDBServerProgramName();
Greg Claytonf74cf862013-11-13 23:28:31 +0000515
Jason Molendaa3329782014-03-29 18:54:20 +0000516 uint32_t
517 GetGDBServerProgramVersion();
518
519 bool
520 AvoidGPackets(ProcessGDBRemote *process);
521
Greg Clayton358cf1e2015-06-25 21:46:34 +0000522 StructuredData::ObjectSP
523 GetThreadsInfo();
524
Jason Molenda705b1802014-06-13 02:37:02 +0000525 bool
526 GetThreadExtendedInfoSupported();
527
Oleksiy Vyalov6801be32015-02-25 22:15:44 +0000528 bool
Jason Molenda20ee21b2015-07-10 23:15:22 +0000529 GetLoadedDynamicLibrariesInfosSupported();
530
531 bool
Jason Molenda37397352016-07-22 00:17:55 +0000532 GetSharedCacheInfoSupported();
533
534 bool
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000535 GetModuleInfo (const FileSpec& module_file_spec,
536 const ArchSpec& arch_spec,
537 ModuleSpec &module_spec);
Oleksiy Vyalov6801be32015-02-25 22:15:44 +0000538
Colin Rileyc3c95b22015-04-16 15:51:33 +0000539 bool
540 ReadExtFeature (const lldb_private::ConstString object,
541 const lldb_private::ConstString annex,
542 std::string & out,
543 lldb_private::Error & err);
544
Greg Clayton0b90be12015-06-23 21:27:50 +0000545 void
546 ServeSymbolLookups(lldb_private::Process *process);
547
Todd Fiala75930012016-08-19 04:21:48 +0000548 //------------------------------------------------------------------
549 /// Return the feature set supported by the gdb-remote server.
550 ///
551 /// This method returns the remote side's response to the qSupported
552 /// packet. The response is the complete string payload returned
553 /// to the client.
554 ///
555 /// @return
556 /// The string returned by the server to the qSupported query.
557 //------------------------------------------------------------------
558 const std::string&
559 GetServerSupportedFeatures() const
560 {
561 return m_qSupported_response;
562 }
563
564 //------------------------------------------------------------------
565 /// Return the array of async JSON packet types supported by the remote.
566 ///
567 /// This method returns the remote side's array of supported JSON
568 /// packet types as a list of type names. Each of the results are
569 /// expected to have an Enable{type_name} command to enable and configure
570 /// the related feature. Each type_name for an enabled feature will
571 /// possibly send async-style packets that contain a payload of a
572 /// binhex-encoded JSON dictionary. The dictionary will have a
573 /// string field named 'type', that contains the type_name of the
574 /// supported packet type.
575 ///
576 /// There is a Plugin category called structured-data plugins.
577 /// A plugin indicates whether it knows how to handle a type_name.
578 /// If so, it can be used to process the async JSON packet.
579 ///
580 /// @return
581 /// The string returned by the server to the qSupported query.
582 //------------------------------------------------------------------
583 lldb_private::StructuredData::Array*
584 GetSupportedStructuredDataPlugins();
585
586 //------------------------------------------------------------------
587 /// Configure a StructuredData feature on the remote end.
588 ///
589 /// @see \b Process::ConfigureStructuredData(...) for details.
590 //------------------------------------------------------------------
591 Error
592 ConfigureRemoteStructuredData(const ConstString &type_name,
593 const StructuredData::ObjectSP &config_sp);
594
Greg Clayton576d8832011-03-22 04:00:09 +0000595protected:
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000596 LazyBool m_supports_not_sending_acks;
597 LazyBool m_supports_thread_suffix;
598 LazyBool m_supports_threads_in_stop_reply;
599 LazyBool m_supports_vCont_all;
600 LazyBool m_supports_vCont_any;
601 LazyBool m_supports_vCont_c;
602 LazyBool m_supports_vCont_C;
603 LazyBool m_supports_vCont_s;
604 LazyBool m_supports_vCont_S;
605 LazyBool m_qHostInfo_is_valid;
606 LazyBool m_curr_pid_is_valid;
607 LazyBool m_qProcessInfo_is_valid;
608 LazyBool m_qGDBServerVersion_is_valid;
609 LazyBool m_supports_alloc_dealloc_memory;
610 LazyBool m_supports_memory_region_info;
611 LazyBool m_supports_watchpoint_support_info;
612 LazyBool m_supports_detach_stay_stopped;
613 LazyBool m_watchpoints_trigger_after_instruction;
614 LazyBool m_attach_or_wait_reply;
615 LazyBool m_prepare_for_reg_writing_reply;
616 LazyBool m_supports_p;
617 LazyBool m_supports_x;
618 LazyBool m_avoid_g_packets;
619 LazyBool m_supports_QSaveRegisterState;
620 LazyBool m_supports_qXfer_auxv_read;
621 LazyBool m_supports_qXfer_libraries_read;
622 LazyBool m_supports_qXfer_libraries_svr4_read;
Colin Rileyc3c95b22015-04-16 15:51:33 +0000623 LazyBool m_supports_qXfer_features_read;
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000624 LazyBool m_supports_augmented_libraries_svr4_read;
625 LazyBool m_supports_jThreadExtendedInfo;
Jason Molenda20ee21b2015-07-10 23:15:22 +0000626 LazyBool m_supports_jLoadedDynamicLibrariesInfos;
Jason Molenda37397352016-07-22 00:17:55 +0000627 LazyBool m_supports_jGetSharedCacheInfo;
Steve Pucci5ae54ae2014-01-25 05:46:51 +0000628
Greg Clayton8b82f082011-04-12 05:54:46 +0000629 bool
630 m_supports_qProcessInfoPID:1,
631 m_supports_qfProcessInfo:1,
632 m_supports_qUserName:1,
633 m_supports_qGroupName:1,
634 m_supports_qThreadStopInfo:1,
635 m_supports_z0:1,
636 m_supports_z1:1,
637 m_supports_z2:1,
638 m_supports_z3:1,
Greg Clayton89600582013-10-10 17:53:50 +0000639 m_supports_z4:1,
640 m_supports_QEnvironment:1,
Greg Clayton0b90be12015-06-23 21:27:50 +0000641 m_supports_QEnvironmentHexEncoded:1,
Greg Clayton358cf1e2015-06-25 21:46:34 +0000642 m_supports_qSymbol:1,
Jason Molenda50018d32016-01-13 04:08:10 +0000643 m_qSymbol_requests_done:1,
Stephane Sezer6f455292016-01-08 00:00:17 +0000644 m_supports_qModuleInfo:1,
Greg Clayton358cf1e2015-06-25 21:46:34 +0000645 m_supports_jThreadsInfo:1;
Greg Clayton2a48f522011-05-14 01:50:35 +0000646
Todd Fiala9f72b3a2014-05-07 19:28:21 +0000647 lldb::pid_t m_curr_pid;
Greg Clayton8b82f082011-04-12 05:54:46 +0000648 lldb::tid_t m_curr_tid; // Current gdb remote protocol thread index for all other operations
649 lldb::tid_t m_curr_tid_run; // Current gdb remote protocol thread index for continue, step, etc
650
Johnny Chen64637202012-05-23 21:09:52 +0000651 uint32_t m_num_supported_hardware_watchpoints;
652
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000653 ArchSpec m_host_arch;
654 ArchSpec m_process_arch;
Greg Clayton1cb64962011-03-24 04:28:38 +0000655 uint32_t m_os_version_major;
656 uint32_t m_os_version_minor;
657 uint32_t m_os_version_update;
658 std::string m_os_build;
659 std::string m_os_kernel;
660 std::string m_hostname;
Jason Molendaa3329782014-03-29 18:54:20 +0000661 std::string m_gdb_server_name; // from reply to qGDBServerVersion, empty if qGDBServerVersion is not supported
662 uint32_t m_gdb_server_version; // from reply to qGDBServerVersion, zero if qGDBServerVersion is not supported
Greg Clayton9ac6d2d2013-10-25 18:13:17 +0000663 uint32_t m_default_packet_timeout;
Steve Pucci5ae54ae2014-01-25 05:46:51 +0000664 uint64_t m_max_packet_size; // as returned by qSupported
Todd Fiala75930012016-08-19 04:21:48 +0000665 std::string m_qSupported_response; // the complete response to qSupported
666
667 bool m_supported_async_json_packets_is_valid;
668 lldb_private::StructuredData::ObjectSP m_supported_async_json_packets_sp;
Jason Molenda91ffe0a2015-06-18 21:46:06 +0000669
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000670 bool
671 GetCurrentProcessInfo (bool allow_lazy_pid = true);
672
673 bool
674 GetGDBServerVersion();
675
676 // Given the list of compression types that the remote debug stub can support,
677 // possibly enable compression if we find an encoding we can handle.
678 void
679 MaybeEnableCompression (std::vector<std::string> supported_compressions);
680
Greg Clayton32e0a752011-03-30 18:16:51 +0000681 bool
682 DecodeProcessInfoResponse (StringExtractorGDBRemote &response,
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000683 ProcessInstanceInfo &process_info);
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000684
Pavel Labath8c1b6bd2016-08-09 12:04:46 +0000685 void
686 OnRunPacketSent(bool first) override;
687
Pavel Labath4b6f9592016-08-18 08:30:03 +0000688 PacketResult
689 SendThreadSpecificPacketAndWaitForResponse(lldb::tid_t tid, StreamString &&payload,
Pavel Labath0faf3732016-08-25 08:34:57 +0000690 StringExtractorGDBRemote &response, const Lock &lock);
691
692 bool
693 SetCurrentThread(uint64_t tid, const Lock &lock);
Pavel Labath4b6f9592016-08-18 08:30:03 +0000694
Greg Clayton576d8832011-03-22 04:00:09 +0000695private:
Greg Clayton576d8832011-03-22 04:00:09 +0000696 DISALLOW_COPY_AND_ASSIGN (GDBRemoteCommunicationClient);
697};
698
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000699} // namespace process_gdb_remote
700} // namespace lldb_private
701
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000702#endif // liblldb_GDBRemoteCommunicationClient_h_