blob: 604e09a9491a948e16bf7b880e10d95901028e42 [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
32 size_t
33 SendPacketAndWaitForResponse (const char *send_payload,
34 StringExtractorGDBRemote &response,
35 bool send_async);
36
37 size_t
38 SendPacketAndWaitForResponse (const char *send_payload,
39 size_t send_length,
40 StringExtractorGDBRemote &response,
41 bool send_async);
42
43 lldb::StateType
44 SendContinuePacketAndWaitForResponse (ProcessGDBRemote *process,
45 const char *packet_payload,
46 size_t packet_length,
47 StringExtractorGDBRemote &response);
48
49 virtual bool
50 GetThreadSuffixSupported ();
51
52 virtual bool
53 GetSendAcks ();
54
55 bool
56 SendAsyncSignal (int signo);
57
58 bool
59 SendInterrupt (lldb_private::Mutex::Locker &locker,
60 uint32_t seconds_to_wait_for_stop,
61 bool &sent_interrupt,
62 bool &timed_out);
63
64 lldb::pid_t
65 GetCurrentProcessID ();
66
67 bool
68 GetLaunchSuccess (std::string &error_str);
69
70 //------------------------------------------------------------------
71 /// Sends a GDB remote protocol 'A' packet that delivers program
72 /// arguments to the remote server.
73 ///
74 /// @param[in] argv
75 /// A NULL terminated array of const C strings to use as the
76 /// arguments.
77 ///
78 /// @return
79 /// Zero if the response was "OK", a positive value if the
80 /// the response was "Exx" where xx are two hex digits, or
81 /// -1 if the call is unsupported or any other unexpected
82 /// response was received.
83 //------------------------------------------------------------------
84 int
85 SendArgumentsPacket (char const *argv[]);
86
87 //------------------------------------------------------------------
88 /// Sends a "QEnvironment:NAME=VALUE" packet that will build up the
89 /// environment that will get used when launching an application
90 /// in conjunction with the 'A' packet. This function can be called
91 /// multiple times in a row in order to pass on the desired
92 /// environment that the inferior should be launched with.
93 ///
94 /// @param[in] name_equal_value
95 /// A NULL terminated C string that contains a single environment
96 /// in the format "NAME=VALUE".
97 ///
98 /// @return
99 /// Zero if the response was "OK", a positive value if the
100 /// the response was "Exx" where xx are two hex digits, or
101 /// -1 if the call is unsupported or any other unexpected
102 /// response was received.
103 //------------------------------------------------------------------
104 int
105 SendEnvironmentPacket (char const *name_equal_value);
106
107 //------------------------------------------------------------------
108 /// Sends a "vAttach:PID" where PID is in hex.
109 ///
110 /// @param[in] pid
111 /// A process ID for the remote gdb server to attach to.
112 ///
113 /// @param[out] response
114 /// The response received from the gdb server. If the return
115 /// value is zero, \a response will contain a stop reply
116 /// packet.
117 ///
118 /// @return
119 /// Zero if the attach was successful, or an error indicating
120 /// an error code.
121 //------------------------------------------------------------------
122 int
123 SendAttach (lldb::pid_t pid,
124 StringExtractorGDBRemote& response);
125
126
127 //------------------------------------------------------------------
128 /// Sets the path to use for stdin/out/err for a process
129 /// that will be launched with the 'A' packet.
130 ///
131 /// @param[in] path
132 /// The path to use for stdin/out/err
133 ///
134 /// @return
135 /// Zero if the for success, or an error code for failure.
136 //------------------------------------------------------------------
137 int
138 SetSTDIN (char const *path);
139 int
140 SetSTDOUT (char const *path);
141 int
142 SetSTDERR (char const *path);
143
144 //------------------------------------------------------------------
145 /// Sets the disable ASLR flag to \a enable for a process that will
146 /// be launched with the 'A' packet.
147 ///
148 /// @param[in] enable
149 /// A boolean value indicating wether to disable ASLR or not.
150 ///
151 /// @return
152 /// Zero if the for success, or an error code for failure.
153 //------------------------------------------------------------------
154 int
155 SetDisableASLR (bool enable);
156
157 //------------------------------------------------------------------
158 /// Sets the working directory to \a path for a process that will
159 /// be launched with the 'A' packet.
160 ///
161 /// @param[in] path
162 /// The path to a directory to use when launching our processs
163 ///
164 /// @return
165 /// Zero if the for success, or an error code for failure.
166 //------------------------------------------------------------------
167 int
168 SetWorkingDir (char const *path);
169
170 lldb::addr_t
171 AllocateMemory (size_t size, uint32_t permissions);
172
173 bool
174 DeallocateMemory (lldb::addr_t addr);
175
176 const lldb_private::ArchSpec &
177 GetHostArchitecture ();
178
179 const lldb_private::ConstString &
180 GetOSString ();
181
182 const lldb_private::ConstString &
183 GetVendorString();
184
185 lldb::ByteOrder
186 GetByteOrder ();
187
188 uint32_t
189 GetAddressByteSize ();
190
191 bool
192 GetVContSupported (char flavor);
193
194 void
195 ResetDiscoverableSettings();
196
197 bool
198 GetHostInfo ();
199
200 bool
201 GetSupportsThreadSuffix ();
202
203 bool
204 HasFullVContSupport ()
205 {
206 return GetVContSupported ('A');
207 }
208
209 bool
210 HasAnyVContSupport ()
211 {
212 return GetVContSupported ('a');
213 }
214
215 uint32_t
216 SetPacketTimeout (uint32_t packet_timeout)
217 {
218 const uint32_t old_packet_timeout = m_packet_timeout;
219 m_packet_timeout = packet_timeout;
220 return old_packet_timeout;
221 }
222
223protected:
224
225 bool
226 HostInfoIsValid () const
227 {
228 return m_supports_qHostInfo != lldb::eLazyBoolCalculate;
229 }
230
231 //------------------------------------------------------------------
232 // Classes that inherit from GDBRemoteCommunicationClient can see and modify these
233 //------------------------------------------------------------------
234 lldb::LazyBool m_supports_not_sending_acks;
235 lldb::LazyBool m_supports_thread_suffix;
236 lldb::LazyBool m_supports_qHostInfo;
237 lldb::LazyBool m_supports_vCont_all;
238 lldb::LazyBool m_supports_vCont_any;
239 lldb::LazyBool m_supports_vCont_c;
240 lldb::LazyBool m_supports_vCont_C;
241 lldb::LazyBool m_supports_vCont_s;
242 lldb::LazyBool m_supports_vCont_S;
243
244 // If we need to send a packet while the target is running, the m_async_XXX
245 // member variables take care of making this happen.
246 lldb_private::Mutex m_async_mutex;
247 lldb_private::Predicate<bool> m_async_packet_predicate;
248 std::string m_async_packet;
249 StringExtractorGDBRemote m_async_response;
250 int m_async_signal; // We were asked to deliver a signal to the inferior process.
251
252 lldb_private::ArchSpec m_arch;
253 uint32_t m_cpusubtype;
254 lldb_private::ConstString m_os;
255 lldb_private::ConstString m_vendor;
256 lldb::ByteOrder m_byte_order;
257 uint32_t m_pointer_byte_size;
258
259
260
261private:
262 //------------------------------------------------------------------
263 // For GDBRemoteCommunicationClient only
264 //------------------------------------------------------------------
265 DISALLOW_COPY_AND_ASSIGN (GDBRemoteCommunicationClient);
266};
267
268#endif // liblldb_GDBRemoteCommunicationClient_h_