blob: a603fcf4982b8cf907bf1c39eae81ad64265c52b [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
Pavel Labath4cb69922016-07-29 15:41:52 +000026#include "GDBRemoteCommunication.h"
Greg Clayton576d8832011-03-22 04:00:09 +000027
Tamas Berghammerdb264a62015-03-31 09:52:22 +000028namespace lldb_private {
29namespace process_gdb_remote {
30
Pavel Labath4cb69922016-07-29 15:41:52 +000031class GDBRemoteCommunicationClient : public GDBRemoteCommunication
Greg Clayton576d8832011-03-22 04:00:09 +000032{
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
Pavel Labath4cb69922016-07-29 15:41:52 +000045 PacketResult
46 SendPacketAndWaitForResponse (const char *send_payload,
47 StringExtractorGDBRemote &response,
48 bool send_async);
49
50 PacketResult
51 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
Pavel Labath4cb69922016-07-29 15:41:52 +000077 lldb::StateType
78 SendContinuePacketAndWaitForResponse (ProcessGDBRemote *process,
79 const char *packet_payload,
80 size_t packet_length,
81 StringExtractorGDBRemote &response);
82
83 bool
84 SendvContPacket (ProcessGDBRemote *process,
85 const char *payload,
86 size_t packet_length,
87 StringExtractorGDBRemote &response);
88
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
Pavel Labath4cb69922016-07-29 15:41:52 +0000104 bool
105 SendAsyncSignal (int signo);
106
107 bool
108 SendInterrupt(std::unique_lock<std::recursive_mutex> &lock, uint32_t seconds_to_wait_for_stop, bool &timed_out);
109
Greg Clayton576d8832011-03-22 04:00:09 +0000110 lldb::pid_t
Oleksiy Vyalov1ef7b2c2015-02-04 23:19:15 +0000111 GetCurrentProcessID (bool allow_lazy = true);
Greg Clayton576d8832011-03-22 04:00:09 +0000112
113 bool
114 GetLaunchSuccess (std::string &error_str);
115
Oleksiy Vyalov9fe526c2015-10-21 19:34:26 +0000116 bool
117 LaunchGDBServer (const char *remote_accept_hostname,
118 lldb::pid_t &pid,
119 uint16_t &port,
120 std::string &socket_name);
Tamas Berghammerccd6cff2015-12-08 14:08:19 +0000121
122 size_t
123 QueryGDBServer (std::vector<std::pair<uint16_t, std::string>>& connection_urls);
124
Daniel Maleae0f8f572013-08-26 23:57:52 +0000125 bool
126 KillSpawnedProcess (lldb::pid_t pid);
Greg Clayton8b82f082011-04-12 05:54:46 +0000127
Greg Clayton576d8832011-03-22 04:00:09 +0000128 //------------------------------------------------------------------
129 /// Sends a GDB remote protocol 'A' packet that delivers program
130 /// arguments to the remote server.
131 ///
132 /// @param[in] argv
133 /// A NULL terminated array of const C strings to use as the
134 /// arguments.
135 ///
136 /// @return
137 /// Zero if the response was "OK", a positive value if the
138 /// the response was "Exx" where xx are two hex digits, or
139 /// -1 if the call is unsupported or any other unexpected
140 /// response was received.
141 //------------------------------------------------------------------
142 int
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000143 SendArgumentsPacket (const ProcessLaunchInfo &launch_info);
Greg Clayton576d8832011-03-22 04:00:09 +0000144
145 //------------------------------------------------------------------
146 /// Sends a "QEnvironment:NAME=VALUE" packet that will build up the
147 /// environment that will get used when launching an application
148 /// in conjunction with the 'A' packet. This function can be called
149 /// multiple times in a row in order to pass on the desired
150 /// environment that the inferior should be launched with.
151 ///
152 /// @param[in] name_equal_value
153 /// A NULL terminated C string that contains a single environment
154 /// in the format "NAME=VALUE".
155 ///
156 /// @return
157 /// Zero if the response was "OK", a positive value if the
158 /// the response was "Exx" where xx are two hex digits, or
159 /// -1 if the call is unsupported or any other unexpected
160 /// response was received.
161 //------------------------------------------------------------------
162 int
163 SendEnvironmentPacket (char const *name_equal_value);
164
Greg Claytonc4103b32011-05-08 04:53:50 +0000165 int
166 SendLaunchArchPacket (const char *arch);
Jason Molendaa3329782014-03-29 18:54:20 +0000167
168 int
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000169 SendLaunchEventDataPacket(const char *data, bool *was_supported = nullptr);
Jason Molendaa3329782014-03-29 18:54:20 +0000170
Greg Clayton576d8832011-03-22 04:00:09 +0000171 //------------------------------------------------------------------
172 /// Sends a "vAttach:PID" where PID is in hex.
173 ///
174 /// @param[in] pid
175 /// A process ID for the remote gdb server to attach to.
176 ///
177 /// @param[out] response
178 /// The response received from the gdb server. If the return
179 /// value is zero, \a response will contain a stop reply
180 /// packet.
181 ///
182 /// @return
183 /// Zero if the attach was successful, or an error indicating
184 /// an error code.
185 //------------------------------------------------------------------
186 int
187 SendAttach (lldb::pid_t pid,
188 StringExtractorGDBRemote& response);
189
Greg Clayton576d8832011-03-22 04:00:09 +0000190 //------------------------------------------------------------------
Vince Harrone0be4252015-02-06 18:32:57 +0000191 /// Sends a GDB remote protocol 'I' packet that delivers stdin
192 /// data to the remote process.
193 ///
194 /// @param[in] data
195 /// A pointer to stdin data.
196 ///
197 /// @param[in] data_len
198 /// The number of bytes available at \a data.
199 ///
200 /// @return
201 /// Zero if the attach was successful, or an error indicating
202 /// an error code.
203 //------------------------------------------------------------------
204 int
205 SendStdinNotification(const char* data, size_t data_len);
206
207 //------------------------------------------------------------------
Greg Clayton576d8832011-03-22 04:00:09 +0000208 /// Sets the path to use for stdin/out/err for a process
209 /// that will be launched with the 'A' packet.
210 ///
211 /// @param[in] path
212 /// The path to use for stdin/out/err
213 ///
214 /// @return
215 /// Zero if the for success, or an error code for failure.
216 //------------------------------------------------------------------
217 int
Chaoren Lind3173f32015-05-29 19:52:29 +0000218 SetSTDIN(const FileSpec &file_spec);
Greg Clayton576d8832011-03-22 04:00:09 +0000219 int
Chaoren Lind3173f32015-05-29 19:52:29 +0000220 SetSTDOUT(const FileSpec &file_spec);
Greg Clayton576d8832011-03-22 04:00:09 +0000221 int
Chaoren Lind3173f32015-05-29 19:52:29 +0000222 SetSTDERR(const FileSpec &file_spec);
Greg Clayton576d8832011-03-22 04:00:09 +0000223
224 //------------------------------------------------------------------
225 /// Sets the disable ASLR flag to \a enable for a process that will
226 /// be launched with the 'A' packet.
227 ///
228 /// @param[in] enable
Jim Ingham106d0282014-06-25 02:32:56 +0000229 /// A boolean value indicating whether to disable ASLR or not.
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
235 SetDisableASLR (bool enable);
Jim Ingham106d0282014-06-25 02:32:56 +0000236
237 //------------------------------------------------------------------
238 /// Sets the DetachOnError flag to \a enable for the process controlled by the stub.
239 ///
240 /// @param[in] enable
241 /// A boolean value indicating whether to detach on error or not.
242 ///
243 /// @return
244 /// Zero if the for success, or an error code for failure.
245 //------------------------------------------------------------------
246 int
247 SetDetachOnError (bool enable);
Greg Clayton576d8832011-03-22 04:00:09 +0000248
249 //------------------------------------------------------------------
250 /// Sets the working directory to \a path for a process that will
Greg Claytonfbb76342013-11-20 21:07:01 +0000251 /// be launched with the 'A' packet for non platform based
252 /// connections. If this packet is sent to a GDB server that
253 /// implements the platform, it will change the current working
254 /// directory for the platform process.
Greg Clayton576d8832011-03-22 04:00:09 +0000255 ///
Chaoren Lind3173f32015-05-29 19:52:29 +0000256 /// @param[in] working_dir
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +0000257 /// The path to a directory to use when launching our process
Greg Clayton576d8832011-03-22 04:00:09 +0000258 ///
259 /// @return
260 /// Zero if the for success, or an error code for failure.
261 //------------------------------------------------------------------
262 int
Chaoren Lind3173f32015-05-29 19:52:29 +0000263 SetWorkingDir(const FileSpec &working_dir);
Greg Clayton576d8832011-03-22 04:00:09 +0000264
Greg Claytonfbb76342013-11-20 21:07:01 +0000265 //------------------------------------------------------------------
266 /// Gets the current working directory of a remote platform GDB
267 /// server.
268 ///
Chaoren Lind3173f32015-05-29 19:52:29 +0000269 /// @param[out] working_dir
Greg Claytonfbb76342013-11-20 21:07:01 +0000270 /// The current working directory on the remote platform.
271 ///
272 /// @return
273 /// Boolean for success
274 //------------------------------------------------------------------
275 bool
Chaoren Lind3173f32015-05-29 19:52:29 +0000276 GetWorkingDir(FileSpec &working_dir);
Greg Claytonfbb76342013-11-20 21:07:01 +0000277
Greg Clayton576d8832011-03-22 04:00:09 +0000278 lldb::addr_t
279 AllocateMemory (size_t size, uint32_t permissions);
280
281 bool
282 DeallocateMemory (lldb::addr_t addr);
283
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000284 Error
Jim Inghamacff8952013-05-02 00:27:30 +0000285 Detach (bool keep_stopped);
Greg Clayton37a0a242012-04-11 00:24:49 +0000286
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000287 Error
288 GetMemoryRegionInfo (lldb::addr_t addr, MemoryRegionInfo &range_info);
Greg Clayton46fb5582011-11-18 07:03:08 +0000289
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000290 Error
Johnny Chen64637202012-05-23 21:09:52 +0000291 GetWatchpointSupportInfo (uint32_t &num);
292
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000293 Error
Jaydeep Patil725666c2015-08-13 03:46:01 +0000294 GetWatchpointSupportInfo (uint32_t &num, bool& after, const ArchSpec &arch);
Enrico Granataf04a2192012-07-13 23:18:48 +0000295
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000296 Error
Jaydeep Patil725666c2015-08-13 03:46:01 +0000297 GetWatchpointsTriggerAfterInstruction (bool &after, const ArchSpec &arch);
Enrico Granataf04a2192012-07-13 23:18:48 +0000298
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000299 const ArchSpec &
Greg Clayton576d8832011-03-22 04:00:09 +0000300 GetHostArchitecture ();
Greg Clayton9ac6d2d2013-10-25 18:13:17 +0000301
302 uint32_t
303 GetHostDefaultPacketTimeout();
Jason Molendaf17b5ac2012-12-19 02:54:03 +0000304
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000305 const ArchSpec &
Jason Molendaf17b5ac2012-12-19 02:54:03 +0000306 GetProcessArchitecture ();
307
Steve Pucci5ae54ae2014-01-25 05:46:51 +0000308 void
309 GetRemoteQSupported();
310
Greg Clayton576d8832011-03-22 04:00:09 +0000311 bool
312 GetVContSupported (char flavor);
313
Jim Inghamcd16df92012-07-20 21:37:13 +0000314 bool
Sean Callananb1de1142013-09-04 23:24:15 +0000315 GetpPacketSupported (lldb::tid_t tid);
Hafiz Abid Qadeer9a78cdf2013-08-29 09:09:45 +0000316
317 bool
Jason Molendabdc4f122014-05-06 02:59:39 +0000318 GetxPacketSupported ();
319
320 bool
Jim Inghamcd16df92012-07-20 21:37:13 +0000321 GetVAttachOrWaitSupported ();
322
Jim Ingham279ceec2012-07-25 21:12:43 +0000323 bool
324 GetSyncThreadStateSupported();
325
Greg Clayton576d8832011-03-22 04:00:09 +0000326 void
Greg Clayton2e59d4f2015-06-29 20:08:51 +0000327 ResetDiscoverableSettings (bool did_exec);
Greg Clayton576d8832011-03-22 04:00:09 +0000328
329 bool
Greg Clayton9b1e1cd2011-04-04 18:18:57 +0000330 GetHostInfo (bool force = false);
Ewan Crawford78baa192015-05-13 09:18:18 +0000331
332 bool
333 GetDefaultThreadId (lldb::tid_t &tid);
Greg Clayton576d8832011-03-22 04:00:09 +0000334
335 bool
Greg Clayton1cb64962011-03-24 04:28:38 +0000336 GetOSVersion (uint32_t &major,
337 uint32_t &minor,
338 uint32_t &update);
339
340 bool
341 GetOSBuildString (std::string &s);
342
343 bool
344 GetOSKernelDescription (std::string &s);
345
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000346 ArchSpec
Greg Clayton1cb64962011-03-24 04:28:38 +0000347 GetSystemArchitecture ();
348
349 bool
350 GetHostname (std::string &s);
351
Greg Clayton37a0a242012-04-11 00:24:49 +0000352 lldb::addr_t
353 GetShlibInfoAddr();
354
Greg Clayton1cb64962011-03-24 04:28:38 +0000355 bool
Greg Clayton576d8832011-03-22 04:00:09 +0000356 GetSupportsThreadSuffix ();
357
358 bool
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000359 GetProcessInfo (lldb::pid_t pid, ProcessInstanceInfo &process_info);
Greg Clayton32e0a752011-03-30 18:16:51 +0000360
361 uint32_t
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000362 FindProcesses (const ProcessInstanceInfoMatch &process_match_info,
363 ProcessInstanceInfoList &process_infos);
Greg Clayton32e0a752011-03-30 18:16:51 +0000364
365 bool
366 GetUserName (uint32_t uid, std::string &name);
367
368 bool
369 GetGroupName (uint32_t gid, std::string &name);
370
371 bool
Greg Clayton576d8832011-03-22 04:00:09 +0000372 HasFullVContSupport ()
373 {
374 return GetVContSupported ('A');
375 }
376
377 bool
378 HasAnyVContSupport ()
379 {
380 return GetVContSupported ('a');
381 }
382
Greg Clayton8b82f082011-04-12 05:54:46 +0000383 bool
384 GetStopReply (StringExtractorGDBRemote &response);
385
386 bool
Greg Claytonf402f782012-10-13 02:11:55 +0000387 GetThreadStopInfo (lldb::tid_t tid,
Greg Clayton8b82f082011-04-12 05:54:46 +0000388 StringExtractorGDBRemote &response);
389
390 bool
391 SupportsGDBStoppointPacket (GDBStoppointType type)
392 {
393 switch (type)
394 {
395 case eBreakpointSoftware: return m_supports_z0;
396 case eBreakpointHardware: return m_supports_z1;
397 case eWatchpointWrite: return m_supports_z2;
398 case eWatchpointRead: return m_supports_z3;
399 case eWatchpointReadWrite: return m_supports_z4;
Zachary Turner568b0de2015-02-18 18:44:03 +0000400 default: return false;
Greg Clayton8b82f082011-04-12 05:54:46 +0000401 }
Greg Clayton8b82f082011-04-12 05:54:46 +0000402 }
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000403
Greg Clayton8b82f082011-04-12 05:54:46 +0000404 uint8_t
405 SendGDBStoppointTypePacket (GDBStoppointType type, // Type of breakpoint or watchpoint
406 bool insert, // Insert or remove?
407 lldb::addr_t addr, // Address of breakpoint or watchpoint
408 uint32_t length); // Byte Size of breakpoint or watchpoint
409
Ewan Crawford78baa192015-05-13 09:18:18 +0000410 bool
411 SetNonStopMode (const bool enable);
412
Greg Clayton9b1e1cd2011-04-04 18:18:57 +0000413 void
Greg Claytone034a042015-05-21 20:52:06 +0000414 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 +0000415
416 // This packet is for testing the speed of the interface only. Both
417 // the client and server need to support it, but this allows us to
418 // measure the packet speed without any other work being done on the
419 // other end and avoids any of that work affecting the packet send
420 // and response times.
421 bool
422 SendSpeedTestPacket (uint32_t send_size,
423 uint32_t recv_size);
Greg Clayton8b82f082011-04-12 05:54:46 +0000424
425 bool
Jason Molendae9ca4af2013-02-23 02:04:45 +0000426 SetCurrentThread (uint64_t tid);
Greg Clayton8b82f082011-04-12 05:54:46 +0000427
428 bool
Jason Molendae9ca4af2013-02-23 02:04:45 +0000429 SetCurrentThreadForRun (uint64_t tid);
Greg Clayton8b82f082011-04-12 05:54:46 +0000430
Steve Pucci5ae54ae2014-01-25 05:46:51 +0000431 bool
Steve Pucci03904ac2014-03-04 23:18:46 +0000432 GetQXferAuxvReadSupported ();
433
434 bool
Steve Pucci5ae54ae2014-01-25 05:46:51 +0000435 GetQXferLibrariesReadSupported ();
436
437 bool
438 GetQXferLibrariesSVR4ReadSupported ();
439
440 uint64_t
441 GetRemoteMaxPacketSize();
442
443 bool
Greg Claytonb30c50c2015-05-29 00:01:55 +0000444 GetEchoSupported ();
445
446 bool
Steve Pucci5ae54ae2014-01-25 05:46:51 +0000447 GetAugmentedLibrariesSVR4ReadSupported ();
448
Colin Rileyc3c95b22015-04-16 15:51:33 +0000449 bool
450 GetQXferFeaturesReadSupported ();
451
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000452 LazyBool
Jim Ingham372787f2012-04-07 00:00:41 +0000453 SupportsAllocDeallocMemory () // const
Greg Clayton2a48f522011-05-14 01:50:35 +0000454 {
Jim Ingham372787f2012-04-07 00:00:41 +0000455 // Uncomment this to have lldb pretend the debug server doesn't respond to alloc/dealloc memory packets.
456 // m_supports_alloc_dealloc_memory = lldb_private::eLazyBoolNo;
Greg Clayton70b57652011-05-15 01:25:55 +0000457 return m_supports_alloc_dealloc_memory;
Greg Clayton2a48f522011-05-14 01:50:35 +0000458 }
459
Greg Claytonadc00cb2011-05-20 23:38:13 +0000460 size_t
461 GetCurrentThreadIDs (std::vector<lldb::tid_t> &thread_ids,
462 bool &sequence_mutex_unavailable);
463
Pavel Labath4cb69922016-07-29 15:41:52 +0000464 bool
465 GetInterruptWasSent () const
466 {
467 return m_interrupt_sent;
468 }
469
Greg Claytonfbb76342013-11-20 21:07:01 +0000470 lldb::user_id_t
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000471 OpenFile (const FileSpec& file_spec, uint32_t flags, mode_t mode, Error &error);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000472
Greg Claytonfbb76342013-11-20 21:07:01 +0000473 bool
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000474 CloseFile (lldb::user_id_t fd, Error &error);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000475
Greg Claytonfbb76342013-11-20 21:07:01 +0000476 lldb::user_id_t
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000477 GetFileSize (const FileSpec& file_spec);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000478
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000479 Error
Chaoren Lind3173f32015-05-29 19:52:29 +0000480 GetFilePermissions(const FileSpec &file_spec, uint32_t &file_permissions);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000481
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000482 Error
Chaoren Lind3173f32015-05-29 19:52:29 +0000483 SetFilePermissions(const FileSpec &file_spec, uint32_t file_permissions);
Greg Claytonfbb76342013-11-20 21:07:01 +0000484
485 uint64_t
Daniel Maleae0f8f572013-08-26 23:57:52 +0000486 ReadFile (lldb::user_id_t fd,
487 uint64_t offset,
488 void *dst,
489 uint64_t dst_len,
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000490 Error &error);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000491
Greg Claytonfbb76342013-11-20 21:07:01 +0000492 uint64_t
Daniel Maleae0f8f572013-08-26 23:57:52 +0000493 WriteFile (lldb::user_id_t fd,
494 uint64_t offset,
495 const void* src,
496 uint64_t src_len,
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000497 Error &error);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000498
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000499 Error
Chaoren Lind3173f32015-05-29 19:52:29 +0000500 CreateSymlink(const FileSpec &src,
501 const FileSpec &dst);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000502
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000503 Error
Chaoren Lind3173f32015-05-29 19:52:29 +0000504 Unlink(const FileSpec &file_spec);
Greg Claytonfbb76342013-11-20 21:07:01 +0000505
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000506 Error
Chaoren Lind3173f32015-05-29 19:52:29 +0000507 MakeDirectory(const FileSpec &file_spec, uint32_t mode);
508
Greg Claytonfbb76342013-11-20 21:07:01 +0000509 bool
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000510 GetFileExists (const FileSpec& file_spec);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000511
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000512 Error
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000513 RunShellCommand(const char *command, // Shouldn't be nullptr
Chaoren Lind3173f32015-05-29 19:52:29 +0000514 const FileSpec &working_dir, // Pass empty FileSpec to use the current working directory
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000515 int *status_ptr, // Pass nullptr if you don't want the process exit status
516 int *signo_ptr, // Pass nullptr if you don't want the signal that caused the process to exit
517 std::string *command_output, // Pass nullptr if you don't want the command output
Chaoren Lind3173f32015-05-29 19:52:29 +0000518 uint32_t timeout_sec); // Timeout in seconds to wait for shell program to finish
519
Greg Claytonfbb76342013-11-20 21:07:01 +0000520 bool
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000521 CalculateMD5 (const FileSpec& file_spec, uint64_t &high, uint64_t &low);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000522
Pavel Labath4cb69922016-07-29 15:41:52 +0000523 std::string
524 HarmonizeThreadIdsForProfileData (ProcessGDBRemote *process,
525 StringExtractorGDBRemote &inputStringExtractor);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000526
Greg Claytonf74cf862013-11-13 23:28:31 +0000527 bool
528 ReadRegister(lldb::tid_t tid,
Francis Ricci39f11892016-04-25 20:59:11 +0000529 uint32_t reg_num, // Must be the eRegisterKindProcessPlugin register number, to be sent to the remote
Greg Claytonf74cf862013-11-13 23:28:31 +0000530 StringExtractorGDBRemote &response);
531
532 bool
533 ReadAllRegisters (lldb::tid_t tid,
534 StringExtractorGDBRemote &response);
535
536 bool
537 SaveRegisterState (lldb::tid_t tid, uint32_t &save_id);
538
539 bool
540 RestoreRegisterState (lldb::tid_t tid, uint32_t save_id);
Jason Molendaa3329782014-03-29 18:54:20 +0000541
542 const char *
543 GetGDBServerProgramName();
Greg Claytonf74cf862013-11-13 23:28:31 +0000544
Jason Molendaa3329782014-03-29 18:54:20 +0000545 uint32_t
546 GetGDBServerProgramVersion();
547
548 bool
549 AvoidGPackets(ProcessGDBRemote *process);
550
Greg Clayton358cf1e2015-06-25 21:46:34 +0000551 StructuredData::ObjectSP
552 GetThreadsInfo();
553
Jason Molenda705b1802014-06-13 02:37:02 +0000554 bool
555 GetThreadExtendedInfoSupported();
556
Oleksiy Vyalov6801be32015-02-25 22:15:44 +0000557 bool
Jason Molenda20ee21b2015-07-10 23:15:22 +0000558 GetLoadedDynamicLibrariesInfosSupported();
559
560 bool
Jason Molenda37397352016-07-22 00:17:55 +0000561 GetSharedCacheInfoSupported();
562
563 bool
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000564 GetModuleInfo (const FileSpec& module_file_spec,
565 const ArchSpec& arch_spec,
566 ModuleSpec &module_spec);
Oleksiy Vyalov6801be32015-02-25 22:15:44 +0000567
Colin Rileyc3c95b22015-04-16 15:51:33 +0000568 bool
569 ReadExtFeature (const lldb_private::ConstString object,
570 const lldb_private::ConstString annex,
571 std::string & out,
572 lldb_private::Error & err);
573
Greg Clayton0b90be12015-06-23 21:27:50 +0000574 void
575 ServeSymbolLookups(lldb_private::Process *process);
576
Greg Clayton576d8832011-03-22 04:00:09 +0000577protected:
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000578 LazyBool m_supports_not_sending_acks;
579 LazyBool m_supports_thread_suffix;
580 LazyBool m_supports_threads_in_stop_reply;
581 LazyBool m_supports_vCont_all;
582 LazyBool m_supports_vCont_any;
583 LazyBool m_supports_vCont_c;
584 LazyBool m_supports_vCont_C;
585 LazyBool m_supports_vCont_s;
586 LazyBool m_supports_vCont_S;
587 LazyBool m_qHostInfo_is_valid;
588 LazyBool m_curr_pid_is_valid;
589 LazyBool m_qProcessInfo_is_valid;
590 LazyBool m_qGDBServerVersion_is_valid;
591 LazyBool m_supports_alloc_dealloc_memory;
592 LazyBool m_supports_memory_region_info;
593 LazyBool m_supports_watchpoint_support_info;
594 LazyBool m_supports_detach_stay_stopped;
595 LazyBool m_watchpoints_trigger_after_instruction;
596 LazyBool m_attach_or_wait_reply;
597 LazyBool m_prepare_for_reg_writing_reply;
598 LazyBool m_supports_p;
599 LazyBool m_supports_x;
600 LazyBool m_avoid_g_packets;
601 LazyBool m_supports_QSaveRegisterState;
602 LazyBool m_supports_qXfer_auxv_read;
603 LazyBool m_supports_qXfer_libraries_read;
604 LazyBool m_supports_qXfer_libraries_svr4_read;
Colin Rileyc3c95b22015-04-16 15:51:33 +0000605 LazyBool m_supports_qXfer_features_read;
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000606 LazyBool m_supports_augmented_libraries_svr4_read;
607 LazyBool m_supports_jThreadExtendedInfo;
Jason Molenda20ee21b2015-07-10 23:15:22 +0000608 LazyBool m_supports_jLoadedDynamicLibrariesInfos;
Jason Molenda37397352016-07-22 00:17:55 +0000609 LazyBool m_supports_jGetSharedCacheInfo;
Steve Pucci5ae54ae2014-01-25 05:46:51 +0000610
Greg Clayton8b82f082011-04-12 05:54:46 +0000611 bool
612 m_supports_qProcessInfoPID:1,
613 m_supports_qfProcessInfo:1,
614 m_supports_qUserName:1,
615 m_supports_qGroupName:1,
616 m_supports_qThreadStopInfo:1,
617 m_supports_z0:1,
618 m_supports_z1:1,
619 m_supports_z2:1,
620 m_supports_z3:1,
Greg Clayton89600582013-10-10 17:53:50 +0000621 m_supports_z4:1,
622 m_supports_QEnvironment:1,
Greg Clayton0b90be12015-06-23 21:27:50 +0000623 m_supports_QEnvironmentHexEncoded:1,
Greg Clayton358cf1e2015-06-25 21:46:34 +0000624 m_supports_qSymbol:1,
Jason Molenda50018d32016-01-13 04:08:10 +0000625 m_qSymbol_requests_done:1,
Stephane Sezer6f455292016-01-08 00:00:17 +0000626 m_supports_qModuleInfo:1,
Greg Clayton358cf1e2015-06-25 21:46:34 +0000627 m_supports_jThreadsInfo:1;
Greg Clayton2a48f522011-05-14 01:50:35 +0000628
Todd Fiala9f72b3a2014-05-07 19:28:21 +0000629 lldb::pid_t m_curr_pid;
Greg Clayton8b82f082011-04-12 05:54:46 +0000630 lldb::tid_t m_curr_tid; // Current gdb remote protocol thread index for all other operations
631 lldb::tid_t m_curr_tid_run; // Current gdb remote protocol thread index for continue, step, etc
632
Johnny Chen64637202012-05-23 21:09:52 +0000633 uint32_t m_num_supported_hardware_watchpoints;
634
Pavel Labath4cb69922016-07-29 15:41:52 +0000635 // If we need to send a packet while the target is running, the m_async_XXX
636 // member variables take care of making this happen.
637 std::recursive_mutex m_async_mutex;
638 Predicate<bool> m_async_packet_predicate;
639 std::string m_async_packet;
640 PacketResult m_async_result;
641 StringExtractorGDBRemote m_async_response;
642 int m_async_signal; // We were asked to deliver a signal to the inferior process.
643 bool m_interrupt_sent;
644 std::string m_partial_profile_data;
645 std::map<uint64_t, uint32_t> m_thread_id_to_used_usec_map;
646
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000647 ArchSpec m_host_arch;
648 ArchSpec m_process_arch;
Greg Clayton1cb64962011-03-24 04:28:38 +0000649 uint32_t m_os_version_major;
650 uint32_t m_os_version_minor;
651 uint32_t m_os_version_update;
652 std::string m_os_build;
653 std::string m_os_kernel;
654 std::string m_hostname;
Jason Molendaa3329782014-03-29 18:54:20 +0000655 std::string m_gdb_server_name; // from reply to qGDBServerVersion, empty if qGDBServerVersion is not supported
656 uint32_t m_gdb_server_version; // from reply to qGDBServerVersion, zero if qGDBServerVersion is not supported
Greg Clayton9ac6d2d2013-10-25 18:13:17 +0000657 uint32_t m_default_packet_timeout;
Steve Pucci5ae54ae2014-01-25 05:46:51 +0000658 uint64_t m_max_packet_size; // as returned by qSupported
Jason Molenda91ffe0a2015-06-18 21:46:06 +0000659
Pavel Labath4cb69922016-07-29 15:41:52 +0000660 PacketResult
661 SendPacketAndWaitForResponseNoLock (const char *payload,
662 size_t payload_length,
663 StringExtractorGDBRemote &response);
664
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000665 bool
666 GetCurrentProcessInfo (bool allow_lazy_pid = true);
667
668 bool
669 GetGDBServerVersion();
670
671 // Given the list of compression types that the remote debug stub can support,
672 // possibly enable compression if we find an encoding we can handle.
673 void
674 MaybeEnableCompression (std::vector<std::string> supported_compressions);
675
Greg Clayton32e0a752011-03-30 18:16:51 +0000676 bool
677 DecodeProcessInfoResponse (StringExtractorGDBRemote &response,
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000678 ProcessInstanceInfo &process_info);
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000679
Greg Clayton576d8832011-03-22 04:00:09 +0000680private:
Greg Clayton576d8832011-03-22 04:00:09 +0000681 DISALLOW_COPY_AND_ASSIGN (GDBRemoteCommunicationClient);
682};
683
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000684} // namespace process_gdb_remote
685} // namespace lldb_private
686
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000687#endif // liblldb_GDBRemoteCommunicationClient_h_