blob: b9cea5f3c67332b611bcfa8371a008645a2e3afc [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 Claytonffb2d442015-06-22 23:12:45 +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);
82
Greg Claytonfbb76342013-11-20 21:07:01 +000083 bool
Tamas Berghammer30b8cd32015-03-23 15:50:03 +000084 GetThreadSuffixSupported () override;
Greg Clayton576d8832011-03-22 04:00:09 +000085
Greg Claytonfb909312013-11-23 01:58:15 +000086 // This packet is usually sent first and the boolean return value
87 // indicates if the packet was send and any response was received
88 // even in the response is UNIMPLEMENTED. If the packet failed to
89 // get a response, then false is returned. This quickly tells us
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +000090 // if we were able to connect and communicate with the remote GDB
Greg Claytonfb909312013-11-23 01:58:15 +000091 // server
92 bool
Greg Clayton1cb64962011-03-24 04:28:38 +000093 QueryNoAckModeSupported ();
Greg Clayton576d8832011-03-22 04:00:09 +000094
Greg Clayton44633992012-04-10 03:22:03 +000095 void
96 GetListThreadsInStopReplySupported ();
97
Greg Clayton576d8832011-03-22 04:00:09 +000098 bool
99 SendAsyncSignal (int signo);
100
101 bool
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000102 SendInterrupt (Mutex::Locker &locker,
Greg Clayton576d8832011-03-22 04:00:09 +0000103 uint32_t seconds_to_wait_for_stop,
Greg Clayton576d8832011-03-22 04:00:09 +0000104 bool &timed_out);
105
106 lldb::pid_t
Oleksiy Vyalov1ef7b2c2015-02-04 23:19:15 +0000107 GetCurrentProcessID (bool allow_lazy = true);
Greg Clayton576d8832011-03-22 04:00:09 +0000108
109 bool
110 GetLaunchSuccess (std::string &error_str);
111
Greg Clayton8b82f082011-04-12 05:54:46 +0000112 uint16_t
Greg Claytondbf04572013-12-04 19:40:33 +0000113 LaunchGDBserverAndGetPort (lldb::pid_t &pid, const char *remote_accept_hostname);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000114
115 bool
116 KillSpawnedProcess (lldb::pid_t pid);
Greg Clayton8b82f082011-04-12 05:54:46 +0000117
Greg Clayton576d8832011-03-22 04:00:09 +0000118 //------------------------------------------------------------------
119 /// Sends a GDB remote protocol 'A' packet that delivers program
120 /// arguments to the remote server.
121 ///
122 /// @param[in] argv
123 /// A NULL terminated array of const C strings to use as the
124 /// arguments.
125 ///
126 /// @return
127 /// Zero if the response was "OK", a positive value if the
128 /// the response was "Exx" where xx are two hex digits, or
129 /// -1 if the call is unsupported or any other unexpected
130 /// response was received.
131 //------------------------------------------------------------------
132 int
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000133 SendArgumentsPacket (const ProcessLaunchInfo &launch_info);
Greg Clayton576d8832011-03-22 04:00:09 +0000134
135 //------------------------------------------------------------------
136 /// Sends a "QEnvironment:NAME=VALUE" packet that will build up the
137 /// environment that will get used when launching an application
138 /// in conjunction with the 'A' packet. This function can be called
139 /// multiple times in a row in order to pass on the desired
140 /// environment that the inferior should be launched with.
141 ///
142 /// @param[in] name_equal_value
143 /// A NULL terminated C string that contains a single environment
144 /// in the format "NAME=VALUE".
145 ///
146 /// @return
147 /// Zero if the response was "OK", a positive value if the
148 /// the response was "Exx" where xx are two hex digits, or
149 /// -1 if the call is unsupported or any other unexpected
150 /// response was received.
151 //------------------------------------------------------------------
152 int
153 SendEnvironmentPacket (char const *name_equal_value);
154
Greg Claytonc4103b32011-05-08 04:53:50 +0000155 int
156 SendLaunchArchPacket (const char *arch);
Jason Molendaa3329782014-03-29 18:54:20 +0000157
158 int
159 SendLaunchEventDataPacket (const char *data, bool *was_supported = NULL);
160
Greg Clayton576d8832011-03-22 04:00:09 +0000161 //------------------------------------------------------------------
162 /// Sends a "vAttach:PID" where PID is in hex.
163 ///
164 /// @param[in] pid
165 /// A process ID for the remote gdb server to attach to.
166 ///
167 /// @param[out] response
168 /// The response received from the gdb server. If the return
169 /// value is zero, \a response will contain a stop reply
170 /// packet.
171 ///
172 /// @return
173 /// Zero if the attach was successful, or an error indicating
174 /// an error code.
175 //------------------------------------------------------------------
176 int
177 SendAttach (lldb::pid_t pid,
178 StringExtractorGDBRemote& response);
179
180
181 //------------------------------------------------------------------
Vince Harrone0be4252015-02-06 18:32:57 +0000182 /// Sends a GDB remote protocol 'I' packet that delivers stdin
183 /// data to the remote process.
184 ///
185 /// @param[in] data
186 /// A pointer to stdin data.
187 ///
188 /// @param[in] data_len
189 /// The number of bytes available at \a data.
190 ///
191 /// @return
192 /// Zero if the attach was successful, or an error indicating
193 /// an error code.
194 //------------------------------------------------------------------
195 int
196 SendStdinNotification(const char* data, size_t data_len);
197
198 //------------------------------------------------------------------
Greg Clayton576d8832011-03-22 04:00:09 +0000199 /// Sets the path to use for stdin/out/err for a process
200 /// that will be launched with the 'A' packet.
201 ///
202 /// @param[in] path
203 /// The path to use for stdin/out/err
204 ///
205 /// @return
206 /// Zero if the for success, or an error code for failure.
207 //------------------------------------------------------------------
208 int
Chaoren Lind3173f32015-05-29 19:52:29 +0000209 SetSTDIN(const FileSpec &file_spec);
Greg Clayton576d8832011-03-22 04:00:09 +0000210 int
Chaoren Lind3173f32015-05-29 19:52:29 +0000211 SetSTDOUT(const FileSpec &file_spec);
Greg Clayton576d8832011-03-22 04:00:09 +0000212 int
Chaoren Lind3173f32015-05-29 19:52:29 +0000213 SetSTDERR(const FileSpec &file_spec);
Greg Clayton576d8832011-03-22 04:00:09 +0000214
215 //------------------------------------------------------------------
216 /// Sets the disable ASLR flag to \a enable for a process that will
217 /// be launched with the 'A' packet.
218 ///
219 /// @param[in] enable
Jim Ingham106d0282014-06-25 02:32:56 +0000220 /// A boolean value indicating whether to disable ASLR or not.
Greg Clayton576d8832011-03-22 04:00:09 +0000221 ///
222 /// @return
223 /// Zero if the for success, or an error code for failure.
224 //------------------------------------------------------------------
225 int
226 SetDisableASLR (bool enable);
Jim Ingham106d0282014-06-25 02:32:56 +0000227
228 //------------------------------------------------------------------
229 /// Sets the DetachOnError flag to \a enable for the process controlled by the stub.
230 ///
231 /// @param[in] enable
232 /// A boolean value indicating whether to detach on error or not.
233 ///
234 /// @return
235 /// Zero if the for success, or an error code for failure.
236 //------------------------------------------------------------------
237 int
238 SetDetachOnError (bool enable);
Greg Clayton576d8832011-03-22 04:00:09 +0000239
240 //------------------------------------------------------------------
241 /// Sets the working directory to \a path for a process that will
Greg Claytonfbb76342013-11-20 21:07:01 +0000242 /// be launched with the 'A' packet for non platform based
243 /// connections. If this packet is sent to a GDB server that
244 /// implements the platform, it will change the current working
245 /// directory for the platform process.
Greg Clayton576d8832011-03-22 04:00:09 +0000246 ///
Chaoren Lind3173f32015-05-29 19:52:29 +0000247 /// @param[in] working_dir
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +0000248 /// The path to a directory to use when launching our process
Greg Clayton576d8832011-03-22 04:00:09 +0000249 ///
250 /// @return
251 /// Zero if the for success, or an error code for failure.
252 //------------------------------------------------------------------
253 int
Chaoren Lind3173f32015-05-29 19:52:29 +0000254 SetWorkingDir(const FileSpec &working_dir);
Greg Clayton576d8832011-03-22 04:00:09 +0000255
Greg Claytonfbb76342013-11-20 21:07:01 +0000256 //------------------------------------------------------------------
257 /// Gets the current working directory of a remote platform GDB
258 /// server.
259 ///
Chaoren Lind3173f32015-05-29 19:52:29 +0000260 /// @param[out] working_dir
Greg Claytonfbb76342013-11-20 21:07:01 +0000261 /// The current working directory on the remote platform.
262 ///
263 /// @return
264 /// Boolean for success
265 //------------------------------------------------------------------
266 bool
Chaoren Lind3173f32015-05-29 19:52:29 +0000267 GetWorkingDir(FileSpec &working_dir);
Greg Claytonfbb76342013-11-20 21:07:01 +0000268
Greg Clayton576d8832011-03-22 04:00:09 +0000269 lldb::addr_t
270 AllocateMemory (size_t size, uint32_t permissions);
271
272 bool
273 DeallocateMemory (lldb::addr_t addr);
274
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000275 Error
Jim Inghamacff8952013-05-02 00:27:30 +0000276 Detach (bool keep_stopped);
Greg Clayton37a0a242012-04-11 00:24:49 +0000277
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000278 Error
279 GetMemoryRegionInfo (lldb::addr_t addr, MemoryRegionInfo &range_info);
Greg Clayton46fb5582011-11-18 07:03:08 +0000280
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000281 Error
Johnny Chen64637202012-05-23 21:09:52 +0000282 GetWatchpointSupportInfo (uint32_t &num);
283
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000284 Error
Enrico Granataf04a2192012-07-13 23:18:48 +0000285 GetWatchpointSupportInfo (uint32_t &num, bool& after);
286
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000287 Error
Enrico Granataf04a2192012-07-13 23:18:48 +0000288 GetWatchpointsTriggerAfterInstruction (bool &after);
289
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000290 const ArchSpec &
Greg Clayton576d8832011-03-22 04:00:09 +0000291 GetHostArchitecture ();
Greg Clayton9ac6d2d2013-10-25 18:13:17 +0000292
293 uint32_t
294 GetHostDefaultPacketTimeout();
Jason Molendaf17b5ac2012-12-19 02:54:03 +0000295
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000296 const ArchSpec &
Jason Molendaf17b5ac2012-12-19 02:54:03 +0000297 GetProcessArchitecture ();
298
Steve Pucci5ae54ae2014-01-25 05:46:51 +0000299 void
300 GetRemoteQSupported();
301
Greg Clayton576d8832011-03-22 04:00:09 +0000302 bool
303 GetVContSupported (char flavor);
304
Jim Inghamcd16df92012-07-20 21:37:13 +0000305 bool
Sean Callananb1de1142013-09-04 23:24:15 +0000306 GetpPacketSupported (lldb::tid_t tid);
Hafiz Abid Qadeer9a78cdf2013-08-29 09:09:45 +0000307
308 bool
Jason Molendabdc4f122014-05-06 02:59:39 +0000309 GetxPacketSupported ();
310
311 bool
Jim Inghamcd16df92012-07-20 21:37:13 +0000312 GetVAttachOrWaitSupported ();
313
Jim Ingham279ceec2012-07-25 21:12:43 +0000314 bool
315 GetSyncThreadStateSupported();
316
Greg Clayton576d8832011-03-22 04:00:09 +0000317 void
318 ResetDiscoverableSettings();
319
320 bool
Greg Clayton9b1e1cd2011-04-04 18:18:57 +0000321 GetHostInfo (bool force = false);
Ewan Crawford78baa192015-05-13 09:18:18 +0000322
323 bool
324 GetDefaultThreadId (lldb::tid_t &tid);
Greg Clayton576d8832011-03-22 04:00:09 +0000325
326 bool
Greg Clayton1cb64962011-03-24 04:28:38 +0000327 GetOSVersion (uint32_t &major,
328 uint32_t &minor,
329 uint32_t &update);
330
331 bool
332 GetOSBuildString (std::string &s);
333
334 bool
335 GetOSKernelDescription (std::string &s);
336
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000337 ArchSpec
Greg Clayton1cb64962011-03-24 04:28:38 +0000338 GetSystemArchitecture ();
339
340 bool
341 GetHostname (std::string &s);
342
Greg Clayton37a0a242012-04-11 00:24:49 +0000343 lldb::addr_t
344 GetShlibInfoAddr();
345
Greg Clayton1cb64962011-03-24 04:28:38 +0000346 bool
Greg Clayton576d8832011-03-22 04:00:09 +0000347 GetSupportsThreadSuffix ();
348
349 bool
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000350 GetProcessInfo (lldb::pid_t pid, ProcessInstanceInfo &process_info);
Greg Clayton32e0a752011-03-30 18:16:51 +0000351
352 uint32_t
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000353 FindProcesses (const ProcessInstanceInfoMatch &process_match_info,
354 ProcessInstanceInfoList &process_infos);
Greg Clayton32e0a752011-03-30 18:16:51 +0000355
356 bool
357 GetUserName (uint32_t uid, std::string &name);
358
359 bool
360 GetGroupName (uint32_t gid, std::string &name);
361
362 bool
Greg Clayton576d8832011-03-22 04:00:09 +0000363 HasFullVContSupport ()
364 {
365 return GetVContSupported ('A');
366 }
367
368 bool
369 HasAnyVContSupport ()
370 {
371 return GetVContSupported ('a');
372 }
373
Greg Clayton8b82f082011-04-12 05:54:46 +0000374 bool
375 GetStopReply (StringExtractorGDBRemote &response);
376
377 bool
Greg Claytonf402f782012-10-13 02:11:55 +0000378 GetThreadStopInfo (lldb::tid_t tid,
Greg Clayton8b82f082011-04-12 05:54:46 +0000379 StringExtractorGDBRemote &response);
380
381 bool
382 SupportsGDBStoppointPacket (GDBStoppointType type)
383 {
384 switch (type)
385 {
386 case eBreakpointSoftware: return m_supports_z0;
387 case eBreakpointHardware: return m_supports_z1;
388 case eWatchpointWrite: return m_supports_z2;
389 case eWatchpointRead: return m_supports_z3;
390 case eWatchpointReadWrite: return m_supports_z4;
Zachary Turner568b0de2015-02-18 18:44:03 +0000391 default: return false;
Greg Clayton8b82f082011-04-12 05:54:46 +0000392 }
Greg Clayton8b82f082011-04-12 05:54:46 +0000393 }
394 uint8_t
395 SendGDBStoppointTypePacket (GDBStoppointType type, // Type of breakpoint or watchpoint
396 bool insert, // Insert or remove?
397 lldb::addr_t addr, // Address of breakpoint or watchpoint
398 uint32_t length); // Byte Size of breakpoint or watchpoint
399
Ewan Crawford78baa192015-05-13 09:18:18 +0000400 bool
401 SetNonStopMode (const bool enable);
402
Greg Clayton9b1e1cd2011-04-04 18:18:57 +0000403 void
Greg Claytone034a042015-05-21 20:52:06 +0000404 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 +0000405
406 // This packet is for testing the speed of the interface only. Both
407 // the client and server need to support it, but this allows us to
408 // measure the packet speed without any other work being done on the
409 // other end and avoids any of that work affecting the packet send
410 // and response times.
411 bool
412 SendSpeedTestPacket (uint32_t send_size,
413 uint32_t recv_size);
Greg Clayton8b82f082011-04-12 05:54:46 +0000414
415 bool
Jason Molendae9ca4af2013-02-23 02:04:45 +0000416 SetCurrentThread (uint64_t tid);
Greg Clayton8b82f082011-04-12 05:54:46 +0000417
418 bool
Jason Molendae9ca4af2013-02-23 02:04:45 +0000419 SetCurrentThreadForRun (uint64_t tid);
Greg Clayton8b82f082011-04-12 05:54:46 +0000420
Steve Pucci5ae54ae2014-01-25 05:46:51 +0000421 bool
Steve Pucci03904ac2014-03-04 23:18:46 +0000422 GetQXferAuxvReadSupported ();
423
424 bool
Steve Pucci5ae54ae2014-01-25 05:46:51 +0000425 GetQXferLibrariesReadSupported ();
426
427 bool
428 GetQXferLibrariesSVR4ReadSupported ();
429
430 uint64_t
431 GetRemoteMaxPacketSize();
432
433 bool
Greg Claytonb30c50c2015-05-29 00:01:55 +0000434 GetEchoSupported ();
435
436 bool
Steve Pucci5ae54ae2014-01-25 05:46:51 +0000437 GetAugmentedLibrariesSVR4ReadSupported ();
438
Colin Rileyc3c95b22015-04-16 15:51:33 +0000439 bool
440 GetQXferFeaturesReadSupported ();
441
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000442 LazyBool
Jim Ingham372787f2012-04-07 00:00:41 +0000443 SupportsAllocDeallocMemory () // const
Greg Clayton2a48f522011-05-14 01:50:35 +0000444 {
Jim Ingham372787f2012-04-07 00:00:41 +0000445 // Uncomment this to have lldb pretend the debug server doesn't respond to alloc/dealloc memory packets.
446 // m_supports_alloc_dealloc_memory = lldb_private::eLazyBoolNo;
Greg Clayton70b57652011-05-15 01:25:55 +0000447 return m_supports_alloc_dealloc_memory;
Greg Clayton2a48f522011-05-14 01:50:35 +0000448 }
449
Greg Claytonadc00cb2011-05-20 23:38:13 +0000450 size_t
451 GetCurrentThreadIDs (std::vector<lldb::tid_t> &thread_ids,
452 bool &sequence_mutex_unavailable);
453
Greg Clayton2687cd12012-03-29 01:55:41 +0000454 bool
455 GetInterruptWasSent () const
456 {
457 return m_interrupt_sent;
458 }
Han Ming Ong4b6459f2013-01-18 23:11:53 +0000459
Greg Claytonfbb76342013-11-20 21:07:01 +0000460 lldb::user_id_t
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000461 OpenFile (const FileSpec& file_spec, uint32_t flags, mode_t mode, Error &error);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000462
Greg Claytonfbb76342013-11-20 21:07:01 +0000463 bool
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000464 CloseFile (lldb::user_id_t fd, Error &error);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000465
Greg Claytonfbb76342013-11-20 21:07:01 +0000466 lldb::user_id_t
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000467 GetFileSize (const FileSpec& file_spec);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000468
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000469 Error
Chaoren Lind3173f32015-05-29 19:52:29 +0000470 GetFilePermissions(const FileSpec &file_spec, uint32_t &file_permissions);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000471
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000472 Error
Chaoren Lind3173f32015-05-29 19:52:29 +0000473 SetFilePermissions(const FileSpec &file_spec, uint32_t file_permissions);
Greg Claytonfbb76342013-11-20 21:07:01 +0000474
475 uint64_t
Daniel Maleae0f8f572013-08-26 23:57:52 +0000476 ReadFile (lldb::user_id_t fd,
477 uint64_t offset,
478 void *dst,
479 uint64_t dst_len,
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000480 Error &error);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000481
Greg Claytonfbb76342013-11-20 21:07:01 +0000482 uint64_t
Daniel Maleae0f8f572013-08-26 23:57:52 +0000483 WriteFile (lldb::user_id_t fd,
484 uint64_t offset,
485 const void* src,
486 uint64_t src_len,
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000487 Error &error);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000488
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000489 Error
Chaoren Lind3173f32015-05-29 19:52:29 +0000490 CreateSymlink(const FileSpec &src,
491 const FileSpec &dst);
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 Unlink(const FileSpec &file_spec);
Greg Claytonfbb76342013-11-20 21:07:01 +0000495
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000496 Error
Chaoren Lind3173f32015-05-29 19:52:29 +0000497 MakeDirectory(const FileSpec &file_spec, uint32_t mode);
498
Greg Claytonfbb76342013-11-20 21:07:01 +0000499 bool
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000500 GetFileExists (const FileSpec& file_spec);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000501
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000502 Error
Chaoren Lind3173f32015-05-29 19:52:29 +0000503 RunShellCommand(const char *command, // Shouldn't be NULL
504 const FileSpec &working_dir, // Pass empty FileSpec to use the current working directory
505 int *status_ptr, // Pass NULL if you don't want the process exit status
506 int *signo_ptr, // Pass NULL if you don't want the signal that caused the process to exit
507 std::string *command_output, // Pass NULL if you don't want the command output
508 uint32_t timeout_sec); // Timeout in seconds to wait for shell program to finish
509
Greg Claytonfbb76342013-11-20 21:07:01 +0000510 bool
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000511 CalculateMD5 (const FileSpec& file_spec, uint64_t &high, uint64_t &low);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000512
Han Ming Ong4b6459f2013-01-18 23:11:53 +0000513 std::string
514 HarmonizeThreadIdsForProfileData (ProcessGDBRemote *process,
515 StringExtractorGDBRemote &inputStringExtractor);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000516
Greg Claytonf74cf862013-11-13 23:28:31 +0000517 bool
518 ReadRegister(lldb::tid_t tid,
519 uint32_t reg_num,
520 StringExtractorGDBRemote &response);
521
522 bool
523 ReadAllRegisters (lldb::tid_t tid,
524 StringExtractorGDBRemote &response);
525
526 bool
527 SaveRegisterState (lldb::tid_t tid, uint32_t &save_id);
528
529 bool
530 RestoreRegisterState (lldb::tid_t tid, uint32_t save_id);
Jason Molendaa3329782014-03-29 18:54:20 +0000531
532 const char *
533 GetGDBServerProgramName();
Greg Claytonf74cf862013-11-13 23:28:31 +0000534
Jason Molendaa3329782014-03-29 18:54:20 +0000535 uint32_t
536 GetGDBServerProgramVersion();
537
538 bool
539 AvoidGPackets(ProcessGDBRemote *process);
540
Greg Claytonffb2d442015-06-22 23:12:45 +0000541 StructuredData::ObjectSP
542 GetThreadsInfo();
543
Jason Molenda705b1802014-06-13 02:37:02 +0000544 bool
545 GetThreadExtendedInfoSupported();
546
Oleksiy Vyalov6801be32015-02-25 22:15:44 +0000547 bool
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000548 GetModuleInfo (const FileSpec& module_file_spec,
549 const ArchSpec& arch_spec,
550 ModuleSpec &module_spec);
Oleksiy Vyalov6801be32015-02-25 22:15:44 +0000551
Colin Rileyc3c95b22015-04-16 15:51:33 +0000552 bool
553 ReadExtFeature (const lldb_private::ConstString object,
554 const lldb_private::ConstString annex,
555 std::string & out,
556 lldb_private::Error & err);
557
Greg Clayton576d8832011-03-22 04:00:09 +0000558protected:
559
Greg Clayton3dedae12013-12-06 21:45:27 +0000560 PacketResult
561 SendPacketAndWaitForResponseNoLock (const char *payload,
562 size_t payload_length,
563 StringExtractorGDBRemote &response);
564
Jason Molendaf17b5ac2012-12-19 02:54:03 +0000565 bool
Oleksiy Vyalov1ef7b2c2015-02-04 23:19:15 +0000566 GetCurrentProcessInfo (bool allow_lazy_pid = true);
Jason Molendaf17b5ac2012-12-19 02:54:03 +0000567
Jason Molendaa3329782014-03-29 18:54:20 +0000568 bool
569 GetGDBServerVersion();
570
Jason Molenda91ffe0a2015-06-18 21:46:06 +0000571 // Given the list of compression types that the remote debug stub can support,
572 // possibly enable compression if we find an encoding we can handle.
573 void
574 MaybeEnableCompression (std::vector<std::string> supported_compressions);
575
Greg Clayton576d8832011-03-22 04:00:09 +0000576 //------------------------------------------------------------------
577 // Classes that inherit from GDBRemoteCommunicationClient can see and modify these
578 //------------------------------------------------------------------
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000579 LazyBool m_supports_not_sending_acks;
580 LazyBool m_supports_thread_suffix;
581 LazyBool m_supports_threads_in_stop_reply;
582 LazyBool m_supports_vCont_all;
583 LazyBool m_supports_vCont_any;
584 LazyBool m_supports_vCont_c;
585 LazyBool m_supports_vCont_C;
586 LazyBool m_supports_vCont_s;
587 LazyBool m_supports_vCont_S;
588 LazyBool m_qHostInfo_is_valid;
589 LazyBool m_curr_pid_is_valid;
590 LazyBool m_qProcessInfo_is_valid;
591 LazyBool m_qGDBServerVersion_is_valid;
592 LazyBool m_supports_alloc_dealloc_memory;
593 LazyBool m_supports_memory_region_info;
594 LazyBool m_supports_watchpoint_support_info;
595 LazyBool m_supports_detach_stay_stopped;
596 LazyBool m_watchpoints_trigger_after_instruction;
597 LazyBool m_attach_or_wait_reply;
598 LazyBool m_prepare_for_reg_writing_reply;
599 LazyBool m_supports_p;
600 LazyBool m_supports_x;
601 LazyBool m_avoid_g_packets;
602 LazyBool m_supports_QSaveRegisterState;
603 LazyBool m_supports_qXfer_auxv_read;
604 LazyBool m_supports_qXfer_libraries_read;
605 LazyBool m_supports_qXfer_libraries_svr4_read;
Colin Rileyc3c95b22015-04-16 15:51:33 +0000606 LazyBool m_supports_qXfer_features_read;
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000607 LazyBool m_supports_augmented_libraries_svr4_read;
608 LazyBool m_supports_jThreadExtendedInfo;
Steve Pucci5ae54ae2014-01-25 05:46:51 +0000609
Greg Clayton8b82f082011-04-12 05:54:46 +0000610 bool
611 m_supports_qProcessInfoPID:1,
612 m_supports_qfProcessInfo:1,
613 m_supports_qUserName:1,
614 m_supports_qGroupName:1,
615 m_supports_qThreadStopInfo:1,
616 m_supports_z0:1,
617 m_supports_z1:1,
618 m_supports_z2:1,
619 m_supports_z3:1,
Greg Clayton89600582013-10-10 17:53:50 +0000620 m_supports_z4:1,
621 m_supports_QEnvironment:1,
Greg Claytonffb2d442015-06-22 23:12:45 +0000622 m_supports_QEnvironmentHexEncoded:1,
623 m_supports_jThreadsInfo: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_