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_
14 #include <unordered_map>
16 #include "lldb/Core/Communication.h"
17 #include "lldb/Host/MainLoop.h"
18 #include "lldb/Host/common/NativeProcessProtocol.h"
19 #include "lldb/lldb-private-forward.h"
21 #include "GDBRemoteCommunicationServerCommon.h"
23 class StringExtractorGDBRemote;
25 namespace lldb_private {
27 namespace process_gdb_remote {
29 class ProcessGDBRemote;
31 class GDBRemoteCommunicationServerLLGS
32 : public GDBRemoteCommunicationServerCommon,
33 public NativeProcessProtocol::NativeDelegate {
35 //------------------------------------------------------------------
36 // Constructors and Destructors
37 //------------------------------------------------------------------
38 GDBRemoteCommunicationServerLLGS(
40 const NativeProcessProtocol::Factory &process_factory);
42 void SetLaunchInfo(const ProcessLaunchInfo &info);
44 //------------------------------------------------------------------
45 /// Launch a process with the current launch settings.
47 /// This method supports running an lldb-gdbserver or similar
48 /// server in a situation where the startup code has been provided
49 /// with all the information for a child process to be launched.
52 /// An Status object indicating the success or failure of the
54 //------------------------------------------------------------------
55 Status LaunchProcess() override;
57 //------------------------------------------------------------------
58 /// Attach to a process.
60 /// This method supports attaching llgs to a process accessible via the
61 /// configured Platform.
64 /// An Status object indicating the success or failure of the
66 //------------------------------------------------------------------
67 Status AttachToProcess(lldb::pid_t pid);
69 //------------------------------------------------------------------
70 // NativeProcessProtocol::NativeDelegate overrides
71 //------------------------------------------------------------------
72 void InitializeDelegate(NativeProcessProtocol *process) override;
74 void ProcessStateChanged(NativeProcessProtocol *process,
75 lldb::StateType state) override;
77 void DidExec(NativeProcessProtocol *process) override;
79 Status InitializeConnection(std::unique_ptr<Connection> &&connection);
83 MainLoop::ReadHandleUP m_network_handle_up;
84 const NativeProcessProtocol::Factory &m_process_factory;
85 lldb::tid_t m_current_tid = LLDB_INVALID_THREAD_ID;
86 lldb::tid_t m_continue_tid = LLDB_INVALID_THREAD_ID;
87 std::recursive_mutex m_debugged_process_mutex;
88 std::unique_ptr<NativeProcessProtocol> m_debugged_process_up;
90 Communication m_stdio_communication;
91 MainLoop::ReadHandleUP m_stdio_handle_up;
93 lldb::StateType m_inferior_prev_state = lldb::StateType::eStateInvalid;
94 std::unique_ptr<llvm::MemoryBuffer> m_active_auxv_buffer_up;
95 std::mutex m_saved_registers_mutex;
96 std::unordered_map<uint32_t, lldb::DataBufferSP> m_saved_registers_map;
97 uint32_t m_next_saved_registers_id = 1;
98 bool m_handshake_completed = false;
100 PacketResult SendONotification(const char *buffer, uint32_t len);
102 PacketResult SendWResponse(NativeProcessProtocol *process);
104 PacketResult SendStopReplyPacketForThread(lldb::tid_t tid);
106 PacketResult SendStopReasonForState(lldb::StateType process_state);
108 PacketResult Handle_k(StringExtractorGDBRemote &packet);
110 PacketResult Handle_qProcessInfo(StringExtractorGDBRemote &packet);
112 PacketResult Handle_qC(StringExtractorGDBRemote &packet);
114 PacketResult Handle_QSetDisableASLR(StringExtractorGDBRemote &packet);
116 PacketResult Handle_QSetWorkingDir(StringExtractorGDBRemote &packet);
118 PacketResult Handle_qGetWorkingDir(StringExtractorGDBRemote &packet);
120 PacketResult Handle_C(StringExtractorGDBRemote &packet);
122 PacketResult Handle_c(StringExtractorGDBRemote &packet);
124 PacketResult Handle_vCont(StringExtractorGDBRemote &packet);
126 PacketResult Handle_vCont_actions(StringExtractorGDBRemote &packet);
128 PacketResult Handle_stop_reason(StringExtractorGDBRemote &packet);
130 PacketResult Handle_qRegisterInfo(StringExtractorGDBRemote &packet);
132 PacketResult Handle_qfThreadInfo(StringExtractorGDBRemote &packet);
134 PacketResult Handle_qsThreadInfo(StringExtractorGDBRemote &packet);
136 PacketResult Handle_p(StringExtractorGDBRemote &packet);
138 PacketResult Handle_P(StringExtractorGDBRemote &packet);
140 PacketResult Handle_H(StringExtractorGDBRemote &packet);
142 PacketResult Handle_I(StringExtractorGDBRemote &packet);
144 PacketResult Handle_interrupt(StringExtractorGDBRemote &packet);
146 // Handles $m and $x packets.
147 PacketResult Handle_memory_read(StringExtractorGDBRemote &packet);
149 PacketResult Handle_M(StringExtractorGDBRemote &packet);
152 Handle_qMemoryRegionInfoSupported(StringExtractorGDBRemote &packet);
154 PacketResult Handle_qMemoryRegionInfo(StringExtractorGDBRemote &packet);
156 PacketResult Handle_Z(StringExtractorGDBRemote &packet);
158 PacketResult Handle_z(StringExtractorGDBRemote &packet);
160 PacketResult Handle_s(StringExtractorGDBRemote &packet);
162 PacketResult Handle_qXfer_auxv_read(StringExtractorGDBRemote &packet);
164 PacketResult Handle_QSaveRegisterState(StringExtractorGDBRemote &packet);
166 PacketResult Handle_jTraceStart(StringExtractorGDBRemote &packet);
168 PacketResult Handle_jTraceRead(StringExtractorGDBRemote &packet);
170 PacketResult Handle_jTraceStop(StringExtractorGDBRemote &packet);
172 PacketResult Handle_jTraceConfigRead(StringExtractorGDBRemote &packet);
174 PacketResult Handle_QRestoreRegisterState(StringExtractorGDBRemote &packet);
176 PacketResult Handle_vAttach(StringExtractorGDBRemote &packet);
178 PacketResult Handle_D(StringExtractorGDBRemote &packet);
180 PacketResult Handle_qThreadStopInfo(StringExtractorGDBRemote &packet);
182 PacketResult Handle_jThreadsInfo(StringExtractorGDBRemote &packet);
184 PacketResult Handle_qWatchpointSupportInfo(StringExtractorGDBRemote &packet);
186 PacketResult Handle_qFileLoadAddress(StringExtractorGDBRemote &packet);
188 PacketResult Handle_QPassSignals(StringExtractorGDBRemote &packet);
190 void SetCurrentThreadID(lldb::tid_t tid);
192 lldb::tid_t GetCurrentThreadID() const;
194 void SetContinueThreadID(lldb::tid_t tid);
196 lldb::tid_t GetContinueThreadID() const { return m_continue_tid; }
198 Status SetSTDIOFileDescriptor(int fd);
200 FileSpec FindModuleFile(const std::string &module_path,
201 const ArchSpec &arch) override;
204 void HandleInferiorState_Exited(NativeProcessProtocol *process);
206 void HandleInferiorState_Stopped(NativeProcessProtocol *process);
208 NativeThreadProtocol *GetThreadFromSuffix(StringExtractorGDBRemote &packet);
210 uint32_t GetNextSavedRegistersID();
212 void MaybeCloseInferiorTerminalConnection();
214 void ClearProcessSpecificData();
216 void RegisterPacketHandlers();
218 void DataAvailableCallback();
220 void SendProcessOutput();
222 void StartSTDIOForwarding();
224 void StopSTDIOForwarding();
226 //------------------------------------------------------------------
227 // For GDBRemoteCommunicationServerLLGS only
228 //------------------------------------------------------------------
229 DISALLOW_COPY_AND_ASSIGN(GDBRemoteCommunicationServerLLGS);
232 } // namespace process_gdb_remote
233 } // namespace lldb_private
235 #endif // liblldb_GDBRemoteCommunicationServerLLGS_h_