blob: deb41b066b4588e70e496dd35a3e2e3898f35805 [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
Greg Claytonadc00cb2011-05-20 23:38:13 +000015#include <vector>
16
Greg Clayton576d8832011-03-22 04:00:09 +000017// Other libraries and framework includes
18// Project includes
19#include "lldb/Core/ArchSpec.h"
Greg Clayton358cf1e2015-06-25 21:46:34 +000020#include "lldb/Core/StructuredData.h"
Greg Clayton46fb5582011-11-18 07:03:08 +000021#include "lldb/Target/Process.h"
Greg Clayton576d8832011-03-22 04:00:09 +000022
23#include "GDBRemoteCommunication.h"
24
Tamas Berghammerdb264a62015-03-31 09:52:22 +000025namespace lldb_private {
26namespace process_gdb_remote {
27
Greg Clayton576d8832011-03-22 04:00:09 +000028class GDBRemoteCommunicationClient : public GDBRemoteCommunication
29{
30public:
31 //------------------------------------------------------------------
32 // Constructors and Destructors
33 //------------------------------------------------------------------
Tamas Berghammere13c2732015-02-11 10:29:30 +000034 GDBRemoteCommunicationClient();
Greg Clayton576d8832011-03-22 04:00:09 +000035
Greg Clayton576d8832011-03-22 04:00:09 +000036 ~GDBRemoteCommunicationClient();
37
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);
Ewan Crawford76df2882015-06-23 12:32:06 +000082 bool
83 SendvContPacket (ProcessGDBRemote *process,
84 const char *payload,
85 size_t packet_length,
86 StringExtractorGDBRemote &response);
Greg Clayton576d8832011-03-22 04:00:09 +000087
Greg Claytonfbb76342013-11-20 21:07:01 +000088 bool
Tamas Berghammer30b8cd32015-03-23 15:50:03 +000089 GetThreadSuffixSupported () override;
Greg Clayton576d8832011-03-22 04:00:09 +000090
Greg Claytonfb909312013-11-23 01:58:15 +000091 // This packet is usually sent first and the boolean return value
92 // indicates if the packet was send and any response was received
93 // even in the response is UNIMPLEMENTED. If the packet failed to
94 // get a response, then false is returned. This quickly tells us
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +000095 // if we were able to connect and communicate with the remote GDB
Greg Claytonfb909312013-11-23 01:58:15 +000096 // server
97 bool
Greg Clayton1cb64962011-03-24 04:28:38 +000098 QueryNoAckModeSupported ();
Greg Clayton576d8832011-03-22 04:00:09 +000099
Greg Clayton44633992012-04-10 03:22:03 +0000100 void
101 GetListThreadsInStopReplySupported ();
102
Greg Clayton576d8832011-03-22 04:00:09 +0000103 bool
104 SendAsyncSignal (int signo);
105
106 bool
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000107 SendInterrupt (Mutex::Locker &locker,
Greg Clayton576d8832011-03-22 04:00:09 +0000108 uint32_t seconds_to_wait_for_stop,
Greg Clayton576d8832011-03-22 04:00:09 +0000109 bool &timed_out);
110
111 lldb::pid_t
Oleksiy Vyalov1ef7b2c2015-02-04 23:19:15 +0000112 GetCurrentProcessID (bool allow_lazy = true);
Greg Clayton576d8832011-03-22 04:00:09 +0000113
114 bool
115 GetLaunchSuccess (std::string &error_str);
116
Greg Clayton8b82f082011-04-12 05:54:46 +0000117 uint16_t
Greg Claytondbf04572013-12-04 19:40:33 +0000118 LaunchGDBserverAndGetPort (lldb::pid_t &pid, const char *remote_accept_hostname);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000119
120 bool
121 KillSpawnedProcess (lldb::pid_t pid);
Greg Clayton8b82f082011-04-12 05:54:46 +0000122
Greg Clayton576d8832011-03-22 04:00:09 +0000123 //------------------------------------------------------------------
124 /// Sends a GDB remote protocol 'A' packet that delivers program
125 /// arguments to the remote server.
126 ///
127 /// @param[in] argv
128 /// A NULL terminated array of const C strings to use as the
129 /// arguments.
130 ///
131 /// @return
132 /// Zero if the response was "OK", a positive value if the
133 /// the response was "Exx" where xx are two hex digits, or
134 /// -1 if the call is unsupported or any other unexpected
135 /// response was received.
136 //------------------------------------------------------------------
137 int
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000138 SendArgumentsPacket (const ProcessLaunchInfo &launch_info);
Greg Clayton576d8832011-03-22 04:00:09 +0000139
140 //------------------------------------------------------------------
141 /// Sends a "QEnvironment:NAME=VALUE" packet that will build up the
142 /// environment that will get used when launching an application
143 /// in conjunction with the 'A' packet. This function can be called
144 /// multiple times in a row in order to pass on the desired
145 /// environment that the inferior should be launched with.
146 ///
147 /// @param[in] name_equal_value
148 /// A NULL terminated C string that contains a single environment
149 /// in the format "NAME=VALUE".
150 ///
151 /// @return
152 /// Zero if the response was "OK", a positive value if the
153 /// the response was "Exx" where xx are two hex digits, or
154 /// -1 if the call is unsupported or any other unexpected
155 /// response was received.
156 //------------------------------------------------------------------
157 int
158 SendEnvironmentPacket (char const *name_equal_value);
159
Greg Claytonc4103b32011-05-08 04:53:50 +0000160 int
161 SendLaunchArchPacket (const char *arch);
Jason Molendaa3329782014-03-29 18:54:20 +0000162
163 int
164 SendLaunchEventDataPacket (const char *data, bool *was_supported = NULL);
165
Greg Clayton576d8832011-03-22 04:00:09 +0000166 //------------------------------------------------------------------
167 /// Sends a "vAttach:PID" where PID is in hex.
168 ///
169 /// @param[in] pid
170 /// A process ID for the remote gdb server to attach to.
171 ///
172 /// @param[out] response
173 /// The response received from the gdb server. If the return
174 /// value is zero, \a response will contain a stop reply
175 /// packet.
176 ///
177 /// @return
178 /// Zero if the attach was successful, or an error indicating
179 /// an error code.
180 //------------------------------------------------------------------
181 int
182 SendAttach (lldb::pid_t pid,
183 StringExtractorGDBRemote& response);
184
185
186 //------------------------------------------------------------------
Vince Harrone0be4252015-02-06 18:32:57 +0000187 /// Sends a GDB remote protocol 'I' packet that delivers stdin
188 /// data to the remote process.
189 ///
190 /// @param[in] data
191 /// A pointer to stdin data.
192 ///
193 /// @param[in] data_len
194 /// The number of bytes available at \a data.
195 ///
196 /// @return
197 /// Zero if the attach was successful, or an error indicating
198 /// an error code.
199 //------------------------------------------------------------------
200 int
201 SendStdinNotification(const char* data, size_t data_len);
202
203 //------------------------------------------------------------------
Greg Clayton576d8832011-03-22 04:00:09 +0000204 /// Sets the path to use for stdin/out/err for a process
205 /// that will be launched with the 'A' packet.
206 ///
207 /// @param[in] path
208 /// The path to use for stdin/out/err
209 ///
210 /// @return
211 /// Zero if the for success, or an error code for failure.
212 //------------------------------------------------------------------
213 int
Chaoren Lind3173f32015-05-29 19:52:29 +0000214 SetSTDIN(const FileSpec &file_spec);
Greg Clayton576d8832011-03-22 04:00:09 +0000215 int
Chaoren Lind3173f32015-05-29 19:52:29 +0000216 SetSTDOUT(const FileSpec &file_spec);
Greg Clayton576d8832011-03-22 04:00:09 +0000217 int
Chaoren Lind3173f32015-05-29 19:52:29 +0000218 SetSTDERR(const FileSpec &file_spec);
Greg Clayton576d8832011-03-22 04:00:09 +0000219
220 //------------------------------------------------------------------
221 /// Sets the disable ASLR flag to \a enable for a process that will
222 /// be launched with the 'A' packet.
223 ///
224 /// @param[in] enable
Jim Ingham106d0282014-06-25 02:32:56 +0000225 /// A boolean value indicating whether to disable ASLR or not.
Greg Clayton576d8832011-03-22 04:00:09 +0000226 ///
227 /// @return
228 /// Zero if the for success, or an error code for failure.
229 //------------------------------------------------------------------
230 int
231 SetDisableASLR (bool enable);
Jim Ingham106d0282014-06-25 02:32:56 +0000232
233 //------------------------------------------------------------------
234 /// Sets the DetachOnError flag to \a enable for the process controlled by the stub.
235 ///
236 /// @param[in] enable
237 /// A boolean value indicating whether to detach on error or not.
238 ///
239 /// @return
240 /// Zero if the for success, or an error code for failure.
241 //------------------------------------------------------------------
242 int
243 SetDetachOnError (bool enable);
Greg Clayton576d8832011-03-22 04:00:09 +0000244
245 //------------------------------------------------------------------
246 /// Sets the working directory to \a path for a process that will
Greg Claytonfbb76342013-11-20 21:07:01 +0000247 /// be launched with the 'A' packet for non platform based
248 /// connections. If this packet is sent to a GDB server that
249 /// implements the platform, it will change the current working
250 /// directory for the platform process.
Greg Clayton576d8832011-03-22 04:00:09 +0000251 ///
Chaoren Lind3173f32015-05-29 19:52:29 +0000252 /// @param[in] working_dir
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +0000253 /// The path to a directory to use when launching our process
Greg Clayton576d8832011-03-22 04:00:09 +0000254 ///
255 /// @return
256 /// Zero if the for success, or an error code for failure.
257 //------------------------------------------------------------------
258 int
Chaoren Lind3173f32015-05-29 19:52:29 +0000259 SetWorkingDir(const FileSpec &working_dir);
Greg Clayton576d8832011-03-22 04:00:09 +0000260
Greg Claytonfbb76342013-11-20 21:07:01 +0000261 //------------------------------------------------------------------
262 /// Gets the current working directory of a remote platform GDB
263 /// server.
264 ///
Chaoren Lind3173f32015-05-29 19:52:29 +0000265 /// @param[out] working_dir
Greg Claytonfbb76342013-11-20 21:07:01 +0000266 /// The current working directory on the remote platform.
267 ///
268 /// @return
269 /// Boolean for success
270 //------------------------------------------------------------------
271 bool
Chaoren Lind3173f32015-05-29 19:52:29 +0000272 GetWorkingDir(FileSpec &working_dir);
Greg Claytonfbb76342013-11-20 21:07:01 +0000273
Greg Clayton576d8832011-03-22 04:00:09 +0000274 lldb::addr_t
275 AllocateMemory (size_t size, uint32_t permissions);
276
277 bool
278 DeallocateMemory (lldb::addr_t addr);
279
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000280 Error
Jim Inghamacff8952013-05-02 00:27:30 +0000281 Detach (bool keep_stopped);
Greg Clayton37a0a242012-04-11 00:24:49 +0000282
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000283 Error
284 GetMemoryRegionInfo (lldb::addr_t addr, MemoryRegionInfo &range_info);
Greg Clayton46fb5582011-11-18 07:03:08 +0000285
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000286 Error
Johnny Chen64637202012-05-23 21:09:52 +0000287 GetWatchpointSupportInfo (uint32_t &num);
288
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000289 Error
Enrico Granataf04a2192012-07-13 23:18:48 +0000290 GetWatchpointSupportInfo (uint32_t &num, bool& after);
291
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000292 Error
Enrico Granataf04a2192012-07-13 23:18:48 +0000293 GetWatchpointsTriggerAfterInstruction (bool &after);
294
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000295 const ArchSpec &
Greg Clayton576d8832011-03-22 04:00:09 +0000296 GetHostArchitecture ();
Greg Clayton9ac6d2d2013-10-25 18:13:17 +0000297
298 uint32_t
299 GetHostDefaultPacketTimeout();
Jason Molendaf17b5ac2012-12-19 02:54:03 +0000300
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000301 const ArchSpec &
Jason Molendaf17b5ac2012-12-19 02:54:03 +0000302 GetProcessArchitecture ();
303
Steve Pucci5ae54ae2014-01-25 05:46:51 +0000304 void
305 GetRemoteQSupported();
306
Greg Clayton576d8832011-03-22 04:00:09 +0000307 bool
308 GetVContSupported (char flavor);
309
Jim Inghamcd16df92012-07-20 21:37:13 +0000310 bool
Sean Callananb1de1142013-09-04 23:24:15 +0000311 GetpPacketSupported (lldb::tid_t tid);
Hafiz Abid Qadeer9a78cdf2013-08-29 09:09:45 +0000312
313 bool
Jason Molendabdc4f122014-05-06 02:59:39 +0000314 GetxPacketSupported ();
315
316 bool
Jim Inghamcd16df92012-07-20 21:37:13 +0000317 GetVAttachOrWaitSupported ();
318
Jim Ingham279ceec2012-07-25 21:12:43 +0000319 bool
320 GetSyncThreadStateSupported();
321
Greg Clayton576d8832011-03-22 04:00:09 +0000322 void
Greg Clayton2e59d4f2015-06-29 20:08:51 +0000323 ResetDiscoverableSettings (bool did_exec);
Greg Clayton576d8832011-03-22 04:00:09 +0000324
325 bool
Greg Clayton9b1e1cd2011-04-04 18:18:57 +0000326 GetHostInfo (bool force = false);
Ewan Crawford78baa192015-05-13 09:18:18 +0000327
328 bool
329 GetDefaultThreadId (lldb::tid_t &tid);
Greg Clayton576d8832011-03-22 04:00:09 +0000330
331 bool
Greg Clayton1cb64962011-03-24 04:28:38 +0000332 GetOSVersion (uint32_t &major,
333 uint32_t &minor,
334 uint32_t &update);
335
336 bool
337 GetOSBuildString (std::string &s);
338
339 bool
340 GetOSKernelDescription (std::string &s);
341
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000342 ArchSpec
Greg Clayton1cb64962011-03-24 04:28:38 +0000343 GetSystemArchitecture ();
344
345 bool
346 GetHostname (std::string &s);
347
Greg Clayton37a0a242012-04-11 00:24:49 +0000348 lldb::addr_t
349 GetShlibInfoAddr();
350
Greg Clayton1cb64962011-03-24 04:28:38 +0000351 bool
Greg Clayton576d8832011-03-22 04:00:09 +0000352 GetSupportsThreadSuffix ();
353
354 bool
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000355 GetProcessInfo (lldb::pid_t pid, ProcessInstanceInfo &process_info);
Greg Clayton32e0a752011-03-30 18:16:51 +0000356
357 uint32_t
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000358 FindProcesses (const ProcessInstanceInfoMatch &process_match_info,
359 ProcessInstanceInfoList &process_infos);
Greg Clayton32e0a752011-03-30 18:16:51 +0000360
361 bool
362 GetUserName (uint32_t uid, std::string &name);
363
364 bool
365 GetGroupName (uint32_t gid, std::string &name);
366
367 bool
Greg Clayton576d8832011-03-22 04:00:09 +0000368 HasFullVContSupport ()
369 {
370 return GetVContSupported ('A');
371 }
372
373 bool
374 HasAnyVContSupport ()
375 {
376 return GetVContSupported ('a');
377 }
378
Greg Clayton8b82f082011-04-12 05:54:46 +0000379 bool
380 GetStopReply (StringExtractorGDBRemote &response);
381
382 bool
Greg Claytonf402f782012-10-13 02:11:55 +0000383 GetThreadStopInfo (lldb::tid_t tid,
Greg Clayton8b82f082011-04-12 05:54:46 +0000384 StringExtractorGDBRemote &response);
385
386 bool
387 SupportsGDBStoppointPacket (GDBStoppointType type)
388 {
389 switch (type)
390 {
391 case eBreakpointSoftware: return m_supports_z0;
392 case eBreakpointHardware: return m_supports_z1;
393 case eWatchpointWrite: return m_supports_z2;
394 case eWatchpointRead: return m_supports_z3;
395 case eWatchpointReadWrite: return m_supports_z4;
Zachary Turner568b0de2015-02-18 18:44:03 +0000396 default: return false;
Greg Clayton8b82f082011-04-12 05:54:46 +0000397 }
Greg Clayton8b82f082011-04-12 05:54:46 +0000398 }
399 uint8_t
400 SendGDBStoppointTypePacket (GDBStoppointType type, // Type of breakpoint or watchpoint
401 bool insert, // Insert or remove?
402 lldb::addr_t addr, // Address of breakpoint or watchpoint
403 uint32_t length); // Byte Size of breakpoint or watchpoint
404
Ewan Crawford78baa192015-05-13 09:18:18 +0000405 bool
406 SetNonStopMode (const bool enable);
407
Greg Clayton9b1e1cd2011-04-04 18:18:57 +0000408 void
Greg Claytone034a042015-05-21 20:52:06 +0000409 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 +0000410
411 // This packet is for testing the speed of the interface only. Both
412 // the client and server need to support it, but this allows us to
413 // measure the packet speed without any other work being done on the
414 // other end and avoids any of that work affecting the packet send
415 // and response times.
416 bool
417 SendSpeedTestPacket (uint32_t send_size,
418 uint32_t recv_size);
Greg Clayton8b82f082011-04-12 05:54:46 +0000419
420 bool
Jason Molendae9ca4af2013-02-23 02:04:45 +0000421 SetCurrentThread (uint64_t tid);
Greg Clayton8b82f082011-04-12 05:54:46 +0000422
423 bool
Jason Molendae9ca4af2013-02-23 02:04:45 +0000424 SetCurrentThreadForRun (uint64_t tid);
Greg Clayton8b82f082011-04-12 05:54:46 +0000425
Steve Pucci5ae54ae2014-01-25 05:46:51 +0000426 bool
Steve Pucci03904ac2014-03-04 23:18:46 +0000427 GetQXferAuxvReadSupported ();
428
429 bool
Steve Pucci5ae54ae2014-01-25 05:46:51 +0000430 GetQXferLibrariesReadSupported ();
431
432 bool
433 GetQXferLibrariesSVR4ReadSupported ();
434
435 uint64_t
436 GetRemoteMaxPacketSize();
437
438 bool
Greg Claytonb30c50c2015-05-29 00:01:55 +0000439 GetEchoSupported ();
440
441 bool
Steve Pucci5ae54ae2014-01-25 05:46:51 +0000442 GetAugmentedLibrariesSVR4ReadSupported ();
443
Colin Rileyc3c95b22015-04-16 15:51:33 +0000444 bool
445 GetQXferFeaturesReadSupported ();
446
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000447 LazyBool
Jim Ingham372787f2012-04-07 00:00:41 +0000448 SupportsAllocDeallocMemory () // const
Greg Clayton2a48f522011-05-14 01:50:35 +0000449 {
Jim Ingham372787f2012-04-07 00:00:41 +0000450 // Uncomment this to have lldb pretend the debug server doesn't respond to alloc/dealloc memory packets.
451 // m_supports_alloc_dealloc_memory = lldb_private::eLazyBoolNo;
Greg Clayton70b57652011-05-15 01:25:55 +0000452 return m_supports_alloc_dealloc_memory;
Greg Clayton2a48f522011-05-14 01:50:35 +0000453 }
454
Greg Claytonadc00cb2011-05-20 23:38:13 +0000455 size_t
456 GetCurrentThreadIDs (std::vector<lldb::tid_t> &thread_ids,
457 bool &sequence_mutex_unavailable);
458
Greg Clayton2687cd12012-03-29 01:55:41 +0000459 bool
460 GetInterruptWasSent () const
461 {
462 return m_interrupt_sent;
463 }
Han Ming Ong4b6459f2013-01-18 23:11:53 +0000464
Greg Claytonfbb76342013-11-20 21:07:01 +0000465 lldb::user_id_t
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000466 OpenFile (const FileSpec& file_spec, uint32_t flags, mode_t mode, Error &error);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000467
Greg Claytonfbb76342013-11-20 21:07:01 +0000468 bool
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000469 CloseFile (lldb::user_id_t fd, Error &error);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000470
Greg Claytonfbb76342013-11-20 21:07:01 +0000471 lldb::user_id_t
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000472 GetFileSize (const FileSpec& file_spec);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000473
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000474 Error
Chaoren Lind3173f32015-05-29 19:52:29 +0000475 GetFilePermissions(const FileSpec &file_spec, uint32_t &file_permissions);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000476
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000477 Error
Chaoren Lind3173f32015-05-29 19:52:29 +0000478 SetFilePermissions(const FileSpec &file_spec, uint32_t file_permissions);
Greg Claytonfbb76342013-11-20 21:07:01 +0000479
480 uint64_t
Daniel Maleae0f8f572013-08-26 23:57:52 +0000481 ReadFile (lldb::user_id_t fd,
482 uint64_t offset,
483 void *dst,
484 uint64_t dst_len,
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000485 Error &error);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000486
Greg Claytonfbb76342013-11-20 21:07:01 +0000487 uint64_t
Daniel Maleae0f8f572013-08-26 23:57:52 +0000488 WriteFile (lldb::user_id_t fd,
489 uint64_t offset,
490 const void* src,
491 uint64_t src_len,
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000492 Error &error);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000493
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000494 Error
Chaoren Lind3173f32015-05-29 19:52:29 +0000495 CreateSymlink(const FileSpec &src,
496 const FileSpec &dst);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000497
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000498 Error
Chaoren Lind3173f32015-05-29 19:52:29 +0000499 Unlink(const FileSpec &file_spec);
Greg Claytonfbb76342013-11-20 21:07:01 +0000500
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000501 Error
Chaoren Lind3173f32015-05-29 19:52:29 +0000502 MakeDirectory(const FileSpec &file_spec, uint32_t mode);
503
Greg Claytonfbb76342013-11-20 21:07:01 +0000504 bool
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000505 GetFileExists (const FileSpec& file_spec);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000506
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000507 Error
Chaoren Lind3173f32015-05-29 19:52:29 +0000508 RunShellCommand(const char *command, // Shouldn't be NULL
509 const FileSpec &working_dir, // Pass empty FileSpec to use the current working directory
510 int *status_ptr, // Pass NULL if you don't want the process exit status
511 int *signo_ptr, // Pass NULL if you don't want the signal that caused the process to exit
512 std::string *command_output, // Pass NULL if you don't want the command output
513 uint32_t timeout_sec); // Timeout in seconds to wait for shell program to finish
514
Greg Claytonfbb76342013-11-20 21:07:01 +0000515 bool
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000516 CalculateMD5 (const FileSpec& file_spec, uint64_t &high, uint64_t &low);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000517
Han Ming Ong4b6459f2013-01-18 23:11:53 +0000518 std::string
519 HarmonizeThreadIdsForProfileData (ProcessGDBRemote *process,
520 StringExtractorGDBRemote &inputStringExtractor);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000521
Greg Claytonf74cf862013-11-13 23:28:31 +0000522 bool
523 ReadRegister(lldb::tid_t tid,
524 uint32_t reg_num,
525 StringExtractorGDBRemote &response);
526
527 bool
528 ReadAllRegisters (lldb::tid_t tid,
529 StringExtractorGDBRemote &response);
530
531 bool
532 SaveRegisterState (lldb::tid_t tid, uint32_t &save_id);
533
534 bool
535 RestoreRegisterState (lldb::tid_t tid, uint32_t save_id);
Jason Molendaa3329782014-03-29 18:54:20 +0000536
537 const char *
538 GetGDBServerProgramName();
Greg Claytonf74cf862013-11-13 23:28:31 +0000539
Jason Molendaa3329782014-03-29 18:54:20 +0000540 uint32_t
541 GetGDBServerProgramVersion();
542
543 bool
544 AvoidGPackets(ProcessGDBRemote *process);
545
Greg Clayton358cf1e2015-06-25 21:46:34 +0000546 StructuredData::ObjectSP
547 GetThreadsInfo();
548
Jason Molenda705b1802014-06-13 02:37:02 +0000549 bool
550 GetThreadExtendedInfoSupported();
551
Oleksiy Vyalov6801be32015-02-25 22:15:44 +0000552 bool
Jason Molenda20ee21b2015-07-10 23:15:22 +0000553 GetLoadedDynamicLibrariesInfosSupported();
554
555 bool
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000556 GetModuleInfo (const FileSpec& module_file_spec,
557 const ArchSpec& arch_spec,
558 ModuleSpec &module_spec);
Oleksiy Vyalov6801be32015-02-25 22:15:44 +0000559
Colin Rileyc3c95b22015-04-16 15:51:33 +0000560 bool
561 ReadExtFeature (const lldb_private::ConstString object,
562 const lldb_private::ConstString annex,
563 std::string & out,
564 lldb_private::Error & err);
565
Greg Clayton0b90be12015-06-23 21:27:50 +0000566 void
567 ServeSymbolLookups(lldb_private::Process *process);
568
Greg Clayton576d8832011-03-22 04:00:09 +0000569protected:
570
Greg Clayton3dedae12013-12-06 21:45:27 +0000571 PacketResult
572 SendPacketAndWaitForResponseNoLock (const char *payload,
573 size_t payload_length,
574 StringExtractorGDBRemote &response);
575
Jason Molendaf17b5ac2012-12-19 02:54:03 +0000576 bool
Oleksiy Vyalov1ef7b2c2015-02-04 23:19:15 +0000577 GetCurrentProcessInfo (bool allow_lazy_pid = true);
Jason Molendaf17b5ac2012-12-19 02:54:03 +0000578
Jason Molendaa3329782014-03-29 18:54:20 +0000579 bool
580 GetGDBServerVersion();
581
Jason Molenda91ffe0a2015-06-18 21:46:06 +0000582 // Given the list of compression types that the remote debug stub can support,
583 // possibly enable compression if we find an encoding we can handle.
584 void
585 MaybeEnableCompression (std::vector<std::string> supported_compressions);
586
Greg Clayton576d8832011-03-22 04:00:09 +0000587 //------------------------------------------------------------------
588 // Classes that inherit from GDBRemoteCommunicationClient can see and modify these
589 //------------------------------------------------------------------
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000590 LazyBool m_supports_not_sending_acks;
591 LazyBool m_supports_thread_suffix;
592 LazyBool m_supports_threads_in_stop_reply;
593 LazyBool m_supports_vCont_all;
594 LazyBool m_supports_vCont_any;
595 LazyBool m_supports_vCont_c;
596 LazyBool m_supports_vCont_C;
597 LazyBool m_supports_vCont_s;
598 LazyBool m_supports_vCont_S;
599 LazyBool m_qHostInfo_is_valid;
600 LazyBool m_curr_pid_is_valid;
601 LazyBool m_qProcessInfo_is_valid;
602 LazyBool m_qGDBServerVersion_is_valid;
603 LazyBool m_supports_alloc_dealloc_memory;
604 LazyBool m_supports_memory_region_info;
605 LazyBool m_supports_watchpoint_support_info;
606 LazyBool m_supports_detach_stay_stopped;
607 LazyBool m_watchpoints_trigger_after_instruction;
608 LazyBool m_attach_or_wait_reply;
609 LazyBool m_prepare_for_reg_writing_reply;
610 LazyBool m_supports_p;
611 LazyBool m_supports_x;
612 LazyBool m_avoid_g_packets;
613 LazyBool m_supports_QSaveRegisterState;
614 LazyBool m_supports_qXfer_auxv_read;
615 LazyBool m_supports_qXfer_libraries_read;
616 LazyBool m_supports_qXfer_libraries_svr4_read;
Colin Rileyc3c95b22015-04-16 15:51:33 +0000617 LazyBool m_supports_qXfer_features_read;
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000618 LazyBool m_supports_augmented_libraries_svr4_read;
619 LazyBool m_supports_jThreadExtendedInfo;
Jason Molenda20ee21b2015-07-10 23:15:22 +0000620 LazyBool m_supports_jLoadedDynamicLibrariesInfos;
Steve Pucci5ae54ae2014-01-25 05:46:51 +0000621
Greg Clayton8b82f082011-04-12 05:54:46 +0000622 bool
623 m_supports_qProcessInfoPID:1,
624 m_supports_qfProcessInfo:1,
625 m_supports_qUserName:1,
626 m_supports_qGroupName:1,
627 m_supports_qThreadStopInfo:1,
628 m_supports_z0:1,
629 m_supports_z1:1,
630 m_supports_z2:1,
631 m_supports_z3:1,
Greg Clayton89600582013-10-10 17:53:50 +0000632 m_supports_z4:1,
633 m_supports_QEnvironment:1,
Greg Clayton0b90be12015-06-23 21:27:50 +0000634 m_supports_QEnvironmentHexEncoded:1,
Greg Clayton358cf1e2015-06-25 21:46:34 +0000635 m_supports_qSymbol:1,
636 m_supports_jThreadsInfo:1;
Greg Clayton2a48f522011-05-14 01:50:35 +0000637
Todd Fiala9f72b3a2014-05-07 19:28:21 +0000638 lldb::pid_t m_curr_pid;
Greg Clayton8b82f082011-04-12 05:54:46 +0000639 lldb::tid_t m_curr_tid; // Current gdb remote protocol thread index for all other operations
640 lldb::tid_t m_curr_tid_run; // Current gdb remote protocol thread index for continue, step, etc
641
Greg Clayton576d8832011-03-22 04:00:09 +0000642
Johnny Chen64637202012-05-23 21:09:52 +0000643 uint32_t m_num_supported_hardware_watchpoints;
644
Greg Clayton576d8832011-03-22 04:00:09 +0000645 // If we need to send a packet while the target is running, the m_async_XXX
646 // member variables take care of making this happen.
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000647 Mutex m_async_mutex;
648 Predicate<bool> m_async_packet_predicate;
Greg Clayton576d8832011-03-22 04:00:09 +0000649 std::string m_async_packet;
Jim Inghama6195b72013-12-18 01:24:33 +0000650 PacketResult m_async_result;
Greg Clayton576d8832011-03-22 04:00:09 +0000651 StringExtractorGDBRemote m_async_response;
652 int m_async_signal; // We were asked to deliver a signal to the inferior process.
Greg Clayton2687cd12012-03-29 01:55:41 +0000653 bool m_interrupt_sent;
Han Ming Ong4b6459f2013-01-18 23:11:53 +0000654 std::string m_partial_profile_data;
655 std::map<uint64_t, uint32_t> m_thread_id_to_used_usec_map;
Greg Clayton576d8832011-03-22 04:00:09 +0000656
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000657 ArchSpec m_host_arch;
658 ArchSpec m_process_arch;
Greg Clayton1cb64962011-03-24 04:28:38 +0000659 uint32_t m_os_version_major;
660 uint32_t m_os_version_minor;
661 uint32_t m_os_version_update;
662 std::string m_os_build;
663 std::string m_os_kernel;
664 std::string m_hostname;
Jason Molendaa3329782014-03-29 18:54:20 +0000665 std::string m_gdb_server_name; // from reply to qGDBServerVersion, empty if qGDBServerVersion is not supported
666 uint32_t m_gdb_server_version; // from reply to qGDBServerVersion, zero if qGDBServerVersion is not supported
Greg Clayton9ac6d2d2013-10-25 18:13:17 +0000667 uint32_t m_default_packet_timeout;
Steve Pucci5ae54ae2014-01-25 05:46:51 +0000668 uint64_t m_max_packet_size; // as returned by qSupported
Jason Molenda91ffe0a2015-06-18 21:46:06 +0000669
Greg Clayton576d8832011-03-22 04:00:09 +0000670
Greg Clayton32e0a752011-03-30 18:16:51 +0000671 bool
672 DecodeProcessInfoResponse (StringExtractorGDBRemote &response,
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000673 ProcessInstanceInfo &process_info);
Greg Clayton576d8832011-03-22 04:00:09 +0000674private:
675 //------------------------------------------------------------------
676 // For GDBRemoteCommunicationClient only
677 //------------------------------------------------------------------
678 DISALLOW_COPY_AND_ASSIGN (GDBRemoteCommunicationClient);
679};
680
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000681} // namespace process_gdb_remote
682} // namespace lldb_private
683
Greg Clayton576d8832011-03-22 04:00:09 +0000684#endif // liblldb_GDBRemoteCommunicationClient_h_