blob: eee3aa50ed1db906961b14a32f154dc3f5406f05 [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
Greg Claytona1f645e2012-04-10 03:22:03 +000074 void
75 GetListThreadsInStopReplySupported ();
76
Greg Clayton61d043b2011-03-22 04:00:09 +000077 bool
78 SendAsyncSignal (int signo);
79
80 bool
81 SendInterrupt (lldb_private::Mutex::Locker &locker,
82 uint32_t seconds_to_wait_for_stop,
Greg Clayton61d043b2011-03-22 04:00:09 +000083 bool &timed_out);
84
85 lldb::pid_t
86 GetCurrentProcessID ();
87
88 bool
89 GetLaunchSuccess (std::string &error_str);
90
Greg Claytonb72d0f02011-04-12 05:54:46 +000091 uint16_t
92 LaunchGDBserverAndGetPort ();
93
Greg Clayton61d043b2011-03-22 04:00:09 +000094 //------------------------------------------------------------------
95 /// Sends a GDB remote protocol 'A' packet that delivers program
96 /// arguments to the remote server.
97 ///
98 /// @param[in] argv
99 /// A NULL terminated array of const C strings to use as the
100 /// arguments.
101 ///
102 /// @return
103 /// Zero if the response was "OK", a positive value if the
104 /// the response was "Exx" where xx are two hex digits, or
105 /// -1 if the call is unsupported or any other unexpected
106 /// response was received.
107 //------------------------------------------------------------------
108 int
109 SendArgumentsPacket (char const *argv[]);
110
111 //------------------------------------------------------------------
112 /// Sends a "QEnvironment:NAME=VALUE" packet that will build up the
113 /// environment that will get used when launching an application
114 /// in conjunction with the 'A' packet. This function can be called
115 /// multiple times in a row in order to pass on the desired
116 /// environment that the inferior should be launched with.
117 ///
118 /// @param[in] name_equal_value
119 /// A NULL terminated C string that contains a single environment
120 /// in the format "NAME=VALUE".
121 ///
122 /// @return
123 /// Zero if the response was "OK", a positive value if the
124 /// the response was "Exx" where xx are two hex digits, or
125 /// -1 if the call is unsupported or any other unexpected
126 /// response was received.
127 //------------------------------------------------------------------
128 int
129 SendEnvironmentPacket (char const *name_equal_value);
130
Greg Claytona4582402011-05-08 04:53:50 +0000131 int
132 SendLaunchArchPacket (const char *arch);
Greg Clayton61d043b2011-03-22 04:00:09 +0000133 //------------------------------------------------------------------
134 /// Sends a "vAttach:PID" where PID is in hex.
135 ///
136 /// @param[in] pid
137 /// A process ID for the remote gdb server to attach to.
138 ///
139 /// @param[out] response
140 /// The response received from the gdb server. If the return
141 /// value is zero, \a response will contain a stop reply
142 /// packet.
143 ///
144 /// @return
145 /// Zero if the attach was successful, or an error indicating
146 /// an error code.
147 //------------------------------------------------------------------
148 int
149 SendAttach (lldb::pid_t pid,
150 StringExtractorGDBRemote& response);
151
152
153 //------------------------------------------------------------------
154 /// Sets the path to use for stdin/out/err for a process
155 /// that will be launched with the 'A' packet.
156 ///
157 /// @param[in] path
158 /// The path to use for stdin/out/err
159 ///
160 /// @return
161 /// Zero if the for success, or an error code for failure.
162 //------------------------------------------------------------------
163 int
164 SetSTDIN (char const *path);
165 int
166 SetSTDOUT (char const *path);
167 int
168 SetSTDERR (char const *path);
169
170 //------------------------------------------------------------------
171 /// Sets the disable ASLR flag to \a enable for a process that will
172 /// be launched with the 'A' packet.
173 ///
174 /// @param[in] enable
175 /// A boolean value indicating wether to disable ASLR or not.
176 ///
177 /// @return
178 /// Zero if the for success, or an error code for failure.
179 //------------------------------------------------------------------
180 int
181 SetDisableASLR (bool enable);
182
183 //------------------------------------------------------------------
184 /// Sets the working directory to \a path for a process that will
185 /// be launched with the 'A' packet.
186 ///
187 /// @param[in] path
188 /// The path to a directory to use when launching our processs
189 ///
190 /// @return
191 /// Zero if the for success, or an error code for failure.
192 //------------------------------------------------------------------
193 int
194 SetWorkingDir (char const *path);
195
196 lldb::addr_t
197 AllocateMemory (size_t size, uint32_t permissions);
198
199 bool
200 DeallocateMemory (lldb::addr_t addr);
201
Greg Clayton516f0842012-04-11 00:24:49 +0000202 bool
203 Detach ();
204
Greg Claytona9385532011-11-18 07:03:08 +0000205 lldb_private::Error
206 GetMemoryRegionInfo (lldb::addr_t addr,
207 lldb_private::MemoryRegionInfo &range_info);
208
Johnny Chen7cbdcfb2012-05-23 21:09:52 +0000209 lldb_private::Error
210 GetWatchpointSupportInfo (uint32_t &num);
211
Enrico Granata7de2a3b2012-07-13 23:18:48 +0000212 lldb_private::Error
213 GetWatchpointSupportInfo (uint32_t &num, bool& after);
214
215 lldb_private::Error
216 GetWatchpointsTriggerAfterInstruction (bool &after);
217
Greg Clayton61d043b2011-03-22 04:00:09 +0000218 const lldb_private::ArchSpec &
219 GetHostArchitecture ();
220
Greg Clayton61d043b2011-03-22 04:00:09 +0000221 bool
222 GetVContSupported (char flavor);
223
Jim Ingham3a458eb2012-07-20 21:37:13 +0000224 bool
225 GetVAttachOrWaitSupported ();
226
Greg Clayton61d043b2011-03-22 04:00:09 +0000227 void
228 ResetDiscoverableSettings();
229
230 bool
Greg Clayton06d7cc82011-04-04 18:18:57 +0000231 GetHostInfo (bool force = false);
Greg Clayton61d043b2011-03-22 04:00:09 +0000232
233 bool
Greg Clayton58e26e02011-03-24 04:28:38 +0000234 GetOSVersion (uint32_t &major,
235 uint32_t &minor,
236 uint32_t &update);
237
238 bool
239 GetOSBuildString (std::string &s);
240
241 bool
242 GetOSKernelDescription (std::string &s);
243
244 lldb_private::ArchSpec
245 GetSystemArchitecture ();
246
247 bool
248 GetHostname (std::string &s);
249
Greg Clayton516f0842012-04-11 00:24:49 +0000250 lldb::addr_t
251 GetShlibInfoAddr();
252
Greg Clayton58e26e02011-03-24 04:28:38 +0000253 bool
Greg Clayton61d043b2011-03-22 04:00:09 +0000254 GetSupportsThreadSuffix ();
255
256 bool
Greg Clayton24bc5d92011-03-30 18:16:51 +0000257 GetProcessInfo (lldb::pid_t pid,
Greg Claytonb72d0f02011-04-12 05:54:46 +0000258 lldb_private::ProcessInstanceInfo &process_info);
Greg Clayton24bc5d92011-03-30 18:16:51 +0000259
260 uint32_t
Greg Claytonb72d0f02011-04-12 05:54:46 +0000261 FindProcesses (const lldb_private::ProcessInstanceInfoMatch &process_match_info,
262 lldb_private::ProcessInstanceInfoList &process_infos);
Greg Clayton24bc5d92011-03-30 18:16:51 +0000263
264 bool
265 GetUserName (uint32_t uid, std::string &name);
266
267 bool
268 GetGroupName (uint32_t gid, std::string &name);
269
270 bool
Greg Clayton61d043b2011-03-22 04:00:09 +0000271 HasFullVContSupport ()
272 {
273 return GetVContSupported ('A');
274 }
275
276 bool
277 HasAnyVContSupport ()
278 {
279 return GetVContSupported ('a');
280 }
281
282 uint32_t
283 SetPacketTimeout (uint32_t packet_timeout)
284 {
285 const uint32_t old_packet_timeout = m_packet_timeout;
286 m_packet_timeout = packet_timeout;
287 return old_packet_timeout;
288 }
289
Greg Claytonb72d0f02011-04-12 05:54:46 +0000290 bool
291 GetStopReply (StringExtractorGDBRemote &response);
292
293 bool
294 GetThreadStopInfo (uint32_t tid,
295 StringExtractorGDBRemote &response);
296
297 bool
298 SupportsGDBStoppointPacket (GDBStoppointType type)
299 {
300 switch (type)
301 {
302 case eBreakpointSoftware: return m_supports_z0;
303 case eBreakpointHardware: return m_supports_z1;
304 case eWatchpointWrite: return m_supports_z2;
305 case eWatchpointRead: return m_supports_z3;
306 case eWatchpointReadWrite: return m_supports_z4;
307 default: break;
308 }
309 return false;
310 }
311 uint8_t
312 SendGDBStoppointTypePacket (GDBStoppointType type, // Type of breakpoint or watchpoint
313 bool insert, // Insert or remove?
314 lldb::addr_t addr, // Address of breakpoint or watchpoint
315 uint32_t length); // Byte Size of breakpoint or watchpoint
316
Greg Clayton06d7cc82011-04-04 18:18:57 +0000317 void
318 TestPacketSpeed (const uint32_t num_packets);
319
320 // This packet is for testing the speed of the interface only. Both
321 // the client and server need to support it, but this allows us to
322 // measure the packet speed without any other work being done on the
323 // other end and avoids any of that work affecting the packet send
324 // and response times.
325 bool
326 SendSpeedTestPacket (uint32_t send_size,
327 uint32_t recv_size);
Greg Claytonb72d0f02011-04-12 05:54:46 +0000328
329 bool
330 SetCurrentThread (int tid);
331
332 bool
333 SetCurrentThreadForRun (int tid);
334
Greg Clayton989816b2011-05-14 01:50:35 +0000335 lldb_private::LazyBool
Jim Ingham1831e782012-04-07 00:00:41 +0000336 SupportsAllocDeallocMemory () // const
Greg Clayton989816b2011-05-14 01:50:35 +0000337 {
Jim Ingham1831e782012-04-07 00:00:41 +0000338 // Uncomment this to have lldb pretend the debug server doesn't respond to alloc/dealloc memory packets.
339 // m_supports_alloc_dealloc_memory = lldb_private::eLazyBoolNo;
Greg Clayton2f085c62011-05-15 01:25:55 +0000340 return m_supports_alloc_dealloc_memory;
Greg Clayton989816b2011-05-14 01:50:35 +0000341 }
342
Greg Clayton4a60f9e2011-05-20 23:38:13 +0000343 size_t
344 GetCurrentThreadIDs (std::vector<lldb::tid_t> &thread_ids,
345 bool &sequence_mutex_unavailable);
346
Greg Clayton05e4d972012-03-29 01:55:41 +0000347 bool
348 GetInterruptWasSent () const
349 {
350 return m_interrupt_sent;
351 }
Greg Clayton61d043b2011-03-22 04:00:09 +0000352protected:
353
Greg Clayton61d043b2011-03-22 04:00:09 +0000354 //------------------------------------------------------------------
355 // Classes that inherit from GDBRemoteCommunicationClient can see and modify these
356 //------------------------------------------------------------------
Greg Claytonb3448432011-03-24 21:19:54 +0000357 lldb_private::LazyBool m_supports_not_sending_acks;
358 lldb_private::LazyBool m_supports_thread_suffix;
Greg Claytona1f645e2012-04-10 03:22:03 +0000359 lldb_private::LazyBool m_supports_threads_in_stop_reply;
Greg Claytonb3448432011-03-24 21:19:54 +0000360 lldb_private::LazyBool m_supports_vCont_all;
361 lldb_private::LazyBool m_supports_vCont_any;
362 lldb_private::LazyBool m_supports_vCont_c;
363 lldb_private::LazyBool m_supports_vCont_C;
364 lldb_private::LazyBool m_supports_vCont_s;
365 lldb_private::LazyBool m_supports_vCont_S;
Greg Clayton24bc5d92011-03-30 18:16:51 +0000366 lldb_private::LazyBool m_qHostInfo_is_valid;
Greg Clayton2f085c62011-05-15 01:25:55 +0000367 lldb_private::LazyBool m_supports_alloc_dealloc_memory;
Greg Claytona9385532011-11-18 07:03:08 +0000368 lldb_private::LazyBool m_supports_memory_region_info;
Johnny Chen7cbdcfb2012-05-23 21:09:52 +0000369 lldb_private::LazyBool m_supports_watchpoint_support_info;
Enrico Granata7de2a3b2012-07-13 23:18:48 +0000370 lldb_private::LazyBool m_watchpoints_trigger_after_instruction;
Jim Ingham3a458eb2012-07-20 21:37:13 +0000371 lldb_private::LazyBool m_attach_or_wait_reply;
372
Greg Claytonb72d0f02011-04-12 05:54:46 +0000373 bool
374 m_supports_qProcessInfoPID:1,
375 m_supports_qfProcessInfo:1,
376 m_supports_qUserName:1,
377 m_supports_qGroupName:1,
378 m_supports_qThreadStopInfo:1,
379 m_supports_z0:1,
380 m_supports_z1:1,
381 m_supports_z2:1,
382 m_supports_z3:1,
383 m_supports_z4:1;
Greg Clayton989816b2011-05-14 01:50:35 +0000384
Greg Claytonb72d0f02011-04-12 05:54:46 +0000385
386 lldb::tid_t m_curr_tid; // Current gdb remote protocol thread index for all other operations
387 lldb::tid_t m_curr_tid_run; // Current gdb remote protocol thread index for continue, step, etc
388
Greg Clayton61d043b2011-03-22 04:00:09 +0000389
Johnny Chen7cbdcfb2012-05-23 21:09:52 +0000390 uint32_t m_num_supported_hardware_watchpoints;
391
Greg Clayton61d043b2011-03-22 04:00:09 +0000392 // If we need to send a packet while the target is running, the m_async_XXX
393 // member variables take care of making this happen.
394 lldb_private::Mutex m_async_mutex;
395 lldb_private::Predicate<bool> m_async_packet_predicate;
396 std::string m_async_packet;
397 StringExtractorGDBRemote m_async_response;
398 int m_async_signal; // We were asked to deliver a signal to the inferior process.
Greg Clayton05e4d972012-03-29 01:55:41 +0000399 bool m_interrupt_sent;
Greg Clayton61d043b2011-03-22 04:00:09 +0000400
Greg Claytoncb8977d2011-03-23 00:09:55 +0000401 lldb_private::ArchSpec m_host_arch;
Greg Clayton58e26e02011-03-24 04:28:38 +0000402 uint32_t m_os_version_major;
403 uint32_t m_os_version_minor;
404 uint32_t m_os_version_update;
405 std::string m_os_build;
406 std::string m_os_kernel;
407 std::string m_hostname;
Greg Clayton61d043b2011-03-22 04:00:09 +0000408
Greg Clayton24bc5d92011-03-30 18:16:51 +0000409 bool
410 DecodeProcessInfoResponse (StringExtractorGDBRemote &response,
Greg Claytonb72d0f02011-04-12 05:54:46 +0000411 lldb_private::ProcessInstanceInfo &process_info);
Greg Clayton61d043b2011-03-22 04:00:09 +0000412private:
413 //------------------------------------------------------------------
414 // For GDBRemoteCommunicationClient only
415 //------------------------------------------------------------------
416 DISALLOW_COPY_AND_ASSIGN (GDBRemoteCommunicationClient);
417};
418
419#endif // liblldb_GDBRemoteCommunicationClient_h_