blob: 30d6fb0707efe49736e97d95518e1d741c0d8a15 [file] [log] [blame]
Greg Clayton61d043b2011-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 Clayton4a60f9e2011-05-20 23:38:13 +000015#include <vector>
16
Greg Clayton61d043b2011-03-22 04:00:09 +000017// Other libraries and framework includes
18// Project includes
19#include "lldb/Core/ArchSpec.h"
Greg Claytona9385532011-11-18 07:03:08 +000020#include "lldb/Target/Process.h"
Greg Clayton61d043b2011-03-22 04:00:09 +000021
22#include "GDBRemoteCommunication.h"
23
Greg Claytonb72d0f02011-04-12 05:54:46 +000024typedef enum
25{
26 eBreakpointSoftware = 0,
27 eBreakpointHardware,
28 eWatchpointWrite,
29 eWatchpointRead,
30 eWatchpointReadWrite
31} GDBStoppointType;
32
Greg Clayton61d043b2011-03-22 04:00:09 +000033class GDBRemoteCommunicationClient : public GDBRemoteCommunication
34{
35public:
36 //------------------------------------------------------------------
37 // Constructors and Destructors
38 //------------------------------------------------------------------
Greg Claytonb72d0f02011-04-12 05:54:46 +000039 GDBRemoteCommunicationClient(bool is_platform);
Greg Clayton61d043b2011-03-22 04:00:09 +000040
41 virtual
42 ~GDBRemoteCommunicationClient();
43
Greg Clayton58e26e02011-03-24 04:28:38 +000044 //------------------------------------------------------------------
45 // After connecting, send the handshake to the server to make sure
46 // we are communicating with it.
47 //------------------------------------------------------------------
48 bool
49 HandshakeWithServer (lldb_private::Error *error_ptr);
50
Greg Clayton61d043b2011-03-22 04:00:09 +000051 size_t
52 SendPacketAndWaitForResponse (const char *send_payload,
53 StringExtractorGDBRemote &response,
54 bool send_async);
55
56 size_t
57 SendPacketAndWaitForResponse (const char *send_payload,
58 size_t send_length,
59 StringExtractorGDBRemote &response,
60 bool send_async);
61
62 lldb::StateType
63 SendContinuePacketAndWaitForResponse (ProcessGDBRemote *process,
64 const char *packet_payload,
65 size_t packet_length,
66 StringExtractorGDBRemote &response);
67
68 virtual bool
69 GetThreadSuffixSupported ();
70
Greg Clayton58e26e02011-03-24 04:28:38 +000071 void
72 QueryNoAckModeSupported ();
Greg Clayton61d043b2011-03-22 04:00:09 +000073
74 bool
75 SendAsyncSignal (int signo);
76
77 bool
78 SendInterrupt (lldb_private::Mutex::Locker &locker,
79 uint32_t seconds_to_wait_for_stop,
80 bool &sent_interrupt,
81 bool &timed_out);
82
83 lldb::pid_t
84 GetCurrentProcessID ();
85
86 bool
87 GetLaunchSuccess (std::string &error_str);
88
Greg Claytonb72d0f02011-04-12 05:54:46 +000089 uint16_t
90 LaunchGDBserverAndGetPort ();
91
Greg Clayton61d043b2011-03-22 04:00:09 +000092 //------------------------------------------------------------------
93 /// Sends a GDB remote protocol 'A' packet that delivers program
94 /// arguments to the remote server.
95 ///
96 /// @param[in] argv
97 /// A NULL terminated array of const C strings to use as the
98 /// arguments.
99 ///
100 /// @return
101 /// Zero if the response was "OK", a positive value if the
102 /// the response was "Exx" where xx are two hex digits, or
103 /// -1 if the call is unsupported or any other unexpected
104 /// response was received.
105 //------------------------------------------------------------------
106 int
107 SendArgumentsPacket (char const *argv[]);
108
109 //------------------------------------------------------------------
110 /// Sends a "QEnvironment:NAME=VALUE" packet that will build up the
111 /// environment that will get used when launching an application
112 /// in conjunction with the 'A' packet. This function can be called
113 /// multiple times in a row in order to pass on the desired
114 /// environment that the inferior should be launched with.
115 ///
116 /// @param[in] name_equal_value
117 /// A NULL terminated C string that contains a single environment
118 /// in the format "NAME=VALUE".
119 ///
120 /// @return
121 /// Zero if the response was "OK", a positive value if the
122 /// the response was "Exx" where xx are two hex digits, or
123 /// -1 if the call is unsupported or any other unexpected
124 /// response was received.
125 //------------------------------------------------------------------
126 int
127 SendEnvironmentPacket (char const *name_equal_value);
128
Greg Claytona4582402011-05-08 04:53:50 +0000129 int
130 SendLaunchArchPacket (const char *arch);
Greg Clayton61d043b2011-03-22 04:00:09 +0000131 //------------------------------------------------------------------
132 /// Sends a "vAttach:PID" where PID is in hex.
133 ///
134 /// @param[in] pid
135 /// A process ID for the remote gdb server to attach to.
136 ///
137 /// @param[out] response
138 /// The response received from the gdb server. If the return
139 /// value is zero, \a response will contain a stop reply
140 /// packet.
141 ///
142 /// @return
143 /// Zero if the attach was successful, or an error indicating
144 /// an error code.
145 //------------------------------------------------------------------
146 int
147 SendAttach (lldb::pid_t pid,
148 StringExtractorGDBRemote& response);
149
150
151 //------------------------------------------------------------------
152 /// Sets the path to use for stdin/out/err for a process
153 /// that will be launched with the 'A' packet.
154 ///
155 /// @param[in] path
156 /// The path to use for stdin/out/err
157 ///
158 /// @return
159 /// Zero if the for success, or an error code for failure.
160 //------------------------------------------------------------------
161 int
162 SetSTDIN (char const *path);
163 int
164 SetSTDOUT (char const *path);
165 int
166 SetSTDERR (char const *path);
167
168 //------------------------------------------------------------------
169 /// Sets the disable ASLR flag to \a enable for a process that will
170 /// be launched with the 'A' packet.
171 ///
172 /// @param[in] enable
173 /// A boolean value indicating wether to disable ASLR or not.
174 ///
175 /// @return
176 /// Zero if the for success, or an error code for failure.
177 //------------------------------------------------------------------
178 int
179 SetDisableASLR (bool enable);
180
181 //------------------------------------------------------------------
182 /// Sets the working directory to \a path for a process that will
183 /// be launched with the 'A' packet.
184 ///
185 /// @param[in] path
186 /// The path to a directory to use when launching our processs
187 ///
188 /// @return
189 /// Zero if the for success, or an error code for failure.
190 //------------------------------------------------------------------
191 int
192 SetWorkingDir (char const *path);
193
194 lldb::addr_t
195 AllocateMemory (size_t size, uint32_t permissions);
196
197 bool
198 DeallocateMemory (lldb::addr_t addr);
199
Greg Claytona9385532011-11-18 07:03:08 +0000200 lldb_private::Error
201 GetMemoryRegionInfo (lldb::addr_t addr,
202 lldb_private::MemoryRegionInfo &range_info);
203
Greg Clayton61d043b2011-03-22 04:00:09 +0000204 const lldb_private::ArchSpec &
205 GetHostArchitecture ();
206
Greg Clayton61d043b2011-03-22 04:00:09 +0000207 bool
208 GetVContSupported (char flavor);
209
210 void
211 ResetDiscoverableSettings();
212
213 bool
Greg Clayton06d7cc82011-04-04 18:18:57 +0000214 GetHostInfo (bool force = false);
Greg Clayton61d043b2011-03-22 04:00:09 +0000215
216 bool
Greg Clayton58e26e02011-03-24 04:28:38 +0000217 GetOSVersion (uint32_t &major,
218 uint32_t &minor,
219 uint32_t &update);
220
221 bool
222 GetOSBuildString (std::string &s);
223
224 bool
225 GetOSKernelDescription (std::string &s);
226
227 lldb_private::ArchSpec
228 GetSystemArchitecture ();
229
230 bool
231 GetHostname (std::string &s);
232
233 bool
Greg Clayton61d043b2011-03-22 04:00:09 +0000234 GetSupportsThreadSuffix ();
235
236 bool
Greg Clayton24bc5d92011-03-30 18:16:51 +0000237 GetProcessInfo (lldb::pid_t pid,
Greg Claytonb72d0f02011-04-12 05:54:46 +0000238 lldb_private::ProcessInstanceInfo &process_info);
Greg Clayton24bc5d92011-03-30 18:16:51 +0000239
240 uint32_t
Greg Claytonb72d0f02011-04-12 05:54:46 +0000241 FindProcesses (const lldb_private::ProcessInstanceInfoMatch &process_match_info,
242 lldb_private::ProcessInstanceInfoList &process_infos);
Greg Clayton24bc5d92011-03-30 18:16:51 +0000243
244 bool
245 GetUserName (uint32_t uid, std::string &name);
246
247 bool
248 GetGroupName (uint32_t gid, std::string &name);
249
250 bool
Greg Clayton61d043b2011-03-22 04:00:09 +0000251 HasFullVContSupport ()
252 {
253 return GetVContSupported ('A');
254 }
255
256 bool
257 HasAnyVContSupport ()
258 {
259 return GetVContSupported ('a');
260 }
261
262 uint32_t
263 SetPacketTimeout (uint32_t packet_timeout)
264 {
265 const uint32_t old_packet_timeout = m_packet_timeout;
266 m_packet_timeout = packet_timeout;
267 return old_packet_timeout;
268 }
269
Greg Claytonb72d0f02011-04-12 05:54:46 +0000270 bool
271 GetStopReply (StringExtractorGDBRemote &response);
272
273 bool
274 GetThreadStopInfo (uint32_t tid,
275 StringExtractorGDBRemote &response);
276
277 bool
278 SupportsGDBStoppointPacket (GDBStoppointType type)
279 {
280 switch (type)
281 {
282 case eBreakpointSoftware: return m_supports_z0;
283 case eBreakpointHardware: return m_supports_z1;
284 case eWatchpointWrite: return m_supports_z2;
285 case eWatchpointRead: return m_supports_z3;
286 case eWatchpointReadWrite: return m_supports_z4;
287 default: break;
288 }
289 return false;
290 }
291 uint8_t
292 SendGDBStoppointTypePacket (GDBStoppointType type, // Type of breakpoint or watchpoint
293 bool insert, // Insert or remove?
294 lldb::addr_t addr, // Address of breakpoint or watchpoint
295 uint32_t length); // Byte Size of breakpoint or watchpoint
296
Greg Clayton06d7cc82011-04-04 18:18:57 +0000297 void
298 TestPacketSpeed (const uint32_t num_packets);
299
300 // This packet is for testing the speed of the interface only. Both
301 // the client and server need to support it, but this allows us to
302 // measure the packet speed without any other work being done on the
303 // other end and avoids any of that work affecting the packet send
304 // and response times.
305 bool
306 SendSpeedTestPacket (uint32_t send_size,
307 uint32_t recv_size);
Greg Claytonb72d0f02011-04-12 05:54:46 +0000308
309 bool
310 SetCurrentThread (int tid);
311
312 bool
313 SetCurrentThreadForRun (int tid);
314
Greg Clayton989816b2011-05-14 01:50:35 +0000315 lldb_private::LazyBool
Greg Clayton2f085c62011-05-15 01:25:55 +0000316 SupportsAllocDeallocMemory () const
Greg Clayton989816b2011-05-14 01:50:35 +0000317 {
Greg Clayton2f085c62011-05-15 01:25:55 +0000318 return m_supports_alloc_dealloc_memory;
Greg Clayton989816b2011-05-14 01:50:35 +0000319 }
320
Greg Clayton4a60f9e2011-05-20 23:38:13 +0000321 size_t
322 GetCurrentThreadIDs (std::vector<lldb::tid_t> &thread_ids,
323 bool &sequence_mutex_unavailable);
324
Greg Clayton61d043b2011-03-22 04:00:09 +0000325protected:
326
Greg Clayton61d043b2011-03-22 04:00:09 +0000327 //------------------------------------------------------------------
328 // Classes that inherit from GDBRemoteCommunicationClient can see and modify these
329 //------------------------------------------------------------------
Greg Claytonb3448432011-03-24 21:19:54 +0000330 lldb_private::LazyBool m_supports_not_sending_acks;
331 lldb_private::LazyBool m_supports_thread_suffix;
Greg Claytonb3448432011-03-24 21:19:54 +0000332 lldb_private::LazyBool m_supports_vCont_all;
333 lldb_private::LazyBool m_supports_vCont_any;
334 lldb_private::LazyBool m_supports_vCont_c;
335 lldb_private::LazyBool m_supports_vCont_C;
336 lldb_private::LazyBool m_supports_vCont_s;
337 lldb_private::LazyBool m_supports_vCont_S;
Greg Clayton24bc5d92011-03-30 18:16:51 +0000338 lldb_private::LazyBool m_qHostInfo_is_valid;
Greg Clayton2f085c62011-05-15 01:25:55 +0000339 lldb_private::LazyBool m_supports_alloc_dealloc_memory;
Greg Claytona9385532011-11-18 07:03:08 +0000340 lldb_private::LazyBool m_supports_memory_region_info;
Greg Clayton989816b2011-05-14 01:50:35 +0000341
Greg Claytonb72d0f02011-04-12 05:54:46 +0000342 bool
343 m_supports_qProcessInfoPID:1,
344 m_supports_qfProcessInfo:1,
345 m_supports_qUserName:1,
346 m_supports_qGroupName:1,
347 m_supports_qThreadStopInfo:1,
348 m_supports_z0:1,
349 m_supports_z1:1,
350 m_supports_z2:1,
351 m_supports_z3:1,
352 m_supports_z4:1;
Greg Clayton989816b2011-05-14 01:50:35 +0000353
Greg Claytonb72d0f02011-04-12 05:54:46 +0000354
355 lldb::tid_t m_curr_tid; // Current gdb remote protocol thread index for all other operations
356 lldb::tid_t m_curr_tid_run; // Current gdb remote protocol thread index for continue, step, etc
357
Greg Clayton61d043b2011-03-22 04:00:09 +0000358
359 // If we need to send a packet while the target is running, the m_async_XXX
360 // member variables take care of making this happen.
361 lldb_private::Mutex m_async_mutex;
362 lldb_private::Predicate<bool> m_async_packet_predicate;
363 std::string m_async_packet;
364 StringExtractorGDBRemote m_async_response;
365 int m_async_signal; // We were asked to deliver a signal to the inferior process.
366
Greg Claytoncb8977d2011-03-23 00:09:55 +0000367 lldb_private::ArchSpec m_host_arch;
Greg Clayton58e26e02011-03-24 04:28:38 +0000368 uint32_t m_os_version_major;
369 uint32_t m_os_version_minor;
370 uint32_t m_os_version_update;
371 std::string m_os_build;
372 std::string m_os_kernel;
373 std::string m_hostname;
Greg Clayton61d043b2011-03-22 04:00:09 +0000374
Greg Clayton24bc5d92011-03-30 18:16:51 +0000375 bool
376 DecodeProcessInfoResponse (StringExtractorGDBRemote &response,
Greg Claytonb72d0f02011-04-12 05:54:46 +0000377 lldb_private::ProcessInstanceInfo &process_info);
Greg Clayton61d043b2011-03-22 04:00:09 +0000378private:
379 //------------------------------------------------------------------
380 // For GDBRemoteCommunicationClient only
381 //------------------------------------------------------------------
382 DISALLOW_COPY_AND_ASSIGN (GDBRemoteCommunicationClient);
383};
384
385#endif // liblldb_GDBRemoteCommunicationClient_h_