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 void SetLaunchInfo(const ProcessLaunchInfo &info);
48 //------------------------------------------------------------------
49 /// Launch a process with the current launch settings.
51 /// This method supports running an lldb-gdbserver or similar
52 /// server in a situation where the startup code has been provided
53 /// with all the information for a child process to be launched.
56 /// An Status object indicating the success or failure of the
58 //------------------------------------------------------------------
59 Status LaunchProcess() override;
61 //------------------------------------------------------------------
62 /// Attach to a process.
64 /// This method supports attaching llgs to a process accessible via the
65 /// configured Platform.
68 /// An Status object indicating the success or failure of the
70 //------------------------------------------------------------------
71 Status AttachToProcess(lldb::pid_t pid);
73 //------------------------------------------------------------------
74 // NativeProcessProtocol::NativeDelegate overrides
75 //------------------------------------------------------------------
76 void InitializeDelegate(NativeProcessProtocol *process) override;
78 void ProcessStateChanged(NativeProcessProtocol *process,
79 lldb::StateType state) override;
81 void DidExec(NativeProcessProtocol *process) override;
83 Status InitializeConnection(std::unique_ptr<Connection> &&connection);
87 MainLoop::ReadHandleUP m_network_handle_up;
88 const NativeProcessProtocol::Factory &m_process_factory;
89 lldb::tid_t m_current_tid = LLDB_INVALID_THREAD_ID;
90 lldb::tid_t m_continue_tid = LLDB_INVALID_THREAD_ID;
91 std::recursive_mutex m_debugged_process_mutex;
92 std::unique_ptr<NativeProcessProtocol> m_debugged_process_up;
94 Communication m_stdio_communication;
95 MainLoop::ReadHandleUP m_stdio_handle_up;
97 lldb::StateType m_inferior_prev_state = lldb::StateType::eStateInvalid;
98 std::unique_ptr<llvm::MemoryBuffer> m_active_auxv_buffer_up;
99 std::mutex m_saved_registers_mutex;
100 std::unordered_map<uint32_t, lldb::DataBufferSP> m_saved_registers_map;
101 uint32_t m_next_saved_registers_id = 1;
102 bool m_handshake_completed = false;
104 PacketResult SendONotification(const char *buffer, uint32_t len);
106 PacketResult SendWResponse(NativeProcessProtocol *process);
108 PacketResult SendStopReplyPacketForThread(lldb::tid_t tid);
110 PacketResult SendStopReasonForState(lldb::StateType process_state);
112 PacketResult Handle_k(StringExtractorGDBRemote &packet);
114 PacketResult Handle_qProcessInfo(StringExtractorGDBRemote &packet);
116 PacketResult Handle_qC(StringExtractorGDBRemote &packet);
118 PacketResult Handle_QSetDisableASLR(StringExtractorGDBRemote &packet);
120 PacketResult Handle_QSetWorkingDir(StringExtractorGDBRemote &packet);
122 PacketResult Handle_qGetWorkingDir(StringExtractorGDBRemote &packet);
124 PacketResult Handle_C(StringExtractorGDBRemote &packet);
126 PacketResult Handle_c(StringExtractorGDBRemote &packet);
128 PacketResult Handle_vCont(StringExtractorGDBRemote &packet);
130 PacketResult Handle_vCont_actions(StringExtractorGDBRemote &packet);
132 PacketResult Handle_stop_reason(StringExtractorGDBRemote &packet);
134 PacketResult Handle_qRegisterInfo(StringExtractorGDBRemote &packet);
136 PacketResult Handle_qfThreadInfo(StringExtractorGDBRemote &packet);
138 PacketResult Handle_qsThreadInfo(StringExtractorGDBRemote &packet);
140 PacketResult Handle_p(StringExtractorGDBRemote &packet);
142 PacketResult Handle_P(StringExtractorGDBRemote &packet);
144 PacketResult Handle_H(StringExtractorGDBRemote &packet);
146 PacketResult Handle_I(StringExtractorGDBRemote &packet);
148 PacketResult Handle_interrupt(StringExtractorGDBRemote &packet);
150 // Handles $m and $x packets.
151 PacketResult Handle_memory_read(StringExtractorGDBRemote &packet);
153 PacketResult Handle_M(StringExtractorGDBRemote &packet);
156 Handle_qMemoryRegionInfoSupported(StringExtractorGDBRemote &packet);
158 PacketResult Handle_qMemoryRegionInfo(StringExtractorGDBRemote &packet);
160 PacketResult Handle_Z(StringExtractorGDBRemote &packet);
162 PacketResult Handle_z(StringExtractorGDBRemote &packet);
164 PacketResult Handle_s(StringExtractorGDBRemote &packet);
166 PacketResult Handle_qXfer_auxv_read(StringExtractorGDBRemote &packet);
168 PacketResult Handle_QSaveRegisterState(StringExtractorGDBRemote &packet);
170 PacketResult Handle_jTraceStart(StringExtractorGDBRemote &packet);
172 PacketResult Handle_jTraceRead(StringExtractorGDBRemote &packet);
174 PacketResult Handle_jTraceStop(StringExtractorGDBRemote &packet);
176 PacketResult Handle_jTraceConfigRead(StringExtractorGDBRemote &packet);
178 PacketResult Handle_QRestoreRegisterState(StringExtractorGDBRemote &packet);
180 PacketResult Handle_vAttach(StringExtractorGDBRemote &packet);
182 PacketResult Handle_D(StringExtractorGDBRemote &packet);
184 PacketResult Handle_qThreadStopInfo(StringExtractorGDBRemote &packet);
186 PacketResult Handle_jThreadsInfo(StringExtractorGDBRemote &packet);
188 PacketResult Handle_qWatchpointSupportInfo(StringExtractorGDBRemote &packet);
190 PacketResult Handle_qFileLoadAddress(StringExtractorGDBRemote &packet);
192 PacketResult Handle_QPassSignals(StringExtractorGDBRemote &packet);
194 void SetCurrentThreadID(lldb::tid_t tid);
196 lldb::tid_t GetCurrentThreadID() const;
198 void SetContinueThreadID(lldb::tid_t tid);
200 lldb::tid_t GetContinueThreadID() const { return m_continue_tid; }
202 Status SetSTDIOFileDescriptor(int fd);
204 FileSpec FindModuleFile(const std::string &module_path,
205 const ArchSpec &arch) override;
208 void HandleInferiorState_Exited(NativeProcessProtocol *process);
210 void HandleInferiorState_Stopped(NativeProcessProtocol *process);
212 NativeThreadProtocol *GetThreadFromSuffix(StringExtractorGDBRemote &packet);
214 uint32_t GetNextSavedRegistersID();
216 void MaybeCloseInferiorTerminalConnection();
218 void ClearProcessSpecificData();
220 void RegisterPacketHandlers();
222 void DataAvailableCallback();
224 void SendProcessOutput();
226 void StartSTDIOForwarding();
228 void StopSTDIOForwarding();
230 //------------------------------------------------------------------
231 // For GDBRemoteCommunicationServerLLGS only
232 //------------------------------------------------------------------
233 DISALLOW_COPY_AND_ASSIGN(GDBRemoteCommunicationServerLLGS);
236 } // namespace process_gdb_remote
237 } // namespace lldb_private
239 #endif // liblldb_GDBRemoteCommunicationServerLLGS_h_