1 //===-- GDBRemoteCommunicationServerCommon.h --------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #ifndef liblldb_GDBRemoteCommunicationServerCommon_h_
10 #define liblldb_GDBRemoteCommunicationServerCommon_h_
14 #include "lldb/Host/ProcessLaunchInfo.h"
15 #include "lldb/lldb-private-forward.h"
17 #include "GDBRemoteCommunicationServer.h"
18 #include "GDBRemoteCommunicationServerCommon.h"
20 class StringExtractorGDBRemote;
22 namespace lldb_private {
23 namespace process_gdb_remote {
25 class ProcessGDBRemote;
27 class GDBRemoteCommunicationServerCommon : public GDBRemoteCommunicationServer {
29 GDBRemoteCommunicationServerCommon(const char *comm_name,
30 const char *listener_name);
32 ~GDBRemoteCommunicationServerCommon() override;
35 ProcessLaunchInfo m_process_launch_info;
36 Status m_process_launch_error;
37 ProcessInstanceInfoList m_proc_infos;
38 uint32_t m_proc_infos_index;
39 bool m_thread_suffix_supported;
40 bool m_list_threads_in_stop_reply;
42 PacketResult Handle_A(StringExtractorGDBRemote &packet);
44 PacketResult Handle_qHostInfo(StringExtractorGDBRemote &packet);
46 PacketResult Handle_qProcessInfoPID(StringExtractorGDBRemote &packet);
48 PacketResult Handle_qfProcessInfo(StringExtractorGDBRemote &packet);
50 PacketResult Handle_qsProcessInfo(StringExtractorGDBRemote &packet);
52 PacketResult Handle_qUserName(StringExtractorGDBRemote &packet);
54 PacketResult Handle_qGroupName(StringExtractorGDBRemote &packet);
56 PacketResult Handle_qSpeedTest(StringExtractorGDBRemote &packet);
58 PacketResult Handle_vFile_Open(StringExtractorGDBRemote &packet);
60 PacketResult Handle_vFile_Close(StringExtractorGDBRemote &packet);
62 PacketResult Handle_vFile_pRead(StringExtractorGDBRemote &packet);
64 PacketResult Handle_vFile_pWrite(StringExtractorGDBRemote &packet);
66 PacketResult Handle_vFile_Size(StringExtractorGDBRemote &packet);
68 PacketResult Handle_vFile_Mode(StringExtractorGDBRemote &packet);
70 PacketResult Handle_vFile_Exists(StringExtractorGDBRemote &packet);
72 PacketResult Handle_vFile_symlink(StringExtractorGDBRemote &packet);
74 PacketResult Handle_vFile_unlink(StringExtractorGDBRemote &packet);
76 PacketResult Handle_vFile_Stat(StringExtractorGDBRemote &packet);
78 PacketResult Handle_vFile_MD5(StringExtractorGDBRemote &packet);
80 PacketResult Handle_qEcho(StringExtractorGDBRemote &packet);
82 PacketResult Handle_qModuleInfo(StringExtractorGDBRemote &packet);
84 PacketResult Handle_jModulesInfo(StringExtractorGDBRemote &packet);
86 PacketResult Handle_qPlatform_shell(StringExtractorGDBRemote &packet);
88 PacketResult Handle_qPlatform_mkdir(StringExtractorGDBRemote &packet);
90 PacketResult Handle_qPlatform_chmod(StringExtractorGDBRemote &packet);
92 PacketResult Handle_qSupported(StringExtractorGDBRemote &packet);
94 PacketResult Handle_QThreadSuffixSupported(StringExtractorGDBRemote &packet);
96 PacketResult Handle_QListThreadsInStopReply(StringExtractorGDBRemote &packet);
98 PacketResult Handle_QSetDetachOnError(StringExtractorGDBRemote &packet);
100 PacketResult Handle_QStartNoAckMode(StringExtractorGDBRemote &packet);
102 PacketResult Handle_QSetSTDIN(StringExtractorGDBRemote &packet);
104 PacketResult Handle_QSetSTDOUT(StringExtractorGDBRemote &packet);
106 PacketResult Handle_QSetSTDERR(StringExtractorGDBRemote &packet);
108 PacketResult Handle_qLaunchSuccess(StringExtractorGDBRemote &packet);
110 PacketResult Handle_QEnvironment(StringExtractorGDBRemote &packet);
112 PacketResult Handle_QEnvironmentHexEncoded(StringExtractorGDBRemote &packet);
114 PacketResult Handle_QLaunchArch(StringExtractorGDBRemote &packet);
116 static void CreateProcessInfoResponse(const ProcessInstanceInfo &proc_info,
117 StreamString &response);
119 static void CreateProcessInfoResponse_DebugServerStyle(
120 const ProcessInstanceInfo &proc_info, StreamString &response);
122 template <typename T>
123 void RegisterMemberFunctionHandler(
124 StringExtractorGDBRemote::ServerPacketType packet_type,
125 PacketResult (T::*handler)(StringExtractorGDBRemote &packet)) {
126 RegisterPacketHandler(packet_type,
127 [this, handler](StringExtractorGDBRemote packet,
128 Status &error, bool &interrupt,
130 return (static_cast<T *>(this)->*handler)(packet);
134 /// Launch a process with the current launch settings.
136 /// This method supports running an lldb-gdbserver or similar
137 /// server in a situation where the startup code has been provided
138 /// with all the information for a child process to be launched.
141 /// An Status object indicating the success or failure of the
143 virtual Status LaunchProcess() = 0;
145 virtual FileSpec FindModuleFile(const std::string &module_path,
146 const ArchSpec &arch);
149 ModuleSpec GetModuleInfo(llvm::StringRef module_path, llvm::StringRef triple);
152 } // namespace process_gdb_remote
153 } // namespace lldb_private
155 #endif // liblldb_GDBRemoteCommunicationServerCommon_h_