blob: a47e9a19f0ba9720b5cdab111193ba6c5499f73a [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 //------------------------------------------------------------------
41 GDBRemoteCommunicationServerLLGS(const lldb::PlatformSP& platform_sp,
42 lldb::DebuggerSP& debugger_sp);
43
44 virtual
45 ~GDBRemoteCommunicationServerLLGS();
46
47 //------------------------------------------------------------------
48 /// Specify the program to launch and its arguments.
49 ///
50 /// @param[in] args
51 /// The command line to launch.
52 ///
53 /// @param[in] argc
54 /// The number of elements in the args array of cstring pointers.
55 ///
56 /// @return
57 /// An Error object indicating the success or failure of making
58 /// the setting.
59 //------------------------------------------------------------------
Tamas Berghammerdb264a62015-03-31 09:52:22 +000060 Error
Tamas Berghammere13c2732015-02-11 10:29:30 +000061 SetLaunchArguments (const char *const args[], int argc);
62
63 //------------------------------------------------------------------
64 /// Specify the launch flags for the process.
65 ///
66 /// @param[in] launch_flags
67 /// The launch flags to use when launching this process.
68 ///
69 /// @return
70 /// An Error object indicating the success or failure of making
71 /// the setting.
72 //------------------------------------------------------------------
Tamas Berghammerdb264a62015-03-31 09:52:22 +000073 Error
Tamas Berghammere13c2732015-02-11 10:29:30 +000074 SetLaunchFlags (unsigned int launch_flags);
75
76 //------------------------------------------------------------------
77 /// Launch a process with the current launch settings.
78 ///
79 /// This method supports running an lldb-gdbserver or similar
80 /// server in a situation where the startup code has been provided
81 /// with all the information for a child process to be launched.
82 ///
83 /// @return
84 /// An Error object indicating the success or failure of the
85 /// launch.
86 //------------------------------------------------------------------
Tamas Berghammerdb264a62015-03-31 09:52:22 +000087 Error
Tamas Berghammere13c2732015-02-11 10:29:30 +000088 LaunchProcess () override;
89
90 //------------------------------------------------------------------
91 /// Attach to a process.
92 ///
93 /// This method supports attaching llgs to a process accessible via the
94 /// configured Platform.
95 ///
96 /// @return
97 /// An Error object indicating the success or failure of the
98 /// attach operation.
99 //------------------------------------------------------------------
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000100 Error
Tamas Berghammere13c2732015-02-11 10:29:30 +0000101 AttachToProcess (lldb::pid_t pid);
102
103 //------------------------------------------------------------------
104 // NativeProcessProtocol::NativeDelegate overrides
105 //------------------------------------------------------------------
106 void
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000107 InitializeDelegate (NativeProcessProtocol *process) override;
Tamas Berghammere13c2732015-02-11 10:29:30 +0000108
109 void
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000110 ProcessStateChanged (NativeProcessProtocol *process, lldb::StateType state) override;
Tamas Berghammere13c2732015-02-11 10:29:30 +0000111
112 void
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000113 DidExec (NativeProcessProtocol *process) override;
Tamas Berghammere13c2732015-02-11 10:29:30 +0000114
115protected:
116 lldb::PlatformSP m_platform_sp;
117 lldb::thread_t m_async_thread;
118 lldb::tid_t m_current_tid;
119 lldb::tid_t m_continue_tid;
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000120 Mutex m_debugged_process_mutex;
121 NativeProcessProtocolSP m_debugged_process_sp;
Tamas Berghammere13c2732015-02-11 10:29:30 +0000122 lldb::DebuggerSP m_debugger_sp;
123 Communication m_stdio_communication;
124 lldb::StateType m_inferior_prev_state;
125 lldb::DataBufferSP m_active_auxv_buffer_sp;
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000126 Mutex m_saved_registers_mutex;
Tamas Berghammere13c2732015-02-11 10:29:30 +0000127 std::unordered_map<uint32_t, lldb::DataBufferSP> m_saved_registers_map;
128 uint32_t m_next_saved_registers_id;
129
130 PacketResult
131 SendONotification (const char *buffer, uint32_t len);
132
133 PacketResult
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000134 SendWResponse (NativeProcessProtocol *process);
Tamas Berghammere13c2732015-02-11 10:29:30 +0000135
136 PacketResult
137 SendStopReplyPacketForThread (lldb::tid_t tid);
138
139 PacketResult
140 SendStopReasonForState (lldb::StateType process_state, bool flush_on_exit);
141
142 PacketResult
143 Handle_k (StringExtractorGDBRemote &packet);
144
145 PacketResult
146 Handle_qProcessInfo (StringExtractorGDBRemote &packet);
147
148 PacketResult
149 Handle_qC (StringExtractorGDBRemote &packet);
150
151 PacketResult
152 Handle_QSetDisableASLR (StringExtractorGDBRemote &packet);
153
154 PacketResult
155 Handle_QSetWorkingDir (StringExtractorGDBRemote &packet);
156
157 PacketResult
158 Handle_qGetWorkingDir (StringExtractorGDBRemote &packet);
159
160 PacketResult
161 Handle_C (StringExtractorGDBRemote &packet);
162
163 PacketResult
164 Handle_c (StringExtractorGDBRemote &packet);
165
166 PacketResult
167 Handle_vCont (StringExtractorGDBRemote &packet);
168
169 PacketResult
170 Handle_vCont_actions (StringExtractorGDBRemote &packet);
171
172 PacketResult
173 Handle_stop_reason (StringExtractorGDBRemote &packet);
174
175 PacketResult
176 Handle_qRegisterInfo (StringExtractorGDBRemote &packet);
177
178 PacketResult
179 Handle_qfThreadInfo (StringExtractorGDBRemote &packet);
180
181 PacketResult
182 Handle_qsThreadInfo (StringExtractorGDBRemote &packet);
183
184 PacketResult
185 Handle_p (StringExtractorGDBRemote &packet);
186
187 PacketResult
188 Handle_P (StringExtractorGDBRemote &packet);
189
190 PacketResult
191 Handle_H (StringExtractorGDBRemote &packet);
192
193 PacketResult
194 Handle_I (StringExtractorGDBRemote &packet);
195
196 PacketResult
197 Handle_interrupt (StringExtractorGDBRemote &packet);
198
199 PacketResult
200 Handle_m (StringExtractorGDBRemote &packet);
201
202 PacketResult
203 Handle_M (StringExtractorGDBRemote &packet);
204
205 PacketResult
206 Handle_qMemoryRegionInfoSupported (StringExtractorGDBRemote &packet);
207
208 PacketResult
209 Handle_qMemoryRegionInfo (StringExtractorGDBRemote &packet);
210
211 PacketResult
212 Handle_Z (StringExtractorGDBRemote &packet);
213
214 PacketResult
215 Handle_z (StringExtractorGDBRemote &packet);
216
217 PacketResult
218 Handle_s (StringExtractorGDBRemote &packet);
219
220 PacketResult
221 Handle_qXfer_auxv_read (StringExtractorGDBRemote &packet);
222
223 PacketResult
224 Handle_QSaveRegisterState (StringExtractorGDBRemote &packet);
225
226 PacketResult
227 Handle_QRestoreRegisterState (StringExtractorGDBRemote &packet);
228
229 PacketResult
230 Handle_vAttach (StringExtractorGDBRemote &packet);
231
232 PacketResult
233 Handle_D (StringExtractorGDBRemote &packet);
234
235 PacketResult
236 Handle_qThreadStopInfo (StringExtractorGDBRemote &packet);
237
238 PacketResult
239 Handle_qWatchpointSupportInfo (StringExtractorGDBRemote &packet);
240
241 void
242 SetCurrentThreadID (lldb::tid_t tid);
243
244 lldb::tid_t
245 GetCurrentThreadID () const;
246
247 void
248 SetContinueThreadID (lldb::tid_t tid);
249
250 lldb::tid_t
251 GetContinueThreadID () const { return m_continue_tid; }
252
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000253 Error
Tamas Berghammere13c2732015-02-11 10:29:30 +0000254 SetSTDIOFileDescriptor (int fd);
255
256 static void
257 STDIOReadThreadBytesReceived (void *baton, const void *src, size_t src_len);
258
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000259 FileSpec
260 FindModuleFile (const std::string& module_path, const ArchSpec& arch) override;
Tamas Berghammer7cb18bf2015-03-24 11:15:23 +0000261
Tamas Berghammere13c2732015-02-11 10:29:30 +0000262private:
263 bool
264 DebuggedProcessReaped (lldb::pid_t pid);
265
266 static bool
267 ReapDebuggedProcess (void *callback_baton,
268 lldb::pid_t pid,
269 bool exited,
270 int signal,
271 int status);
272
273 void
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000274 HandleInferiorState_Exited (NativeProcessProtocol *process);
Tamas Berghammere13c2732015-02-11 10:29:30 +0000275
276 void
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000277 HandleInferiorState_Stopped (NativeProcessProtocol *process);
Tamas Berghammere13c2732015-02-11 10:29:30 +0000278
279 void
280 FlushInferiorOutput ();
281
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000282 NativeThreadProtocolSP
Tamas Berghammere13c2732015-02-11 10:29:30 +0000283 GetThreadFromSuffix (StringExtractorGDBRemote &packet);
284
285 uint32_t
286 GetNextSavedRegistersID ();
287
288 void
289 MaybeCloseInferiorTerminalConnection ();
290
291 void
292 ClearProcessSpecificData ();
293
Tamas Berghammere13c2732015-02-11 10:29:30 +0000294 void
295 RegisterPacketHandlers ();
296
297 //------------------------------------------------------------------
298 // For GDBRemoteCommunicationServerLLGS only
299 //------------------------------------------------------------------
300 DISALLOW_COPY_AND_ASSIGN (GDBRemoteCommunicationServerLLGS);
301};
302
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000303} // namespace process_gdb_remote
304} // namespace lldb_private
305
Tamas Berghammere13c2732015-02-11 10:29:30 +0000306#endif // liblldb_GDBRemoteCommunicationServerLLGS_h_