blob: eeeecb53992cf6d5ec1984d409cb4b9c96ae74c4 [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
Greg Claytonfbb76342013-11-20 21:07:01 +000067 bool
Pavel Labath5a123c42016-08-16 09:36:29 +000068 GetThreadSuffixSupported();
Greg Clayton576d8832011-03-22 04:00:09 +000069
Greg Claytonfb909312013-11-23 01:58:15 +000070 // This packet is usually sent first and the boolean return value
71 // indicates if the packet was send and any response was received
72 // even in the response is UNIMPLEMENTED. If the packet failed to
73 // get a response, then false is returned. This quickly tells us
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +000074 // if we were able to connect and communicate with the remote GDB
Greg Claytonfb909312013-11-23 01:58:15 +000075 // server
76 bool
Greg Clayton1cb64962011-03-24 04:28:38 +000077 QueryNoAckModeSupported ();
Greg Clayton576d8832011-03-22 04:00:09 +000078
Greg Clayton44633992012-04-10 03:22:03 +000079 void
80 GetListThreadsInStopReplySupported ();
81
Greg Clayton576d8832011-03-22 04:00:09 +000082 lldb::pid_t
Oleksiy Vyalov1ef7b2c2015-02-04 23:19:15 +000083 GetCurrentProcessID (bool allow_lazy = true);
Greg Clayton576d8832011-03-22 04:00:09 +000084
85 bool
86 GetLaunchSuccess (std::string &error_str);
87
Oleksiy Vyalov9fe526c2015-10-21 19:34:26 +000088 bool
89 LaunchGDBServer (const char *remote_accept_hostname,
90 lldb::pid_t &pid,
91 uint16_t &port,
92 std::string &socket_name);
Tamas Berghammerccd6cff2015-12-08 14:08:19 +000093
94 size_t
95 QueryGDBServer (std::vector<std::pair<uint16_t, std::string>>& connection_urls);
96
Daniel Maleae0f8f572013-08-26 23:57:52 +000097 bool
98 KillSpawnedProcess (lldb::pid_t pid);
Greg Clayton8b82f082011-04-12 05:54:46 +000099
Greg Clayton576d8832011-03-22 04:00:09 +0000100 //------------------------------------------------------------------
101 /// Sends a GDB remote protocol 'A' packet that delivers program
102 /// arguments to the remote server.
103 ///
104 /// @param[in] argv
105 /// A NULL terminated array of const C strings to use as the
106 /// arguments.
107 ///
108 /// @return
109 /// Zero if the response was "OK", a positive value if the
110 /// the response was "Exx" where xx are two hex digits, or
111 /// -1 if the call is unsupported or any other unexpected
112 /// response was received.
113 //------------------------------------------------------------------
114 int
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000115 SendArgumentsPacket (const ProcessLaunchInfo &launch_info);
Greg Clayton576d8832011-03-22 04:00:09 +0000116
117 //------------------------------------------------------------------
118 /// Sends a "QEnvironment:NAME=VALUE" packet that will build up the
119 /// environment that will get used when launching an application
120 /// in conjunction with the 'A' packet. This function can be called
121 /// multiple times in a row in order to pass on the desired
122 /// environment that the inferior should be launched with.
123 ///
124 /// @param[in] name_equal_value
125 /// A NULL terminated C string that contains a single environment
126 /// in the format "NAME=VALUE".
127 ///
128 /// @return
129 /// Zero if the response was "OK", a positive value if the
130 /// the response was "Exx" where xx are two hex digits, or
131 /// -1 if the call is unsupported or any other unexpected
132 /// response was received.
133 //------------------------------------------------------------------
134 int
135 SendEnvironmentPacket (char const *name_equal_value);
136
Greg Claytonc4103b32011-05-08 04:53:50 +0000137 int
138 SendLaunchArchPacket (const char *arch);
Jason Molendaa3329782014-03-29 18:54:20 +0000139
140 int
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000141 SendLaunchEventDataPacket(const char *data, bool *was_supported = nullptr);
Jason Molendaa3329782014-03-29 18:54:20 +0000142
Greg Clayton576d8832011-03-22 04:00:09 +0000143 //------------------------------------------------------------------
144 /// Sends a "vAttach:PID" where PID is in hex.
145 ///
146 /// @param[in] pid
147 /// A process ID for the remote gdb server to attach to.
148 ///
149 /// @param[out] response
150 /// The response received from the gdb server. If the return
151 /// value is zero, \a response will contain a stop reply
152 /// packet.
153 ///
154 /// @return
155 /// Zero if the attach was successful, or an error indicating
156 /// an error code.
157 //------------------------------------------------------------------
158 int
159 SendAttach (lldb::pid_t pid,
160 StringExtractorGDBRemote& response);
161
Greg Clayton576d8832011-03-22 04:00:09 +0000162 //------------------------------------------------------------------
Vince Harrone0be4252015-02-06 18:32:57 +0000163 /// Sends a GDB remote protocol 'I' packet that delivers stdin
164 /// data to the remote process.
165 ///
166 /// @param[in] data
167 /// A pointer to stdin data.
168 ///
169 /// @param[in] data_len
170 /// The number of bytes available at \a data.
171 ///
172 /// @return
173 /// Zero if the attach was successful, or an error indicating
174 /// an error code.
175 //------------------------------------------------------------------
176 int
177 SendStdinNotification(const char* data, size_t data_len);
178
179 //------------------------------------------------------------------
Greg Clayton576d8832011-03-22 04:00:09 +0000180 /// Sets the path to use for stdin/out/err for a process
181 /// that will be launched with the 'A' packet.
182 ///
183 /// @param[in] path
184 /// The path to use for stdin/out/err
185 ///
186 /// @return
187 /// Zero if the for success, or an error code for failure.
188 //------------------------------------------------------------------
189 int
Chaoren Lind3173f32015-05-29 19:52:29 +0000190 SetSTDIN(const FileSpec &file_spec);
Greg Clayton576d8832011-03-22 04:00:09 +0000191 int
Chaoren Lind3173f32015-05-29 19:52:29 +0000192 SetSTDOUT(const FileSpec &file_spec);
Greg Clayton576d8832011-03-22 04:00:09 +0000193 int
Chaoren Lind3173f32015-05-29 19:52:29 +0000194 SetSTDERR(const FileSpec &file_spec);
Greg Clayton576d8832011-03-22 04:00:09 +0000195
196 //------------------------------------------------------------------
197 /// Sets the disable ASLR flag to \a enable for a process that will
198 /// be launched with the 'A' packet.
199 ///
200 /// @param[in] enable
Jim Ingham106d0282014-06-25 02:32:56 +0000201 /// A boolean value indicating whether to disable ASLR or not.
Greg Clayton576d8832011-03-22 04:00:09 +0000202 ///
203 /// @return
204 /// Zero if the for success, or an error code for failure.
205 //------------------------------------------------------------------
206 int
207 SetDisableASLR (bool enable);
Jim Ingham106d0282014-06-25 02:32:56 +0000208
209 //------------------------------------------------------------------
210 /// Sets the DetachOnError flag to \a enable for the process controlled by the stub.
211 ///
212 /// @param[in] enable
213 /// A boolean value indicating whether to detach on error or not.
214 ///
215 /// @return
216 /// Zero if the for success, or an error code for failure.
217 //------------------------------------------------------------------
218 int
219 SetDetachOnError (bool enable);
Greg Clayton576d8832011-03-22 04:00:09 +0000220
221 //------------------------------------------------------------------
222 /// Sets the working directory to \a path for a process that will
Greg Claytonfbb76342013-11-20 21:07:01 +0000223 /// be launched with the 'A' packet for non platform based
224 /// connections. If this packet is sent to a GDB server that
225 /// implements the platform, it will change the current working
226 /// directory for the platform process.
Greg Clayton576d8832011-03-22 04:00:09 +0000227 ///
Chaoren Lind3173f32015-05-29 19:52:29 +0000228 /// @param[in] working_dir
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +0000229 /// The path to a directory to use when launching our process
Greg Clayton576d8832011-03-22 04:00:09 +0000230 ///
231 /// @return
232 /// Zero if the for success, or an error code for failure.
233 //------------------------------------------------------------------
234 int
Chaoren Lind3173f32015-05-29 19:52:29 +0000235 SetWorkingDir(const FileSpec &working_dir);
Greg Clayton576d8832011-03-22 04:00:09 +0000236
Greg Claytonfbb76342013-11-20 21:07:01 +0000237 //------------------------------------------------------------------
238 /// Gets the current working directory of a remote platform GDB
239 /// server.
240 ///
Chaoren Lind3173f32015-05-29 19:52:29 +0000241 /// @param[out] working_dir
Greg Claytonfbb76342013-11-20 21:07:01 +0000242 /// The current working directory on the remote platform.
243 ///
244 /// @return
245 /// Boolean for success
246 //------------------------------------------------------------------
247 bool
Chaoren Lind3173f32015-05-29 19:52:29 +0000248 GetWorkingDir(FileSpec &working_dir);
Greg Claytonfbb76342013-11-20 21:07:01 +0000249
Greg Clayton576d8832011-03-22 04:00:09 +0000250 lldb::addr_t
251 AllocateMemory (size_t size, uint32_t permissions);
252
253 bool
254 DeallocateMemory (lldb::addr_t addr);
255
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000256 Error
Jim Inghamacff8952013-05-02 00:27:30 +0000257 Detach (bool keep_stopped);
Greg Clayton37a0a242012-04-11 00:24:49 +0000258
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000259 Error
260 GetMemoryRegionInfo (lldb::addr_t addr, MemoryRegionInfo &range_info);
Greg Clayton46fb5582011-11-18 07:03:08 +0000261
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000262 Error
Johnny Chen64637202012-05-23 21:09:52 +0000263 GetWatchpointSupportInfo (uint32_t &num);
264
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000265 Error
Jaydeep Patil725666c2015-08-13 03:46:01 +0000266 GetWatchpointSupportInfo (uint32_t &num, bool& after, const ArchSpec &arch);
Enrico Granataf04a2192012-07-13 23:18:48 +0000267
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000268 Error
Jaydeep Patil725666c2015-08-13 03:46:01 +0000269 GetWatchpointsTriggerAfterInstruction (bool &after, const ArchSpec &arch);
Enrico Granataf04a2192012-07-13 23:18:48 +0000270
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000271 const ArchSpec &
Greg Clayton576d8832011-03-22 04:00:09 +0000272 GetHostArchitecture ();
Greg Clayton9ac6d2d2013-10-25 18:13:17 +0000273
274 uint32_t
275 GetHostDefaultPacketTimeout();
Jason Molendaf17b5ac2012-12-19 02:54:03 +0000276
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000277 const ArchSpec &
Jason Molendaf17b5ac2012-12-19 02:54:03 +0000278 GetProcessArchitecture ();
279
Steve Pucci5ae54ae2014-01-25 05:46:51 +0000280 void
281 GetRemoteQSupported();
282
Greg Clayton576d8832011-03-22 04:00:09 +0000283 bool
284 GetVContSupported (char flavor);
285
Jim Inghamcd16df92012-07-20 21:37:13 +0000286 bool
Sean Callananb1de1142013-09-04 23:24:15 +0000287 GetpPacketSupported (lldb::tid_t tid);
Hafiz Abid Qadeer9a78cdf2013-08-29 09:09:45 +0000288
289 bool
Jason Molendabdc4f122014-05-06 02:59:39 +0000290 GetxPacketSupported ();
291
292 bool
Jim Inghamcd16df92012-07-20 21:37:13 +0000293 GetVAttachOrWaitSupported ();
294
Jim Ingham279ceec2012-07-25 21:12:43 +0000295 bool
296 GetSyncThreadStateSupported();
297
Greg Clayton576d8832011-03-22 04:00:09 +0000298 void
Greg Clayton2e59d4f2015-06-29 20:08:51 +0000299 ResetDiscoverableSettings (bool did_exec);
Greg Clayton576d8832011-03-22 04:00:09 +0000300
301 bool
Greg Clayton9b1e1cd2011-04-04 18:18:57 +0000302 GetHostInfo (bool force = false);
Ewan Crawford78baa192015-05-13 09:18:18 +0000303
304 bool
305 GetDefaultThreadId (lldb::tid_t &tid);
Greg Clayton576d8832011-03-22 04:00:09 +0000306
307 bool
Greg Clayton1cb64962011-03-24 04:28:38 +0000308 GetOSVersion (uint32_t &major,
309 uint32_t &minor,
310 uint32_t &update);
311
312 bool
313 GetOSBuildString (std::string &s);
314
315 bool
316 GetOSKernelDescription (std::string &s);
317
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000318 ArchSpec
Greg Clayton1cb64962011-03-24 04:28:38 +0000319 GetSystemArchitecture ();
320
321 bool
322 GetHostname (std::string &s);
323
Greg Clayton37a0a242012-04-11 00:24:49 +0000324 lldb::addr_t
325 GetShlibInfoAddr();
326
Greg Clayton1cb64962011-03-24 04:28:38 +0000327 bool
Greg Clayton576d8832011-03-22 04:00:09 +0000328 GetSupportsThreadSuffix ();
329
330 bool
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000331 GetProcessInfo (lldb::pid_t pid, ProcessInstanceInfo &process_info);
Greg Clayton32e0a752011-03-30 18:16:51 +0000332
333 uint32_t
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000334 FindProcesses (const ProcessInstanceInfoMatch &process_match_info,
335 ProcessInstanceInfoList &process_infos);
Greg Clayton32e0a752011-03-30 18:16:51 +0000336
337 bool
338 GetUserName (uint32_t uid, std::string &name);
339
340 bool
341 GetGroupName (uint32_t gid, std::string &name);
342
343 bool
Greg Clayton576d8832011-03-22 04:00:09 +0000344 HasFullVContSupport ()
345 {
346 return GetVContSupported ('A');
347 }
348
349 bool
350 HasAnyVContSupport ()
351 {
352 return GetVContSupported ('a');
353 }
354
Greg Clayton8b82f082011-04-12 05:54:46 +0000355 bool
356 GetStopReply (StringExtractorGDBRemote &response);
357
358 bool
Greg Claytonf402f782012-10-13 02:11:55 +0000359 GetThreadStopInfo (lldb::tid_t tid,
Greg Clayton8b82f082011-04-12 05:54:46 +0000360 StringExtractorGDBRemote &response);
361
362 bool
363 SupportsGDBStoppointPacket (GDBStoppointType type)
364 {
365 switch (type)
366 {
367 case eBreakpointSoftware: return m_supports_z0;
368 case eBreakpointHardware: return m_supports_z1;
369 case eWatchpointWrite: return m_supports_z2;
370 case eWatchpointRead: return m_supports_z3;
371 case eWatchpointReadWrite: return m_supports_z4;
Zachary Turner568b0de2015-02-18 18:44:03 +0000372 default: return false;
Greg Clayton8b82f082011-04-12 05:54:46 +0000373 }
Greg Clayton8b82f082011-04-12 05:54:46 +0000374 }
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000375
Greg Clayton8b82f082011-04-12 05:54:46 +0000376 uint8_t
377 SendGDBStoppointTypePacket (GDBStoppointType type, // Type of breakpoint or watchpoint
378 bool insert, // Insert or remove?
379 lldb::addr_t addr, // Address of breakpoint or watchpoint
380 uint32_t length); // Byte Size of breakpoint or watchpoint
381
Ewan Crawford78baa192015-05-13 09:18:18 +0000382 bool
383 SetNonStopMode (const bool enable);
384
Greg Clayton9b1e1cd2011-04-04 18:18:57 +0000385 void
Greg Claytone034a042015-05-21 20:52:06 +0000386 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 +0000387
388 // This packet is for testing the speed of the interface only. Both
389 // the client and server need to support it, but this allows us to
390 // measure the packet speed without any other work being done on the
391 // other end and avoids any of that work affecting the packet send
392 // and response times.
393 bool
394 SendSpeedTestPacket (uint32_t send_size,
395 uint32_t recv_size);
Greg Clayton8b82f082011-04-12 05:54:46 +0000396
397 bool
Pavel Labath5c95ee42016-08-30 13:56:11 +0000398 SetCurrentThread (uint64_t tid);
399
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 Labath5c95ee42016-08-30 13:56:11 +0000491 uint32_t reg_num); // Must be the eRegisterKindProcessPlugin register number
Greg Claytonf74cf862013-11-13 23:28:31 +0000492
Pavel Labathb42b48e2016-08-19 12:31:49 +0000493 lldb::DataBufferSP
Pavel Labath5c95ee42016-08-30 13:56:11 +0000494 ReadAllRegisters(lldb::tid_t tid);
Greg Claytonf74cf862013-11-13 23:28:31 +0000495
496 bool
Pavel Labath56d72622016-08-17 08:53:31 +0000497 WriteRegister(lldb::tid_t tid, uint32_t reg_num, // eRegisterKindProcessPlugin register number
Pavel Labath5c95ee42016-08-30 13:56:11 +0000498 llvm::ArrayRef<uint8_t> data);
Pavel Labath56d72622016-08-17 08:53:31 +0000499
500 bool
Pavel Labath5c95ee42016-08-30 13:56:11 +0000501 WriteAllRegisters(lldb::tid_t tid, llvm::ArrayRef<uint8_t> data);
Pavel Labath56d72622016-08-17 08:53:31 +0000502
503 bool
504 SaveRegisterState(lldb::tid_t tid, uint32_t &save_id);
505
Greg Claytonf74cf862013-11-13 23:28:31 +0000506 bool
507 RestoreRegisterState (lldb::tid_t tid, uint32_t save_id);
Jason Molendaa3329782014-03-29 18:54:20 +0000508
Pavel Labath27402d22016-08-18 12:32:41 +0000509 bool
510 SyncThreadState(lldb::tid_t tid);
511
Jason Molendaa3329782014-03-29 18:54:20 +0000512 const char *
513 GetGDBServerProgramName();
Greg Claytonf74cf862013-11-13 23:28:31 +0000514
Jason Molendaa3329782014-03-29 18:54:20 +0000515 uint32_t
516 GetGDBServerProgramVersion();
517
518 bool
519 AvoidGPackets(ProcessGDBRemote *process);
520
Greg Clayton358cf1e2015-06-25 21:46:34 +0000521 StructuredData::ObjectSP
522 GetThreadsInfo();
523
Jason Molenda705b1802014-06-13 02:37:02 +0000524 bool
525 GetThreadExtendedInfoSupported();
526
Oleksiy Vyalov6801be32015-02-25 22:15:44 +0000527 bool
Jason Molenda20ee21b2015-07-10 23:15:22 +0000528 GetLoadedDynamicLibrariesInfosSupported();
529
530 bool
Jason Molenda37397352016-07-22 00:17:55 +0000531 GetSharedCacheInfoSupported();
532
533 bool
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000534 GetModuleInfo (const FileSpec& module_file_spec,
535 const ArchSpec& arch_spec,
536 ModuleSpec &module_spec);
Oleksiy Vyalov6801be32015-02-25 22:15:44 +0000537
Colin Rileyc3c95b22015-04-16 15:51:33 +0000538 bool
539 ReadExtFeature (const lldb_private::ConstString object,
540 const lldb_private::ConstString annex,
541 std::string & out,
542 lldb_private::Error & err);
543
Greg Clayton0b90be12015-06-23 21:27:50 +0000544 void
545 ServeSymbolLookups(lldb_private::Process *process);
546
Todd Fiala75930012016-08-19 04:21:48 +0000547 //------------------------------------------------------------------
548 /// Return the feature set supported by the gdb-remote server.
549 ///
550 /// This method returns the remote side's response to the qSupported
551 /// packet. The response is the complete string payload returned
552 /// to the client.
553 ///
554 /// @return
555 /// The string returned by the server to the qSupported query.
556 //------------------------------------------------------------------
557 const std::string&
558 GetServerSupportedFeatures() const
559 {
560 return m_qSupported_response;
561 }
562
563 //------------------------------------------------------------------
564 /// Return the array of async JSON packet types supported by the remote.
565 ///
566 /// This method returns the remote side's array of supported JSON
567 /// packet types as a list of type names. Each of the results are
568 /// expected to have an Enable{type_name} command to enable and configure
569 /// the related feature. Each type_name for an enabled feature will
570 /// possibly send async-style packets that contain a payload of a
571 /// binhex-encoded JSON dictionary. The dictionary will have a
572 /// string field named 'type', that contains the type_name of the
573 /// supported packet type.
574 ///
575 /// There is a Plugin category called structured-data plugins.
576 /// A plugin indicates whether it knows how to handle a type_name.
577 /// If so, it can be used to process the async JSON packet.
578 ///
579 /// @return
580 /// The string returned by the server to the qSupported query.
581 //------------------------------------------------------------------
582 lldb_private::StructuredData::Array*
583 GetSupportedStructuredDataPlugins();
584
585 //------------------------------------------------------------------
586 /// Configure a StructuredData feature on the remote end.
587 ///
588 /// @see \b Process::ConfigureStructuredData(...) for details.
589 //------------------------------------------------------------------
590 Error
591 ConfigureRemoteStructuredData(const ConstString &type_name,
592 const StructuredData::ObjectSP &config_sp);
593
Greg Clayton576d8832011-03-22 04:00:09 +0000594protected:
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000595 LazyBool m_supports_not_sending_acks;
596 LazyBool m_supports_thread_suffix;
597 LazyBool m_supports_threads_in_stop_reply;
598 LazyBool m_supports_vCont_all;
599 LazyBool m_supports_vCont_any;
600 LazyBool m_supports_vCont_c;
601 LazyBool m_supports_vCont_C;
602 LazyBool m_supports_vCont_s;
603 LazyBool m_supports_vCont_S;
604 LazyBool m_qHostInfo_is_valid;
605 LazyBool m_curr_pid_is_valid;
606 LazyBool m_qProcessInfo_is_valid;
607 LazyBool m_qGDBServerVersion_is_valid;
608 LazyBool m_supports_alloc_dealloc_memory;
609 LazyBool m_supports_memory_region_info;
610 LazyBool m_supports_watchpoint_support_info;
611 LazyBool m_supports_detach_stay_stopped;
612 LazyBool m_watchpoints_trigger_after_instruction;
613 LazyBool m_attach_or_wait_reply;
614 LazyBool m_prepare_for_reg_writing_reply;
615 LazyBool m_supports_p;
616 LazyBool m_supports_x;
617 LazyBool m_avoid_g_packets;
618 LazyBool m_supports_QSaveRegisterState;
619 LazyBool m_supports_qXfer_auxv_read;
620 LazyBool m_supports_qXfer_libraries_read;
621 LazyBool m_supports_qXfer_libraries_svr4_read;
Colin Rileyc3c95b22015-04-16 15:51:33 +0000622 LazyBool m_supports_qXfer_features_read;
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000623 LazyBool m_supports_augmented_libraries_svr4_read;
624 LazyBool m_supports_jThreadExtendedInfo;
Jason Molenda20ee21b2015-07-10 23:15:22 +0000625 LazyBool m_supports_jLoadedDynamicLibrariesInfos;
Jason Molenda37397352016-07-22 00:17:55 +0000626 LazyBool m_supports_jGetSharedCacheInfo;
Steve Pucci5ae54ae2014-01-25 05:46:51 +0000627
Greg Clayton8b82f082011-04-12 05:54:46 +0000628 bool
629 m_supports_qProcessInfoPID:1,
630 m_supports_qfProcessInfo:1,
631 m_supports_qUserName:1,
632 m_supports_qGroupName:1,
633 m_supports_qThreadStopInfo:1,
634 m_supports_z0:1,
635 m_supports_z1:1,
636 m_supports_z2:1,
637 m_supports_z3:1,
Greg Clayton89600582013-10-10 17:53:50 +0000638 m_supports_z4:1,
639 m_supports_QEnvironment:1,
Greg Clayton0b90be12015-06-23 21:27:50 +0000640 m_supports_QEnvironmentHexEncoded:1,
Greg Clayton358cf1e2015-06-25 21:46:34 +0000641 m_supports_qSymbol:1,
Jason Molenda50018d32016-01-13 04:08:10 +0000642 m_qSymbol_requests_done:1,
Stephane Sezer6f455292016-01-08 00:00:17 +0000643 m_supports_qModuleInfo:1,
Greg Clayton358cf1e2015-06-25 21:46:34 +0000644 m_supports_jThreadsInfo:1;
Greg Clayton2a48f522011-05-14 01:50:35 +0000645
Todd Fiala9f72b3a2014-05-07 19:28:21 +0000646 lldb::pid_t m_curr_pid;
Greg Clayton8b82f082011-04-12 05:54:46 +0000647 lldb::tid_t m_curr_tid; // Current gdb remote protocol thread index for all other operations
648 lldb::tid_t m_curr_tid_run; // Current gdb remote protocol thread index for continue, step, etc
649
Johnny Chen64637202012-05-23 21:09:52 +0000650 uint32_t m_num_supported_hardware_watchpoints;
651
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000652 ArchSpec m_host_arch;
653 ArchSpec m_process_arch;
Greg Clayton1cb64962011-03-24 04:28:38 +0000654 uint32_t m_os_version_major;
655 uint32_t m_os_version_minor;
656 uint32_t m_os_version_update;
657 std::string m_os_build;
658 std::string m_os_kernel;
659 std::string m_hostname;
Jason Molendaa3329782014-03-29 18:54:20 +0000660 std::string m_gdb_server_name; // from reply to qGDBServerVersion, empty if qGDBServerVersion is not supported
661 uint32_t m_gdb_server_version; // from reply to qGDBServerVersion, zero if qGDBServerVersion is not supported
Greg Clayton9ac6d2d2013-10-25 18:13:17 +0000662 uint32_t m_default_packet_timeout;
Steve Pucci5ae54ae2014-01-25 05:46:51 +0000663 uint64_t m_max_packet_size; // as returned by qSupported
Todd Fiala75930012016-08-19 04:21:48 +0000664 std::string m_qSupported_response; // the complete response to qSupported
665
666 bool m_supported_async_json_packets_is_valid;
667 lldb_private::StructuredData::ObjectSP m_supported_async_json_packets_sp;
Jason Molenda91ffe0a2015-06-18 21:46:06 +0000668
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000669 bool
670 GetCurrentProcessInfo (bool allow_lazy_pid = true);
671
672 bool
673 GetGDBServerVersion();
674
675 // Given the list of compression types that the remote debug stub can support,
676 // possibly enable compression if we find an encoding we can handle.
677 void
678 MaybeEnableCompression (std::vector<std::string> supported_compressions);
679
Greg Clayton32e0a752011-03-30 18:16:51 +0000680 bool
681 DecodeProcessInfoResponse (StringExtractorGDBRemote &response,
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000682 ProcessInstanceInfo &process_info);
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000683
Pavel Labath8c1b6bd2016-08-09 12:04:46 +0000684 void
685 OnRunPacketSent(bool first) override;
686
Pavel Labath4b6f9592016-08-18 08:30:03 +0000687 PacketResult
688 SendThreadSpecificPacketAndWaitForResponse(lldb::tid_t tid, StreamString &&payload,
Pavel Labath5c95ee42016-08-30 13:56:11 +0000689 StringExtractorGDBRemote &response, bool send_async);
Pavel Labath4b6f9592016-08-18 08:30:03 +0000690
Greg Clayton576d8832011-03-22 04:00:09 +0000691private:
Greg Clayton576d8832011-03-22 04:00:09 +0000692 DISALLOW_COPY_AND_ASSIGN (GDBRemoteCommunicationClient);
693};
694
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000695} // namespace process_gdb_remote
696} // namespace lldb_private
697
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000698#endif // liblldb_GDBRemoteCommunicationClient_h_