blob: 0f980fe102b6502e276f3e75dc9b292b6237cc08 [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"
20
21#include "GDBRemoteCommunication.h"
22
Greg Claytonb72d0f02011-04-12 05:54:46 +000023typedef enum
24{
25 eBreakpointSoftware = 0,
26 eBreakpointHardware,
27 eWatchpointWrite,
28 eWatchpointRead,
29 eWatchpointReadWrite
30} GDBStoppointType;
31
Greg Clayton61d043b2011-03-22 04:00:09 +000032class GDBRemoteCommunicationClient : public GDBRemoteCommunication
33{
34public:
35 //------------------------------------------------------------------
36 // Constructors and Destructors
37 //------------------------------------------------------------------
Greg Claytonb72d0f02011-04-12 05:54:46 +000038 GDBRemoteCommunicationClient(bool is_platform);
Greg Clayton61d043b2011-03-22 04:00:09 +000039
40 virtual
41 ~GDBRemoteCommunicationClient();
42
Greg Clayton58e26e02011-03-24 04:28:38 +000043 //------------------------------------------------------------------
44 // After connecting, send the handshake to the server to make sure
45 // we are communicating with it.
46 //------------------------------------------------------------------
47 bool
48 HandshakeWithServer (lldb_private::Error *error_ptr);
49
Greg Clayton61d043b2011-03-22 04:00:09 +000050 size_t
51 SendPacketAndWaitForResponse (const char *send_payload,
52 StringExtractorGDBRemote &response,
53 bool send_async);
54
55 size_t
56 SendPacketAndWaitForResponse (const char *send_payload,
57 size_t send_length,
58 StringExtractorGDBRemote &response,
59 bool send_async);
60
61 lldb::StateType
62 SendContinuePacketAndWaitForResponse (ProcessGDBRemote *process,
63 const char *packet_payload,
64 size_t packet_length,
65 StringExtractorGDBRemote &response);
66
67 virtual bool
68 GetThreadSuffixSupported ();
69
Greg Clayton58e26e02011-03-24 04:28:38 +000070 void
71 QueryNoAckModeSupported ();
Greg Clayton61d043b2011-03-22 04:00:09 +000072
73 bool
74 SendAsyncSignal (int signo);
75
76 bool
77 SendInterrupt (lldb_private::Mutex::Locker &locker,
78 uint32_t seconds_to_wait_for_stop,
79 bool &sent_interrupt,
80 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
199 const lldb_private::ArchSpec &
200 GetHostArchitecture ();
201
Greg Clayton61d043b2011-03-22 04:00:09 +0000202 bool
203 GetVContSupported (char flavor);
204
205 void
206 ResetDiscoverableSettings();
207
208 bool
Greg Clayton06d7cc82011-04-04 18:18:57 +0000209 GetHostInfo (bool force = false);
Greg Clayton61d043b2011-03-22 04:00:09 +0000210
211 bool
Greg Clayton58e26e02011-03-24 04:28:38 +0000212 GetOSVersion (uint32_t &major,
213 uint32_t &minor,
214 uint32_t &update);
215
216 bool
217 GetOSBuildString (std::string &s);
218
219 bool
220 GetOSKernelDescription (std::string &s);
221
222 lldb_private::ArchSpec
223 GetSystemArchitecture ();
224
225 bool
226 GetHostname (std::string &s);
227
228 bool
Greg Clayton61d043b2011-03-22 04:00:09 +0000229 GetSupportsThreadSuffix ();
230
231 bool
Greg Clayton24bc5d92011-03-30 18:16:51 +0000232 GetProcessInfo (lldb::pid_t pid,
Greg Claytonb72d0f02011-04-12 05:54:46 +0000233 lldb_private::ProcessInstanceInfo &process_info);
Greg Clayton24bc5d92011-03-30 18:16:51 +0000234
235 uint32_t
Greg Claytonb72d0f02011-04-12 05:54:46 +0000236 FindProcesses (const lldb_private::ProcessInstanceInfoMatch &process_match_info,
237 lldb_private::ProcessInstanceInfoList &process_infos);
Greg Clayton24bc5d92011-03-30 18:16:51 +0000238
239 bool
240 GetUserName (uint32_t uid, std::string &name);
241
242 bool
243 GetGroupName (uint32_t gid, std::string &name);
244
245 bool
Greg Clayton61d043b2011-03-22 04:00:09 +0000246 HasFullVContSupport ()
247 {
248 return GetVContSupported ('A');
249 }
250
251 bool
252 HasAnyVContSupport ()
253 {
254 return GetVContSupported ('a');
255 }
256
257 uint32_t
258 SetPacketTimeout (uint32_t packet_timeout)
259 {
260 const uint32_t old_packet_timeout = m_packet_timeout;
261 m_packet_timeout = packet_timeout;
262 return old_packet_timeout;
263 }
264
Greg Claytonb72d0f02011-04-12 05:54:46 +0000265 bool
266 GetStopReply (StringExtractorGDBRemote &response);
267
268 bool
269 GetThreadStopInfo (uint32_t tid,
270 StringExtractorGDBRemote &response);
271
272 bool
273 SupportsGDBStoppointPacket (GDBStoppointType type)
274 {
275 switch (type)
276 {
277 case eBreakpointSoftware: return m_supports_z0;
278 case eBreakpointHardware: return m_supports_z1;
279 case eWatchpointWrite: return m_supports_z2;
280 case eWatchpointRead: return m_supports_z3;
281 case eWatchpointReadWrite: return m_supports_z4;
282 default: break;
283 }
284 return false;
285 }
286 uint8_t
287 SendGDBStoppointTypePacket (GDBStoppointType type, // Type of breakpoint or watchpoint
288 bool insert, // Insert or remove?
289 lldb::addr_t addr, // Address of breakpoint or watchpoint
290 uint32_t length); // Byte Size of breakpoint or watchpoint
291
Greg Clayton06d7cc82011-04-04 18:18:57 +0000292 void
293 TestPacketSpeed (const uint32_t num_packets);
294
295 // This packet is for testing the speed of the interface only. Both
296 // the client and server need to support it, but this allows us to
297 // measure the packet speed without any other work being done on the
298 // other end and avoids any of that work affecting the packet send
299 // and response times.
300 bool
301 SendSpeedTestPacket (uint32_t send_size,
302 uint32_t recv_size);
Greg Claytonb72d0f02011-04-12 05:54:46 +0000303
304 bool
305 SetCurrentThread (int tid);
306
307 bool
308 SetCurrentThreadForRun (int tid);
309
Greg Clayton989816b2011-05-14 01:50:35 +0000310 lldb_private::LazyBool
Greg Clayton2f085c62011-05-15 01:25:55 +0000311 SupportsAllocDeallocMemory () const
Greg Clayton989816b2011-05-14 01:50:35 +0000312 {
Greg Clayton2f085c62011-05-15 01:25:55 +0000313 return m_supports_alloc_dealloc_memory;
Greg Clayton989816b2011-05-14 01:50:35 +0000314 }
315
Greg Clayton4a60f9e2011-05-20 23:38:13 +0000316 size_t
317 GetCurrentThreadIDs (std::vector<lldb::tid_t> &thread_ids,
318 bool &sequence_mutex_unavailable);
319
Greg Clayton61d043b2011-03-22 04:00:09 +0000320protected:
321
Greg Clayton61d043b2011-03-22 04:00:09 +0000322 //------------------------------------------------------------------
323 // Classes that inherit from GDBRemoteCommunicationClient can see and modify these
324 //------------------------------------------------------------------
Greg Claytonb3448432011-03-24 21:19:54 +0000325 lldb_private::LazyBool m_supports_not_sending_acks;
326 lldb_private::LazyBool m_supports_thread_suffix;
Greg Claytonb3448432011-03-24 21:19:54 +0000327 lldb_private::LazyBool m_supports_vCont_all;
328 lldb_private::LazyBool m_supports_vCont_any;
329 lldb_private::LazyBool m_supports_vCont_c;
330 lldb_private::LazyBool m_supports_vCont_C;
331 lldb_private::LazyBool m_supports_vCont_s;
332 lldb_private::LazyBool m_supports_vCont_S;
Greg Clayton24bc5d92011-03-30 18:16:51 +0000333 lldb_private::LazyBool m_qHostInfo_is_valid;
Greg Clayton2f085c62011-05-15 01:25:55 +0000334 lldb_private::LazyBool m_supports_alloc_dealloc_memory;
Greg Clayton989816b2011-05-14 01:50:35 +0000335
Greg Claytonb72d0f02011-04-12 05:54:46 +0000336 bool
337 m_supports_qProcessInfoPID:1,
338 m_supports_qfProcessInfo:1,
339 m_supports_qUserName:1,
340 m_supports_qGroupName:1,
341 m_supports_qThreadStopInfo:1,
342 m_supports_z0:1,
343 m_supports_z1:1,
344 m_supports_z2:1,
345 m_supports_z3:1,
346 m_supports_z4:1;
Greg Clayton989816b2011-05-14 01:50:35 +0000347
Greg Claytonb72d0f02011-04-12 05:54:46 +0000348
349 lldb::tid_t m_curr_tid; // Current gdb remote protocol thread index for all other operations
350 lldb::tid_t m_curr_tid_run; // Current gdb remote protocol thread index for continue, step, etc
351
Greg Clayton61d043b2011-03-22 04:00:09 +0000352
353 // If we need to send a packet while the target is running, the m_async_XXX
354 // member variables take care of making this happen.
355 lldb_private::Mutex m_async_mutex;
356 lldb_private::Predicate<bool> m_async_packet_predicate;
357 std::string m_async_packet;
358 StringExtractorGDBRemote m_async_response;
359 int m_async_signal; // We were asked to deliver a signal to the inferior process.
360
Greg Claytoncb8977d2011-03-23 00:09:55 +0000361 lldb_private::ArchSpec m_host_arch;
Greg Clayton58e26e02011-03-24 04:28:38 +0000362 uint32_t m_os_version_major;
363 uint32_t m_os_version_minor;
364 uint32_t m_os_version_update;
365 std::string m_os_build;
366 std::string m_os_kernel;
367 std::string m_hostname;
Greg Clayton61d043b2011-03-22 04:00:09 +0000368
Greg Clayton24bc5d92011-03-30 18:16:51 +0000369 bool
370 DecodeProcessInfoResponse (StringExtractorGDBRemote &response,
Greg Claytonb72d0f02011-04-12 05:54:46 +0000371 lldb_private::ProcessInstanceInfo &process_info);
Greg Clayton61d043b2011-03-22 04:00:09 +0000372private:
373 //------------------------------------------------------------------
374 // For GDBRemoteCommunicationClient only
375 //------------------------------------------------------------------
376 DISALLOW_COPY_AND_ASSIGN (GDBRemoteCommunicationClient);
377};
378
379#endif // liblldb_GDBRemoteCommunicationClient_h_