blob: abd7250ea1bf5004407c4b0f8a6d4662f29598cd [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
26class ProcessGDBRemote;
27class StringExtractorGDBRemote;
28
29class GDBRemoteCommunicationServerLLGS :
30 public GDBRemoteCommunicationServerCommon,
31 public lldb_private::NativeProcessProtocol::NativeDelegate
32{
33public:
34 //------------------------------------------------------------------
35 // Constructors and Destructors
36 //------------------------------------------------------------------
37 GDBRemoteCommunicationServerLLGS(const lldb::PlatformSP& platform_sp,
38 lldb::DebuggerSP& debugger_sp);
39
40 virtual
41 ~GDBRemoteCommunicationServerLLGS();
42
43 //------------------------------------------------------------------
44 /// Specify the program to launch and its arguments.
45 ///
46 /// @param[in] args
47 /// The command line to launch.
48 ///
49 /// @param[in] argc
50 /// The number of elements in the args array of cstring pointers.
51 ///
52 /// @return
53 /// An Error object indicating the success or failure of making
54 /// the setting.
55 //------------------------------------------------------------------
56 lldb_private::Error
57 SetLaunchArguments (const char *const args[], int argc);
58
59 //------------------------------------------------------------------
60 /// Specify the launch flags for the process.
61 ///
62 /// @param[in] launch_flags
63 /// The launch flags to use when launching this process.
64 ///
65 /// @return
66 /// An Error object indicating the success or failure of making
67 /// the setting.
68 //------------------------------------------------------------------
69 lldb_private::Error
70 SetLaunchFlags (unsigned int launch_flags);
71
72 //------------------------------------------------------------------
73 /// Launch a process with the current launch settings.
74 ///
75 /// This method supports running an lldb-gdbserver or similar
76 /// server in a situation where the startup code has been provided
77 /// with all the information for a child process to be launched.
78 ///
79 /// @return
80 /// An Error object indicating the success or failure of the
81 /// launch.
82 //------------------------------------------------------------------
83 lldb_private::Error
84 LaunchProcess () override;
85
86 //------------------------------------------------------------------
87 /// Attach to a process.
88 ///
89 /// This method supports attaching llgs to a process accessible via the
90 /// configured Platform.
91 ///
92 /// @return
93 /// An Error object indicating the success or failure of the
94 /// attach operation.
95 //------------------------------------------------------------------
96 lldb_private::Error
97 AttachToProcess (lldb::pid_t pid);
98
99 //------------------------------------------------------------------
100 // NativeProcessProtocol::NativeDelegate overrides
101 //------------------------------------------------------------------
102 void
103 InitializeDelegate (lldb_private::NativeProcessProtocol *process) override;
104
105 void
106 ProcessStateChanged (lldb_private::NativeProcessProtocol *process, lldb::StateType state) override;
107
108 void
109 DidExec (lldb_private::NativeProcessProtocol *process) override;
110
111protected:
112 lldb::PlatformSP m_platform_sp;
113 lldb::thread_t m_async_thread;
114 lldb::tid_t m_current_tid;
115 lldb::tid_t m_continue_tid;
116 lldb_private::Mutex m_debugged_process_mutex;
117 lldb_private::NativeProcessProtocolSP m_debugged_process_sp;
118 lldb::DebuggerSP m_debugger_sp;
119 Communication m_stdio_communication;
120 lldb::StateType m_inferior_prev_state;
121 lldb::DataBufferSP m_active_auxv_buffer_sp;
122 lldb_private::Mutex m_saved_registers_mutex;
123 std::unordered_map<uint32_t, lldb::DataBufferSP> m_saved_registers_map;
124 uint32_t m_next_saved_registers_id;
125
126 PacketResult
127 SendONotification (const char *buffer, uint32_t len);
128
129 PacketResult
130 SendWResponse (lldb_private::NativeProcessProtocol *process);
131
132 PacketResult
133 SendStopReplyPacketForThread (lldb::tid_t tid);
134
135 PacketResult
136 SendStopReasonForState (lldb::StateType process_state, bool flush_on_exit);
137
138 PacketResult
139 Handle_k (StringExtractorGDBRemote &packet);
140
141 PacketResult
142 Handle_qProcessInfo (StringExtractorGDBRemote &packet);
143
144 PacketResult
145 Handle_qC (StringExtractorGDBRemote &packet);
146
147 PacketResult
148 Handle_QSetDisableASLR (StringExtractorGDBRemote &packet);
149
150 PacketResult
151 Handle_QSetWorkingDir (StringExtractorGDBRemote &packet);
152
153 PacketResult
154 Handle_qGetWorkingDir (StringExtractorGDBRemote &packet);
155
156 PacketResult
157 Handle_C (StringExtractorGDBRemote &packet);
158
159 PacketResult
160 Handle_c (StringExtractorGDBRemote &packet);
161
162 PacketResult
163 Handle_vCont (StringExtractorGDBRemote &packet);
164
165 PacketResult
166 Handle_vCont_actions (StringExtractorGDBRemote &packet);
167
168 PacketResult
169 Handle_stop_reason (StringExtractorGDBRemote &packet);
170
171 PacketResult
172 Handle_qRegisterInfo (StringExtractorGDBRemote &packet);
173
174 PacketResult
175 Handle_qfThreadInfo (StringExtractorGDBRemote &packet);
176
177 PacketResult
178 Handle_qsThreadInfo (StringExtractorGDBRemote &packet);
179
180 PacketResult
181 Handle_p (StringExtractorGDBRemote &packet);
182
183 PacketResult
184 Handle_P (StringExtractorGDBRemote &packet);
185
186 PacketResult
187 Handle_H (StringExtractorGDBRemote &packet);
188
189 PacketResult
190 Handle_I (StringExtractorGDBRemote &packet);
191
192 PacketResult
193 Handle_interrupt (StringExtractorGDBRemote &packet);
194
195 PacketResult
196 Handle_m (StringExtractorGDBRemote &packet);
197
198 PacketResult
199 Handle_M (StringExtractorGDBRemote &packet);
200
201 PacketResult
202 Handle_qMemoryRegionInfoSupported (StringExtractorGDBRemote &packet);
203
204 PacketResult
205 Handle_qMemoryRegionInfo (StringExtractorGDBRemote &packet);
206
207 PacketResult
208 Handle_Z (StringExtractorGDBRemote &packet);
209
210 PacketResult
211 Handle_z (StringExtractorGDBRemote &packet);
212
213 PacketResult
214 Handle_s (StringExtractorGDBRemote &packet);
215
216 PacketResult
217 Handle_qXfer_auxv_read (StringExtractorGDBRemote &packet);
218
219 PacketResult
220 Handle_QSaveRegisterState (StringExtractorGDBRemote &packet);
221
222 PacketResult
223 Handle_QRestoreRegisterState (StringExtractorGDBRemote &packet);
224
225 PacketResult
226 Handle_vAttach (StringExtractorGDBRemote &packet);
227
228 PacketResult
229 Handle_D (StringExtractorGDBRemote &packet);
230
231 PacketResult
232 Handle_qThreadStopInfo (StringExtractorGDBRemote &packet);
233
234 PacketResult
235 Handle_qWatchpointSupportInfo (StringExtractorGDBRemote &packet);
236
237 void
238 SetCurrentThreadID (lldb::tid_t tid);
239
240 lldb::tid_t
241 GetCurrentThreadID () const;
242
243 void
244 SetContinueThreadID (lldb::tid_t tid);
245
246 lldb::tid_t
247 GetContinueThreadID () const { return m_continue_tid; }
248
249 lldb_private::Error
250 SetSTDIOFileDescriptor (int fd);
251
252 static void
253 STDIOReadThreadBytesReceived (void *baton, const void *src, size_t src_len);
254
255private:
256 bool
257 DebuggedProcessReaped (lldb::pid_t pid);
258
259 static bool
260 ReapDebuggedProcess (void *callback_baton,
261 lldb::pid_t pid,
262 bool exited,
263 int signal,
264 int status);
265
266 void
267 HandleInferiorState_Exited (lldb_private::NativeProcessProtocol *process);
268
269 void
270 HandleInferiorState_Stopped (lldb_private::NativeProcessProtocol *process);
271
272 void
273 FlushInferiorOutput ();
274
275 lldb_private::NativeThreadProtocolSP
276 GetThreadFromSuffix (StringExtractorGDBRemote &packet);
277
278 uint32_t
279 GetNextSavedRegistersID ();
280
281 void
282 MaybeCloseInferiorTerminalConnection ();
283
284 void
285 ClearProcessSpecificData ();
286
287 bool
288 ShouldRedirectInferiorOutputOverGdbRemote (const lldb_private::ProcessLaunchInfo &launch_info) const;
289
290 void
291 RegisterPacketHandlers ();
292
293 //------------------------------------------------------------------
294 // For GDBRemoteCommunicationServerLLGS only
295 //------------------------------------------------------------------
296 DISALLOW_COPY_AND_ASSIGN (GDBRemoteCommunicationServerLLGS);
297};
298
299#endif // liblldb_GDBRemoteCommunicationServerLLGS_h_