blob: 7088bc0287c1395a9c8f9129c210c5b6f6762ab8 [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
13// C Includes
14// C++ Includes
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 Clayton576d8832011-03-22 04:00:09 +000020// Other libraries and framework includes
21// Project includes
22#include "lldb/Core/ArchSpec.h"
Greg Clayton358cf1e2015-06-25 21:46:34 +000023#include "lldb/Core/StructuredData.h"
Greg Clayton46fb5582011-11-18 07:03:08 +000024#include "lldb/Target/Process.h"
Greg Clayton576d8832011-03-22 04:00:09 +000025
26#include "GDBRemoteCommunication.h"
27
Tamas Berghammerdb264a62015-03-31 09:52:22 +000028namespace lldb_private {
29namespace process_gdb_remote {
30
Greg Clayton576d8832011-03-22 04:00:09 +000031class GDBRemoteCommunicationClient : public GDBRemoteCommunication
32{
33public:
Tamas Berghammere13c2732015-02-11 10:29:30 +000034 GDBRemoteCommunicationClient();
Greg Clayton576d8832011-03-22 04:00:09 +000035
Eugene Zelenkoedb35d92015-10-24 01:08:35 +000036 ~GDBRemoteCommunicationClient() override;
Greg Clayton576d8832011-03-22 04:00:09 +000037
Greg Clayton1cb64962011-03-24 04:28:38 +000038 //------------------------------------------------------------------
39 // After connecting, send the handshake to the server to make sure
40 // we are communicating with it.
41 //------------------------------------------------------------------
42 bool
Tamas Berghammerdb264a62015-03-31 09:52:22 +000043 HandshakeWithServer (Error *error_ptr);
Greg Clayton1cb64962011-03-24 04:28:38 +000044
Greg Clayton3dedae12013-12-06 21:45:27 +000045 PacketResult
Greg Clayton576d8832011-03-22 04:00:09 +000046 SendPacketAndWaitForResponse (const char *send_payload,
47 StringExtractorGDBRemote &response,
48 bool send_async);
49
Greg Clayton3dedae12013-12-06 21:45:27 +000050 PacketResult
Greg Clayton576d8832011-03-22 04:00:09 +000051 SendPacketAndWaitForResponse (const char *send_payload,
52 size_t send_length,
53 StringExtractorGDBRemote &response,
54 bool send_async);
55
Steve Pucci5ae54ae2014-01-25 05:46:51 +000056 // For packets which specify a range of output to be returned,
57 // return all of the output via a series of request packets of the form
58 // <prefix>0,<size>
59 // <prefix><size>,<size>
60 // <prefix><size>*2,<size>
61 // <prefix><size>*3,<size>
62 // ...
63 // until a "$l..." packet is received, indicating the end.
64 // (size is in hex; this format is used by a standard gdbserver to
65 // return the given portion of the output specified by <prefix>;
66 // for example, "qXfer:libraries-svr4:read::fff,1000" means
67 // "return a chunk of the xml description file for shared
68 // library load addresses, where the chunk starts at offset 0xfff
69 // and continues for 0x1000 bytes").
70 // Concatenate the resulting server response packets together and
71 // return in response_string. If any packet fails, the return value
72 // indicates that failure and the returned string value is undefined.
73 PacketResult
74 SendPacketsAndConcatenateResponses (const char *send_payload_prefix,
75 std::string &response_string);
76
Greg Clayton576d8832011-03-22 04:00:09 +000077 lldb::StateType
78 SendContinuePacketAndWaitForResponse (ProcessGDBRemote *process,
79 const char *packet_payload,
80 size_t packet_length,
81 StringExtractorGDBRemote &response);
Eugene Zelenkoedb35d92015-10-24 01:08:35 +000082
Ewan Crawford76df2882015-06-23 12:32:06 +000083 bool
84 SendvContPacket (ProcessGDBRemote *process,
85 const char *payload,
86 size_t packet_length,
87 StringExtractorGDBRemote &response);
Greg Clayton576d8832011-03-22 04:00:09 +000088
Greg Claytonfbb76342013-11-20 21:07:01 +000089 bool
Tamas Berghammer30b8cd32015-03-23 15:50:03 +000090 GetThreadSuffixSupported () override;
Greg Clayton576d8832011-03-22 04:00:09 +000091
Greg Claytonfb909312013-11-23 01:58:15 +000092 // This packet is usually sent first and the boolean return value
93 // indicates if the packet was send and any response was received
94 // even in the response is UNIMPLEMENTED. If the packet failed to
95 // get a response, then false is returned. This quickly tells us
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +000096 // if we were able to connect and communicate with the remote GDB
Greg Claytonfb909312013-11-23 01:58:15 +000097 // server
98 bool
Greg Clayton1cb64962011-03-24 04:28:38 +000099 QueryNoAckModeSupported ();
Greg Clayton576d8832011-03-22 04:00:09 +0000100
Greg Clayton44633992012-04-10 03:22:03 +0000101 void
102 GetListThreadsInStopReplySupported ();
103
Greg Clayton576d8832011-03-22 04:00:09 +0000104 bool
105 SendAsyncSignal (int signo);
106
107 bool
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000108 SendInterrupt (Mutex::Locker &locker,
Greg Clayton576d8832011-03-22 04:00:09 +0000109 uint32_t seconds_to_wait_for_stop,
Greg Clayton576d8832011-03-22 04:00:09 +0000110 bool &timed_out);
111
112 lldb::pid_t
Oleksiy Vyalov1ef7b2c2015-02-04 23:19:15 +0000113 GetCurrentProcessID (bool allow_lazy = true);
Greg Clayton576d8832011-03-22 04:00:09 +0000114
115 bool
116 GetLaunchSuccess (std::string &error_str);
117
Oleksiy Vyalov9fe526c2015-10-21 19:34:26 +0000118 bool
119 LaunchGDBServer (const char *remote_accept_hostname,
120 lldb::pid_t &pid,
121 uint16_t &port,
122 std::string &socket_name);
Tamas Berghammerccd6cff2015-12-08 14:08:19 +0000123
124 size_t
125 QueryGDBServer (std::vector<std::pair<uint16_t, std::string>>& connection_urls);
126
Daniel Maleae0f8f572013-08-26 23:57:52 +0000127 bool
128 KillSpawnedProcess (lldb::pid_t pid);
Greg Clayton8b82f082011-04-12 05:54:46 +0000129
Greg Clayton576d8832011-03-22 04:00:09 +0000130 //------------------------------------------------------------------
131 /// Sends a GDB remote protocol 'A' packet that delivers program
132 /// arguments to the remote server.
133 ///
134 /// @param[in] argv
135 /// A NULL terminated array of const C strings to use as the
136 /// arguments.
137 ///
138 /// @return
139 /// Zero if the response was "OK", a positive value if the
140 /// the response was "Exx" where xx are two hex digits, or
141 /// -1 if the call is unsupported or any other unexpected
142 /// response was received.
143 //------------------------------------------------------------------
144 int
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000145 SendArgumentsPacket (const ProcessLaunchInfo &launch_info);
Greg Clayton576d8832011-03-22 04:00:09 +0000146
147 //------------------------------------------------------------------
148 /// Sends a "QEnvironment:NAME=VALUE" packet that will build up the
149 /// environment that will get used when launching an application
150 /// in conjunction with the 'A' packet. This function can be called
151 /// multiple times in a row in order to pass on the desired
152 /// environment that the inferior should be launched with.
153 ///
154 /// @param[in] name_equal_value
155 /// A NULL terminated C string that contains a single environment
156 /// in the format "NAME=VALUE".
157 ///
158 /// @return
159 /// Zero if the response was "OK", a positive value if the
160 /// the response was "Exx" where xx are two hex digits, or
161 /// -1 if the call is unsupported or any other unexpected
162 /// response was received.
163 //------------------------------------------------------------------
164 int
165 SendEnvironmentPacket (char const *name_equal_value);
166
Greg Claytonc4103b32011-05-08 04:53:50 +0000167 int
168 SendLaunchArchPacket (const char *arch);
Jason Molendaa3329782014-03-29 18:54:20 +0000169
170 int
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000171 SendLaunchEventDataPacket(const char *data, bool *was_supported = nullptr);
Jason Molendaa3329782014-03-29 18:54:20 +0000172
Greg Clayton576d8832011-03-22 04:00:09 +0000173 //------------------------------------------------------------------
174 /// Sends a "vAttach:PID" where PID is in hex.
175 ///
176 /// @param[in] pid
177 /// A process ID for the remote gdb server to attach to.
178 ///
179 /// @param[out] response
180 /// The response received from the gdb server. If the return
181 /// value is zero, \a response will contain a stop reply
182 /// packet.
183 ///
184 /// @return
185 /// Zero if the attach was successful, or an error indicating
186 /// an error code.
187 //------------------------------------------------------------------
188 int
189 SendAttach (lldb::pid_t pid,
190 StringExtractorGDBRemote& response);
191
Greg Clayton576d8832011-03-22 04:00:09 +0000192 //------------------------------------------------------------------
Vince Harrone0be4252015-02-06 18:32:57 +0000193 /// Sends a GDB remote protocol 'I' packet that delivers stdin
194 /// data to the remote process.
195 ///
196 /// @param[in] data
197 /// A pointer to stdin data.
198 ///
199 /// @param[in] data_len
200 /// The number of bytes available at \a data.
201 ///
202 /// @return
203 /// Zero if the attach was successful, or an error indicating
204 /// an error code.
205 //------------------------------------------------------------------
206 int
207 SendStdinNotification(const char* data, size_t data_len);
208
209 //------------------------------------------------------------------
Greg Clayton576d8832011-03-22 04:00:09 +0000210 /// Sets the path to use for stdin/out/err for a process
211 /// that will be launched with the 'A' packet.
212 ///
213 /// @param[in] path
214 /// The path to use for stdin/out/err
215 ///
216 /// @return
217 /// Zero if the for success, or an error code for failure.
218 //------------------------------------------------------------------
219 int
Chaoren Lind3173f32015-05-29 19:52:29 +0000220 SetSTDIN(const FileSpec &file_spec);
Greg Clayton576d8832011-03-22 04:00:09 +0000221 int
Chaoren Lind3173f32015-05-29 19:52:29 +0000222 SetSTDOUT(const FileSpec &file_spec);
Greg Clayton576d8832011-03-22 04:00:09 +0000223 int
Chaoren Lind3173f32015-05-29 19:52:29 +0000224 SetSTDERR(const FileSpec &file_spec);
Greg Clayton576d8832011-03-22 04:00:09 +0000225
226 //------------------------------------------------------------------
227 /// Sets the disable ASLR flag to \a enable for a process that will
228 /// be launched with the 'A' packet.
229 ///
230 /// @param[in] enable
Jim Ingham106d0282014-06-25 02:32:56 +0000231 /// A boolean value indicating whether to disable ASLR or not.
Greg Clayton576d8832011-03-22 04:00:09 +0000232 ///
233 /// @return
234 /// Zero if the for success, or an error code for failure.
235 //------------------------------------------------------------------
236 int
237 SetDisableASLR (bool enable);
Jim Ingham106d0282014-06-25 02:32:56 +0000238
239 //------------------------------------------------------------------
240 /// Sets the DetachOnError flag to \a enable for the process controlled by the stub.
241 ///
242 /// @param[in] enable
243 /// A boolean value indicating whether to detach on error or not.
244 ///
245 /// @return
246 /// Zero if the for success, or an error code for failure.
247 //------------------------------------------------------------------
248 int
249 SetDetachOnError (bool enable);
Greg Clayton576d8832011-03-22 04:00:09 +0000250
251 //------------------------------------------------------------------
252 /// Sets the working directory to \a path for a process that will
Greg Claytonfbb76342013-11-20 21:07:01 +0000253 /// be launched with the 'A' packet for non platform based
254 /// connections. If this packet is sent to a GDB server that
255 /// implements the platform, it will change the current working
256 /// directory for the platform process.
Greg Clayton576d8832011-03-22 04:00:09 +0000257 ///
Chaoren Lind3173f32015-05-29 19:52:29 +0000258 /// @param[in] working_dir
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +0000259 /// The path to a directory to use when launching our process
Greg Clayton576d8832011-03-22 04:00:09 +0000260 ///
261 /// @return
262 /// Zero if the for success, or an error code for failure.
263 //------------------------------------------------------------------
264 int
Chaoren Lind3173f32015-05-29 19:52:29 +0000265 SetWorkingDir(const FileSpec &working_dir);
Greg Clayton576d8832011-03-22 04:00:09 +0000266
Greg Claytonfbb76342013-11-20 21:07:01 +0000267 //------------------------------------------------------------------
268 /// Gets the current working directory of a remote platform GDB
269 /// server.
270 ///
Chaoren Lind3173f32015-05-29 19:52:29 +0000271 /// @param[out] working_dir
Greg Claytonfbb76342013-11-20 21:07:01 +0000272 /// The current working directory on the remote platform.
273 ///
274 /// @return
275 /// Boolean for success
276 //------------------------------------------------------------------
277 bool
Chaoren Lind3173f32015-05-29 19:52:29 +0000278 GetWorkingDir(FileSpec &working_dir);
Greg Claytonfbb76342013-11-20 21:07:01 +0000279
Greg Clayton576d8832011-03-22 04:00:09 +0000280 lldb::addr_t
281 AllocateMemory (size_t size, uint32_t permissions);
282
283 bool
284 DeallocateMemory (lldb::addr_t addr);
285
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000286 Error
Jim Inghamacff8952013-05-02 00:27:30 +0000287 Detach (bool keep_stopped);
Greg Clayton37a0a242012-04-11 00:24:49 +0000288
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000289 Error
290 GetMemoryRegionInfo (lldb::addr_t addr, MemoryRegionInfo &range_info);
Greg Clayton46fb5582011-11-18 07:03:08 +0000291
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000292 Error
Johnny Chen64637202012-05-23 21:09:52 +0000293 GetWatchpointSupportInfo (uint32_t &num);
294
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000295 Error
Jaydeep Patil725666c2015-08-13 03:46:01 +0000296 GetWatchpointSupportInfo (uint32_t &num, bool& after, const ArchSpec &arch);
Enrico Granataf04a2192012-07-13 23:18:48 +0000297
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000298 Error
Jaydeep Patil725666c2015-08-13 03:46:01 +0000299 GetWatchpointsTriggerAfterInstruction (bool &after, const ArchSpec &arch);
Enrico Granataf04a2192012-07-13 23:18:48 +0000300
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000301 const ArchSpec &
Greg Clayton576d8832011-03-22 04:00:09 +0000302 GetHostArchitecture ();
Greg Clayton9ac6d2d2013-10-25 18:13:17 +0000303
304 uint32_t
305 GetHostDefaultPacketTimeout();
Jason Molendaf17b5ac2012-12-19 02:54:03 +0000306
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000307 const ArchSpec &
Jason Molendaf17b5ac2012-12-19 02:54:03 +0000308 GetProcessArchitecture ();
309
Steve Pucci5ae54ae2014-01-25 05:46:51 +0000310 void
311 GetRemoteQSupported();
312
Greg Clayton576d8832011-03-22 04:00:09 +0000313 bool
314 GetVContSupported (char flavor);
315
Jim Inghamcd16df92012-07-20 21:37:13 +0000316 bool
Sean Callananb1de1142013-09-04 23:24:15 +0000317 GetpPacketSupported (lldb::tid_t tid);
Hafiz Abid Qadeer9a78cdf2013-08-29 09:09:45 +0000318
319 bool
Jason Molendabdc4f122014-05-06 02:59:39 +0000320 GetxPacketSupported ();
321
322 bool
Jim Inghamcd16df92012-07-20 21:37:13 +0000323 GetVAttachOrWaitSupported ();
324
Jim Ingham279ceec2012-07-25 21:12:43 +0000325 bool
326 GetSyncThreadStateSupported();
327
Greg Clayton576d8832011-03-22 04:00:09 +0000328 void
Greg Clayton2e59d4f2015-06-29 20:08:51 +0000329 ResetDiscoverableSettings (bool did_exec);
Greg Clayton576d8832011-03-22 04:00:09 +0000330
331 bool
Greg Clayton9b1e1cd2011-04-04 18:18:57 +0000332 GetHostInfo (bool force = false);
Ewan Crawford78baa192015-05-13 09:18:18 +0000333
334 bool
335 GetDefaultThreadId (lldb::tid_t &tid);
Greg Clayton576d8832011-03-22 04:00:09 +0000336
337 bool
Greg Clayton1cb64962011-03-24 04:28:38 +0000338 GetOSVersion (uint32_t &major,
339 uint32_t &minor,
340 uint32_t &update);
341
342 bool
343 GetOSBuildString (std::string &s);
344
345 bool
346 GetOSKernelDescription (std::string &s);
347
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000348 ArchSpec
Greg Clayton1cb64962011-03-24 04:28:38 +0000349 GetSystemArchitecture ();
350
351 bool
352 GetHostname (std::string &s);
353
Greg Clayton37a0a242012-04-11 00:24:49 +0000354 lldb::addr_t
355 GetShlibInfoAddr();
356
Greg Clayton1cb64962011-03-24 04:28:38 +0000357 bool
Greg Clayton576d8832011-03-22 04:00:09 +0000358 GetSupportsThreadSuffix ();
359
360 bool
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000361 GetProcessInfo (lldb::pid_t pid, ProcessInstanceInfo &process_info);
Greg Clayton32e0a752011-03-30 18:16:51 +0000362
363 uint32_t
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000364 FindProcesses (const ProcessInstanceInfoMatch &process_match_info,
365 ProcessInstanceInfoList &process_infos);
Greg Clayton32e0a752011-03-30 18:16:51 +0000366
367 bool
368 GetUserName (uint32_t uid, std::string &name);
369
370 bool
371 GetGroupName (uint32_t gid, std::string &name);
372
373 bool
Greg Clayton576d8832011-03-22 04:00:09 +0000374 HasFullVContSupport ()
375 {
376 return GetVContSupported ('A');
377 }
378
379 bool
380 HasAnyVContSupport ()
381 {
382 return GetVContSupported ('a');
383 }
384
Greg Clayton8b82f082011-04-12 05:54:46 +0000385 bool
386 GetStopReply (StringExtractorGDBRemote &response);
387
388 bool
Greg Claytonf402f782012-10-13 02:11:55 +0000389 GetThreadStopInfo (lldb::tid_t tid,
Greg Clayton8b82f082011-04-12 05:54:46 +0000390 StringExtractorGDBRemote &response);
391
392 bool
393 SupportsGDBStoppointPacket (GDBStoppointType type)
394 {
395 switch (type)
396 {
397 case eBreakpointSoftware: return m_supports_z0;
398 case eBreakpointHardware: return m_supports_z1;
399 case eWatchpointWrite: return m_supports_z2;
400 case eWatchpointRead: return m_supports_z3;
401 case eWatchpointReadWrite: return m_supports_z4;
Zachary Turner568b0de2015-02-18 18:44:03 +0000402 default: return false;
Greg Clayton8b82f082011-04-12 05:54:46 +0000403 }
Greg Clayton8b82f082011-04-12 05:54:46 +0000404 }
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000405
Greg Clayton8b82f082011-04-12 05:54:46 +0000406 uint8_t
407 SendGDBStoppointTypePacket (GDBStoppointType type, // Type of breakpoint or watchpoint
408 bool insert, // Insert or remove?
409 lldb::addr_t addr, // Address of breakpoint or watchpoint
410 uint32_t length); // Byte Size of breakpoint or watchpoint
411
Ewan Crawford78baa192015-05-13 09:18:18 +0000412 bool
413 SetNonStopMode (const bool enable);
414
Greg Clayton9b1e1cd2011-04-04 18:18:57 +0000415 void
Greg Claytone034a042015-05-21 20:52:06 +0000416 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 +0000417
418 // This packet is for testing the speed of the interface only. Both
419 // the client and server need to support it, but this allows us to
420 // measure the packet speed without any other work being done on the
421 // other end and avoids any of that work affecting the packet send
422 // and response times.
423 bool
424 SendSpeedTestPacket (uint32_t send_size,
425 uint32_t recv_size);
Greg Clayton8b82f082011-04-12 05:54:46 +0000426
427 bool
Jason Molendae9ca4af2013-02-23 02:04:45 +0000428 SetCurrentThread (uint64_t tid);
Greg Clayton8b82f082011-04-12 05:54:46 +0000429
430 bool
Jason Molendae9ca4af2013-02-23 02:04:45 +0000431 SetCurrentThreadForRun (uint64_t tid);
Greg Clayton8b82f082011-04-12 05:54:46 +0000432
Steve Pucci5ae54ae2014-01-25 05:46:51 +0000433 bool
Steve Pucci03904ac2014-03-04 23:18:46 +0000434 GetQXferAuxvReadSupported ();
435
436 bool
Steve Pucci5ae54ae2014-01-25 05:46:51 +0000437 GetQXferLibrariesReadSupported ();
438
439 bool
440 GetQXferLibrariesSVR4ReadSupported ();
441
442 uint64_t
443 GetRemoteMaxPacketSize();
444
445 bool
Greg Claytonb30c50c2015-05-29 00:01:55 +0000446 GetEchoSupported ();
447
448 bool
Steve Pucci5ae54ae2014-01-25 05:46:51 +0000449 GetAugmentedLibrariesSVR4ReadSupported ();
450
Colin Rileyc3c95b22015-04-16 15:51:33 +0000451 bool
452 GetQXferFeaturesReadSupported ();
453
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000454 LazyBool
Jim Ingham372787f2012-04-07 00:00:41 +0000455 SupportsAllocDeallocMemory () // const
Greg Clayton2a48f522011-05-14 01:50:35 +0000456 {
Jim Ingham372787f2012-04-07 00:00:41 +0000457 // Uncomment this to have lldb pretend the debug server doesn't respond to alloc/dealloc memory packets.
458 // m_supports_alloc_dealloc_memory = lldb_private::eLazyBoolNo;
Greg Clayton70b57652011-05-15 01:25:55 +0000459 return m_supports_alloc_dealloc_memory;
Greg Clayton2a48f522011-05-14 01:50:35 +0000460 }
461
Greg Claytonadc00cb2011-05-20 23:38:13 +0000462 size_t
463 GetCurrentThreadIDs (std::vector<lldb::tid_t> &thread_ids,
464 bool &sequence_mutex_unavailable);
465
Greg Clayton2687cd12012-03-29 01:55:41 +0000466 bool
467 GetInterruptWasSent () const
468 {
469 return m_interrupt_sent;
470 }
Han Ming Ong4b6459f2013-01-18 23:11:53 +0000471
Greg Claytonfbb76342013-11-20 21:07:01 +0000472 lldb::user_id_t
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000473 OpenFile (const FileSpec& file_spec, uint32_t flags, mode_t mode, Error &error);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000474
Greg Claytonfbb76342013-11-20 21:07:01 +0000475 bool
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000476 CloseFile (lldb::user_id_t fd, Error &error);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000477
Greg Claytonfbb76342013-11-20 21:07:01 +0000478 lldb::user_id_t
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000479 GetFileSize (const FileSpec& file_spec);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000480
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000481 Error
Chaoren Lind3173f32015-05-29 19:52:29 +0000482 GetFilePermissions(const FileSpec &file_spec, uint32_t &file_permissions);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000483
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000484 Error
Chaoren Lind3173f32015-05-29 19:52:29 +0000485 SetFilePermissions(const FileSpec &file_spec, uint32_t file_permissions);
Greg Claytonfbb76342013-11-20 21:07:01 +0000486
487 uint64_t
Daniel Maleae0f8f572013-08-26 23:57:52 +0000488 ReadFile (lldb::user_id_t fd,
489 uint64_t offset,
490 void *dst,
491 uint64_t dst_len,
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000492 Error &error);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000493
Greg Claytonfbb76342013-11-20 21:07:01 +0000494 uint64_t
Daniel Maleae0f8f572013-08-26 23:57:52 +0000495 WriteFile (lldb::user_id_t fd,
496 uint64_t offset,
497 const void* src,
498 uint64_t src_len,
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000499 Error &error);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000500
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000501 Error
Chaoren Lind3173f32015-05-29 19:52:29 +0000502 CreateSymlink(const FileSpec &src,
503 const FileSpec &dst);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000504
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000505 Error
Chaoren Lind3173f32015-05-29 19:52:29 +0000506 Unlink(const FileSpec &file_spec);
Greg Claytonfbb76342013-11-20 21:07:01 +0000507
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000508 Error
Chaoren Lind3173f32015-05-29 19:52:29 +0000509 MakeDirectory(const FileSpec &file_spec, uint32_t mode);
510
Greg Claytonfbb76342013-11-20 21:07:01 +0000511 bool
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000512 GetFileExists (const FileSpec& file_spec);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000513
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000514 Error
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000515 RunShellCommand(const char *command, // Shouldn't be nullptr
Chaoren Lind3173f32015-05-29 19:52:29 +0000516 const FileSpec &working_dir, // Pass empty FileSpec to use the current working directory
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000517 int *status_ptr, // Pass nullptr if you don't want the process exit status
518 int *signo_ptr, // Pass nullptr if you don't want the signal that caused the process to exit
519 std::string *command_output, // Pass nullptr if you don't want the command output
Chaoren Lind3173f32015-05-29 19:52:29 +0000520 uint32_t timeout_sec); // Timeout in seconds to wait for shell program to finish
521
Greg Claytonfbb76342013-11-20 21:07:01 +0000522 bool
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000523 CalculateMD5 (const FileSpec& file_spec, uint64_t &high, uint64_t &low);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000524
Han Ming Ong4b6459f2013-01-18 23:11:53 +0000525 std::string
526 HarmonizeThreadIdsForProfileData (ProcessGDBRemote *process,
527 StringExtractorGDBRemote &inputStringExtractor);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000528
Greg Claytonf74cf862013-11-13 23:28:31 +0000529 bool
530 ReadRegister(lldb::tid_t tid,
Francis Ricci39f11892016-04-25 20:59:11 +0000531 uint32_t reg_num, // Must be the eRegisterKindProcessPlugin register number, to be sent to the remote
Greg Claytonf74cf862013-11-13 23:28:31 +0000532 StringExtractorGDBRemote &response);
533
534 bool
535 ReadAllRegisters (lldb::tid_t tid,
536 StringExtractorGDBRemote &response);
537
538 bool
539 SaveRegisterState (lldb::tid_t tid, uint32_t &save_id);
540
541 bool
542 RestoreRegisterState (lldb::tid_t tid, uint32_t save_id);
Jason Molendaa3329782014-03-29 18:54:20 +0000543
544 const char *
545 GetGDBServerProgramName();
Greg Claytonf74cf862013-11-13 23:28:31 +0000546
Jason Molendaa3329782014-03-29 18:54:20 +0000547 uint32_t
548 GetGDBServerProgramVersion();
549
550 bool
551 AvoidGPackets(ProcessGDBRemote *process);
552
Greg Clayton358cf1e2015-06-25 21:46:34 +0000553 StructuredData::ObjectSP
554 GetThreadsInfo();
555
Jason Molenda705b1802014-06-13 02:37:02 +0000556 bool
557 GetThreadExtendedInfoSupported();
558
Oleksiy Vyalov6801be32015-02-25 22:15:44 +0000559 bool
Jason Molenda20ee21b2015-07-10 23:15:22 +0000560 GetLoadedDynamicLibrariesInfosSupported();
561
562 bool
Jason Molenda37397352016-07-22 00:17:55 +0000563 GetSharedCacheInfoSupported();
564
565 bool
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000566 GetModuleInfo (const FileSpec& module_file_spec,
567 const ArchSpec& arch_spec,
568 ModuleSpec &module_spec);
Oleksiy Vyalov6801be32015-02-25 22:15:44 +0000569
Colin Rileyc3c95b22015-04-16 15:51:33 +0000570 bool
571 ReadExtFeature (const lldb_private::ConstString object,
572 const lldb_private::ConstString annex,
573 std::string & out,
574 lldb_private::Error & err);
575
Greg Clayton0b90be12015-06-23 21:27:50 +0000576 void
577 ServeSymbolLookups(lldb_private::Process *process);
578
Greg Clayton576d8832011-03-22 04:00:09 +0000579protected:
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000580 LazyBool m_supports_not_sending_acks;
581 LazyBool m_supports_thread_suffix;
582 LazyBool m_supports_threads_in_stop_reply;
583 LazyBool m_supports_vCont_all;
584 LazyBool m_supports_vCont_any;
585 LazyBool m_supports_vCont_c;
586 LazyBool m_supports_vCont_C;
587 LazyBool m_supports_vCont_s;
588 LazyBool m_supports_vCont_S;
589 LazyBool m_qHostInfo_is_valid;
590 LazyBool m_curr_pid_is_valid;
591 LazyBool m_qProcessInfo_is_valid;
592 LazyBool m_qGDBServerVersion_is_valid;
593 LazyBool m_supports_alloc_dealloc_memory;
594 LazyBool m_supports_memory_region_info;
595 LazyBool m_supports_watchpoint_support_info;
596 LazyBool m_supports_detach_stay_stopped;
597 LazyBool m_watchpoints_trigger_after_instruction;
598 LazyBool m_attach_or_wait_reply;
599 LazyBool m_prepare_for_reg_writing_reply;
600 LazyBool m_supports_p;
601 LazyBool m_supports_x;
602 LazyBool m_avoid_g_packets;
603 LazyBool m_supports_QSaveRegisterState;
604 LazyBool m_supports_qXfer_auxv_read;
605 LazyBool m_supports_qXfer_libraries_read;
606 LazyBool m_supports_qXfer_libraries_svr4_read;
Colin Rileyc3c95b22015-04-16 15:51:33 +0000607 LazyBool m_supports_qXfer_features_read;
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000608 LazyBool m_supports_augmented_libraries_svr4_read;
609 LazyBool m_supports_jThreadExtendedInfo;
Jason Molenda20ee21b2015-07-10 23:15:22 +0000610 LazyBool m_supports_jLoadedDynamicLibrariesInfos;
Jason Molenda37397352016-07-22 00:17:55 +0000611 LazyBool m_supports_jGetSharedCacheInfo;
Steve Pucci5ae54ae2014-01-25 05:46:51 +0000612
Greg Clayton8b82f082011-04-12 05:54:46 +0000613 bool
614 m_supports_qProcessInfoPID:1,
615 m_supports_qfProcessInfo:1,
616 m_supports_qUserName:1,
617 m_supports_qGroupName:1,
618 m_supports_qThreadStopInfo:1,
619 m_supports_z0:1,
620 m_supports_z1:1,
621 m_supports_z2:1,
622 m_supports_z3:1,
Greg Clayton89600582013-10-10 17:53:50 +0000623 m_supports_z4:1,
624 m_supports_QEnvironment:1,
Greg Clayton0b90be12015-06-23 21:27:50 +0000625 m_supports_QEnvironmentHexEncoded:1,
Greg Clayton358cf1e2015-06-25 21:46:34 +0000626 m_supports_qSymbol:1,
Jason Molenda50018d32016-01-13 04:08:10 +0000627 m_qSymbol_requests_done:1,
Stephane Sezer6f455292016-01-08 00:00:17 +0000628 m_supports_qModuleInfo:1,
Greg Clayton358cf1e2015-06-25 21:46:34 +0000629 m_supports_jThreadsInfo:1;
Greg Clayton2a48f522011-05-14 01:50:35 +0000630
Todd Fiala9f72b3a2014-05-07 19:28:21 +0000631 lldb::pid_t m_curr_pid;
Greg Clayton8b82f082011-04-12 05:54:46 +0000632 lldb::tid_t m_curr_tid; // Current gdb remote protocol thread index for all other operations
633 lldb::tid_t m_curr_tid_run; // Current gdb remote protocol thread index for continue, step, etc
634
Johnny Chen64637202012-05-23 21:09:52 +0000635 uint32_t m_num_supported_hardware_watchpoints;
636
Greg Clayton576d8832011-03-22 04:00:09 +0000637 // If we need to send a packet while the target is running, the m_async_XXX
638 // member variables take care of making this happen.
Saleem Abdulrasool16ff8602016-05-18 01:59:10 +0000639 std::recursive_mutex m_async_mutex;
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000640 Predicate<bool> m_async_packet_predicate;
Greg Clayton576d8832011-03-22 04:00:09 +0000641 std::string m_async_packet;
Jim Inghama6195b72013-12-18 01:24:33 +0000642 PacketResult m_async_result;
Greg Clayton576d8832011-03-22 04:00:09 +0000643 StringExtractorGDBRemote m_async_response;
644 int m_async_signal; // We were asked to deliver a signal to the inferior process.
Greg Clayton2687cd12012-03-29 01:55:41 +0000645 bool m_interrupt_sent;
Han Ming Ong4b6459f2013-01-18 23:11:53 +0000646 std::string m_partial_profile_data;
647 std::map<uint64_t, uint32_t> m_thread_id_to_used_usec_map;
Greg Clayton576d8832011-03-22 04:00:09 +0000648
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000649 ArchSpec m_host_arch;
650 ArchSpec m_process_arch;
Greg Clayton1cb64962011-03-24 04:28:38 +0000651 uint32_t m_os_version_major;
652 uint32_t m_os_version_minor;
653 uint32_t m_os_version_update;
654 std::string m_os_build;
655 std::string m_os_kernel;
656 std::string m_hostname;
Jason Molendaa3329782014-03-29 18:54:20 +0000657 std::string m_gdb_server_name; // from reply to qGDBServerVersion, empty if qGDBServerVersion is not supported
658 uint32_t m_gdb_server_version; // from reply to qGDBServerVersion, zero if qGDBServerVersion is not supported
Greg Clayton9ac6d2d2013-10-25 18:13:17 +0000659 uint32_t m_default_packet_timeout;
Steve Pucci5ae54ae2014-01-25 05:46:51 +0000660 uint64_t m_max_packet_size; // as returned by qSupported
Jason Molenda91ffe0a2015-06-18 21:46:06 +0000661
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000662 PacketResult
663 SendPacketAndWaitForResponseNoLock (const char *payload,
664 size_t payload_length,
665 StringExtractorGDBRemote &response);
666
667 bool
668 GetCurrentProcessInfo (bool allow_lazy_pid = true);
669
670 bool
671 GetGDBServerVersion();
672
673 // Given the list of compression types that the remote debug stub can support,
674 // possibly enable compression if we find an encoding we can handle.
675 void
676 MaybeEnableCompression (std::vector<std::string> supported_compressions);
677
Greg Clayton32e0a752011-03-30 18:16:51 +0000678 bool
679 DecodeProcessInfoResponse (StringExtractorGDBRemote &response,
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000680 ProcessInstanceInfo &process_info);
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000681
Greg Clayton576d8832011-03-22 04:00:09 +0000682private:
Greg Clayton576d8832011-03-22 04:00:09 +0000683 DISALLOW_COPY_AND_ASSIGN (GDBRemoteCommunicationClient);
684};
685
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000686} // namespace process_gdb_remote
687} // namespace lldb_private
688
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000689#endif // liblldb_GDBRemoteCommunicationClient_h_