blob: d28c8275bd4b1b16020046195af493d0c55fb943 [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
21class GDBRemoteCommunicationClient : public GDBRemoteCommunication
22{
23public:
24 //------------------------------------------------------------------
25 // Constructors and Destructors
26 //------------------------------------------------------------------
27 GDBRemoteCommunicationClient();
28
29 virtual
30 ~GDBRemoteCommunicationClient();
31
Greg Clayton58e26e02011-03-24 04:28:38 +000032 //------------------------------------------------------------------
33 // After connecting, send the handshake to the server to make sure
34 // we are communicating with it.
35 //------------------------------------------------------------------
36 bool
37 HandshakeWithServer (lldb_private::Error *error_ptr);
38
Greg Clayton61d043b2011-03-22 04:00:09 +000039 size_t
40 SendPacketAndWaitForResponse (const char *send_payload,
41 StringExtractorGDBRemote &response,
42 bool send_async);
43
44 size_t
45 SendPacketAndWaitForResponse (const char *send_payload,
46 size_t send_length,
47 StringExtractorGDBRemote &response,
48 bool send_async);
49
50 lldb::StateType
51 SendContinuePacketAndWaitForResponse (ProcessGDBRemote *process,
52 const char *packet_payload,
53 size_t packet_length,
54 StringExtractorGDBRemote &response);
55
56 virtual bool
57 GetThreadSuffixSupported ();
58
Greg Clayton58e26e02011-03-24 04:28:38 +000059 void
60 QueryNoAckModeSupported ();
Greg Clayton61d043b2011-03-22 04:00:09 +000061
62 bool
63 SendAsyncSignal (int signo);
64
65 bool
66 SendInterrupt (lldb_private::Mutex::Locker &locker,
67 uint32_t seconds_to_wait_for_stop,
68 bool &sent_interrupt,
69 bool &timed_out);
70
71 lldb::pid_t
72 GetCurrentProcessID ();
73
74 bool
75 GetLaunchSuccess (std::string &error_str);
76
77 //------------------------------------------------------------------
78 /// Sends a GDB remote protocol 'A' packet that delivers program
79 /// arguments to the remote server.
80 ///
81 /// @param[in] argv
82 /// A NULL terminated array of const C strings to use as the
83 /// arguments.
84 ///
85 /// @return
86 /// Zero if the response was "OK", a positive value if the
87 /// the response was "Exx" where xx are two hex digits, or
88 /// -1 if the call is unsupported or any other unexpected
89 /// response was received.
90 //------------------------------------------------------------------
91 int
92 SendArgumentsPacket (char const *argv[]);
93
94 //------------------------------------------------------------------
95 /// Sends a "QEnvironment:NAME=VALUE" packet that will build up the
96 /// environment that will get used when launching an application
97 /// in conjunction with the 'A' packet. This function can be called
98 /// multiple times in a row in order to pass on the desired
99 /// environment that the inferior should be launched with.
100 ///
101 /// @param[in] name_equal_value
102 /// A NULL terminated C string that contains a single environment
103 /// in the format "NAME=VALUE".
104 ///
105 /// @return
106 /// Zero if the response was "OK", a positive value if the
107 /// the response was "Exx" where xx are two hex digits, or
108 /// -1 if the call is unsupported or any other unexpected
109 /// response was received.
110 //------------------------------------------------------------------
111 int
112 SendEnvironmentPacket (char const *name_equal_value);
113
114 //------------------------------------------------------------------
115 /// Sends a "vAttach:PID" where PID is in hex.
116 ///
117 /// @param[in] pid
118 /// A process ID for the remote gdb server to attach to.
119 ///
120 /// @param[out] response
121 /// The response received from the gdb server. If the return
122 /// value is zero, \a response will contain a stop reply
123 /// packet.
124 ///
125 /// @return
126 /// Zero if the attach was successful, or an error indicating
127 /// an error code.
128 //------------------------------------------------------------------
129 int
130 SendAttach (lldb::pid_t pid,
131 StringExtractorGDBRemote& response);
132
133
134 //------------------------------------------------------------------
135 /// Sets the path to use for stdin/out/err for a process
136 /// that will be launched with the 'A' packet.
137 ///
138 /// @param[in] path
139 /// The path to use for stdin/out/err
140 ///
141 /// @return
142 /// Zero if the for success, or an error code for failure.
143 //------------------------------------------------------------------
144 int
145 SetSTDIN (char const *path);
146 int
147 SetSTDOUT (char const *path);
148 int
149 SetSTDERR (char const *path);
150
151 //------------------------------------------------------------------
152 /// Sets the disable ASLR flag to \a enable for a process that will
153 /// be launched with the 'A' packet.
154 ///
155 /// @param[in] enable
156 /// A boolean value indicating wether to disable ASLR or not.
157 ///
158 /// @return
159 /// Zero if the for success, or an error code for failure.
160 //------------------------------------------------------------------
161 int
162 SetDisableASLR (bool enable);
163
164 //------------------------------------------------------------------
165 /// Sets the working directory to \a path for a process that will
166 /// be launched with the 'A' packet.
167 ///
168 /// @param[in] path
169 /// The path to a directory to use when launching our processs
170 ///
171 /// @return
172 /// Zero if the for success, or an error code for failure.
173 //------------------------------------------------------------------
174 int
175 SetWorkingDir (char const *path);
176
177 lldb::addr_t
178 AllocateMemory (size_t size, uint32_t permissions);
179
180 bool
181 DeallocateMemory (lldb::addr_t addr);
182
183 const lldb_private::ArchSpec &
184 GetHostArchitecture ();
185
Greg Clayton61d043b2011-03-22 04:00:09 +0000186 bool
187 GetVContSupported (char flavor);
188
189 void
190 ResetDiscoverableSettings();
191
192 bool
193 GetHostInfo ();
194
195 bool
Greg Clayton58e26e02011-03-24 04:28:38 +0000196 GetOSVersion (uint32_t &major,
197 uint32_t &minor,
198 uint32_t &update);
199
200 bool
201 GetOSBuildString (std::string &s);
202
203 bool
204 GetOSKernelDescription (std::string &s);
205
206 lldb_private::ArchSpec
207 GetSystemArchitecture ();
208
209 bool
210 GetHostname (std::string &s);
211
212 bool
Greg Clayton61d043b2011-03-22 04:00:09 +0000213 GetSupportsThreadSuffix ();
214
215 bool
Greg Clayton24bc5d92011-03-30 18:16:51 +0000216 GetProcessInfo (lldb::pid_t pid,
217 lldb_private::ProcessInfo &process_info);
218
219 uint32_t
220 FindProcesses (const lldb_private::ProcessInfoMatch &process_match_info,
221 lldb_private::ProcessInfoList &process_infos);
222
223 bool
224 GetUserName (uint32_t uid, std::string &name);
225
226 bool
227 GetGroupName (uint32_t gid, std::string &name);
228
229 bool
Greg Clayton61d043b2011-03-22 04:00:09 +0000230 HasFullVContSupport ()
231 {
232 return GetVContSupported ('A');
233 }
234
235 bool
236 HasAnyVContSupport ()
237 {
238 return GetVContSupported ('a');
239 }
240
241 uint32_t
242 SetPacketTimeout (uint32_t packet_timeout)
243 {
244 const uint32_t old_packet_timeout = m_packet_timeout;
245 m_packet_timeout = packet_timeout;
246 return old_packet_timeout;
247 }
248
249protected:
250
Greg Clayton61d043b2011-03-22 04:00:09 +0000251 //------------------------------------------------------------------
252 // Classes that inherit from GDBRemoteCommunicationClient can see and modify these
253 //------------------------------------------------------------------
Greg Claytonb3448432011-03-24 21:19:54 +0000254 lldb_private::LazyBool m_supports_not_sending_acks;
255 lldb_private::LazyBool m_supports_thread_suffix;
Greg Claytonb3448432011-03-24 21:19:54 +0000256 lldb_private::LazyBool m_supports_vCont_all;
257 lldb_private::LazyBool m_supports_vCont_any;
258 lldb_private::LazyBool m_supports_vCont_c;
259 lldb_private::LazyBool m_supports_vCont_C;
260 lldb_private::LazyBool m_supports_vCont_s;
261 lldb_private::LazyBool m_supports_vCont_S;
Greg Clayton24bc5d92011-03-30 18:16:51 +0000262 lldb_private::LazyBool m_qHostInfo_is_valid;
263 bool m_supports_qProcessInfoPID;
264 bool m_supports_qfProcessInfo;
265 bool m_supports_qUserName;
266 bool m_supports_qGroupName;
Greg Clayton61d043b2011-03-22 04:00:09 +0000267
268 // If we need to send a packet while the target is running, the m_async_XXX
269 // member variables take care of making this happen.
270 lldb_private::Mutex m_async_mutex;
271 lldb_private::Predicate<bool> m_async_packet_predicate;
272 std::string m_async_packet;
273 StringExtractorGDBRemote m_async_response;
274 int m_async_signal; // We were asked to deliver a signal to the inferior process.
275
Greg Claytoncb8977d2011-03-23 00:09:55 +0000276 lldb_private::ArchSpec m_host_arch;
Greg Clayton58e26e02011-03-24 04:28:38 +0000277 uint32_t m_os_version_major;
278 uint32_t m_os_version_minor;
279 uint32_t m_os_version_update;
280 std::string m_os_build;
281 std::string m_os_kernel;
282 std::string m_hostname;
Greg Clayton61d043b2011-03-22 04:00:09 +0000283
Greg Clayton24bc5d92011-03-30 18:16:51 +0000284 bool
285 DecodeProcessInfoResponse (StringExtractorGDBRemote &response,
286 lldb_private::ProcessInfo &process_info);
Greg Clayton61d043b2011-03-22 04:00:09 +0000287private:
288 //------------------------------------------------------------------
289 // For GDBRemoteCommunicationClient only
290 //------------------------------------------------------------------
291 DISALLOW_COPY_AND_ASSIGN (GDBRemoteCommunicationClient);
292};
293
294#endif // liblldb_GDBRemoteCommunicationClient_h_