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