blob: 3e5d954c8af00b2c321091107937e0930ca4f9fe [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 Clayton46fb5582011-11-18 07:03:08 +000020#include "lldb/Target/Process.h"
Greg Clayton576d8832011-03-22 04:00:09 +000021
22#include "GDBRemoteCommunication.h"
23
Tamas Berghammerdb264a62015-03-31 09:52:22 +000024namespace lldb_private {
25namespace process_gdb_remote {
26
Greg Clayton576d8832011-03-22 04:00:09 +000027class GDBRemoteCommunicationClient : public GDBRemoteCommunication
28{
29public:
30 //------------------------------------------------------------------
31 // Constructors and Destructors
32 //------------------------------------------------------------------
Tamas Berghammere13c2732015-02-11 10:29:30 +000033 GDBRemoteCommunicationClient();
Greg Clayton576d8832011-03-22 04:00:09 +000034
Greg Clayton576d8832011-03-22 04:00:09 +000035 ~GDBRemoteCommunicationClient();
36
Greg Clayton1cb64962011-03-24 04:28:38 +000037 //------------------------------------------------------------------
38 // After connecting, send the handshake to the server to make sure
39 // we are communicating with it.
40 //------------------------------------------------------------------
41 bool
Tamas Berghammerdb264a62015-03-31 09:52:22 +000042 HandshakeWithServer (Error *error_ptr);
Greg Clayton1cb64962011-03-24 04:28:38 +000043
Greg Clayton3dedae12013-12-06 21:45:27 +000044 PacketResult
Greg Clayton576d8832011-03-22 04:00:09 +000045 SendPacketAndWaitForResponse (const char *send_payload,
46 StringExtractorGDBRemote &response,
47 bool send_async);
48
Greg Clayton3dedae12013-12-06 21:45:27 +000049 PacketResult
Greg Clayton576d8832011-03-22 04:00:09 +000050 SendPacketAndWaitForResponse (const char *send_payload,
51 size_t send_length,
52 StringExtractorGDBRemote &response,
53 bool send_async);
54
Steve Pucci5ae54ae2014-01-25 05:46:51 +000055 // For packets which specify a range of output to be returned,
56 // return all of the output via a series of request packets of the form
57 // <prefix>0,<size>
58 // <prefix><size>,<size>
59 // <prefix><size>*2,<size>
60 // <prefix><size>*3,<size>
61 // ...
62 // until a "$l..." packet is received, indicating the end.
63 // (size is in hex; this format is used by a standard gdbserver to
64 // return the given portion of the output specified by <prefix>;
65 // for example, "qXfer:libraries-svr4:read::fff,1000" means
66 // "return a chunk of the xml description file for shared
67 // library load addresses, where the chunk starts at offset 0xfff
68 // and continues for 0x1000 bytes").
69 // Concatenate the resulting server response packets together and
70 // return in response_string. If any packet fails, the return value
71 // indicates that failure and the returned string value is undefined.
72 PacketResult
73 SendPacketsAndConcatenateResponses (const char *send_payload_prefix,
74 std::string &response_string);
75
Greg Clayton576d8832011-03-22 04:00:09 +000076 lldb::StateType
77 SendContinuePacketAndWaitForResponse (ProcessGDBRemote *process,
78 const char *packet_payload,
79 size_t packet_length,
80 StringExtractorGDBRemote &response);
Ewan Crawford76df2882015-06-23 12:32:06 +000081 bool
82 SendvContPacket (ProcessGDBRemote *process,
83 const char *payload,
84 size_t packet_length,
85 StringExtractorGDBRemote &response);
Greg Clayton576d8832011-03-22 04:00:09 +000086
Greg Claytonfbb76342013-11-20 21:07:01 +000087 bool
Tamas Berghammer30b8cd32015-03-23 15:50:03 +000088 GetThreadSuffixSupported () override;
Greg Clayton576d8832011-03-22 04:00:09 +000089
Greg Claytonfb909312013-11-23 01:58:15 +000090 // This packet is usually sent first and the boolean return value
91 // indicates if the packet was send and any response was received
92 // even in the response is UNIMPLEMENTED. If the packet failed to
93 // get a response, then false is returned. This quickly tells us
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +000094 // if we were able to connect and communicate with the remote GDB
Greg Claytonfb909312013-11-23 01:58:15 +000095 // server
96 bool
Greg Clayton1cb64962011-03-24 04:28:38 +000097 QueryNoAckModeSupported ();
Greg Clayton576d8832011-03-22 04:00:09 +000098
Greg Clayton44633992012-04-10 03:22:03 +000099 void
100 GetListThreadsInStopReplySupported ();
101
Greg Clayton576d8832011-03-22 04:00:09 +0000102 bool
103 SendAsyncSignal (int signo);
104
105 bool
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000106 SendInterrupt (Mutex::Locker &locker,
Greg Clayton576d8832011-03-22 04:00:09 +0000107 uint32_t seconds_to_wait_for_stop,
Greg Clayton576d8832011-03-22 04:00:09 +0000108 bool &timed_out);
109
110 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
Greg Clayton8b82f082011-04-12 05:54:46 +0000116 uint16_t
Greg Claytondbf04572013-12-04 19:40:33 +0000117 LaunchGDBserverAndGetPort (lldb::pid_t &pid, const char *remote_accept_hostname);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000118
119 bool
120 KillSpawnedProcess (lldb::pid_t pid);
Greg Clayton8b82f082011-04-12 05:54:46 +0000121
Greg Clayton576d8832011-03-22 04:00:09 +0000122 //------------------------------------------------------------------
123 /// Sends a GDB remote protocol 'A' packet that delivers program
124 /// arguments to the remote server.
125 ///
126 /// @param[in] argv
127 /// A NULL terminated array of const C strings to use as the
128 /// arguments.
129 ///
130 /// @return
131 /// Zero if the response was "OK", a positive value if the
132 /// the response was "Exx" where xx are two hex digits, or
133 /// -1 if the call is unsupported or any other unexpected
134 /// response was received.
135 //------------------------------------------------------------------
136 int
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000137 SendArgumentsPacket (const ProcessLaunchInfo &launch_info);
Greg Clayton576d8832011-03-22 04:00:09 +0000138
139 //------------------------------------------------------------------
140 /// Sends a "QEnvironment:NAME=VALUE" packet that will build up the
141 /// environment that will get used when launching an application
142 /// in conjunction with the 'A' packet. This function can be called
143 /// multiple times in a row in order to pass on the desired
144 /// environment that the inferior should be launched with.
145 ///
146 /// @param[in] name_equal_value
147 /// A NULL terminated C string that contains a single environment
148 /// in the format "NAME=VALUE".
149 ///
150 /// @return
151 /// Zero if the response was "OK", a positive value if the
152 /// the response was "Exx" where xx are two hex digits, or
153 /// -1 if the call is unsupported or any other unexpected
154 /// response was received.
155 //------------------------------------------------------------------
156 int
157 SendEnvironmentPacket (char const *name_equal_value);
158
Greg Claytonc4103b32011-05-08 04:53:50 +0000159 int
160 SendLaunchArchPacket (const char *arch);
Jason Molendaa3329782014-03-29 18:54:20 +0000161
162 int
163 SendLaunchEventDataPacket (const char *data, bool *was_supported = NULL);
164
Greg Clayton576d8832011-03-22 04:00:09 +0000165 //------------------------------------------------------------------
166 /// Sends a "vAttach:PID" where PID is in hex.
167 ///
168 /// @param[in] pid
169 /// A process ID for the remote gdb server to attach to.
170 ///
171 /// @param[out] response
172 /// The response received from the gdb server. If the return
173 /// value is zero, \a response will contain a stop reply
174 /// packet.
175 ///
176 /// @return
177 /// Zero if the attach was successful, or an error indicating
178 /// an error code.
179 //------------------------------------------------------------------
180 int
181 SendAttach (lldb::pid_t pid,
182 StringExtractorGDBRemote& response);
183
184
185 //------------------------------------------------------------------
Vince Harrone0be4252015-02-06 18:32:57 +0000186 /// Sends a GDB remote protocol 'I' packet that delivers stdin
187 /// data to the remote process.
188 ///
189 /// @param[in] data
190 /// A pointer to stdin data.
191 ///
192 /// @param[in] data_len
193 /// The number of bytes available at \a data.
194 ///
195 /// @return
196 /// Zero if the attach was successful, or an error indicating
197 /// an error code.
198 //------------------------------------------------------------------
199 int
200 SendStdinNotification(const char* data, size_t data_len);
201
202 //------------------------------------------------------------------
Greg Clayton576d8832011-03-22 04:00:09 +0000203 /// Sets the path to use for stdin/out/err for a process
204 /// that will be launched with the 'A' packet.
205 ///
206 /// @param[in] path
207 /// The path to use for stdin/out/err
208 ///
209 /// @return
210 /// Zero if the for success, or an error code for failure.
211 //------------------------------------------------------------------
212 int
Chaoren Lind3173f32015-05-29 19:52:29 +0000213 SetSTDIN(const FileSpec &file_spec);
Greg Clayton576d8832011-03-22 04:00:09 +0000214 int
Chaoren Lind3173f32015-05-29 19:52:29 +0000215 SetSTDOUT(const FileSpec &file_spec);
Greg Clayton576d8832011-03-22 04:00:09 +0000216 int
Chaoren Lind3173f32015-05-29 19:52:29 +0000217 SetSTDERR(const FileSpec &file_spec);
Greg Clayton576d8832011-03-22 04:00:09 +0000218
219 //------------------------------------------------------------------
220 /// Sets the disable ASLR flag to \a enable for a process that will
221 /// be launched with the 'A' packet.
222 ///
223 /// @param[in] enable
Jim Ingham106d0282014-06-25 02:32:56 +0000224 /// A boolean value indicating whether to disable ASLR or not.
Greg Clayton576d8832011-03-22 04:00:09 +0000225 ///
226 /// @return
227 /// Zero if the for success, or an error code for failure.
228 //------------------------------------------------------------------
229 int
230 SetDisableASLR (bool enable);
Jim Ingham106d0282014-06-25 02:32:56 +0000231
232 //------------------------------------------------------------------
233 /// Sets the DetachOnError flag to \a enable for the process controlled by the stub.
234 ///
235 /// @param[in] enable
236 /// A boolean value indicating whether to detach on error or not.
237 ///
238 /// @return
239 /// Zero if the for success, or an error code for failure.
240 //------------------------------------------------------------------
241 int
242 SetDetachOnError (bool enable);
Greg Clayton576d8832011-03-22 04:00:09 +0000243
244 //------------------------------------------------------------------
245 /// Sets the working directory to \a path for a process that will
Greg Claytonfbb76342013-11-20 21:07:01 +0000246 /// be launched with the 'A' packet for non platform based
247 /// connections. If this packet is sent to a GDB server that
248 /// implements the platform, it will change the current working
249 /// directory for the platform process.
Greg Clayton576d8832011-03-22 04:00:09 +0000250 ///
Chaoren Lind3173f32015-05-29 19:52:29 +0000251 /// @param[in] working_dir
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +0000252 /// The path to a directory to use when launching our process
Greg Clayton576d8832011-03-22 04:00:09 +0000253 ///
254 /// @return
255 /// Zero if the for success, or an error code for failure.
256 //------------------------------------------------------------------
257 int
Chaoren Lind3173f32015-05-29 19:52:29 +0000258 SetWorkingDir(const FileSpec &working_dir);
Greg Clayton576d8832011-03-22 04:00:09 +0000259
Greg Claytonfbb76342013-11-20 21:07:01 +0000260 //------------------------------------------------------------------
261 /// Gets the current working directory of a remote platform GDB
262 /// server.
263 ///
Chaoren Lind3173f32015-05-29 19:52:29 +0000264 /// @param[out] working_dir
Greg Claytonfbb76342013-11-20 21:07:01 +0000265 /// The current working directory on the remote platform.
266 ///
267 /// @return
268 /// Boolean for success
269 //------------------------------------------------------------------
270 bool
Chaoren Lind3173f32015-05-29 19:52:29 +0000271 GetWorkingDir(FileSpec &working_dir);
Greg Claytonfbb76342013-11-20 21:07:01 +0000272
Greg Clayton576d8832011-03-22 04:00:09 +0000273 lldb::addr_t
274 AllocateMemory (size_t size, uint32_t permissions);
275
276 bool
277 DeallocateMemory (lldb::addr_t addr);
278
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000279 Error
Jim Inghamacff8952013-05-02 00:27:30 +0000280 Detach (bool keep_stopped);
Greg Clayton37a0a242012-04-11 00:24:49 +0000281
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000282 Error
283 GetMemoryRegionInfo (lldb::addr_t addr, MemoryRegionInfo &range_info);
Greg Clayton46fb5582011-11-18 07:03:08 +0000284
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000285 Error
Johnny Chen64637202012-05-23 21:09:52 +0000286 GetWatchpointSupportInfo (uint32_t &num);
287
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000288 Error
Enrico Granataf04a2192012-07-13 23:18:48 +0000289 GetWatchpointSupportInfo (uint32_t &num, bool& after);
290
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000291 Error
Enrico Granataf04a2192012-07-13 23:18:48 +0000292 GetWatchpointsTriggerAfterInstruction (bool &after);
293
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000294 const ArchSpec &
Greg Clayton576d8832011-03-22 04:00:09 +0000295 GetHostArchitecture ();
Greg Clayton9ac6d2d2013-10-25 18:13:17 +0000296
297 uint32_t
298 GetHostDefaultPacketTimeout();
Jason Molendaf17b5ac2012-12-19 02:54:03 +0000299
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000300 const ArchSpec &
Jason Molendaf17b5ac2012-12-19 02:54:03 +0000301 GetProcessArchitecture ();
302
Steve Pucci5ae54ae2014-01-25 05:46:51 +0000303 void
304 GetRemoteQSupported();
305
Greg Clayton576d8832011-03-22 04:00:09 +0000306 bool
307 GetVContSupported (char flavor);
308
Jim Inghamcd16df92012-07-20 21:37:13 +0000309 bool
Sean Callananb1de1142013-09-04 23:24:15 +0000310 GetpPacketSupported (lldb::tid_t tid);
Hafiz Abid Qadeer9a78cdf2013-08-29 09:09:45 +0000311
312 bool
Jason Molendabdc4f122014-05-06 02:59:39 +0000313 GetxPacketSupported ();
314
315 bool
Jim Inghamcd16df92012-07-20 21:37:13 +0000316 GetVAttachOrWaitSupported ();
317
Jim Ingham279ceec2012-07-25 21:12:43 +0000318 bool
319 GetSyncThreadStateSupported();
320
Greg Clayton576d8832011-03-22 04:00:09 +0000321 void
322 ResetDiscoverableSettings();
323
324 bool
Greg Clayton9b1e1cd2011-04-04 18:18:57 +0000325 GetHostInfo (bool force = false);
Ewan Crawford78baa192015-05-13 09:18:18 +0000326
327 bool
328 GetDefaultThreadId (lldb::tid_t &tid);
Greg Clayton576d8832011-03-22 04:00:09 +0000329
330 bool
Greg Clayton1cb64962011-03-24 04:28:38 +0000331 GetOSVersion (uint32_t &major,
332 uint32_t &minor,
333 uint32_t &update);
334
335 bool
336 GetOSBuildString (std::string &s);
337
338 bool
339 GetOSKernelDescription (std::string &s);
340
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000341 ArchSpec
Greg Clayton1cb64962011-03-24 04:28:38 +0000342 GetSystemArchitecture ();
343
344 bool
345 GetHostname (std::string &s);
346
Greg Clayton37a0a242012-04-11 00:24:49 +0000347 lldb::addr_t
348 GetShlibInfoAddr();
349
Greg Clayton1cb64962011-03-24 04:28:38 +0000350 bool
Greg Clayton576d8832011-03-22 04:00:09 +0000351 GetSupportsThreadSuffix ();
352
353 bool
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000354 GetProcessInfo (lldb::pid_t pid, ProcessInstanceInfo &process_info);
Greg Clayton32e0a752011-03-30 18:16:51 +0000355
356 uint32_t
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000357 FindProcesses (const ProcessInstanceInfoMatch &process_match_info,
358 ProcessInstanceInfoList &process_infos);
Greg Clayton32e0a752011-03-30 18:16:51 +0000359
360 bool
361 GetUserName (uint32_t uid, std::string &name);
362
363 bool
364 GetGroupName (uint32_t gid, std::string &name);
365
366 bool
Greg Clayton576d8832011-03-22 04:00:09 +0000367 HasFullVContSupport ()
368 {
369 return GetVContSupported ('A');
370 }
371
372 bool
373 HasAnyVContSupport ()
374 {
375 return GetVContSupported ('a');
376 }
377
Greg Clayton8b82f082011-04-12 05:54:46 +0000378 bool
379 GetStopReply (StringExtractorGDBRemote &response);
380
381 bool
Greg Claytonf402f782012-10-13 02:11:55 +0000382 GetThreadStopInfo (lldb::tid_t tid,
Greg Clayton8b82f082011-04-12 05:54:46 +0000383 StringExtractorGDBRemote &response);
384
385 bool
386 SupportsGDBStoppointPacket (GDBStoppointType type)
387 {
388 switch (type)
389 {
390 case eBreakpointSoftware: return m_supports_z0;
391 case eBreakpointHardware: return m_supports_z1;
392 case eWatchpointWrite: return m_supports_z2;
393 case eWatchpointRead: return m_supports_z3;
394 case eWatchpointReadWrite: return m_supports_z4;
Zachary Turner568b0de2015-02-18 18:44:03 +0000395 default: return false;
Greg Clayton8b82f082011-04-12 05:54:46 +0000396 }
Greg Clayton8b82f082011-04-12 05:54:46 +0000397 }
398 uint8_t
399 SendGDBStoppointTypePacket (GDBStoppointType type, // Type of breakpoint or watchpoint
400 bool insert, // Insert or remove?
401 lldb::addr_t addr, // Address of breakpoint or watchpoint
402 uint32_t length); // Byte Size of breakpoint or watchpoint
403
Ewan Crawford78baa192015-05-13 09:18:18 +0000404 bool
405 SetNonStopMode (const bool enable);
406
Greg Clayton9b1e1cd2011-04-04 18:18:57 +0000407 void
Greg Claytone034a042015-05-21 20:52:06 +0000408 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 +0000409
410 // This packet is for testing the speed of the interface only. Both
411 // the client and server need to support it, but this allows us to
412 // measure the packet speed without any other work being done on the
413 // other end and avoids any of that work affecting the packet send
414 // and response times.
415 bool
416 SendSpeedTestPacket (uint32_t send_size,
417 uint32_t recv_size);
Greg Clayton8b82f082011-04-12 05:54:46 +0000418
419 bool
Jason Molendae9ca4af2013-02-23 02:04:45 +0000420 SetCurrentThread (uint64_t tid);
Greg Clayton8b82f082011-04-12 05:54:46 +0000421
422 bool
Jason Molendae9ca4af2013-02-23 02:04:45 +0000423 SetCurrentThreadForRun (uint64_t tid);
Greg Clayton8b82f082011-04-12 05:54:46 +0000424
Steve Pucci5ae54ae2014-01-25 05:46:51 +0000425 bool
Steve Pucci03904ac2014-03-04 23:18:46 +0000426 GetQXferAuxvReadSupported ();
427
428 bool
Steve Pucci5ae54ae2014-01-25 05:46:51 +0000429 GetQXferLibrariesReadSupported ();
430
431 bool
432 GetQXferLibrariesSVR4ReadSupported ();
433
434 uint64_t
435 GetRemoteMaxPacketSize();
436
437 bool
Greg Claytonb30c50c2015-05-29 00:01:55 +0000438 GetEchoSupported ();
439
440 bool
Steve Pucci5ae54ae2014-01-25 05:46:51 +0000441 GetAugmentedLibrariesSVR4ReadSupported ();
442
Colin Rileyc3c95b22015-04-16 15:51:33 +0000443 bool
444 GetQXferFeaturesReadSupported ();
445
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000446 LazyBool
Jim Ingham372787f2012-04-07 00:00:41 +0000447 SupportsAllocDeallocMemory () // const
Greg Clayton2a48f522011-05-14 01:50:35 +0000448 {
Jim Ingham372787f2012-04-07 00:00:41 +0000449 // Uncomment this to have lldb pretend the debug server doesn't respond to alloc/dealloc memory packets.
450 // m_supports_alloc_dealloc_memory = lldb_private::eLazyBoolNo;
Greg Clayton70b57652011-05-15 01:25:55 +0000451 return m_supports_alloc_dealloc_memory;
Greg Clayton2a48f522011-05-14 01:50:35 +0000452 }
453
Greg Claytonadc00cb2011-05-20 23:38:13 +0000454 size_t
455 GetCurrentThreadIDs (std::vector<lldb::tid_t> &thread_ids,
456 bool &sequence_mutex_unavailable);
457
Greg Clayton2687cd12012-03-29 01:55:41 +0000458 bool
459 GetInterruptWasSent () const
460 {
461 return m_interrupt_sent;
462 }
Han Ming Ong4b6459f2013-01-18 23:11:53 +0000463
Greg Claytonfbb76342013-11-20 21:07:01 +0000464 lldb::user_id_t
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000465 OpenFile (const FileSpec& file_spec, uint32_t flags, mode_t mode, Error &error);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000466
Greg Claytonfbb76342013-11-20 21:07:01 +0000467 bool
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000468 CloseFile (lldb::user_id_t fd, Error &error);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000469
Greg Claytonfbb76342013-11-20 21:07:01 +0000470 lldb::user_id_t
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000471 GetFileSize (const FileSpec& file_spec);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000472
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000473 Error
Chaoren Lind3173f32015-05-29 19:52:29 +0000474 GetFilePermissions(const FileSpec &file_spec, uint32_t &file_permissions);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000475
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000476 Error
Chaoren Lind3173f32015-05-29 19:52:29 +0000477 SetFilePermissions(const FileSpec &file_spec, uint32_t file_permissions);
Greg Claytonfbb76342013-11-20 21:07:01 +0000478
479 uint64_t
Daniel Maleae0f8f572013-08-26 23:57:52 +0000480 ReadFile (lldb::user_id_t fd,
481 uint64_t offset,
482 void *dst,
483 uint64_t dst_len,
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000484 Error &error);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000485
Greg Claytonfbb76342013-11-20 21:07:01 +0000486 uint64_t
Daniel Maleae0f8f572013-08-26 23:57:52 +0000487 WriteFile (lldb::user_id_t fd,
488 uint64_t offset,
489 const void* src,
490 uint64_t src_len,
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000491 Error &error);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000492
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000493 Error
Chaoren Lind3173f32015-05-29 19:52:29 +0000494 CreateSymlink(const FileSpec &src,
495 const FileSpec &dst);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000496
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000497 Error
Chaoren Lind3173f32015-05-29 19:52:29 +0000498 Unlink(const FileSpec &file_spec);
Greg Claytonfbb76342013-11-20 21:07:01 +0000499
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000500 Error
Chaoren Lind3173f32015-05-29 19:52:29 +0000501 MakeDirectory(const FileSpec &file_spec, uint32_t mode);
502
Greg Claytonfbb76342013-11-20 21:07:01 +0000503 bool
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000504 GetFileExists (const FileSpec& file_spec);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000505
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000506 Error
Chaoren Lind3173f32015-05-29 19:52:29 +0000507 RunShellCommand(const char *command, // Shouldn't be NULL
508 const FileSpec &working_dir, // Pass empty FileSpec to use the current working directory
509 int *status_ptr, // Pass NULL if you don't want the process exit status
510 int *signo_ptr, // Pass NULL if you don't want the signal that caused the process to exit
511 std::string *command_output, // Pass NULL if you don't want the command output
512 uint32_t timeout_sec); // Timeout in seconds to wait for shell program to finish
513
Greg Claytonfbb76342013-11-20 21:07:01 +0000514 bool
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000515 CalculateMD5 (const FileSpec& file_spec, uint64_t &high, uint64_t &low);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000516
Han Ming Ong4b6459f2013-01-18 23:11:53 +0000517 std::string
518 HarmonizeThreadIdsForProfileData (ProcessGDBRemote *process,
519 StringExtractorGDBRemote &inputStringExtractor);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000520
Greg Claytonf74cf862013-11-13 23:28:31 +0000521 bool
522 ReadRegister(lldb::tid_t tid,
523 uint32_t reg_num,
524 StringExtractorGDBRemote &response);
525
526 bool
527 ReadAllRegisters (lldb::tid_t tid,
528 StringExtractorGDBRemote &response);
529
530 bool
531 SaveRegisterState (lldb::tid_t tid, uint32_t &save_id);
532
533 bool
534 RestoreRegisterState (lldb::tid_t tid, uint32_t save_id);
Jason Molendaa3329782014-03-29 18:54:20 +0000535
536 const char *
537 GetGDBServerProgramName();
Greg Claytonf74cf862013-11-13 23:28:31 +0000538
Jason Molendaa3329782014-03-29 18:54:20 +0000539 uint32_t
540 GetGDBServerProgramVersion();
541
542 bool
543 AvoidGPackets(ProcessGDBRemote *process);
544
Jason Molenda705b1802014-06-13 02:37:02 +0000545 bool
546 GetThreadExtendedInfoSupported();
547
Oleksiy Vyalov6801be32015-02-25 22:15:44 +0000548 bool
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000549 GetModuleInfo (const FileSpec& module_file_spec,
550 const ArchSpec& arch_spec,
551 ModuleSpec &module_spec);
Oleksiy Vyalov6801be32015-02-25 22:15:44 +0000552
Colin Rileyc3c95b22015-04-16 15:51:33 +0000553 bool
554 ReadExtFeature (const lldb_private::ConstString object,
555 const lldb_private::ConstString annex,
556 std::string & out,
557 lldb_private::Error & err);
558
Greg Clayton576d8832011-03-22 04:00:09 +0000559protected:
560
Greg Clayton3dedae12013-12-06 21:45:27 +0000561 PacketResult
562 SendPacketAndWaitForResponseNoLock (const char *payload,
563 size_t payload_length,
564 StringExtractorGDBRemote &response);
565
Jason Molendaf17b5ac2012-12-19 02:54:03 +0000566 bool
Oleksiy Vyalov1ef7b2c2015-02-04 23:19:15 +0000567 GetCurrentProcessInfo (bool allow_lazy_pid = true);
Jason Molendaf17b5ac2012-12-19 02:54:03 +0000568
Jason Molendaa3329782014-03-29 18:54:20 +0000569 bool
570 GetGDBServerVersion();
571
Jason Molenda91ffe0a2015-06-18 21:46:06 +0000572 // Given the list of compression types that the remote debug stub can support,
573 // possibly enable compression if we find an encoding we can handle.
574 void
575 MaybeEnableCompression (std::vector<std::string> supported_compressions);
576
Greg Clayton576d8832011-03-22 04:00:09 +0000577 //------------------------------------------------------------------
578 // Classes that inherit from GDBRemoteCommunicationClient can see and modify these
579 //------------------------------------------------------------------
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000580 LazyBool m_supports_not_sending_acks;
581 LazyBool m_supports_thread_suffix;
582 LazyBool m_supports_threads_in_stop_reply;
583 LazyBool m_supports_vCont_all;
584 LazyBool m_supports_vCont_any;
585 LazyBool m_supports_vCont_c;
586 LazyBool m_supports_vCont_C;
587 LazyBool m_supports_vCont_s;
588 LazyBool m_supports_vCont_S;
589 LazyBool m_qHostInfo_is_valid;
590 LazyBool m_curr_pid_is_valid;
591 LazyBool m_qProcessInfo_is_valid;
592 LazyBool m_qGDBServerVersion_is_valid;
593 LazyBool m_supports_alloc_dealloc_memory;
594 LazyBool m_supports_memory_region_info;
595 LazyBool m_supports_watchpoint_support_info;
596 LazyBool m_supports_detach_stay_stopped;
597 LazyBool m_watchpoints_trigger_after_instruction;
598 LazyBool m_attach_or_wait_reply;
599 LazyBool m_prepare_for_reg_writing_reply;
600 LazyBool m_supports_p;
601 LazyBool m_supports_x;
602 LazyBool m_avoid_g_packets;
603 LazyBool m_supports_QSaveRegisterState;
604 LazyBool m_supports_qXfer_auxv_read;
605 LazyBool m_supports_qXfer_libraries_read;
606 LazyBool m_supports_qXfer_libraries_svr4_read;
Colin Rileyc3c95b22015-04-16 15:51:33 +0000607 LazyBool m_supports_qXfer_features_read;
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000608 LazyBool m_supports_augmented_libraries_svr4_read;
609 LazyBool m_supports_jThreadExtendedInfo;
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,
Chaoren Lin7a306082015-06-23 03:17:01 +0000623 m_supports_QEnvironmentHexEncoded:1;
Greg Clayton2a48f522011-05-14 01:50:35 +0000624
Todd Fiala9f72b3a2014-05-07 19:28:21 +0000625 lldb::pid_t m_curr_pid;
Greg Clayton8b82f082011-04-12 05:54:46 +0000626 lldb::tid_t m_curr_tid; // Current gdb remote protocol thread index for all other operations
627 lldb::tid_t m_curr_tid_run; // Current gdb remote protocol thread index for continue, step, etc
628
Greg Clayton576d8832011-03-22 04:00:09 +0000629
Johnny Chen64637202012-05-23 21:09:52 +0000630 uint32_t m_num_supported_hardware_watchpoints;
631
Greg Clayton576d8832011-03-22 04:00:09 +0000632 // If we need to send a packet while the target is running, the m_async_XXX
633 // member variables take care of making this happen.
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000634 Mutex m_async_mutex;
635 Predicate<bool> m_async_packet_predicate;
Greg Clayton576d8832011-03-22 04:00:09 +0000636 std::string m_async_packet;
Jim Inghama6195b72013-12-18 01:24:33 +0000637 PacketResult m_async_result;
Greg Clayton576d8832011-03-22 04:00:09 +0000638 StringExtractorGDBRemote m_async_response;
639 int m_async_signal; // We were asked to deliver a signal to the inferior process.
Greg Clayton2687cd12012-03-29 01:55:41 +0000640 bool m_interrupt_sent;
Han Ming Ong4b6459f2013-01-18 23:11:53 +0000641 std::string m_partial_profile_data;
642 std::map<uint64_t, uint32_t> m_thread_id_to_used_usec_map;
Greg Clayton576d8832011-03-22 04:00:09 +0000643
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000644 ArchSpec m_host_arch;
645 ArchSpec m_process_arch;
Greg Clayton1cb64962011-03-24 04:28:38 +0000646 uint32_t m_os_version_major;
647 uint32_t m_os_version_minor;
648 uint32_t m_os_version_update;
649 std::string m_os_build;
650 std::string m_os_kernel;
651 std::string m_hostname;
Jason Molendaa3329782014-03-29 18:54:20 +0000652 std::string m_gdb_server_name; // from reply to qGDBServerVersion, empty if qGDBServerVersion is not supported
653 uint32_t m_gdb_server_version; // from reply to qGDBServerVersion, zero if qGDBServerVersion is not supported
Greg Clayton9ac6d2d2013-10-25 18:13:17 +0000654 uint32_t m_default_packet_timeout;
Steve Pucci5ae54ae2014-01-25 05:46:51 +0000655 uint64_t m_max_packet_size; // as returned by qSupported
Jason Molenda91ffe0a2015-06-18 21:46:06 +0000656
Greg Clayton576d8832011-03-22 04:00:09 +0000657
Greg Clayton32e0a752011-03-30 18:16:51 +0000658 bool
659 DecodeProcessInfoResponse (StringExtractorGDBRemote &response,
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000660 ProcessInstanceInfo &process_info);
Greg Clayton576d8832011-03-22 04:00:09 +0000661private:
662 //------------------------------------------------------------------
663 // For GDBRemoteCommunicationClient only
664 //------------------------------------------------------------------
665 DISALLOW_COPY_AND_ASSIGN (GDBRemoteCommunicationClient);
666};
667
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000668} // namespace process_gdb_remote
669} // namespace lldb_private
670
Greg Clayton576d8832011-03-22 04:00:09 +0000671#endif // liblldb_GDBRemoteCommunicationClient_h_