1 //===-- GDBRemoteCommunicationServerLLGS.h ----------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_GDBRemoteCommunicationServerLLGS_h_
11 #define liblldb_GDBRemoteCommunicationServerLLGS_h_
16 #include <unordered_map>
18 // Other libraries and framework includes
19 #include "lldb/Core/Communication.h"
20 #include "lldb/Host/MainLoop.h"
21 #include "lldb/Host/common/NativeProcessProtocol.h"
22 #include "lldb/lldb-private-forward.h"
25 #include "GDBRemoteCommunicationServerCommon.h"
27 class StringExtractorGDBRemote;
29 namespace lldb_private {
31 namespace process_gdb_remote {
33 class ProcessGDBRemote;
35 class GDBRemoteCommunicationServerLLGS
36 : public GDBRemoteCommunicationServerCommon,
37 public NativeProcessProtocol::NativeDelegate {
39 //------------------------------------------------------------------
40 // Constructors and Destructors
41 //------------------------------------------------------------------
42 GDBRemoteCommunicationServerLLGS(
44 const NativeProcessProtocol::Factory &process_factory);
46 //------------------------------------------------------------------
47 /// Specify the program to launch and its arguments.
50 /// The command line to launch.
53 /// The number of elements in the args array of cstring pointers.
56 /// An Status object indicating the success or failure of making
58 //------------------------------------------------------------------
59 Status SetLaunchArguments(const char *const args[], int argc);
61 //------------------------------------------------------------------
62 /// Specify the launch flags for the process.
64 /// @param[in] launch_flags
65 /// The launch flags to use when launching this process.
68 /// An Status object indicating the success or failure of making
70 //------------------------------------------------------------------
71 Status SetLaunchFlags(unsigned int launch_flags);
73 //------------------------------------------------------------------
74 /// Launch a process with the current launch settings.
76 /// This method supports running an lldb-gdbserver or similar
77 /// server in a situation where the startup code has been provided
78 /// with all the information for a child process to be launched.
81 /// An Status object indicating the success or failure of the
83 //------------------------------------------------------------------
84 Status LaunchProcess() override;
86 //------------------------------------------------------------------
87 /// Attach to a process.
89 /// This method supports attaching llgs to a process accessible via the
90 /// configured Platform.
93 /// An Status object indicating the success or failure of the
95 //------------------------------------------------------------------
96 Status AttachToProcess(lldb::pid_t pid);
98 //------------------------------------------------------------------
99 // NativeProcessProtocol::NativeDelegate overrides
100 //------------------------------------------------------------------
101 void InitializeDelegate(NativeProcessProtocol *process) override;
103 void ProcessStateChanged(NativeProcessProtocol *process,
104 lldb::StateType state) override;
106 void DidExec(NativeProcessProtocol *process) override;
108 Status InitializeConnection(std::unique_ptr<Connection> &&connection);
111 MainLoop &m_mainloop;
112 MainLoop::ReadHandleUP m_network_handle_up;
113 const NativeProcessProtocol::Factory &m_process_factory;
114 lldb::tid_t m_current_tid = LLDB_INVALID_THREAD_ID;
115 lldb::tid_t m_continue_tid = LLDB_INVALID_THREAD_ID;
116 std::recursive_mutex m_debugged_process_mutex;
117 std::unique_ptr<NativeProcessProtocol> m_debugged_process_up;
119 Communication m_stdio_communication;
120 MainLoop::ReadHandleUP m_stdio_handle_up;
122 lldb::StateType m_inferior_prev_state = lldb::StateType::eStateInvalid;
123 std::unique_ptr<llvm::MemoryBuffer> m_active_auxv_buffer_up;
124 std::mutex m_saved_registers_mutex;
125 std::unordered_map<uint32_t, lldb::DataBufferSP> m_saved_registers_map;
126 uint32_t m_next_saved_registers_id = 1;
127 bool m_handshake_completed = false;
129 PacketResult SendONotification(const char *buffer, uint32_t len);
131 PacketResult SendWResponse(NativeProcessProtocol *process);
133 PacketResult SendStopReplyPacketForThread(lldb::tid_t tid);
135 PacketResult SendStopReasonForState(lldb::StateType process_state);
137 PacketResult Handle_k(StringExtractorGDBRemote &packet);
139 PacketResult Handle_qProcessInfo(StringExtractorGDBRemote &packet);
141 PacketResult Handle_qC(StringExtractorGDBRemote &packet);
143 PacketResult Handle_QSetDisableASLR(StringExtractorGDBRemote &packet);
145 PacketResult Handle_QSetWorkingDir(StringExtractorGDBRemote &packet);
147 PacketResult Handle_qGetWorkingDir(StringExtractorGDBRemote &packet);
149 PacketResult Handle_C(StringExtractorGDBRemote &packet);
151 PacketResult Handle_c(StringExtractorGDBRemote &packet);
153 PacketResult Handle_vCont(StringExtractorGDBRemote &packet);
155 PacketResult Handle_vCont_actions(StringExtractorGDBRemote &packet);
157 PacketResult Handle_stop_reason(StringExtractorGDBRemote &packet);
159 PacketResult Handle_qRegisterInfo(StringExtractorGDBRemote &packet);
161 PacketResult Handle_qfThreadInfo(StringExtractorGDBRemote &packet);
163 PacketResult Handle_qsThreadInfo(StringExtractorGDBRemote &packet);
165 PacketResult Handle_p(StringExtractorGDBRemote &packet);
167 PacketResult Handle_P(StringExtractorGDBRemote &packet);
169 PacketResult Handle_H(StringExtractorGDBRemote &packet);
171 PacketResult Handle_I(StringExtractorGDBRemote &packet);
173 PacketResult Handle_interrupt(StringExtractorGDBRemote &packet);
175 // Handles $m and $x packets.
176 PacketResult Handle_memory_read(StringExtractorGDBRemote &packet);
178 PacketResult Handle_M(StringExtractorGDBRemote &packet);
181 Handle_qMemoryRegionInfoSupported(StringExtractorGDBRemote &packet);
183 PacketResult Handle_qMemoryRegionInfo(StringExtractorGDBRemote &packet);
185 PacketResult Handle_Z(StringExtractorGDBRemote &packet);
187 PacketResult Handle_z(StringExtractorGDBRemote &packet);
189 PacketResult Handle_s(StringExtractorGDBRemote &packet);
191 PacketResult Handle_qXfer_auxv_read(StringExtractorGDBRemote &packet);
193 PacketResult Handle_QSaveRegisterState(StringExtractorGDBRemote &packet);
195 PacketResult Handle_jTraceStart(StringExtractorGDBRemote &packet);
197 PacketResult Handle_jTraceRead(StringExtractorGDBRemote &packet);
199 PacketResult Handle_jTraceStop(StringExtractorGDBRemote &packet);
201 PacketResult Handle_jTraceConfigRead(StringExtractorGDBRemote &packet);
203 PacketResult Handle_QRestoreRegisterState(StringExtractorGDBRemote &packet);
205 PacketResult Handle_vAttach(StringExtractorGDBRemote &packet);
207 PacketResult Handle_D(StringExtractorGDBRemote &packet);
209 PacketResult Handle_qThreadStopInfo(StringExtractorGDBRemote &packet);
211 PacketResult Handle_jThreadsInfo(StringExtractorGDBRemote &packet);
213 PacketResult Handle_qWatchpointSupportInfo(StringExtractorGDBRemote &packet);
215 PacketResult Handle_qFileLoadAddress(StringExtractorGDBRemote &packet);
217 PacketResult Handle_QPassSignals(StringExtractorGDBRemote &packet);
219 void SetCurrentThreadID(lldb::tid_t tid);
221 lldb::tid_t GetCurrentThreadID() const;
223 void SetContinueThreadID(lldb::tid_t tid);
225 lldb::tid_t GetContinueThreadID() const { return m_continue_tid; }
227 Status SetSTDIOFileDescriptor(int fd);
229 FileSpec FindModuleFile(const std::string &module_path,
230 const ArchSpec &arch) override;
233 void HandleInferiorState_Exited(NativeProcessProtocol *process);
235 void HandleInferiorState_Stopped(NativeProcessProtocol *process);
237 NativeThreadProtocolSP GetThreadFromSuffix(StringExtractorGDBRemote &packet);
239 uint32_t GetNextSavedRegistersID();
241 void MaybeCloseInferiorTerminalConnection();
243 void ClearProcessSpecificData();
245 void RegisterPacketHandlers();
247 void DataAvailableCallback();
249 void SendProcessOutput();
251 void StartSTDIOForwarding();
253 void StopSTDIOForwarding();
255 //------------------------------------------------------------------
256 // For GDBRemoteCommunicationServerLLGS only
257 //------------------------------------------------------------------
258 DISALLOW_COPY_AND_ASSIGN(GDBRemoteCommunicationServerLLGS);
261 } // namespace process_gdb_remote
262 } // namespace lldb_private
264 #endif // liblldb_GDBRemoteCommunicationServerLLGS_h_