blob: 2c41d199ca58f120006ea505bc27aa911b5ec0b2 [file] [log] [blame]
Greg Clayton576d8832011-03-22 04:00:09 +00001//===-- GDBRemoteCommunicationClient.h --------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef liblldb_GDBRemoteCommunicationClient_h_
11#define liblldb_GDBRemoteCommunicationClient_h_
12
13// C Includes
14// C++ Includes
Eugene Zelenkoedb35d92015-10-24 01:08:35 +000015#include <map>
16#include <string>
Greg Claytonadc00cb2011-05-20 23:38:13 +000017#include <vector>
18
Greg Clayton576d8832011-03-22 04:00:09 +000019// Other libraries and framework includes
20// Project includes
21#include "lldb/Core/ArchSpec.h"
Greg Clayton358cf1e2015-06-25 21:46:34 +000022#include "lldb/Core/StructuredData.h"
Greg Clayton46fb5582011-11-18 07:03:08 +000023#include "lldb/Target/Process.h"
Greg Clayton576d8832011-03-22 04:00:09 +000024
25#include "GDBRemoteCommunication.h"
26
Tamas Berghammerdb264a62015-03-31 09:52:22 +000027namespace lldb_private {
28namespace process_gdb_remote {
29
Greg Clayton576d8832011-03-22 04:00:09 +000030class GDBRemoteCommunicationClient : public GDBRemoteCommunication
31{
32public:
Tamas Berghammere13c2732015-02-11 10:29:30 +000033 GDBRemoteCommunicationClient();
Greg Clayton576d8832011-03-22 04:00:09 +000034
Eugene Zelenkoedb35d92015-10-24 01:08:35 +000035 ~GDBRemoteCommunicationClient() override;
Greg Clayton576d8832011-03-22 04:00:09 +000036
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);
Eugene Zelenkoedb35d92015-10-24 01:08:35 +000081
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
Oleksiy Vyalov9fe526c2015-10-21 19:34:26 +0000117 bool
118 LaunchGDBServer (const char *remote_accept_hostname,
119 lldb::pid_t &pid,
120 uint16_t &port,
121 std::string &socket_name);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000122
123 bool
124 KillSpawnedProcess (lldb::pid_t pid);
Greg Clayton8b82f082011-04-12 05:54:46 +0000125
Greg Clayton576d8832011-03-22 04:00:09 +0000126 //------------------------------------------------------------------
127 /// Sends a GDB remote protocol 'A' packet that delivers program
128 /// arguments to the remote server.
129 ///
130 /// @param[in] argv
131 /// A NULL terminated array of const C strings to use as the
132 /// arguments.
133 ///
134 /// @return
135 /// Zero if the response was "OK", a positive value if the
136 /// the response was "Exx" where xx are two hex digits, or
137 /// -1 if the call is unsupported or any other unexpected
138 /// response was received.
139 //------------------------------------------------------------------
140 int
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000141 SendArgumentsPacket (const ProcessLaunchInfo &launch_info);
Greg Clayton576d8832011-03-22 04:00:09 +0000142
143 //------------------------------------------------------------------
144 /// Sends a "QEnvironment:NAME=VALUE" packet that will build up the
145 /// environment that will get used when launching an application
146 /// in conjunction with the 'A' packet. This function can be called
147 /// multiple times in a row in order to pass on the desired
148 /// environment that the inferior should be launched with.
149 ///
150 /// @param[in] name_equal_value
151 /// A NULL terminated C string that contains a single environment
152 /// in the format "NAME=VALUE".
153 ///
154 /// @return
155 /// Zero if the response was "OK", a positive value if the
156 /// the response was "Exx" where xx are two hex digits, or
157 /// -1 if the call is unsupported or any other unexpected
158 /// response was received.
159 //------------------------------------------------------------------
160 int
161 SendEnvironmentPacket (char const *name_equal_value);
162
Greg Claytonc4103b32011-05-08 04:53:50 +0000163 int
164 SendLaunchArchPacket (const char *arch);
Jason Molendaa3329782014-03-29 18:54:20 +0000165
166 int
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000167 SendLaunchEventDataPacket(const char *data, bool *was_supported = nullptr);
Jason Molendaa3329782014-03-29 18:54:20 +0000168
Greg Clayton576d8832011-03-22 04:00:09 +0000169 //------------------------------------------------------------------
170 /// Sends a "vAttach:PID" where PID is in hex.
171 ///
172 /// @param[in] pid
173 /// A process ID for the remote gdb server to attach to.
174 ///
175 /// @param[out] response
176 /// The response received from the gdb server. If the return
177 /// value is zero, \a response will contain a stop reply
178 /// packet.
179 ///
180 /// @return
181 /// Zero if the attach was successful, or an error indicating
182 /// an error code.
183 //------------------------------------------------------------------
184 int
185 SendAttach (lldb::pid_t pid,
186 StringExtractorGDBRemote& response);
187
Greg Clayton576d8832011-03-22 04:00:09 +0000188 //------------------------------------------------------------------
Vince Harrone0be4252015-02-06 18:32:57 +0000189 /// Sends a GDB remote protocol 'I' packet that delivers stdin
190 /// data to the remote process.
191 ///
192 /// @param[in] data
193 /// A pointer to stdin data.
194 ///
195 /// @param[in] data_len
196 /// The number of bytes available at \a data.
197 ///
198 /// @return
199 /// Zero if the attach was successful, or an error indicating
200 /// an error code.
201 //------------------------------------------------------------------
202 int
203 SendStdinNotification(const char* data, size_t data_len);
204
205 //------------------------------------------------------------------
Greg Clayton576d8832011-03-22 04:00:09 +0000206 /// Sets the path to use for stdin/out/err for a process
207 /// that will be launched with the 'A' packet.
208 ///
209 /// @param[in] path
210 /// The path to use for stdin/out/err
211 ///
212 /// @return
213 /// Zero if the for success, or an error code for failure.
214 //------------------------------------------------------------------
215 int
Chaoren Lind3173f32015-05-29 19:52:29 +0000216 SetSTDIN(const FileSpec &file_spec);
Greg Clayton576d8832011-03-22 04:00:09 +0000217 int
Chaoren Lind3173f32015-05-29 19:52:29 +0000218 SetSTDOUT(const FileSpec &file_spec);
Greg Clayton576d8832011-03-22 04:00:09 +0000219 int
Chaoren Lind3173f32015-05-29 19:52:29 +0000220 SetSTDERR(const FileSpec &file_spec);
Greg Clayton576d8832011-03-22 04:00:09 +0000221
222 //------------------------------------------------------------------
223 /// Sets the disable ASLR flag to \a enable for a process that will
224 /// be launched with the 'A' packet.
225 ///
226 /// @param[in] enable
Jim Ingham106d0282014-06-25 02:32:56 +0000227 /// A boolean value indicating whether to disable ASLR or not.
Greg Clayton576d8832011-03-22 04:00:09 +0000228 ///
229 /// @return
230 /// Zero if the for success, or an error code for failure.
231 //------------------------------------------------------------------
232 int
233 SetDisableASLR (bool enable);
Jim Ingham106d0282014-06-25 02:32:56 +0000234
235 //------------------------------------------------------------------
236 /// Sets the DetachOnError flag to \a enable for the process controlled by the stub.
237 ///
238 /// @param[in] enable
239 /// A boolean value indicating whether to detach on error or not.
240 ///
241 /// @return
242 /// Zero if the for success, or an error code for failure.
243 //------------------------------------------------------------------
244 int
245 SetDetachOnError (bool enable);
Greg Clayton576d8832011-03-22 04:00:09 +0000246
247 //------------------------------------------------------------------
248 /// Sets the working directory to \a path for a process that will
Greg Claytonfbb76342013-11-20 21:07:01 +0000249 /// be launched with the 'A' packet for non platform based
250 /// connections. If this packet is sent to a GDB server that
251 /// implements the platform, it will change the current working
252 /// directory for the platform process.
Greg Clayton576d8832011-03-22 04:00:09 +0000253 ///
Chaoren Lind3173f32015-05-29 19:52:29 +0000254 /// @param[in] working_dir
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +0000255 /// The path to a directory to use when launching our process
Greg Clayton576d8832011-03-22 04:00:09 +0000256 ///
257 /// @return
258 /// Zero if the for success, or an error code for failure.
259 //------------------------------------------------------------------
260 int
Chaoren Lind3173f32015-05-29 19:52:29 +0000261 SetWorkingDir(const FileSpec &working_dir);
Greg Clayton576d8832011-03-22 04:00:09 +0000262
Greg Claytonfbb76342013-11-20 21:07:01 +0000263 //------------------------------------------------------------------
264 /// Gets the current working directory of a remote platform GDB
265 /// server.
266 ///
Chaoren Lind3173f32015-05-29 19:52:29 +0000267 /// @param[out] working_dir
Greg Claytonfbb76342013-11-20 21:07:01 +0000268 /// The current working directory on the remote platform.
269 ///
270 /// @return
271 /// Boolean for success
272 //------------------------------------------------------------------
273 bool
Chaoren Lind3173f32015-05-29 19:52:29 +0000274 GetWorkingDir(FileSpec &working_dir);
Greg Claytonfbb76342013-11-20 21:07:01 +0000275
Greg Clayton576d8832011-03-22 04:00:09 +0000276 lldb::addr_t
277 AllocateMemory (size_t size, uint32_t permissions);
278
279 bool
280 DeallocateMemory (lldb::addr_t addr);
281
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000282 Error
Jim Inghamacff8952013-05-02 00:27:30 +0000283 Detach (bool keep_stopped);
Greg Clayton37a0a242012-04-11 00:24:49 +0000284
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000285 Error
286 GetMemoryRegionInfo (lldb::addr_t addr, MemoryRegionInfo &range_info);
Greg Clayton46fb5582011-11-18 07:03:08 +0000287
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000288 Error
Johnny Chen64637202012-05-23 21:09:52 +0000289 GetWatchpointSupportInfo (uint32_t &num);
290
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000291 Error
Jaydeep Patil725666c2015-08-13 03:46:01 +0000292 GetWatchpointSupportInfo (uint32_t &num, bool& after, const ArchSpec &arch);
Enrico Granataf04a2192012-07-13 23:18:48 +0000293
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000294 Error
Jaydeep Patil725666c2015-08-13 03:46:01 +0000295 GetWatchpointsTriggerAfterInstruction (bool &after, const ArchSpec &arch);
Enrico Granataf04a2192012-07-13 23:18:48 +0000296
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000297 const ArchSpec &
Greg Clayton576d8832011-03-22 04:00:09 +0000298 GetHostArchitecture ();
Greg Clayton9ac6d2d2013-10-25 18:13:17 +0000299
300 uint32_t
301 GetHostDefaultPacketTimeout();
Jason Molendaf17b5ac2012-12-19 02:54:03 +0000302
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000303 const ArchSpec &
Jason Molendaf17b5ac2012-12-19 02:54:03 +0000304 GetProcessArchitecture ();
305
Steve Pucci5ae54ae2014-01-25 05:46:51 +0000306 void
307 GetRemoteQSupported();
308
Greg Clayton576d8832011-03-22 04:00:09 +0000309 bool
310 GetVContSupported (char flavor);
311
Jim Inghamcd16df92012-07-20 21:37:13 +0000312 bool
Sean Callananb1de1142013-09-04 23:24:15 +0000313 GetpPacketSupported (lldb::tid_t tid);
Hafiz Abid Qadeer9a78cdf2013-08-29 09:09:45 +0000314
315 bool
Jason Molendabdc4f122014-05-06 02:59:39 +0000316 GetxPacketSupported ();
317
318 bool
Jim Inghamcd16df92012-07-20 21:37:13 +0000319 GetVAttachOrWaitSupported ();
320
Jim Ingham279ceec2012-07-25 21:12:43 +0000321 bool
322 GetSyncThreadStateSupported();
323
Greg Clayton576d8832011-03-22 04:00:09 +0000324 void
Greg Clayton2e59d4f2015-06-29 20:08:51 +0000325 ResetDiscoverableSettings (bool did_exec);
Greg Clayton576d8832011-03-22 04:00:09 +0000326
327 bool
Greg Clayton9b1e1cd2011-04-04 18:18:57 +0000328 GetHostInfo (bool force = false);
Ewan Crawford78baa192015-05-13 09:18:18 +0000329
330 bool
331 GetDefaultThreadId (lldb::tid_t &tid);
Greg Clayton576d8832011-03-22 04:00:09 +0000332
333 bool
Greg Clayton1cb64962011-03-24 04:28:38 +0000334 GetOSVersion (uint32_t &major,
335 uint32_t &minor,
336 uint32_t &update);
337
338 bool
339 GetOSBuildString (std::string &s);
340
341 bool
342 GetOSKernelDescription (std::string &s);
343
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000344 ArchSpec
Greg Clayton1cb64962011-03-24 04:28:38 +0000345 GetSystemArchitecture ();
346
347 bool
348 GetHostname (std::string &s);
349
Greg Clayton37a0a242012-04-11 00:24:49 +0000350 lldb::addr_t
351 GetShlibInfoAddr();
352
Greg Clayton1cb64962011-03-24 04:28:38 +0000353 bool
Greg Clayton576d8832011-03-22 04:00:09 +0000354 GetSupportsThreadSuffix ();
355
356 bool
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000357 GetProcessInfo (lldb::pid_t pid, ProcessInstanceInfo &process_info);
Greg Clayton32e0a752011-03-30 18:16:51 +0000358
359 uint32_t
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000360 FindProcesses (const ProcessInstanceInfoMatch &process_match_info,
361 ProcessInstanceInfoList &process_infos);
Greg Clayton32e0a752011-03-30 18:16:51 +0000362
363 bool
364 GetUserName (uint32_t uid, std::string &name);
365
366 bool
367 GetGroupName (uint32_t gid, std::string &name);
368
369 bool
Greg Clayton576d8832011-03-22 04:00:09 +0000370 HasFullVContSupport ()
371 {
372 return GetVContSupported ('A');
373 }
374
375 bool
376 HasAnyVContSupport ()
377 {
378 return GetVContSupported ('a');
379 }
380
Greg Clayton8b82f082011-04-12 05:54:46 +0000381 bool
382 GetStopReply (StringExtractorGDBRemote &response);
383
384 bool
Greg Claytonf402f782012-10-13 02:11:55 +0000385 GetThreadStopInfo (lldb::tid_t tid,
Greg Clayton8b82f082011-04-12 05:54:46 +0000386 StringExtractorGDBRemote &response);
387
388 bool
389 SupportsGDBStoppointPacket (GDBStoppointType type)
390 {
391 switch (type)
392 {
393 case eBreakpointSoftware: return m_supports_z0;
394 case eBreakpointHardware: return m_supports_z1;
395 case eWatchpointWrite: return m_supports_z2;
396 case eWatchpointRead: return m_supports_z3;
397 case eWatchpointReadWrite: return m_supports_z4;
Zachary Turner568b0de2015-02-18 18:44:03 +0000398 default: return false;
Greg Clayton8b82f082011-04-12 05:54:46 +0000399 }
Greg Clayton8b82f082011-04-12 05:54:46 +0000400 }
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000401
Greg Clayton8b82f082011-04-12 05:54:46 +0000402 uint8_t
403 SendGDBStoppointTypePacket (GDBStoppointType type, // Type of breakpoint or watchpoint
404 bool insert, // Insert or remove?
405 lldb::addr_t addr, // Address of breakpoint or watchpoint
406 uint32_t length); // Byte Size of breakpoint or watchpoint
407
Ewan Crawford78baa192015-05-13 09:18:18 +0000408 bool
409 SetNonStopMode (const bool enable);
410
Greg Clayton9b1e1cd2011-04-04 18:18:57 +0000411 void
Greg Claytone034a042015-05-21 20:52:06 +0000412 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 +0000413
414 // This packet is for testing the speed of the interface only. Both
415 // the client and server need to support it, but this allows us to
416 // measure the packet speed without any other work being done on the
417 // other end and avoids any of that work affecting the packet send
418 // and response times.
419 bool
420 SendSpeedTestPacket (uint32_t send_size,
421 uint32_t recv_size);
Greg Clayton8b82f082011-04-12 05:54:46 +0000422
423 bool
Jason Molendae9ca4af2013-02-23 02:04:45 +0000424 SetCurrentThread (uint64_t tid);
Greg Clayton8b82f082011-04-12 05:54:46 +0000425
426 bool
Jason Molendae9ca4af2013-02-23 02:04:45 +0000427 SetCurrentThreadForRun (uint64_t tid);
Greg Clayton8b82f082011-04-12 05:54:46 +0000428
Steve Pucci5ae54ae2014-01-25 05:46:51 +0000429 bool
Steve Pucci03904ac2014-03-04 23:18:46 +0000430 GetQXferAuxvReadSupported ();
431
432 bool
Steve Pucci5ae54ae2014-01-25 05:46:51 +0000433 GetQXferLibrariesReadSupported ();
434
435 bool
436 GetQXferLibrariesSVR4ReadSupported ();
437
438 uint64_t
439 GetRemoteMaxPacketSize();
440
441 bool
Greg Claytonb30c50c2015-05-29 00:01:55 +0000442 GetEchoSupported ();
443
444 bool
Steve Pucci5ae54ae2014-01-25 05:46:51 +0000445 GetAugmentedLibrariesSVR4ReadSupported ();
446
Colin Rileyc3c95b22015-04-16 15:51:33 +0000447 bool
448 GetQXferFeaturesReadSupported ();
449
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000450 LazyBool
Jim Ingham372787f2012-04-07 00:00:41 +0000451 SupportsAllocDeallocMemory () // const
Greg Clayton2a48f522011-05-14 01:50:35 +0000452 {
Jim Ingham372787f2012-04-07 00:00:41 +0000453 // Uncomment this to have lldb pretend the debug server doesn't respond to alloc/dealloc memory packets.
454 // m_supports_alloc_dealloc_memory = lldb_private::eLazyBoolNo;
Greg Clayton70b57652011-05-15 01:25:55 +0000455 return m_supports_alloc_dealloc_memory;
Greg Clayton2a48f522011-05-14 01:50:35 +0000456 }
457
Greg Claytonadc00cb2011-05-20 23:38:13 +0000458 size_t
459 GetCurrentThreadIDs (std::vector<lldb::tid_t> &thread_ids,
460 bool &sequence_mutex_unavailable);
461
Greg Clayton2687cd12012-03-29 01:55:41 +0000462 bool
463 GetInterruptWasSent () const
464 {
465 return m_interrupt_sent;
466 }
Han Ming Ong4b6459f2013-01-18 23:11:53 +0000467
Greg Claytonfbb76342013-11-20 21:07:01 +0000468 lldb::user_id_t
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000469 OpenFile (const FileSpec& file_spec, uint32_t flags, mode_t mode, Error &error);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000470
Greg Claytonfbb76342013-11-20 21:07:01 +0000471 bool
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000472 CloseFile (lldb::user_id_t fd, Error &error);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000473
Greg Claytonfbb76342013-11-20 21:07:01 +0000474 lldb::user_id_t
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000475 GetFileSize (const FileSpec& file_spec);
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 GetFilePermissions(const FileSpec &file_spec, uint32_t &file_permissions);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000479
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000480 Error
Chaoren Lind3173f32015-05-29 19:52:29 +0000481 SetFilePermissions(const FileSpec &file_spec, uint32_t file_permissions);
Greg Claytonfbb76342013-11-20 21:07:01 +0000482
483 uint64_t
Daniel Maleae0f8f572013-08-26 23:57:52 +0000484 ReadFile (lldb::user_id_t fd,
485 uint64_t offset,
486 void *dst,
487 uint64_t dst_len,
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000488 Error &error);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000489
Greg Claytonfbb76342013-11-20 21:07:01 +0000490 uint64_t
Daniel Maleae0f8f572013-08-26 23:57:52 +0000491 WriteFile (lldb::user_id_t fd,
492 uint64_t offset,
493 const void* src,
494 uint64_t src_len,
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000495 Error &error);
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 CreateSymlink(const FileSpec &src,
499 const FileSpec &dst);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000500
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000501 Error
Chaoren Lind3173f32015-05-29 19:52:29 +0000502 Unlink(const FileSpec &file_spec);
Greg Claytonfbb76342013-11-20 21:07:01 +0000503
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000504 Error
Chaoren Lind3173f32015-05-29 19:52:29 +0000505 MakeDirectory(const FileSpec &file_spec, uint32_t mode);
506
Greg Claytonfbb76342013-11-20 21:07:01 +0000507 bool
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000508 GetFileExists (const FileSpec& file_spec);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000509
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000510 Error
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000511 RunShellCommand(const char *command, // Shouldn't be nullptr
Chaoren Lind3173f32015-05-29 19:52:29 +0000512 const FileSpec &working_dir, // Pass empty FileSpec to use the current working directory
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000513 int *status_ptr, // Pass nullptr if you don't want the process exit status
514 int *signo_ptr, // Pass nullptr if you don't want the signal that caused the process to exit
515 std::string *command_output, // Pass nullptr if you don't want the command output
Chaoren Lind3173f32015-05-29 19:52:29 +0000516 uint32_t timeout_sec); // Timeout in seconds to wait for shell program to finish
517
Greg Claytonfbb76342013-11-20 21:07:01 +0000518 bool
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000519 CalculateMD5 (const FileSpec& file_spec, uint64_t &high, uint64_t &low);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000520
Han Ming Ong4b6459f2013-01-18 23:11:53 +0000521 std::string
522 HarmonizeThreadIdsForProfileData (ProcessGDBRemote *process,
523 StringExtractorGDBRemote &inputStringExtractor);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000524
Greg Claytonf74cf862013-11-13 23:28:31 +0000525 bool
526 ReadRegister(lldb::tid_t tid,
527 uint32_t reg_num,
528 StringExtractorGDBRemote &response);
529
530 bool
531 ReadAllRegisters (lldb::tid_t tid,
532 StringExtractorGDBRemote &response);
533
534 bool
535 SaveRegisterState (lldb::tid_t tid, uint32_t &save_id);
536
537 bool
538 RestoreRegisterState (lldb::tid_t tid, uint32_t save_id);
Jason Molendaa3329782014-03-29 18:54:20 +0000539
540 const char *
541 GetGDBServerProgramName();
Greg Claytonf74cf862013-11-13 23:28:31 +0000542
Jason Molendaa3329782014-03-29 18:54:20 +0000543 uint32_t
544 GetGDBServerProgramVersion();
545
546 bool
547 AvoidGPackets(ProcessGDBRemote *process);
548
Greg Clayton358cf1e2015-06-25 21:46:34 +0000549 StructuredData::ObjectSP
550 GetThreadsInfo();
551
Jason Molenda705b1802014-06-13 02:37:02 +0000552 bool
553 GetThreadExtendedInfoSupported();
554
Oleksiy Vyalov6801be32015-02-25 22:15:44 +0000555 bool
Jason Molenda20ee21b2015-07-10 23:15:22 +0000556 GetLoadedDynamicLibrariesInfosSupported();
557
558 bool
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000559 GetModuleInfo (const FileSpec& module_file_spec,
560 const ArchSpec& arch_spec,
561 ModuleSpec &module_spec);
Oleksiy Vyalov6801be32015-02-25 22:15:44 +0000562
Colin Rileyc3c95b22015-04-16 15:51:33 +0000563 bool
564 ReadExtFeature (const lldb_private::ConstString object,
565 const lldb_private::ConstString annex,
566 std::string & out,
567 lldb_private::Error & err);
568
Greg Clayton0b90be12015-06-23 21:27:50 +0000569 void
570 ServeSymbolLookups(lldb_private::Process *process);
571
Greg Clayton576d8832011-03-22 04:00:09 +0000572protected:
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000573 LazyBool m_supports_not_sending_acks;
574 LazyBool m_supports_thread_suffix;
575 LazyBool m_supports_threads_in_stop_reply;
576 LazyBool m_supports_vCont_all;
577 LazyBool m_supports_vCont_any;
578 LazyBool m_supports_vCont_c;
579 LazyBool m_supports_vCont_C;
580 LazyBool m_supports_vCont_s;
581 LazyBool m_supports_vCont_S;
582 LazyBool m_qHostInfo_is_valid;
583 LazyBool m_curr_pid_is_valid;
584 LazyBool m_qProcessInfo_is_valid;
585 LazyBool m_qGDBServerVersion_is_valid;
586 LazyBool m_supports_alloc_dealloc_memory;
587 LazyBool m_supports_memory_region_info;
588 LazyBool m_supports_watchpoint_support_info;
589 LazyBool m_supports_detach_stay_stopped;
590 LazyBool m_watchpoints_trigger_after_instruction;
591 LazyBool m_attach_or_wait_reply;
592 LazyBool m_prepare_for_reg_writing_reply;
593 LazyBool m_supports_p;
594 LazyBool m_supports_x;
595 LazyBool m_avoid_g_packets;
596 LazyBool m_supports_QSaveRegisterState;
597 LazyBool m_supports_qXfer_auxv_read;
598 LazyBool m_supports_qXfer_libraries_read;
599 LazyBool m_supports_qXfer_libraries_svr4_read;
Colin Rileyc3c95b22015-04-16 15:51:33 +0000600 LazyBool m_supports_qXfer_features_read;
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000601 LazyBool m_supports_augmented_libraries_svr4_read;
602 LazyBool m_supports_jThreadExtendedInfo;
Jason Molenda20ee21b2015-07-10 23:15:22 +0000603 LazyBool m_supports_jLoadedDynamicLibrariesInfos;
Steve Pucci5ae54ae2014-01-25 05:46:51 +0000604
Greg Clayton8b82f082011-04-12 05:54:46 +0000605 bool
606 m_supports_qProcessInfoPID:1,
607 m_supports_qfProcessInfo:1,
608 m_supports_qUserName:1,
609 m_supports_qGroupName:1,
610 m_supports_qThreadStopInfo:1,
611 m_supports_z0:1,
612 m_supports_z1:1,
613 m_supports_z2:1,
614 m_supports_z3:1,
Greg Clayton89600582013-10-10 17:53:50 +0000615 m_supports_z4:1,
616 m_supports_QEnvironment:1,
Greg Clayton0b90be12015-06-23 21:27:50 +0000617 m_supports_QEnvironmentHexEncoded:1,
Greg Clayton358cf1e2015-06-25 21:46:34 +0000618 m_supports_qSymbol:1,
619 m_supports_jThreadsInfo:1;
Greg Clayton2a48f522011-05-14 01:50:35 +0000620
Todd Fiala9f72b3a2014-05-07 19:28:21 +0000621 lldb::pid_t m_curr_pid;
Greg Clayton8b82f082011-04-12 05:54:46 +0000622 lldb::tid_t m_curr_tid; // Current gdb remote protocol thread index for all other operations
623 lldb::tid_t m_curr_tid_run; // Current gdb remote protocol thread index for continue, step, etc
624
Johnny Chen64637202012-05-23 21:09:52 +0000625 uint32_t m_num_supported_hardware_watchpoints;
626
Greg Clayton576d8832011-03-22 04:00:09 +0000627 // If we need to send a packet while the target is running, the m_async_XXX
628 // member variables take care of making this happen.
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000629 Mutex m_async_mutex;
630 Predicate<bool> m_async_packet_predicate;
Greg Clayton576d8832011-03-22 04:00:09 +0000631 std::string m_async_packet;
Jim Inghama6195b72013-12-18 01:24:33 +0000632 PacketResult m_async_result;
Greg Clayton576d8832011-03-22 04:00:09 +0000633 StringExtractorGDBRemote m_async_response;
634 int m_async_signal; // We were asked to deliver a signal to the inferior process.
Greg Clayton2687cd12012-03-29 01:55:41 +0000635 bool m_interrupt_sent;
Han Ming Ong4b6459f2013-01-18 23:11:53 +0000636 std::string m_partial_profile_data;
637 std::map<uint64_t, uint32_t> m_thread_id_to_used_usec_map;
Greg Clayton576d8832011-03-22 04:00:09 +0000638
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000639 ArchSpec m_host_arch;
640 ArchSpec m_process_arch;
Greg Clayton1cb64962011-03-24 04:28:38 +0000641 uint32_t m_os_version_major;
642 uint32_t m_os_version_minor;
643 uint32_t m_os_version_update;
644 std::string m_os_build;
645 std::string m_os_kernel;
646 std::string m_hostname;
Jason Molendaa3329782014-03-29 18:54:20 +0000647 std::string m_gdb_server_name; // from reply to qGDBServerVersion, empty if qGDBServerVersion is not supported
648 uint32_t m_gdb_server_version; // from reply to qGDBServerVersion, zero if qGDBServerVersion is not supported
Greg Clayton9ac6d2d2013-10-25 18:13:17 +0000649 uint32_t m_default_packet_timeout;
Steve Pucci5ae54ae2014-01-25 05:46:51 +0000650 uint64_t m_max_packet_size; // as returned by qSupported
Jason Molenda91ffe0a2015-06-18 21:46:06 +0000651
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000652 PacketResult
653 SendPacketAndWaitForResponseNoLock (const char *payload,
654 size_t payload_length,
655 StringExtractorGDBRemote &response);
656
657 bool
658 GetCurrentProcessInfo (bool allow_lazy_pid = true);
659
660 bool
661 GetGDBServerVersion();
662
663 // Given the list of compression types that the remote debug stub can support,
664 // possibly enable compression if we find an encoding we can handle.
665 void
666 MaybeEnableCompression (std::vector<std::string> supported_compressions);
667
Greg Clayton32e0a752011-03-30 18:16:51 +0000668 bool
669 DecodeProcessInfoResponse (StringExtractorGDBRemote &response,
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000670 ProcessInstanceInfo &process_info);
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000671
Greg Clayton576d8832011-03-22 04:00:09 +0000672private:
Greg Clayton576d8832011-03-22 04:00:09 +0000673 DISALLOW_COPY_AND_ASSIGN (GDBRemoteCommunicationClient);
674};
675
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000676} // namespace process_gdb_remote
677} // namespace lldb_private
678
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000679#endif // liblldb_GDBRemoteCommunicationClient_h_