blob: dd0eea9f4a156f167e4c5b279fba7dbd93b9c715 [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,
Greg Clayton61d043b2011-03-22 04:00:09 +000080 bool &timed_out);
81
82 lldb::pid_t
83 GetCurrentProcessID ();
84
85 bool
86 GetLaunchSuccess (std::string &error_str);
87
Greg Claytonb72d0f02011-04-12 05:54:46 +000088 uint16_t
89 LaunchGDBserverAndGetPort ();
90
Greg Clayton61d043b2011-03-22 04:00:09 +000091 //------------------------------------------------------------------
92 /// Sends a GDB remote protocol 'A' packet that delivers program
93 /// arguments to the remote server.
94 ///
95 /// @param[in] argv
96 /// A NULL terminated array of const C strings to use as the
97 /// arguments.
98 ///
99 /// @return
100 /// Zero if the response was "OK", a positive value if the
101 /// the response was "Exx" where xx are two hex digits, or
102 /// -1 if the call is unsupported or any other unexpected
103 /// response was received.
104 //------------------------------------------------------------------
105 int
106 SendArgumentsPacket (char const *argv[]);
107
108 //------------------------------------------------------------------
109 /// Sends a "QEnvironment:NAME=VALUE" packet that will build up the
110 /// environment that will get used when launching an application
111 /// in conjunction with the 'A' packet. This function can be called
112 /// multiple times in a row in order to pass on the desired
113 /// environment that the inferior should be launched with.
114 ///
115 /// @param[in] name_equal_value
116 /// A NULL terminated C string that contains a single environment
117 /// in the format "NAME=VALUE".
118 ///
119 /// @return
120 /// Zero if the response was "OK", a positive value if the
121 /// the response was "Exx" where xx are two hex digits, or
122 /// -1 if the call is unsupported or any other unexpected
123 /// response was received.
124 //------------------------------------------------------------------
125 int
126 SendEnvironmentPacket (char const *name_equal_value);
127
Greg Claytona4582402011-05-08 04:53:50 +0000128 int
129 SendLaunchArchPacket (const char *arch);
Greg Clayton61d043b2011-03-22 04:00:09 +0000130 //------------------------------------------------------------------
131 /// Sends a "vAttach:PID" where PID is in hex.
132 ///
133 /// @param[in] pid
134 /// A process ID for the remote gdb server to attach to.
135 ///
136 /// @param[out] response
137 /// The response received from the gdb server. If the return
138 /// value is zero, \a response will contain a stop reply
139 /// packet.
140 ///
141 /// @return
142 /// Zero if the attach was successful, or an error indicating
143 /// an error code.
144 //------------------------------------------------------------------
145 int
146 SendAttach (lldb::pid_t pid,
147 StringExtractorGDBRemote& response);
148
149
150 //------------------------------------------------------------------
151 /// Sets the path to use for stdin/out/err for a process
152 /// that will be launched with the 'A' packet.
153 ///
154 /// @param[in] path
155 /// The path to use for stdin/out/err
156 ///
157 /// @return
158 /// Zero if the for success, or an error code for failure.
159 //------------------------------------------------------------------
160 int
161 SetSTDIN (char const *path);
162 int
163 SetSTDOUT (char const *path);
164 int
165 SetSTDERR (char const *path);
166
167 //------------------------------------------------------------------
168 /// Sets the disable ASLR flag to \a enable for a process that will
169 /// be launched with the 'A' packet.
170 ///
171 /// @param[in] enable
172 /// A boolean value indicating wether to disable ASLR or not.
173 ///
174 /// @return
175 /// Zero if the for success, or an error code for failure.
176 //------------------------------------------------------------------
177 int
178 SetDisableASLR (bool enable);
179
180 //------------------------------------------------------------------
181 /// Sets the working directory to \a path for a process that will
182 /// be launched with the 'A' packet.
183 ///
184 /// @param[in] path
185 /// The path to a directory to use when launching our processs
186 ///
187 /// @return
188 /// Zero if the for success, or an error code for failure.
189 //------------------------------------------------------------------
190 int
191 SetWorkingDir (char const *path);
192
193 lldb::addr_t
194 AllocateMemory (size_t size, uint32_t permissions);
195
196 bool
197 DeallocateMemory (lldb::addr_t addr);
198
Greg Claytona9385532011-11-18 07:03:08 +0000199 lldb_private::Error
200 GetMemoryRegionInfo (lldb::addr_t addr,
201 lldb_private::MemoryRegionInfo &range_info);
202
Greg Clayton61d043b2011-03-22 04:00:09 +0000203 const lldb_private::ArchSpec &
204 GetHostArchitecture ();
205
Greg Clayton61d043b2011-03-22 04:00:09 +0000206 bool
207 GetVContSupported (char flavor);
208
209 void
210 ResetDiscoverableSettings();
211
212 bool
Greg Clayton06d7cc82011-04-04 18:18:57 +0000213 GetHostInfo (bool force = false);
Greg Clayton61d043b2011-03-22 04:00:09 +0000214
215 bool
Greg Clayton58e26e02011-03-24 04:28:38 +0000216 GetOSVersion (uint32_t &major,
217 uint32_t &minor,
218 uint32_t &update);
219
220 bool
221 GetOSBuildString (std::string &s);
222
223 bool
224 GetOSKernelDescription (std::string &s);
225
226 lldb_private::ArchSpec
227 GetSystemArchitecture ();
228
229 bool
230 GetHostname (std::string &s);
231
232 bool
Greg Clayton61d043b2011-03-22 04:00:09 +0000233 GetSupportsThreadSuffix ();
234
235 bool
Greg Clayton24bc5d92011-03-30 18:16:51 +0000236 GetProcessInfo (lldb::pid_t pid,
Greg Claytonb72d0f02011-04-12 05:54:46 +0000237 lldb_private::ProcessInstanceInfo &process_info);
Greg Clayton24bc5d92011-03-30 18:16:51 +0000238
239 uint32_t
Greg Claytonb72d0f02011-04-12 05:54:46 +0000240 FindProcesses (const lldb_private::ProcessInstanceInfoMatch &process_match_info,
241 lldb_private::ProcessInstanceInfoList &process_infos);
Greg Clayton24bc5d92011-03-30 18:16:51 +0000242
243 bool
244 GetUserName (uint32_t uid, std::string &name);
245
246 bool
247 GetGroupName (uint32_t gid, std::string &name);
248
249 bool
Greg Clayton61d043b2011-03-22 04:00:09 +0000250 HasFullVContSupport ()
251 {
252 return GetVContSupported ('A');
253 }
254
255 bool
256 HasAnyVContSupport ()
257 {
258 return GetVContSupported ('a');
259 }
260
261 uint32_t
262 SetPacketTimeout (uint32_t packet_timeout)
263 {
264 const uint32_t old_packet_timeout = m_packet_timeout;
265 m_packet_timeout = packet_timeout;
266 return old_packet_timeout;
267 }
268
Greg Claytonb72d0f02011-04-12 05:54:46 +0000269 bool
270 GetStopReply (StringExtractorGDBRemote &response);
271
272 bool
273 GetThreadStopInfo (uint32_t tid,
274 StringExtractorGDBRemote &response);
275
276 bool
277 SupportsGDBStoppointPacket (GDBStoppointType type)
278 {
279 switch (type)
280 {
281 case eBreakpointSoftware: return m_supports_z0;
282 case eBreakpointHardware: return m_supports_z1;
283 case eWatchpointWrite: return m_supports_z2;
284 case eWatchpointRead: return m_supports_z3;
285 case eWatchpointReadWrite: return m_supports_z4;
286 default: break;
287 }
288 return false;
289 }
290 uint8_t
291 SendGDBStoppointTypePacket (GDBStoppointType type, // Type of breakpoint or watchpoint
292 bool insert, // Insert or remove?
293 lldb::addr_t addr, // Address of breakpoint or watchpoint
294 uint32_t length); // Byte Size of breakpoint or watchpoint
295
Greg Clayton06d7cc82011-04-04 18:18:57 +0000296 void
297 TestPacketSpeed (const uint32_t num_packets);
298
299 // This packet is for testing the speed of the interface only. Both
300 // the client and server need to support it, but this allows us to
301 // measure the packet speed without any other work being done on the
302 // other end and avoids any of that work affecting the packet send
303 // and response times.
304 bool
305 SendSpeedTestPacket (uint32_t send_size,
306 uint32_t recv_size);
Greg Claytonb72d0f02011-04-12 05:54:46 +0000307
308 bool
309 SetCurrentThread (int tid);
310
311 bool
312 SetCurrentThreadForRun (int tid);
313
Greg Clayton989816b2011-05-14 01:50:35 +0000314 lldb_private::LazyBool
Greg Clayton2f085c62011-05-15 01:25:55 +0000315 SupportsAllocDeallocMemory () const
Greg Clayton989816b2011-05-14 01:50:35 +0000316 {
Greg Clayton2f085c62011-05-15 01:25:55 +0000317 return m_supports_alloc_dealloc_memory;
Greg Clayton989816b2011-05-14 01:50:35 +0000318 }
319
Greg Clayton4a60f9e2011-05-20 23:38:13 +0000320 size_t
321 GetCurrentThreadIDs (std::vector<lldb::tid_t> &thread_ids,
322 bool &sequence_mutex_unavailable);
323
Greg Clayton05e4d972012-03-29 01:55:41 +0000324 bool
325 GetInterruptWasSent () const
326 {
327 return m_interrupt_sent;
328 }
Greg Clayton61d043b2011-03-22 04:00:09 +0000329protected:
330
Greg Clayton61d043b2011-03-22 04:00:09 +0000331 //------------------------------------------------------------------
332 // Classes that inherit from GDBRemoteCommunicationClient can see and modify these
333 //------------------------------------------------------------------
Greg Claytonb3448432011-03-24 21:19:54 +0000334 lldb_private::LazyBool m_supports_not_sending_acks;
335 lldb_private::LazyBool m_supports_thread_suffix;
Greg Claytonb3448432011-03-24 21:19:54 +0000336 lldb_private::LazyBool m_supports_vCont_all;
337 lldb_private::LazyBool m_supports_vCont_any;
338 lldb_private::LazyBool m_supports_vCont_c;
339 lldb_private::LazyBool m_supports_vCont_C;
340 lldb_private::LazyBool m_supports_vCont_s;
341 lldb_private::LazyBool m_supports_vCont_S;
Greg Clayton24bc5d92011-03-30 18:16:51 +0000342 lldb_private::LazyBool m_qHostInfo_is_valid;
Greg Clayton2f085c62011-05-15 01:25:55 +0000343 lldb_private::LazyBool m_supports_alloc_dealloc_memory;
Greg Claytona9385532011-11-18 07:03:08 +0000344 lldb_private::LazyBool m_supports_memory_region_info;
Greg Clayton989816b2011-05-14 01:50:35 +0000345
Greg Claytonb72d0f02011-04-12 05:54:46 +0000346 bool
347 m_supports_qProcessInfoPID:1,
348 m_supports_qfProcessInfo:1,
349 m_supports_qUserName:1,
350 m_supports_qGroupName:1,
351 m_supports_qThreadStopInfo:1,
352 m_supports_z0:1,
353 m_supports_z1:1,
354 m_supports_z2:1,
355 m_supports_z3:1,
356 m_supports_z4:1;
Greg Clayton989816b2011-05-14 01:50:35 +0000357
Greg Claytonb72d0f02011-04-12 05:54:46 +0000358
359 lldb::tid_t m_curr_tid; // Current gdb remote protocol thread index for all other operations
360 lldb::tid_t m_curr_tid_run; // Current gdb remote protocol thread index for continue, step, etc
361
Greg Clayton61d043b2011-03-22 04:00:09 +0000362
363 // If we need to send a packet while the target is running, the m_async_XXX
364 // member variables take care of making this happen.
365 lldb_private::Mutex m_async_mutex;
366 lldb_private::Predicate<bool> m_async_packet_predicate;
367 std::string m_async_packet;
368 StringExtractorGDBRemote m_async_response;
369 int m_async_signal; // We were asked to deliver a signal to the inferior process.
Greg Clayton05e4d972012-03-29 01:55:41 +0000370 bool m_interrupt_sent;
Greg Clayton61d043b2011-03-22 04:00:09 +0000371
Greg Claytoncb8977d2011-03-23 00:09:55 +0000372 lldb_private::ArchSpec m_host_arch;
Greg Clayton58e26e02011-03-24 04:28:38 +0000373 uint32_t m_os_version_major;
374 uint32_t m_os_version_minor;
375 uint32_t m_os_version_update;
376 std::string m_os_build;
377 std::string m_os_kernel;
378 std::string m_hostname;
Greg Clayton61d043b2011-03-22 04:00:09 +0000379
Greg Clayton24bc5d92011-03-30 18:16:51 +0000380 bool
381 DecodeProcessInfoResponse (StringExtractorGDBRemote &response,
Greg Claytonb72d0f02011-04-12 05:54:46 +0000382 lldb_private::ProcessInstanceInfo &process_info);
Greg Clayton61d043b2011-03-22 04:00:09 +0000383private:
384 //------------------------------------------------------------------
385 // For GDBRemoteCommunicationClient only
386 //------------------------------------------------------------------
387 DISALLOW_COPY_AND_ASSIGN (GDBRemoteCommunicationClient);
388};
389
390#endif // liblldb_GDBRemoteCommunicationClient_h_