blob: 99b29a9242353ccdddb0bba005d30718e4b06efc [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);
81
Greg Claytonfbb76342013-11-20 21:07:01 +000082 bool
Tamas Berghammer30b8cd32015-03-23 15:50:03 +000083 GetThreadSuffixSupported () override;
Greg Clayton576d8832011-03-22 04:00:09 +000084
Greg Claytonfb909312013-11-23 01:58:15 +000085 // This packet is usually sent first and the boolean return value
86 // indicates if the packet was send and any response was received
87 // even in the response is UNIMPLEMENTED. If the packet failed to
88 // get a response, then false is returned. This quickly tells us
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +000089 // if we were able to connect and communicate with the remote GDB
Greg Claytonfb909312013-11-23 01:58:15 +000090 // server
91 bool
Greg Clayton1cb64962011-03-24 04:28:38 +000092 QueryNoAckModeSupported ();
Greg Clayton576d8832011-03-22 04:00:09 +000093
Greg Clayton44633992012-04-10 03:22:03 +000094 void
95 GetListThreadsInStopReplySupported ();
96
Greg Clayton576d8832011-03-22 04:00:09 +000097 bool
98 SendAsyncSignal (int signo);
99
100 bool
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000101 SendInterrupt (Mutex::Locker &locker,
Greg Clayton576d8832011-03-22 04:00:09 +0000102 uint32_t seconds_to_wait_for_stop,
Greg Clayton576d8832011-03-22 04:00:09 +0000103 bool &timed_out);
104
105 lldb::pid_t
Oleksiy Vyalov1ef7b2c2015-02-04 23:19:15 +0000106 GetCurrentProcessID (bool allow_lazy = true);
Greg Clayton576d8832011-03-22 04:00:09 +0000107
108 bool
109 GetLaunchSuccess (std::string &error_str);
110
Greg Clayton8b82f082011-04-12 05:54:46 +0000111 uint16_t
Greg Claytondbf04572013-12-04 19:40:33 +0000112 LaunchGDBserverAndGetPort (lldb::pid_t &pid, const char *remote_accept_hostname);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000113
114 bool
115 KillSpawnedProcess (lldb::pid_t pid);
Greg Clayton8b82f082011-04-12 05:54:46 +0000116
Greg Clayton576d8832011-03-22 04:00:09 +0000117 //------------------------------------------------------------------
118 /// Sends a GDB remote protocol 'A' packet that delivers program
119 /// arguments to the remote server.
120 ///
121 /// @param[in] argv
122 /// A NULL terminated array of const C strings to use as the
123 /// arguments.
124 ///
125 /// @return
126 /// Zero if the response was "OK", a positive value if the
127 /// the response was "Exx" where xx are two hex digits, or
128 /// -1 if the call is unsupported or any other unexpected
129 /// response was received.
130 //------------------------------------------------------------------
131 int
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000132 SendArgumentsPacket (const ProcessLaunchInfo &launch_info);
Greg Clayton576d8832011-03-22 04:00:09 +0000133
134 //------------------------------------------------------------------
135 /// Sends a "QEnvironment:NAME=VALUE" packet that will build up the
136 /// environment that will get used when launching an application
137 /// in conjunction with the 'A' packet. This function can be called
138 /// multiple times in a row in order to pass on the desired
139 /// environment that the inferior should be launched with.
140 ///
141 /// @param[in] name_equal_value
142 /// A NULL terminated C string that contains a single environment
143 /// in the format "NAME=VALUE".
144 ///
145 /// @return
146 /// Zero if the response was "OK", a positive value if the
147 /// the response was "Exx" where xx are two hex digits, or
148 /// -1 if the call is unsupported or any other unexpected
149 /// response was received.
150 //------------------------------------------------------------------
151 int
152 SendEnvironmentPacket (char const *name_equal_value);
153
Greg Claytonc4103b32011-05-08 04:53:50 +0000154 int
155 SendLaunchArchPacket (const char *arch);
Jason Molendaa3329782014-03-29 18:54:20 +0000156
157 int
158 SendLaunchEventDataPacket (const char *data, bool *was_supported = NULL);
159
Greg Clayton576d8832011-03-22 04:00:09 +0000160 //------------------------------------------------------------------
161 /// Sends a "vAttach:PID" where PID is in hex.
162 ///
163 /// @param[in] pid
164 /// A process ID for the remote gdb server to attach to.
165 ///
166 /// @param[out] response
167 /// The response received from the gdb server. If the return
168 /// value is zero, \a response will contain a stop reply
169 /// packet.
170 ///
171 /// @return
172 /// Zero if the attach was successful, or an error indicating
173 /// an error code.
174 //------------------------------------------------------------------
175 int
176 SendAttach (lldb::pid_t pid,
177 StringExtractorGDBRemote& response);
178
179
180 //------------------------------------------------------------------
Vince Harrone0be4252015-02-06 18:32:57 +0000181 /// Sends a GDB remote protocol 'I' packet that delivers stdin
182 /// data to the remote process.
183 ///
184 /// @param[in] data
185 /// A pointer to stdin data.
186 ///
187 /// @param[in] data_len
188 /// The number of bytes available at \a data.
189 ///
190 /// @return
191 /// Zero if the attach was successful, or an error indicating
192 /// an error code.
193 //------------------------------------------------------------------
194 int
195 SendStdinNotification(const char* data, size_t data_len);
196
197 //------------------------------------------------------------------
Greg Clayton576d8832011-03-22 04:00:09 +0000198 /// Sets the path to use for stdin/out/err for a process
199 /// that will be launched with the 'A' packet.
200 ///
201 /// @param[in] path
202 /// The path to use for stdin/out/err
203 ///
204 /// @return
205 /// Zero if the for success, or an error code for failure.
206 //------------------------------------------------------------------
207 int
208 SetSTDIN (char const *path);
209 int
210 SetSTDOUT (char const *path);
211 int
212 SetSTDERR (char const *path);
213
214 //------------------------------------------------------------------
215 /// Sets the disable ASLR flag to \a enable for a process that will
216 /// be launched with the 'A' packet.
217 ///
218 /// @param[in] enable
Jim Ingham106d0282014-06-25 02:32:56 +0000219 /// A boolean value indicating whether to disable ASLR or not.
Greg Clayton576d8832011-03-22 04:00:09 +0000220 ///
221 /// @return
222 /// Zero if the for success, or an error code for failure.
223 //------------------------------------------------------------------
224 int
225 SetDisableASLR (bool enable);
Jim Ingham106d0282014-06-25 02:32:56 +0000226
227 //------------------------------------------------------------------
228 /// Sets the DetachOnError flag to \a enable for the process controlled by the stub.
229 ///
230 /// @param[in] enable
231 /// A boolean value indicating whether to detach on error or not.
232 ///
233 /// @return
234 /// Zero if the for success, or an error code for failure.
235 //------------------------------------------------------------------
236 int
237 SetDetachOnError (bool enable);
Greg Clayton576d8832011-03-22 04:00:09 +0000238
239 //------------------------------------------------------------------
240 /// Sets the working directory to \a path for a process that will
Greg Claytonfbb76342013-11-20 21:07:01 +0000241 /// be launched with the 'A' packet for non platform based
242 /// connections. If this packet is sent to a GDB server that
243 /// implements the platform, it will change the current working
244 /// directory for the platform process.
Greg Clayton576d8832011-03-22 04:00:09 +0000245 ///
246 /// @param[in] path
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +0000247 /// The path to a directory to use when launching our process
Greg Clayton576d8832011-03-22 04:00:09 +0000248 ///
249 /// @return
250 /// Zero if the for success, or an error code for failure.
251 //------------------------------------------------------------------
252 int
253 SetWorkingDir (char const *path);
254
Greg Claytonfbb76342013-11-20 21:07:01 +0000255 //------------------------------------------------------------------
256 /// Gets the current working directory of a remote platform GDB
257 /// server.
258 ///
259 /// @param[out] cwd
260 /// The current working directory on the remote platform.
261 ///
262 /// @return
263 /// Boolean for success
264 //------------------------------------------------------------------
265 bool
266 GetWorkingDir (std::string &cwd);
267
Greg Clayton576d8832011-03-22 04:00:09 +0000268 lldb::addr_t
269 AllocateMemory (size_t size, uint32_t permissions);
270
271 bool
272 DeallocateMemory (lldb::addr_t addr);
273
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000274 Error
Jim Inghamacff8952013-05-02 00:27:30 +0000275 Detach (bool keep_stopped);
Greg Clayton37a0a242012-04-11 00:24:49 +0000276
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000277 Error
278 GetMemoryRegionInfo (lldb::addr_t addr, MemoryRegionInfo &range_info);
Greg Clayton46fb5582011-11-18 07:03:08 +0000279
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000280 Error
Johnny Chen64637202012-05-23 21:09:52 +0000281 GetWatchpointSupportInfo (uint32_t &num);
282
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000283 Error
Enrico Granataf04a2192012-07-13 23:18:48 +0000284 GetWatchpointSupportInfo (uint32_t &num, bool& after);
285
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000286 Error
Enrico Granataf04a2192012-07-13 23:18:48 +0000287 GetWatchpointsTriggerAfterInstruction (bool &after);
288
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000289 const ArchSpec &
Greg Clayton576d8832011-03-22 04:00:09 +0000290 GetHostArchitecture ();
Greg Clayton9ac6d2d2013-10-25 18:13:17 +0000291
292 uint32_t
293 GetHostDefaultPacketTimeout();
Jason Molendaf17b5ac2012-12-19 02:54:03 +0000294
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000295 const ArchSpec &
Jason Molendaf17b5ac2012-12-19 02:54:03 +0000296 GetProcessArchitecture ();
297
Steve Pucci5ae54ae2014-01-25 05:46:51 +0000298 void
299 GetRemoteQSupported();
300
Greg Clayton576d8832011-03-22 04:00:09 +0000301 bool
302 GetVContSupported (char flavor);
303
Jim Inghamcd16df92012-07-20 21:37:13 +0000304 bool
Sean Callananb1de1142013-09-04 23:24:15 +0000305 GetpPacketSupported (lldb::tid_t tid);
Hafiz Abid Qadeer9a78cdf2013-08-29 09:09:45 +0000306
307 bool
Jason Molendabdc4f122014-05-06 02:59:39 +0000308 GetxPacketSupported ();
309
310 bool
Jim Inghamcd16df92012-07-20 21:37:13 +0000311 GetVAttachOrWaitSupported ();
312
Jim Ingham279ceec2012-07-25 21:12:43 +0000313 bool
314 GetSyncThreadStateSupported();
315
Greg Clayton576d8832011-03-22 04:00:09 +0000316 void
317 ResetDiscoverableSettings();
318
319 bool
Greg Clayton9b1e1cd2011-04-04 18:18:57 +0000320 GetHostInfo (bool force = false);
Ewan Crawford78baa192015-05-13 09:18:18 +0000321
322 bool
323 GetDefaultThreadId (lldb::tid_t &tid);
Greg Clayton576d8832011-03-22 04:00:09 +0000324
325 bool
Greg Clayton1cb64962011-03-24 04:28:38 +0000326 GetOSVersion (uint32_t &major,
327 uint32_t &minor,
328 uint32_t &update);
329
330 bool
331 GetOSBuildString (std::string &s);
332
333 bool
334 GetOSKernelDescription (std::string &s);
335
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000336 ArchSpec
Greg Clayton1cb64962011-03-24 04:28:38 +0000337 GetSystemArchitecture ();
338
339 bool
340 GetHostname (std::string &s);
341
Greg Clayton37a0a242012-04-11 00:24:49 +0000342 lldb::addr_t
343 GetShlibInfoAddr();
344
Greg Clayton1cb64962011-03-24 04:28:38 +0000345 bool
Greg Clayton576d8832011-03-22 04:00:09 +0000346 GetSupportsThreadSuffix ();
347
348 bool
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000349 GetProcessInfo (lldb::pid_t pid, ProcessInstanceInfo &process_info);
Greg Clayton32e0a752011-03-30 18:16:51 +0000350
351 uint32_t
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000352 FindProcesses (const ProcessInstanceInfoMatch &process_match_info,
353 ProcessInstanceInfoList &process_infos);
Greg Clayton32e0a752011-03-30 18:16:51 +0000354
355 bool
356 GetUserName (uint32_t uid, std::string &name);
357
358 bool
359 GetGroupName (uint32_t gid, std::string &name);
360
361 bool
Greg Clayton576d8832011-03-22 04:00:09 +0000362 HasFullVContSupport ()
363 {
364 return GetVContSupported ('A');
365 }
366
367 bool
368 HasAnyVContSupport ()
369 {
370 return GetVContSupported ('a');
371 }
372
Greg Clayton8b82f082011-04-12 05:54:46 +0000373 bool
374 GetStopReply (StringExtractorGDBRemote &response);
375
376 bool
Greg Claytonf402f782012-10-13 02:11:55 +0000377 GetThreadStopInfo (lldb::tid_t tid,
Greg Clayton8b82f082011-04-12 05:54:46 +0000378 StringExtractorGDBRemote &response);
379
380 bool
381 SupportsGDBStoppointPacket (GDBStoppointType type)
382 {
383 switch (type)
384 {
385 case eBreakpointSoftware: return m_supports_z0;
386 case eBreakpointHardware: return m_supports_z1;
387 case eWatchpointWrite: return m_supports_z2;
388 case eWatchpointRead: return m_supports_z3;
389 case eWatchpointReadWrite: return m_supports_z4;
Zachary Turner568b0de2015-02-18 18:44:03 +0000390 default: return false;
Greg Clayton8b82f082011-04-12 05:54:46 +0000391 }
Greg Clayton8b82f082011-04-12 05:54:46 +0000392 }
393 uint8_t
394 SendGDBStoppointTypePacket (GDBStoppointType type, // Type of breakpoint or watchpoint
395 bool insert, // Insert or remove?
396 lldb::addr_t addr, // Address of breakpoint or watchpoint
397 uint32_t length); // Byte Size of breakpoint or watchpoint
398
Ewan Crawford78baa192015-05-13 09:18:18 +0000399 bool
400 SetNonStopMode (const bool enable);
401
Greg Clayton9b1e1cd2011-04-04 18:18:57 +0000402 void
403 TestPacketSpeed (const uint32_t num_packets);
404
405 // This packet is for testing the speed of the interface only. Both
406 // the client and server need to support it, but this allows us to
407 // measure the packet speed without any other work being done on the
408 // other end and avoids any of that work affecting the packet send
409 // and response times.
410 bool
411 SendSpeedTestPacket (uint32_t send_size,
412 uint32_t recv_size);
Greg Clayton8b82f082011-04-12 05:54:46 +0000413
414 bool
Jason Molendae9ca4af2013-02-23 02:04:45 +0000415 SetCurrentThread (uint64_t tid);
Greg Clayton8b82f082011-04-12 05:54:46 +0000416
417 bool
Jason Molendae9ca4af2013-02-23 02:04:45 +0000418 SetCurrentThreadForRun (uint64_t tid);
Greg Clayton8b82f082011-04-12 05:54:46 +0000419
Steve Pucci5ae54ae2014-01-25 05:46:51 +0000420 bool
Steve Pucci03904ac2014-03-04 23:18:46 +0000421 GetQXferAuxvReadSupported ();
422
423 bool
Steve Pucci5ae54ae2014-01-25 05:46:51 +0000424 GetQXferLibrariesReadSupported ();
425
426 bool
427 GetQXferLibrariesSVR4ReadSupported ();
428
429 uint64_t
430 GetRemoteMaxPacketSize();
431
432 bool
433 GetAugmentedLibrariesSVR4ReadSupported ();
434
Colin Rileyc3c95b22015-04-16 15:51:33 +0000435 bool
436 GetQXferFeaturesReadSupported ();
437
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000438 LazyBool
Jim Ingham372787f2012-04-07 00:00:41 +0000439 SupportsAllocDeallocMemory () // const
Greg Clayton2a48f522011-05-14 01:50:35 +0000440 {
Jim Ingham372787f2012-04-07 00:00:41 +0000441 // Uncomment this to have lldb pretend the debug server doesn't respond to alloc/dealloc memory packets.
442 // m_supports_alloc_dealloc_memory = lldb_private::eLazyBoolNo;
Greg Clayton70b57652011-05-15 01:25:55 +0000443 return m_supports_alloc_dealloc_memory;
Greg Clayton2a48f522011-05-14 01:50:35 +0000444 }
445
Greg Claytonadc00cb2011-05-20 23:38:13 +0000446 size_t
447 GetCurrentThreadIDs (std::vector<lldb::tid_t> &thread_ids,
448 bool &sequence_mutex_unavailable);
449
Greg Clayton2687cd12012-03-29 01:55:41 +0000450 bool
451 GetInterruptWasSent () const
452 {
453 return m_interrupt_sent;
454 }
Han Ming Ong4b6459f2013-01-18 23:11:53 +0000455
Greg Claytonfbb76342013-11-20 21:07:01 +0000456 lldb::user_id_t
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000457 OpenFile (const FileSpec& file_spec, uint32_t flags, mode_t mode, Error &error);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000458
Greg Claytonfbb76342013-11-20 21:07:01 +0000459 bool
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000460 CloseFile (lldb::user_id_t fd, Error &error);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000461
Greg Claytonfbb76342013-11-20 21:07:01 +0000462 lldb::user_id_t
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000463 GetFileSize (const FileSpec& file_spec);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000464
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000465 Error
Greg Claytonfbb76342013-11-20 21:07:01 +0000466 GetFilePermissions(const char *path, uint32_t &file_permissions);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000467
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000468 Error
Greg Claytonfbb76342013-11-20 21:07:01 +0000469 SetFilePermissions(const char *path, uint32_t file_permissions);
470
471 uint64_t
Daniel Maleae0f8f572013-08-26 23:57:52 +0000472 ReadFile (lldb::user_id_t fd,
473 uint64_t offset,
474 void *dst,
475 uint64_t dst_len,
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000476 Error &error);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000477
Greg Claytonfbb76342013-11-20 21:07:01 +0000478 uint64_t
Daniel Maleae0f8f572013-08-26 23:57:52 +0000479 WriteFile (lldb::user_id_t fd,
480 uint64_t offset,
481 const void* src,
482 uint64_t src_len,
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000483 Error &error);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000484
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000485 Error
Greg Claytonfbb76342013-11-20 21:07:01 +0000486 CreateSymlink (const char *src,
487 const char *dst);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000488
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000489 Error
Greg Claytonfbb76342013-11-20 21:07:01 +0000490 Unlink (const char *path);
491
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000492 Error
493 MakeDirectory (const char *path, uint32_t mode);
Greg Claytonfbb76342013-11-20 21:07:01 +0000494
495 bool
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000496 GetFileExists (const FileSpec& file_spec);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000497
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000498 Error
Daniel Maleae0f8f572013-08-26 23:57:52 +0000499 RunShellCommand (const char *command, // Shouldn't be NULL
500 const char *working_dir, // Pass NULL to use the current working directory
501 int *status_ptr, // Pass NULL if you don't want the process exit status
502 int *signo_ptr, // Pass NULL if you don't want the signal that caused the process to exit
503 std::string *command_output, // Pass NULL if you don't want the command output
504 uint32_t timeout_sec); // Timeout in seconds to wait for shell program to finish
505
Greg Claytonfbb76342013-11-20 21:07:01 +0000506 bool
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000507 CalculateMD5 (const FileSpec& file_spec, uint64_t &high, uint64_t &low);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000508
Han Ming Ong4b6459f2013-01-18 23:11:53 +0000509 std::string
510 HarmonizeThreadIdsForProfileData (ProcessGDBRemote *process,
511 StringExtractorGDBRemote &inputStringExtractor);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000512
Greg Claytonf74cf862013-11-13 23:28:31 +0000513 bool
514 ReadRegister(lldb::tid_t tid,
515 uint32_t reg_num,
516 StringExtractorGDBRemote &response);
517
518 bool
519 ReadAllRegisters (lldb::tid_t tid,
520 StringExtractorGDBRemote &response);
521
522 bool
523 SaveRegisterState (lldb::tid_t tid, uint32_t &save_id);
524
525 bool
526 RestoreRegisterState (lldb::tid_t tid, uint32_t save_id);
Jason Molendaa3329782014-03-29 18:54:20 +0000527
528 const char *
529 GetGDBServerProgramName();
Greg Claytonf74cf862013-11-13 23:28:31 +0000530
Jason Molendaa3329782014-03-29 18:54:20 +0000531 uint32_t
532 GetGDBServerProgramVersion();
533
534 bool
535 AvoidGPackets(ProcessGDBRemote *process);
536
Jason Molenda705b1802014-06-13 02:37:02 +0000537 bool
538 GetThreadExtendedInfoSupported();
539
Oleksiy Vyalov6801be32015-02-25 22:15:44 +0000540 bool
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000541 GetModuleInfo (const FileSpec& module_file_spec,
542 const ArchSpec& arch_spec,
543 ModuleSpec &module_spec);
Oleksiy Vyalov6801be32015-02-25 22:15:44 +0000544
Colin Rileyc3c95b22015-04-16 15:51:33 +0000545 bool
546 ReadExtFeature (const lldb_private::ConstString object,
547 const lldb_private::ConstString annex,
548 std::string & out,
549 lldb_private::Error & err);
550
Greg Clayton576d8832011-03-22 04:00:09 +0000551protected:
552
Greg Clayton3dedae12013-12-06 21:45:27 +0000553 PacketResult
554 SendPacketAndWaitForResponseNoLock (const char *payload,
555 size_t payload_length,
556 StringExtractorGDBRemote &response);
557
Jason Molendaf17b5ac2012-12-19 02:54:03 +0000558 bool
Oleksiy Vyalov1ef7b2c2015-02-04 23:19:15 +0000559 GetCurrentProcessInfo (bool allow_lazy_pid = true);
Jason Molendaf17b5ac2012-12-19 02:54:03 +0000560
Jason Molendaa3329782014-03-29 18:54:20 +0000561 bool
562 GetGDBServerVersion();
563
Greg Clayton576d8832011-03-22 04:00:09 +0000564 //------------------------------------------------------------------
565 // Classes that inherit from GDBRemoteCommunicationClient can see and modify these
566 //------------------------------------------------------------------
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000567 LazyBool m_supports_not_sending_acks;
568 LazyBool m_supports_thread_suffix;
569 LazyBool m_supports_threads_in_stop_reply;
570 LazyBool m_supports_vCont_all;
571 LazyBool m_supports_vCont_any;
572 LazyBool m_supports_vCont_c;
573 LazyBool m_supports_vCont_C;
574 LazyBool m_supports_vCont_s;
575 LazyBool m_supports_vCont_S;
576 LazyBool m_qHostInfo_is_valid;
577 LazyBool m_curr_pid_is_valid;
578 LazyBool m_qProcessInfo_is_valid;
579 LazyBool m_qGDBServerVersion_is_valid;
580 LazyBool m_supports_alloc_dealloc_memory;
581 LazyBool m_supports_memory_region_info;
582 LazyBool m_supports_watchpoint_support_info;
583 LazyBool m_supports_detach_stay_stopped;
584 LazyBool m_watchpoints_trigger_after_instruction;
585 LazyBool m_attach_or_wait_reply;
586 LazyBool m_prepare_for_reg_writing_reply;
587 LazyBool m_supports_p;
588 LazyBool m_supports_x;
589 LazyBool m_avoid_g_packets;
590 LazyBool m_supports_QSaveRegisterState;
591 LazyBool m_supports_qXfer_auxv_read;
592 LazyBool m_supports_qXfer_libraries_read;
593 LazyBool m_supports_qXfer_libraries_svr4_read;
Colin Rileyc3c95b22015-04-16 15:51:33 +0000594 LazyBool m_supports_qXfer_features_read;
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000595 LazyBool m_supports_augmented_libraries_svr4_read;
596 LazyBool m_supports_jThreadExtendedInfo;
Steve Pucci5ae54ae2014-01-25 05:46:51 +0000597
Greg Clayton8b82f082011-04-12 05:54:46 +0000598 bool
599 m_supports_qProcessInfoPID:1,
600 m_supports_qfProcessInfo:1,
601 m_supports_qUserName:1,
602 m_supports_qGroupName:1,
603 m_supports_qThreadStopInfo:1,
604 m_supports_z0:1,
605 m_supports_z1:1,
606 m_supports_z2:1,
607 m_supports_z3:1,
Greg Clayton89600582013-10-10 17:53:50 +0000608 m_supports_z4:1,
609 m_supports_QEnvironment:1,
610 m_supports_QEnvironmentHexEncoded:1;
Greg Clayton2a48f522011-05-14 01:50:35 +0000611
Todd Fiala9f72b3a2014-05-07 19:28:21 +0000612 lldb::pid_t m_curr_pid;
Greg Clayton8b82f082011-04-12 05:54:46 +0000613 lldb::tid_t m_curr_tid; // Current gdb remote protocol thread index for all other operations
614 lldb::tid_t m_curr_tid_run; // Current gdb remote protocol thread index for continue, step, etc
615
Greg Clayton576d8832011-03-22 04:00:09 +0000616
Johnny Chen64637202012-05-23 21:09:52 +0000617 uint32_t m_num_supported_hardware_watchpoints;
618
Greg Clayton576d8832011-03-22 04:00:09 +0000619 // If we need to send a packet while the target is running, the m_async_XXX
620 // member variables take care of making this happen.
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000621 Mutex m_async_mutex;
622 Predicate<bool> m_async_packet_predicate;
Greg Clayton576d8832011-03-22 04:00:09 +0000623 std::string m_async_packet;
Jim Inghama6195b72013-12-18 01:24:33 +0000624 PacketResult m_async_result;
Greg Clayton576d8832011-03-22 04:00:09 +0000625 StringExtractorGDBRemote m_async_response;
626 int m_async_signal; // We were asked to deliver a signal to the inferior process.
Greg Clayton2687cd12012-03-29 01:55:41 +0000627 bool m_interrupt_sent;
Han Ming Ong4b6459f2013-01-18 23:11:53 +0000628 std::string m_partial_profile_data;
629 std::map<uint64_t, uint32_t> m_thread_id_to_used_usec_map;
Greg Clayton576d8832011-03-22 04:00:09 +0000630
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000631 ArchSpec m_host_arch;
632 ArchSpec m_process_arch;
Greg Clayton1cb64962011-03-24 04:28:38 +0000633 uint32_t m_os_version_major;
634 uint32_t m_os_version_minor;
635 uint32_t m_os_version_update;
636 std::string m_os_build;
637 std::string m_os_kernel;
638 std::string m_hostname;
Jason Molendaa3329782014-03-29 18:54:20 +0000639 std::string m_gdb_server_name; // from reply to qGDBServerVersion, empty if qGDBServerVersion is not supported
640 uint32_t m_gdb_server_version; // from reply to qGDBServerVersion, zero if qGDBServerVersion is not supported
Greg Clayton9ac6d2d2013-10-25 18:13:17 +0000641 uint32_t m_default_packet_timeout;
Steve Pucci5ae54ae2014-01-25 05:46:51 +0000642 uint64_t m_max_packet_size; // as returned by qSupported
Greg Clayton576d8832011-03-22 04:00:09 +0000643
Greg Clayton32e0a752011-03-30 18:16:51 +0000644 bool
645 DecodeProcessInfoResponse (StringExtractorGDBRemote &response,
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000646 ProcessInstanceInfo &process_info);
Greg Clayton576d8832011-03-22 04:00:09 +0000647private:
648 //------------------------------------------------------------------
649 // For GDBRemoteCommunicationClient only
650 //------------------------------------------------------------------
651 DISALLOW_COPY_AND_ASSIGN (GDBRemoteCommunicationClient);
652};
653
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000654} // namespace process_gdb_remote
655} // namespace lldb_private
656
Greg Clayton576d8832011-03-22 04:00:09 +0000657#endif // liblldb_GDBRemoteCommunicationClient_h_