blob: 33114d2611fe48c687e2235687e8df0989f19278 [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);
Tamas Berghammerccd6cff2015-12-08 14:08:19 +0000122
123 size_t
124 QueryGDBServer (std::vector<std::pair<uint16_t, std::string>>& connection_urls);
125
Daniel Maleae0f8f572013-08-26 23:57:52 +0000126 bool
127 KillSpawnedProcess (lldb::pid_t pid);
Greg Clayton8b82f082011-04-12 05:54:46 +0000128
Greg Clayton576d8832011-03-22 04:00:09 +0000129 //------------------------------------------------------------------
130 /// Sends a GDB remote protocol 'A' packet that delivers program
131 /// arguments to the remote server.
132 ///
133 /// @param[in] argv
134 /// A NULL terminated array of const C strings to use as the
135 /// arguments.
136 ///
137 /// @return
138 /// Zero if the response was "OK", a positive value if the
139 /// the response was "Exx" where xx are two hex digits, or
140 /// -1 if the call is unsupported or any other unexpected
141 /// response was received.
142 //------------------------------------------------------------------
143 int
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000144 SendArgumentsPacket (const ProcessLaunchInfo &launch_info);
Greg Clayton576d8832011-03-22 04:00:09 +0000145
146 //------------------------------------------------------------------
147 /// Sends a "QEnvironment:NAME=VALUE" packet that will build up the
148 /// environment that will get used when launching an application
149 /// in conjunction with the 'A' packet. This function can be called
150 /// multiple times in a row in order to pass on the desired
151 /// environment that the inferior should be launched with.
152 ///
153 /// @param[in] name_equal_value
154 /// A NULL terminated C string that contains a single environment
155 /// in the format "NAME=VALUE".
156 ///
157 /// @return
158 /// Zero if the response was "OK", a positive value if the
159 /// the response was "Exx" where xx are two hex digits, or
160 /// -1 if the call is unsupported or any other unexpected
161 /// response was received.
162 //------------------------------------------------------------------
163 int
164 SendEnvironmentPacket (char const *name_equal_value);
165
Greg Claytonc4103b32011-05-08 04:53:50 +0000166 int
167 SendLaunchArchPacket (const char *arch);
Jason Molendaa3329782014-03-29 18:54:20 +0000168
169 int
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000170 SendLaunchEventDataPacket(const char *data, bool *was_supported = nullptr);
Jason Molendaa3329782014-03-29 18:54:20 +0000171
Greg Clayton576d8832011-03-22 04:00:09 +0000172 //------------------------------------------------------------------
173 /// Sends a "vAttach:PID" where PID is in hex.
174 ///
175 /// @param[in] pid
176 /// A process ID for the remote gdb server to attach to.
177 ///
178 /// @param[out] response
179 /// The response received from the gdb server. If the return
180 /// value is zero, \a response will contain a stop reply
181 /// packet.
182 ///
183 /// @return
184 /// Zero if the attach was successful, or an error indicating
185 /// an error code.
186 //------------------------------------------------------------------
187 int
188 SendAttach (lldb::pid_t pid,
189 StringExtractorGDBRemote& response);
190
Greg Clayton576d8832011-03-22 04:00:09 +0000191 //------------------------------------------------------------------
Vince Harrone0be4252015-02-06 18:32:57 +0000192 /// Sends a GDB remote protocol 'I' packet that delivers stdin
193 /// data to the remote process.
194 ///
195 /// @param[in] data
196 /// A pointer to stdin data.
197 ///
198 /// @param[in] data_len
199 /// The number of bytes available at \a data.
200 ///
201 /// @return
202 /// Zero if the attach was successful, or an error indicating
203 /// an error code.
204 //------------------------------------------------------------------
205 int
206 SendStdinNotification(const char* data, size_t data_len);
207
208 //------------------------------------------------------------------
Greg Clayton576d8832011-03-22 04:00:09 +0000209 /// Sets the path to use for stdin/out/err for a process
210 /// that will be launched with the 'A' packet.
211 ///
212 /// @param[in] path
213 /// The path to use for stdin/out/err
214 ///
215 /// @return
216 /// Zero if the for success, or an error code for failure.
217 //------------------------------------------------------------------
218 int
Chaoren Lind3173f32015-05-29 19:52:29 +0000219 SetSTDIN(const FileSpec &file_spec);
Greg Clayton576d8832011-03-22 04:00:09 +0000220 int
Chaoren Lind3173f32015-05-29 19:52:29 +0000221 SetSTDOUT(const FileSpec &file_spec);
Greg Clayton576d8832011-03-22 04:00:09 +0000222 int
Chaoren Lind3173f32015-05-29 19:52:29 +0000223 SetSTDERR(const FileSpec &file_spec);
Greg Clayton576d8832011-03-22 04:00:09 +0000224
225 //------------------------------------------------------------------
226 /// Sets the disable ASLR flag to \a enable for a process that will
227 /// be launched with the 'A' packet.
228 ///
229 /// @param[in] enable
Jim Ingham106d0282014-06-25 02:32:56 +0000230 /// A boolean value indicating whether to disable ASLR or not.
Greg Clayton576d8832011-03-22 04:00:09 +0000231 ///
232 /// @return
233 /// Zero if the for success, or an error code for failure.
234 //------------------------------------------------------------------
235 int
236 SetDisableASLR (bool enable);
Jim Ingham106d0282014-06-25 02:32:56 +0000237
238 //------------------------------------------------------------------
239 /// Sets the DetachOnError flag to \a enable for the process controlled by the stub.
240 ///
241 /// @param[in] enable
242 /// A boolean value indicating whether to detach on error or not.
243 ///
244 /// @return
245 /// Zero if the for success, or an error code for failure.
246 //------------------------------------------------------------------
247 int
248 SetDetachOnError (bool enable);
Greg Clayton576d8832011-03-22 04:00:09 +0000249
250 //------------------------------------------------------------------
251 /// Sets the working directory to \a path for a process that will
Greg Claytonfbb76342013-11-20 21:07:01 +0000252 /// be launched with the 'A' packet for non platform based
253 /// connections. If this packet is sent to a GDB server that
254 /// implements the platform, it will change the current working
255 /// directory for the platform process.
Greg Clayton576d8832011-03-22 04:00:09 +0000256 ///
Chaoren Lind3173f32015-05-29 19:52:29 +0000257 /// @param[in] working_dir
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +0000258 /// The path to a directory to use when launching our process
Greg Clayton576d8832011-03-22 04:00:09 +0000259 ///
260 /// @return
261 /// Zero if the for success, or an error code for failure.
262 //------------------------------------------------------------------
263 int
Chaoren Lind3173f32015-05-29 19:52:29 +0000264 SetWorkingDir(const FileSpec &working_dir);
Greg Clayton576d8832011-03-22 04:00:09 +0000265
Greg Claytonfbb76342013-11-20 21:07:01 +0000266 //------------------------------------------------------------------
267 /// Gets the current working directory of a remote platform GDB
268 /// server.
269 ///
Chaoren Lind3173f32015-05-29 19:52:29 +0000270 /// @param[out] working_dir
Greg Claytonfbb76342013-11-20 21:07:01 +0000271 /// The current working directory on the remote platform.
272 ///
273 /// @return
274 /// Boolean for success
275 //------------------------------------------------------------------
276 bool
Chaoren Lind3173f32015-05-29 19:52:29 +0000277 GetWorkingDir(FileSpec &working_dir);
Greg Claytonfbb76342013-11-20 21:07:01 +0000278
Greg Clayton576d8832011-03-22 04:00:09 +0000279 lldb::addr_t
280 AllocateMemory (size_t size, uint32_t permissions);
281
282 bool
283 DeallocateMemory (lldb::addr_t addr);
284
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000285 Error
Jim Inghamacff8952013-05-02 00:27:30 +0000286 Detach (bool keep_stopped);
Greg Clayton37a0a242012-04-11 00:24:49 +0000287
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000288 Error
289 GetMemoryRegionInfo (lldb::addr_t addr, MemoryRegionInfo &range_info);
Greg Clayton46fb5582011-11-18 07:03:08 +0000290
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000291 Error
Johnny Chen64637202012-05-23 21:09:52 +0000292 GetWatchpointSupportInfo (uint32_t &num);
293
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000294 Error
Jaydeep Patil725666c2015-08-13 03:46:01 +0000295 GetWatchpointSupportInfo (uint32_t &num, bool& after, const ArchSpec &arch);
Enrico Granataf04a2192012-07-13 23:18:48 +0000296
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000297 Error
Jaydeep Patil725666c2015-08-13 03:46:01 +0000298 GetWatchpointsTriggerAfterInstruction (bool &after, const ArchSpec &arch);
Enrico Granataf04a2192012-07-13 23:18:48 +0000299
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000300 const ArchSpec &
Greg Clayton576d8832011-03-22 04:00:09 +0000301 GetHostArchitecture ();
Greg Clayton9ac6d2d2013-10-25 18:13:17 +0000302
303 uint32_t
304 GetHostDefaultPacketTimeout();
Jason Molendaf17b5ac2012-12-19 02:54:03 +0000305
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000306 const ArchSpec &
Jason Molendaf17b5ac2012-12-19 02:54:03 +0000307 GetProcessArchitecture ();
308
Steve Pucci5ae54ae2014-01-25 05:46:51 +0000309 void
310 GetRemoteQSupported();
311
Greg Clayton576d8832011-03-22 04:00:09 +0000312 bool
313 GetVContSupported (char flavor);
314
Jim Inghamcd16df92012-07-20 21:37:13 +0000315 bool
Sean Callananb1de1142013-09-04 23:24:15 +0000316 GetpPacketSupported (lldb::tid_t tid);
Hafiz Abid Qadeer9a78cdf2013-08-29 09:09:45 +0000317
318 bool
Jason Molendabdc4f122014-05-06 02:59:39 +0000319 GetxPacketSupported ();
320
321 bool
Jim Inghamcd16df92012-07-20 21:37:13 +0000322 GetVAttachOrWaitSupported ();
323
Jim Ingham279ceec2012-07-25 21:12:43 +0000324 bool
325 GetSyncThreadStateSupported();
326
Greg Clayton576d8832011-03-22 04:00:09 +0000327 void
Greg Clayton2e59d4f2015-06-29 20:08:51 +0000328 ResetDiscoverableSettings (bool did_exec);
Greg Clayton576d8832011-03-22 04:00:09 +0000329
330 bool
Greg Clayton9b1e1cd2011-04-04 18:18:57 +0000331 GetHostInfo (bool force = false);
Ewan Crawford78baa192015-05-13 09:18:18 +0000332
333 bool
334 GetDefaultThreadId (lldb::tid_t &tid);
Greg Clayton576d8832011-03-22 04:00:09 +0000335
336 bool
Greg Clayton1cb64962011-03-24 04:28:38 +0000337 GetOSVersion (uint32_t &major,
338 uint32_t &minor,
339 uint32_t &update);
340
341 bool
342 GetOSBuildString (std::string &s);
343
344 bool
345 GetOSKernelDescription (std::string &s);
346
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000347 ArchSpec
Greg Clayton1cb64962011-03-24 04:28:38 +0000348 GetSystemArchitecture ();
349
350 bool
351 GetHostname (std::string &s);
352
Greg Clayton37a0a242012-04-11 00:24:49 +0000353 lldb::addr_t
354 GetShlibInfoAddr();
355
Greg Clayton1cb64962011-03-24 04:28:38 +0000356 bool
Greg Clayton576d8832011-03-22 04:00:09 +0000357 GetSupportsThreadSuffix ();
358
359 bool
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000360 GetProcessInfo (lldb::pid_t pid, ProcessInstanceInfo &process_info);
Greg Clayton32e0a752011-03-30 18:16:51 +0000361
362 uint32_t
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000363 FindProcesses (const ProcessInstanceInfoMatch &process_match_info,
364 ProcessInstanceInfoList &process_infos);
Greg Clayton32e0a752011-03-30 18:16:51 +0000365
366 bool
367 GetUserName (uint32_t uid, std::string &name);
368
369 bool
370 GetGroupName (uint32_t gid, std::string &name);
371
372 bool
Greg Clayton576d8832011-03-22 04:00:09 +0000373 HasFullVContSupport ()
374 {
375 return GetVContSupported ('A');
376 }
377
378 bool
379 HasAnyVContSupport ()
380 {
381 return GetVContSupported ('a');
382 }
383
Greg Clayton8b82f082011-04-12 05:54:46 +0000384 bool
385 GetStopReply (StringExtractorGDBRemote &response);
386
387 bool
Greg Claytonf402f782012-10-13 02:11:55 +0000388 GetThreadStopInfo (lldb::tid_t tid,
Greg Clayton8b82f082011-04-12 05:54:46 +0000389 StringExtractorGDBRemote &response);
390
391 bool
392 SupportsGDBStoppointPacket (GDBStoppointType type)
393 {
394 switch (type)
395 {
396 case eBreakpointSoftware: return m_supports_z0;
397 case eBreakpointHardware: return m_supports_z1;
398 case eWatchpointWrite: return m_supports_z2;
399 case eWatchpointRead: return m_supports_z3;
400 case eWatchpointReadWrite: return m_supports_z4;
Zachary Turner568b0de2015-02-18 18:44:03 +0000401 default: return false;
Greg Clayton8b82f082011-04-12 05:54:46 +0000402 }
Greg Clayton8b82f082011-04-12 05:54:46 +0000403 }
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000404
Greg Clayton8b82f082011-04-12 05:54:46 +0000405 uint8_t
406 SendGDBStoppointTypePacket (GDBStoppointType type, // Type of breakpoint or watchpoint
407 bool insert, // Insert or remove?
408 lldb::addr_t addr, // Address of breakpoint or watchpoint
409 uint32_t length); // Byte Size of breakpoint or watchpoint
410
Ewan Crawford78baa192015-05-13 09:18:18 +0000411 bool
412 SetNonStopMode (const bool enable);
413
Greg Clayton9b1e1cd2011-04-04 18:18:57 +0000414 void
Greg Claytone034a042015-05-21 20:52:06 +0000415 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 +0000416
417 // This packet is for testing the speed of the interface only. Both
418 // the client and server need to support it, but this allows us to
419 // measure the packet speed without any other work being done on the
420 // other end and avoids any of that work affecting the packet send
421 // and response times.
422 bool
423 SendSpeedTestPacket (uint32_t send_size,
424 uint32_t recv_size);
Greg Clayton8b82f082011-04-12 05:54:46 +0000425
426 bool
Jason Molendae9ca4af2013-02-23 02:04:45 +0000427 SetCurrentThread (uint64_t tid);
Greg Clayton8b82f082011-04-12 05:54:46 +0000428
429 bool
Jason Molendae9ca4af2013-02-23 02:04:45 +0000430 SetCurrentThreadForRun (uint64_t tid);
Greg Clayton8b82f082011-04-12 05:54:46 +0000431
Steve Pucci5ae54ae2014-01-25 05:46:51 +0000432 bool
Steve Pucci03904ac2014-03-04 23:18:46 +0000433 GetQXferAuxvReadSupported ();
434
435 bool
Steve Pucci5ae54ae2014-01-25 05:46:51 +0000436 GetQXferLibrariesReadSupported ();
437
438 bool
439 GetQXferLibrariesSVR4ReadSupported ();
440
441 uint64_t
442 GetRemoteMaxPacketSize();
443
444 bool
Greg Claytonb30c50c2015-05-29 00:01:55 +0000445 GetEchoSupported ();
446
447 bool
Steve Pucci5ae54ae2014-01-25 05:46:51 +0000448 GetAugmentedLibrariesSVR4ReadSupported ();
449
Colin Rileyc3c95b22015-04-16 15:51:33 +0000450 bool
451 GetQXferFeaturesReadSupported ();
452
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000453 LazyBool
Jim Ingham372787f2012-04-07 00:00:41 +0000454 SupportsAllocDeallocMemory () // const
Greg Clayton2a48f522011-05-14 01:50:35 +0000455 {
Jim Ingham372787f2012-04-07 00:00:41 +0000456 // Uncomment this to have lldb pretend the debug server doesn't respond to alloc/dealloc memory packets.
457 // m_supports_alloc_dealloc_memory = lldb_private::eLazyBoolNo;
Greg Clayton70b57652011-05-15 01:25:55 +0000458 return m_supports_alloc_dealloc_memory;
Greg Clayton2a48f522011-05-14 01:50:35 +0000459 }
460
Greg Claytonadc00cb2011-05-20 23:38:13 +0000461 size_t
462 GetCurrentThreadIDs (std::vector<lldb::tid_t> &thread_ids,
463 bool &sequence_mutex_unavailable);
464
Greg Clayton2687cd12012-03-29 01:55:41 +0000465 bool
466 GetInterruptWasSent () const
467 {
468 return m_interrupt_sent;
469 }
Han Ming Ong4b6459f2013-01-18 23:11:53 +0000470
Greg Claytonfbb76342013-11-20 21:07:01 +0000471 lldb::user_id_t
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000472 OpenFile (const FileSpec& file_spec, uint32_t flags, mode_t mode, Error &error);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000473
Greg Claytonfbb76342013-11-20 21:07:01 +0000474 bool
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000475 CloseFile (lldb::user_id_t fd, Error &error);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000476
Greg Claytonfbb76342013-11-20 21:07:01 +0000477 lldb::user_id_t
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000478 GetFileSize (const FileSpec& file_spec);
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 GetFilePermissions(const FileSpec &file_spec, uint32_t &file_permissions);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000482
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000483 Error
Chaoren Lind3173f32015-05-29 19:52:29 +0000484 SetFilePermissions(const FileSpec &file_spec, uint32_t file_permissions);
Greg Claytonfbb76342013-11-20 21:07:01 +0000485
486 uint64_t
Daniel Maleae0f8f572013-08-26 23:57:52 +0000487 ReadFile (lldb::user_id_t fd,
488 uint64_t offset,
489 void *dst,
490 uint64_t dst_len,
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000491 Error &error);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000492
Greg Claytonfbb76342013-11-20 21:07:01 +0000493 uint64_t
Daniel Maleae0f8f572013-08-26 23:57:52 +0000494 WriteFile (lldb::user_id_t fd,
495 uint64_t offset,
496 const void* src,
497 uint64_t src_len,
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000498 Error &error);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000499
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000500 Error
Chaoren Lind3173f32015-05-29 19:52:29 +0000501 CreateSymlink(const FileSpec &src,
502 const FileSpec &dst);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000503
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000504 Error
Chaoren Lind3173f32015-05-29 19:52:29 +0000505 Unlink(const FileSpec &file_spec);
Greg Claytonfbb76342013-11-20 21:07:01 +0000506
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000507 Error
Chaoren Lind3173f32015-05-29 19:52:29 +0000508 MakeDirectory(const FileSpec &file_spec, uint32_t mode);
509
Greg Claytonfbb76342013-11-20 21:07:01 +0000510 bool
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000511 GetFileExists (const FileSpec& file_spec);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000512
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000513 Error
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000514 RunShellCommand(const char *command, // Shouldn't be nullptr
Chaoren Lind3173f32015-05-29 19:52:29 +0000515 const FileSpec &working_dir, // Pass empty FileSpec to use the current working directory
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000516 int *status_ptr, // Pass nullptr if you don't want the process exit status
517 int *signo_ptr, // Pass nullptr if you don't want the signal that caused the process to exit
518 std::string *command_output, // Pass nullptr if you don't want the command output
Chaoren Lind3173f32015-05-29 19:52:29 +0000519 uint32_t timeout_sec); // Timeout in seconds to wait for shell program to finish
520
Greg Claytonfbb76342013-11-20 21:07:01 +0000521 bool
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000522 CalculateMD5 (const FileSpec& file_spec, uint64_t &high, uint64_t &low);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000523
Han Ming Ong4b6459f2013-01-18 23:11:53 +0000524 std::string
525 HarmonizeThreadIdsForProfileData (ProcessGDBRemote *process,
526 StringExtractorGDBRemote &inputStringExtractor);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000527
Greg Claytonf74cf862013-11-13 23:28:31 +0000528 bool
529 ReadRegister(lldb::tid_t tid,
Francis Ricci39f11892016-04-25 20:59:11 +0000530 uint32_t reg_num, // Must be the eRegisterKindProcessPlugin register number, to be sent to the remote
Greg Claytonf74cf862013-11-13 23:28:31 +0000531 StringExtractorGDBRemote &response);
532
533 bool
534 ReadAllRegisters (lldb::tid_t tid,
535 StringExtractorGDBRemote &response);
536
537 bool
538 SaveRegisterState (lldb::tid_t tid, uint32_t &save_id);
539
540 bool
541 RestoreRegisterState (lldb::tid_t tid, uint32_t save_id);
Jason Molendaa3329782014-03-29 18:54:20 +0000542
543 const char *
544 GetGDBServerProgramName();
Greg Claytonf74cf862013-11-13 23:28:31 +0000545
Jason Molendaa3329782014-03-29 18:54:20 +0000546 uint32_t
547 GetGDBServerProgramVersion();
548
549 bool
550 AvoidGPackets(ProcessGDBRemote *process);
551
Greg Clayton358cf1e2015-06-25 21:46:34 +0000552 StructuredData::ObjectSP
553 GetThreadsInfo();
554
Jason Molenda705b1802014-06-13 02:37:02 +0000555 bool
556 GetThreadExtendedInfoSupported();
557
Oleksiy Vyalov6801be32015-02-25 22:15:44 +0000558 bool
Jason Molenda20ee21b2015-07-10 23:15:22 +0000559 GetLoadedDynamicLibrariesInfosSupported();
560
561 bool
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000562 GetModuleInfo (const FileSpec& module_file_spec,
563 const ArchSpec& arch_spec,
564 ModuleSpec &module_spec);
Oleksiy Vyalov6801be32015-02-25 22:15:44 +0000565
Colin Rileyc3c95b22015-04-16 15:51:33 +0000566 bool
567 ReadExtFeature (const lldb_private::ConstString object,
568 const lldb_private::ConstString annex,
569 std::string & out,
570 lldb_private::Error & err);
571
Greg Clayton0b90be12015-06-23 21:27:50 +0000572 void
573 ServeSymbolLookups(lldb_private::Process *process);
574
Greg Clayton576d8832011-03-22 04:00:09 +0000575protected:
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000576 LazyBool m_supports_not_sending_acks;
577 LazyBool m_supports_thread_suffix;
578 LazyBool m_supports_threads_in_stop_reply;
579 LazyBool m_supports_vCont_all;
580 LazyBool m_supports_vCont_any;
581 LazyBool m_supports_vCont_c;
582 LazyBool m_supports_vCont_C;
583 LazyBool m_supports_vCont_s;
584 LazyBool m_supports_vCont_S;
585 LazyBool m_qHostInfo_is_valid;
586 LazyBool m_curr_pid_is_valid;
587 LazyBool m_qProcessInfo_is_valid;
588 LazyBool m_qGDBServerVersion_is_valid;
589 LazyBool m_supports_alloc_dealloc_memory;
590 LazyBool m_supports_memory_region_info;
591 LazyBool m_supports_watchpoint_support_info;
592 LazyBool m_supports_detach_stay_stopped;
593 LazyBool m_watchpoints_trigger_after_instruction;
594 LazyBool m_attach_or_wait_reply;
595 LazyBool m_prepare_for_reg_writing_reply;
596 LazyBool m_supports_p;
597 LazyBool m_supports_x;
598 LazyBool m_avoid_g_packets;
599 LazyBool m_supports_QSaveRegisterState;
600 LazyBool m_supports_qXfer_auxv_read;
601 LazyBool m_supports_qXfer_libraries_read;
602 LazyBool m_supports_qXfer_libraries_svr4_read;
Colin Rileyc3c95b22015-04-16 15:51:33 +0000603 LazyBool m_supports_qXfer_features_read;
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000604 LazyBool m_supports_augmented_libraries_svr4_read;
605 LazyBool m_supports_jThreadExtendedInfo;
Jason Molenda20ee21b2015-07-10 23:15:22 +0000606 LazyBool m_supports_jLoadedDynamicLibrariesInfos;
Steve Pucci5ae54ae2014-01-25 05:46:51 +0000607
Greg Clayton8b82f082011-04-12 05:54:46 +0000608 bool
609 m_supports_qProcessInfoPID:1,
610 m_supports_qfProcessInfo:1,
611 m_supports_qUserName:1,
612 m_supports_qGroupName:1,
613 m_supports_qThreadStopInfo:1,
614 m_supports_z0:1,
615 m_supports_z1:1,
616 m_supports_z2:1,
617 m_supports_z3:1,
Greg Clayton89600582013-10-10 17:53:50 +0000618 m_supports_z4:1,
619 m_supports_QEnvironment:1,
Greg Clayton0b90be12015-06-23 21:27:50 +0000620 m_supports_QEnvironmentHexEncoded:1,
Greg Clayton358cf1e2015-06-25 21:46:34 +0000621 m_supports_qSymbol:1,
Jason Molenda50018d32016-01-13 04:08:10 +0000622 m_qSymbol_requests_done:1,
Stephane Sezer6f455292016-01-08 00:00:17 +0000623 m_supports_qModuleInfo:1,
Greg Clayton358cf1e2015-06-25 21:46:34 +0000624 m_supports_jThreadsInfo:1;
Greg Clayton2a48f522011-05-14 01:50:35 +0000625
Todd Fiala9f72b3a2014-05-07 19:28:21 +0000626 lldb::pid_t m_curr_pid;
Greg Clayton8b82f082011-04-12 05:54:46 +0000627 lldb::tid_t m_curr_tid; // Current gdb remote protocol thread index for all other operations
628 lldb::tid_t m_curr_tid_run; // Current gdb remote protocol thread index for continue, step, etc
629
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
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000657 PacketResult
658 SendPacketAndWaitForResponseNoLock (const char *payload,
659 size_t payload_length,
660 StringExtractorGDBRemote &response);
661
662 bool
663 GetCurrentProcessInfo (bool allow_lazy_pid = true);
664
665 bool
666 GetGDBServerVersion();
667
668 // Given the list of compression types that the remote debug stub can support,
669 // possibly enable compression if we find an encoding we can handle.
670 void
671 MaybeEnableCompression (std::vector<std::string> supported_compressions);
672
Greg Clayton32e0a752011-03-30 18:16:51 +0000673 bool
674 DecodeProcessInfoResponse (StringExtractorGDBRemote &response,
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000675 ProcessInstanceInfo &process_info);
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000676
Greg Clayton576d8832011-03-22 04:00:09 +0000677private:
Greg Clayton576d8832011-03-22 04:00:09 +0000678 DISALLOW_COPY_AND_ASSIGN (GDBRemoteCommunicationClient);
679};
680
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000681} // namespace process_gdb_remote
682} // namespace lldb_private
683
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000684#endif // liblldb_GDBRemoteCommunicationClient_h_