blob: 1eda0b052bb79d7b7f6c4bbad4f6d2ebcde81773 [file] [log] [blame]
Tamas Berghammere13c2732015-02-11 10:29:30 +00001//===-- GDBRemoteCommunicationServerLLGS.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_GDBRemoteCommunicationServerLLGS_h_
11#define liblldb_GDBRemoteCommunicationServerLLGS_h_
12
13// C Includes
14// C++ Includes
15#include <unordered_map>
16
17// Other libraries and framework includes
18#include "lldb/lldb-private-forward.h"
19#include "lldb/Core/Communication.h"
20#include "lldb/Host/Mutex.h"
21#include "lldb/Host/common/NativeProcessProtocol.h"
22
23// Project includes
24#include "GDBRemoteCommunicationServerCommon.h"
25
Tamas Berghammere13c2732015-02-11 10:29:30 +000026class StringExtractorGDBRemote;
27
Tamas Berghammerdb264a62015-03-31 09:52:22 +000028namespace lldb_private {
29namespace process_gdb_remote {
30
31class ProcessGDBRemote;
32
Tamas Berghammere13c2732015-02-11 10:29:30 +000033class GDBRemoteCommunicationServerLLGS :
34 public GDBRemoteCommunicationServerCommon,
Tamas Berghammerdb264a62015-03-31 09:52:22 +000035 public NativeProcessProtocol::NativeDelegate
Tamas Berghammere13c2732015-02-11 10:29:30 +000036{
37public:
38 //------------------------------------------------------------------
39 // Constructors and Destructors
40 //------------------------------------------------------------------
Tamas Berghammer9c9ecce2015-05-27 13:34:04 +000041 GDBRemoteCommunicationServerLLGS(const lldb::PlatformSP& platform_sp);
Tamas Berghammere13c2732015-02-11 10:29:30 +000042
43 virtual
44 ~GDBRemoteCommunicationServerLLGS();
45
46 //------------------------------------------------------------------
47 /// Specify the program to launch and its arguments.
48 ///
49 /// @param[in] args
50 /// The command line to launch.
51 ///
52 /// @param[in] argc
53 /// The number of elements in the args array of cstring pointers.
54 ///
55 /// @return
56 /// An Error object indicating the success or failure of making
57 /// the setting.
58 //------------------------------------------------------------------
Tamas Berghammerdb264a62015-03-31 09:52:22 +000059 Error
Tamas Berghammere13c2732015-02-11 10:29:30 +000060 SetLaunchArguments (const char *const args[], int argc);
61
62 //------------------------------------------------------------------
63 /// Specify the launch flags for the process.
64 ///
65 /// @param[in] launch_flags
66 /// The launch flags to use when launching this process.
67 ///
68 /// @return
69 /// An Error object indicating the success or failure of making
70 /// the setting.
71 //------------------------------------------------------------------
Tamas Berghammerdb264a62015-03-31 09:52:22 +000072 Error
Tamas Berghammere13c2732015-02-11 10:29:30 +000073 SetLaunchFlags (unsigned int launch_flags);
74
75 //------------------------------------------------------------------
76 /// Launch a process with the current launch settings.
77 ///
78 /// This method supports running an lldb-gdbserver or similar
79 /// server in a situation where the startup code has been provided
80 /// with all the information for a child process to be launched.
81 ///
82 /// @return
83 /// An Error object indicating the success or failure of the
84 /// launch.
85 //------------------------------------------------------------------
Tamas Berghammerdb264a62015-03-31 09:52:22 +000086 Error
Tamas Berghammere13c2732015-02-11 10:29:30 +000087 LaunchProcess () override;
88
89 //------------------------------------------------------------------
90 /// Attach to a process.
91 ///
92 /// This method supports attaching llgs to a process accessible via the
93 /// configured Platform.
94 ///
95 /// @return
96 /// An Error object indicating the success or failure of the
97 /// attach operation.
98 //------------------------------------------------------------------
Tamas Berghammerdb264a62015-03-31 09:52:22 +000099 Error
Tamas Berghammere13c2732015-02-11 10:29:30 +0000100 AttachToProcess (lldb::pid_t pid);
101
102 //------------------------------------------------------------------
103 // NativeProcessProtocol::NativeDelegate overrides
104 //------------------------------------------------------------------
105 void
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000106 InitializeDelegate (NativeProcessProtocol *process) override;
Tamas Berghammere13c2732015-02-11 10:29:30 +0000107
108 void
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000109 ProcessStateChanged (NativeProcessProtocol *process, lldb::StateType state) override;
Tamas Berghammere13c2732015-02-11 10:29:30 +0000110
111 void
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000112 DidExec (NativeProcessProtocol *process) override;
Tamas Berghammere13c2732015-02-11 10:29:30 +0000113
114protected:
115 lldb::PlatformSP m_platform_sp;
116 lldb::thread_t m_async_thread;
117 lldb::tid_t m_current_tid;
118 lldb::tid_t m_continue_tid;
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000119 Mutex m_debugged_process_mutex;
120 NativeProcessProtocolSP m_debugged_process_sp;
Tamas Berghammere13c2732015-02-11 10:29:30 +0000121 Communication m_stdio_communication;
122 lldb::StateType m_inferior_prev_state;
123 lldb::DataBufferSP m_active_auxv_buffer_sp;
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000124 Mutex m_saved_registers_mutex;
Tamas Berghammere13c2732015-02-11 10:29:30 +0000125 std::unordered_map<uint32_t, lldb::DataBufferSP> m_saved_registers_map;
126 uint32_t m_next_saved_registers_id;
127
128 PacketResult
129 SendONotification (const char *buffer, uint32_t len);
130
131 PacketResult
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000132 SendWResponse (NativeProcessProtocol *process);
Tamas Berghammere13c2732015-02-11 10:29:30 +0000133
134 PacketResult
135 SendStopReplyPacketForThread (lldb::tid_t tid);
136
137 PacketResult
138 SendStopReasonForState (lldb::StateType process_state, bool flush_on_exit);
139
140 PacketResult
141 Handle_k (StringExtractorGDBRemote &packet);
142
143 PacketResult
144 Handle_qProcessInfo (StringExtractorGDBRemote &packet);
145
146 PacketResult
147 Handle_qC (StringExtractorGDBRemote &packet);
148
149 PacketResult
150 Handle_QSetDisableASLR (StringExtractorGDBRemote &packet);
151
152 PacketResult
153 Handle_QSetWorkingDir (StringExtractorGDBRemote &packet);
154
155 PacketResult
156 Handle_qGetWorkingDir (StringExtractorGDBRemote &packet);
157
158 PacketResult
159 Handle_C (StringExtractorGDBRemote &packet);
160
161 PacketResult
162 Handle_c (StringExtractorGDBRemote &packet);
163
164 PacketResult
165 Handle_vCont (StringExtractorGDBRemote &packet);
166
167 PacketResult
168 Handle_vCont_actions (StringExtractorGDBRemote &packet);
169
170 PacketResult
171 Handle_stop_reason (StringExtractorGDBRemote &packet);
172
173 PacketResult
174 Handle_qRegisterInfo (StringExtractorGDBRemote &packet);
175
176 PacketResult
177 Handle_qfThreadInfo (StringExtractorGDBRemote &packet);
178
179 PacketResult
180 Handle_qsThreadInfo (StringExtractorGDBRemote &packet);
181
182 PacketResult
183 Handle_p (StringExtractorGDBRemote &packet);
184
185 PacketResult
186 Handle_P (StringExtractorGDBRemote &packet);
187
188 PacketResult
189 Handle_H (StringExtractorGDBRemote &packet);
190
191 PacketResult
192 Handle_I (StringExtractorGDBRemote &packet);
193
194 PacketResult
195 Handle_interrupt (StringExtractorGDBRemote &packet);
196
197 PacketResult
198 Handle_m (StringExtractorGDBRemote &packet);
199
200 PacketResult
201 Handle_M (StringExtractorGDBRemote &packet);
202
203 PacketResult
204 Handle_qMemoryRegionInfoSupported (StringExtractorGDBRemote &packet);
205
206 PacketResult
207 Handle_qMemoryRegionInfo (StringExtractorGDBRemote &packet);
208
209 PacketResult
210 Handle_Z (StringExtractorGDBRemote &packet);
211
212 PacketResult
213 Handle_z (StringExtractorGDBRemote &packet);
214
215 PacketResult
216 Handle_s (StringExtractorGDBRemote &packet);
217
218 PacketResult
219 Handle_qXfer_auxv_read (StringExtractorGDBRemote &packet);
220
221 PacketResult
222 Handle_QSaveRegisterState (StringExtractorGDBRemote &packet);
223
224 PacketResult
225 Handle_QRestoreRegisterState (StringExtractorGDBRemote &packet);
226
227 PacketResult
228 Handle_vAttach (StringExtractorGDBRemote &packet);
229
230 PacketResult
231 Handle_D (StringExtractorGDBRemote &packet);
232
233 PacketResult
234 Handle_qThreadStopInfo (StringExtractorGDBRemote &packet);
235
236 PacketResult
237 Handle_qWatchpointSupportInfo (StringExtractorGDBRemote &packet);
238
Tamas Berghammer783bfc82015-06-18 20:43:56 +0000239 PacketResult
240 Handle_qFileLoadAddress (StringExtractorGDBRemote &packet);
241
Tamas Berghammere13c2732015-02-11 10:29:30 +0000242 void
243 SetCurrentThreadID (lldb::tid_t tid);
244
245 lldb::tid_t
246 GetCurrentThreadID () const;
247
248 void
249 SetContinueThreadID (lldb::tid_t tid);
250
251 lldb::tid_t
252 GetContinueThreadID () const { return m_continue_tid; }
253
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000254 Error
Tamas Berghammere13c2732015-02-11 10:29:30 +0000255 SetSTDIOFileDescriptor (int fd);
256
257 static void
258 STDIOReadThreadBytesReceived (void *baton, const void *src, size_t src_len);
259
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000260 FileSpec
261 FindModuleFile (const std::string& module_path, const ArchSpec& arch) override;
Tamas Berghammer7cb18bf2015-03-24 11:15:23 +0000262
Tamas Berghammere13c2732015-02-11 10:29:30 +0000263private:
264 bool
265 DebuggedProcessReaped (lldb::pid_t pid);
266
267 static bool
268 ReapDebuggedProcess (void *callback_baton,
269 lldb::pid_t pid,
270 bool exited,
271 int signal,
272 int status);
273
274 void
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000275 HandleInferiorState_Exited (NativeProcessProtocol *process);
Tamas Berghammere13c2732015-02-11 10:29:30 +0000276
277 void
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000278 HandleInferiorState_Stopped (NativeProcessProtocol *process);
Tamas Berghammere13c2732015-02-11 10:29:30 +0000279
280 void
281 FlushInferiorOutput ();
282
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000283 NativeThreadProtocolSP
Tamas Berghammere13c2732015-02-11 10:29:30 +0000284 GetThreadFromSuffix (StringExtractorGDBRemote &packet);
285
286 uint32_t
287 GetNextSavedRegistersID ();
288
289 void
290 MaybeCloseInferiorTerminalConnection ();
291
292 void
293 ClearProcessSpecificData ();
294
Tamas Berghammere13c2732015-02-11 10:29:30 +0000295 void
296 RegisterPacketHandlers ();
297
298 //------------------------------------------------------------------
299 // For GDBRemoteCommunicationServerLLGS only
300 //------------------------------------------------------------------
301 DISALLOW_COPY_AND_ASSIGN (GDBRemoteCommunicationServerLLGS);
302};
303
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000304} // namespace process_gdb_remote
305} // namespace lldb_private
306
Tamas Berghammere13c2732015-02-11 10:29:30 +0000307#endif // liblldb_GDBRemoteCommunicationServerLLGS_h_