blob: bcf23f2c58914e4bb2701bcd6b9364f3f3d032c0 [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
Greg Clayton61d043b2011-03-22 04:00:09 +0000179 bool
180 GetVContSupported (char flavor);
181
182 void
183 ResetDiscoverableSettings();
184
185 bool
186 GetHostInfo ();
187
188 bool
189 GetSupportsThreadSuffix ();
190
191 bool
192 HasFullVContSupport ()
193 {
194 return GetVContSupported ('A');
195 }
196
197 bool
198 HasAnyVContSupport ()
199 {
200 return GetVContSupported ('a');
201 }
202
203 uint32_t
204 SetPacketTimeout (uint32_t packet_timeout)
205 {
206 const uint32_t old_packet_timeout = m_packet_timeout;
207 m_packet_timeout = packet_timeout;
208 return old_packet_timeout;
209 }
210
211protected:
212
Greg Clayton61d043b2011-03-22 04:00:09 +0000213 //------------------------------------------------------------------
214 // Classes that inherit from GDBRemoteCommunicationClient can see and modify these
215 //------------------------------------------------------------------
216 lldb::LazyBool m_supports_not_sending_acks;
217 lldb::LazyBool m_supports_thread_suffix;
218 lldb::LazyBool m_supports_qHostInfo;
219 lldb::LazyBool m_supports_vCont_all;
220 lldb::LazyBool m_supports_vCont_any;
221 lldb::LazyBool m_supports_vCont_c;
222 lldb::LazyBool m_supports_vCont_C;
223 lldb::LazyBool m_supports_vCont_s;
224 lldb::LazyBool m_supports_vCont_S;
225
226 // If we need to send a packet while the target is running, the m_async_XXX
227 // member variables take care of making this happen.
228 lldb_private::Mutex m_async_mutex;
229 lldb_private::Predicate<bool> m_async_packet_predicate;
230 std::string m_async_packet;
231 StringExtractorGDBRemote m_async_response;
232 int m_async_signal; // We were asked to deliver a signal to the inferior process.
233
Greg Claytoncb8977d2011-03-23 00:09:55 +0000234 lldb_private::ArchSpec m_host_arch;
Greg Clayton61d043b2011-03-22 04:00:09 +0000235 uint32_t m_cpusubtype;
Greg Clayton61d043b2011-03-22 04:00:09 +0000236
237private:
238 //------------------------------------------------------------------
239 // For GDBRemoteCommunicationClient only
240 //------------------------------------------------------------------
241 DISALLOW_COPY_AND_ASSIGN (GDBRemoteCommunicationClient);
242};
243
244#endif // liblldb_GDBRemoteCommunicationClient_h_