blob: 5c24d642470f1ed28a5e85cb2a522169fe94df15 [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
126 //------------------------------------------------------------------
127 /// Sends a "vAttach:PID" where PID is in hex.
128 ///
129 /// @param[in] pid
130 /// A process ID for the remote gdb server to attach to.
131 ///
132 /// @param[out] response
133 /// The response received from the gdb server. If the return
134 /// value is zero, \a response will contain a stop reply
135 /// packet.
136 ///
137 /// @return
138 /// Zero if the attach was successful, or an error indicating
139 /// an error code.
140 //------------------------------------------------------------------
141 int
142 SendAttach (lldb::pid_t pid,
143 StringExtractorGDBRemote& response);
144
145
146 //------------------------------------------------------------------
147 /// Sets the path to use for stdin/out/err for a process
148 /// that will be launched with the 'A' packet.
149 ///
150 /// @param[in] path
151 /// The path to use for stdin/out/err
152 ///
153 /// @return
154 /// Zero if the for success, or an error code for failure.
155 //------------------------------------------------------------------
156 int
157 SetSTDIN (char const *path);
158 int
159 SetSTDOUT (char const *path);
160 int
161 SetSTDERR (char const *path);
162
163 //------------------------------------------------------------------
164 /// Sets the disable ASLR flag to \a enable for a process that will
165 /// be launched with the 'A' packet.
166 ///
167 /// @param[in] enable
168 /// A boolean value indicating wether to disable ASLR or not.
169 ///
170 /// @return
171 /// Zero if the for success, or an error code for failure.
172 //------------------------------------------------------------------
173 int
174 SetDisableASLR (bool enable);
175
176 //------------------------------------------------------------------
177 /// Sets the working directory to \a path for a process that will
178 /// be launched with the 'A' packet.
179 ///
180 /// @param[in] path
181 /// The path to a directory to use when launching our processs
182 ///
183 /// @return
184 /// Zero if the for success, or an error code for failure.
185 //------------------------------------------------------------------
186 int
187 SetWorkingDir (char const *path);
188
189 lldb::addr_t
190 AllocateMemory (size_t size, uint32_t permissions);
191
192 bool
193 DeallocateMemory (lldb::addr_t addr);
194
195 const lldb_private::ArchSpec &
196 GetHostArchitecture ();
197
Greg Clayton61d043b2011-03-22 04:00:09 +0000198 bool
199 GetVContSupported (char flavor);
200
201 void
202 ResetDiscoverableSettings();
203
204 bool
Greg Clayton06d7cc82011-04-04 18:18:57 +0000205 GetHostInfo (bool force = false);
Greg Clayton61d043b2011-03-22 04:00:09 +0000206
207 bool
Greg Clayton58e26e02011-03-24 04:28:38 +0000208 GetOSVersion (uint32_t &major,
209 uint32_t &minor,
210 uint32_t &update);
211
212 bool
213 GetOSBuildString (std::string &s);
214
215 bool
216 GetOSKernelDescription (std::string &s);
217
218 lldb_private::ArchSpec
219 GetSystemArchitecture ();
220
221 bool
222 GetHostname (std::string &s);
223
224 bool
Greg Clayton61d043b2011-03-22 04:00:09 +0000225 GetSupportsThreadSuffix ();
226
227 bool
Greg Clayton24bc5d92011-03-30 18:16:51 +0000228 GetProcessInfo (lldb::pid_t pid,
Greg Claytonb72d0f02011-04-12 05:54:46 +0000229 lldb_private::ProcessInstanceInfo &process_info);
Greg Clayton24bc5d92011-03-30 18:16:51 +0000230
231 uint32_t
Greg Claytonb72d0f02011-04-12 05:54:46 +0000232 FindProcesses (const lldb_private::ProcessInstanceInfoMatch &process_match_info,
233 lldb_private::ProcessInstanceInfoList &process_infos);
Greg Clayton24bc5d92011-03-30 18:16:51 +0000234
235 bool
236 GetUserName (uint32_t uid, std::string &name);
237
238 bool
239 GetGroupName (uint32_t gid, std::string &name);
240
241 bool
Greg Clayton61d043b2011-03-22 04:00:09 +0000242 HasFullVContSupport ()
243 {
244 return GetVContSupported ('A');
245 }
246
247 bool
248 HasAnyVContSupport ()
249 {
250 return GetVContSupported ('a');
251 }
252
253 uint32_t
254 SetPacketTimeout (uint32_t packet_timeout)
255 {
256 const uint32_t old_packet_timeout = m_packet_timeout;
257 m_packet_timeout = packet_timeout;
258 return old_packet_timeout;
259 }
260
Greg Claytonb72d0f02011-04-12 05:54:46 +0000261 bool
262 GetStopReply (StringExtractorGDBRemote &response);
263
264 bool
265 GetThreadStopInfo (uint32_t tid,
266 StringExtractorGDBRemote &response);
267
268 bool
269 SupportsGDBStoppointPacket (GDBStoppointType type)
270 {
271 switch (type)
272 {
273 case eBreakpointSoftware: return m_supports_z0;
274 case eBreakpointHardware: return m_supports_z1;
275 case eWatchpointWrite: return m_supports_z2;
276 case eWatchpointRead: return m_supports_z3;
277 case eWatchpointReadWrite: return m_supports_z4;
278 default: break;
279 }
280 return false;
281 }
282 uint8_t
283 SendGDBStoppointTypePacket (GDBStoppointType type, // Type of breakpoint or watchpoint
284 bool insert, // Insert or remove?
285 lldb::addr_t addr, // Address of breakpoint or watchpoint
286 uint32_t length); // Byte Size of breakpoint or watchpoint
287
Greg Clayton06d7cc82011-04-04 18:18:57 +0000288 void
289 TestPacketSpeed (const uint32_t num_packets);
290
291 // This packet is for testing the speed of the interface only. Both
292 // the client and server need to support it, but this allows us to
293 // measure the packet speed without any other work being done on the
294 // other end and avoids any of that work affecting the packet send
295 // and response times.
296 bool
297 SendSpeedTestPacket (uint32_t send_size,
298 uint32_t recv_size);
Greg Claytonb72d0f02011-04-12 05:54:46 +0000299
300 bool
301 SetCurrentThread (int tid);
302
303 bool
304 SetCurrentThreadForRun (int tid);
305
Greg Clayton61d043b2011-03-22 04:00:09 +0000306protected:
307
Greg Clayton61d043b2011-03-22 04:00:09 +0000308 //------------------------------------------------------------------
309 // Classes that inherit from GDBRemoteCommunicationClient can see and modify these
310 //------------------------------------------------------------------
Greg Claytonb3448432011-03-24 21:19:54 +0000311 lldb_private::LazyBool m_supports_not_sending_acks;
312 lldb_private::LazyBool m_supports_thread_suffix;
Greg Claytonb3448432011-03-24 21:19:54 +0000313 lldb_private::LazyBool m_supports_vCont_all;
314 lldb_private::LazyBool m_supports_vCont_any;
315 lldb_private::LazyBool m_supports_vCont_c;
316 lldb_private::LazyBool m_supports_vCont_C;
317 lldb_private::LazyBool m_supports_vCont_s;
318 lldb_private::LazyBool m_supports_vCont_S;
Greg Clayton24bc5d92011-03-30 18:16:51 +0000319 lldb_private::LazyBool m_qHostInfo_is_valid;
Greg Claytonb72d0f02011-04-12 05:54:46 +0000320 bool
321 m_supports_qProcessInfoPID:1,
322 m_supports_qfProcessInfo:1,
323 m_supports_qUserName:1,
324 m_supports_qGroupName:1,
325 m_supports_qThreadStopInfo:1,
326 m_supports_z0:1,
327 m_supports_z1:1,
328 m_supports_z2:1,
329 m_supports_z3:1,
330 m_supports_z4:1;
331
332 lldb::tid_t m_curr_tid; // Current gdb remote protocol thread index for all other operations
333 lldb::tid_t m_curr_tid_run; // Current gdb remote protocol thread index for continue, step, etc
334
Greg Clayton61d043b2011-03-22 04:00:09 +0000335
336 // If we need to send a packet while the target is running, the m_async_XXX
337 // member variables take care of making this happen.
338 lldb_private::Mutex m_async_mutex;
339 lldb_private::Predicate<bool> m_async_packet_predicate;
340 std::string m_async_packet;
341 StringExtractorGDBRemote m_async_response;
342 int m_async_signal; // We were asked to deliver a signal to the inferior process.
343
Greg Claytoncb8977d2011-03-23 00:09:55 +0000344 lldb_private::ArchSpec m_host_arch;
Greg Clayton58e26e02011-03-24 04:28:38 +0000345 uint32_t m_os_version_major;
346 uint32_t m_os_version_minor;
347 uint32_t m_os_version_update;
348 std::string m_os_build;
349 std::string m_os_kernel;
350 std::string m_hostname;
Greg Clayton61d043b2011-03-22 04:00:09 +0000351
Greg Clayton24bc5d92011-03-30 18:16:51 +0000352 bool
353 DecodeProcessInfoResponse (StringExtractorGDBRemote &response,
Greg Claytonb72d0f02011-04-12 05:54:46 +0000354 lldb_private::ProcessInstanceInfo &process_info);
Greg Clayton61d043b2011-03-22 04:00:09 +0000355private:
356 //------------------------------------------------------------------
357 // For GDBRemoteCommunicationClient only
358 //------------------------------------------------------------------
359 DISALLOW_COPY_AND_ASSIGN (GDBRemoteCommunicationClient);
360};
361
362#endif // liblldb_GDBRemoteCommunicationClient_h_