10b57cec5SDimitry Andric //===-- GDBRemoteCommunicationServerCommon.h --------------------*- C++ -*-===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric 
95ffd83dbSDimitry Andric #ifndef LLDB_SOURCE_PLUGINS_PROCESS_GDB_REMOTE_GDBREMOTECOMMUNICATIONSERVERCOMMON_H
105ffd83dbSDimitry Andric #define LLDB_SOURCE_PLUGINS_PROCESS_GDB_REMOTE_GDBREMOTECOMMUNICATIONSERVERCOMMON_H
110b57cec5SDimitry Andric 
120b57cec5SDimitry Andric #include <string>
130b57cec5SDimitry Andric 
140b57cec5SDimitry Andric #include "lldb/Host/ProcessLaunchInfo.h"
150b57cec5SDimitry Andric #include "lldb/lldb-private-forward.h"
160b57cec5SDimitry Andric 
170b57cec5SDimitry Andric #include "GDBRemoteCommunicationServer.h"
180b57cec5SDimitry Andric 
190b57cec5SDimitry Andric class StringExtractorGDBRemote;
200b57cec5SDimitry Andric 
210b57cec5SDimitry Andric namespace lldb_private {
220b57cec5SDimitry Andric namespace process_gdb_remote {
230b57cec5SDimitry Andric 
240b57cec5SDimitry Andric class ProcessGDBRemote;
250b57cec5SDimitry Andric 
260b57cec5SDimitry Andric class GDBRemoteCommunicationServerCommon : public GDBRemoteCommunicationServer {
270b57cec5SDimitry Andric public:
28*bdd1243dSDimitry Andric   GDBRemoteCommunicationServerCommon();
290b57cec5SDimitry Andric 
300b57cec5SDimitry Andric   ~GDBRemoteCommunicationServerCommon() override;
310b57cec5SDimitry Andric 
320b57cec5SDimitry Andric protected:
330b57cec5SDimitry Andric   ProcessLaunchInfo m_process_launch_info;
340b57cec5SDimitry Andric   Status m_process_launch_error;
350b57cec5SDimitry Andric   ProcessInstanceInfoList m_proc_infos;
360b57cec5SDimitry Andric   uint32_t m_proc_infos_index;
370b57cec5SDimitry Andric 
380b57cec5SDimitry Andric   PacketResult Handle_A(StringExtractorGDBRemote &packet);
390b57cec5SDimitry Andric 
400b57cec5SDimitry Andric   PacketResult Handle_qHostInfo(StringExtractorGDBRemote &packet);
410b57cec5SDimitry Andric 
420b57cec5SDimitry Andric   PacketResult Handle_qProcessInfoPID(StringExtractorGDBRemote &packet);
430b57cec5SDimitry Andric 
440b57cec5SDimitry Andric   PacketResult Handle_qfProcessInfo(StringExtractorGDBRemote &packet);
450b57cec5SDimitry Andric 
460b57cec5SDimitry Andric   PacketResult Handle_qsProcessInfo(StringExtractorGDBRemote &packet);
470b57cec5SDimitry Andric 
480b57cec5SDimitry Andric   PacketResult Handle_qUserName(StringExtractorGDBRemote &packet);
490b57cec5SDimitry Andric 
500b57cec5SDimitry Andric   PacketResult Handle_qGroupName(StringExtractorGDBRemote &packet);
510b57cec5SDimitry Andric 
520b57cec5SDimitry Andric   PacketResult Handle_qSpeedTest(StringExtractorGDBRemote &packet);
530b57cec5SDimitry Andric 
540b57cec5SDimitry Andric   PacketResult Handle_vFile_Open(StringExtractorGDBRemote &packet);
550b57cec5SDimitry Andric 
560b57cec5SDimitry Andric   PacketResult Handle_vFile_Close(StringExtractorGDBRemote &packet);
570b57cec5SDimitry Andric 
580b57cec5SDimitry Andric   PacketResult Handle_vFile_pRead(StringExtractorGDBRemote &packet);
590b57cec5SDimitry Andric 
600b57cec5SDimitry Andric   PacketResult Handle_vFile_pWrite(StringExtractorGDBRemote &packet);
610b57cec5SDimitry Andric 
620b57cec5SDimitry Andric   PacketResult Handle_vFile_Size(StringExtractorGDBRemote &packet);
630b57cec5SDimitry Andric 
640b57cec5SDimitry Andric   PacketResult Handle_vFile_Mode(StringExtractorGDBRemote &packet);
650b57cec5SDimitry Andric 
660b57cec5SDimitry Andric   PacketResult Handle_vFile_Exists(StringExtractorGDBRemote &packet);
670b57cec5SDimitry Andric 
680b57cec5SDimitry Andric   PacketResult Handle_vFile_symlink(StringExtractorGDBRemote &packet);
690b57cec5SDimitry Andric 
700b57cec5SDimitry Andric   PacketResult Handle_vFile_unlink(StringExtractorGDBRemote &packet);
710b57cec5SDimitry Andric 
72349cc55cSDimitry Andric   PacketResult Handle_vFile_FStat(StringExtractorGDBRemote &packet);
73349cc55cSDimitry Andric 
740b57cec5SDimitry Andric   PacketResult Handle_vFile_Stat(StringExtractorGDBRemote &packet);
750b57cec5SDimitry Andric 
760b57cec5SDimitry Andric   PacketResult Handle_vFile_MD5(StringExtractorGDBRemote &packet);
770b57cec5SDimitry Andric 
780b57cec5SDimitry Andric   PacketResult Handle_qEcho(StringExtractorGDBRemote &packet);
790b57cec5SDimitry Andric 
800b57cec5SDimitry Andric   PacketResult Handle_qModuleInfo(StringExtractorGDBRemote &packet);
810b57cec5SDimitry Andric 
820b57cec5SDimitry Andric   PacketResult Handle_jModulesInfo(StringExtractorGDBRemote &packet);
830b57cec5SDimitry Andric 
840b57cec5SDimitry Andric   PacketResult Handle_qPlatform_shell(StringExtractorGDBRemote &packet);
850b57cec5SDimitry Andric 
860b57cec5SDimitry Andric   PacketResult Handle_qPlatform_mkdir(StringExtractorGDBRemote &packet);
870b57cec5SDimitry Andric 
880b57cec5SDimitry Andric   PacketResult Handle_qPlatform_chmod(StringExtractorGDBRemote &packet);
890b57cec5SDimitry Andric 
900b57cec5SDimitry Andric   PacketResult Handle_qSupported(StringExtractorGDBRemote &packet);
910b57cec5SDimitry Andric 
920b57cec5SDimitry Andric   PacketResult Handle_QSetDetachOnError(StringExtractorGDBRemote &packet);
930b57cec5SDimitry Andric 
940b57cec5SDimitry Andric   PacketResult Handle_QStartNoAckMode(StringExtractorGDBRemote &packet);
950b57cec5SDimitry Andric 
960b57cec5SDimitry Andric   PacketResult Handle_QSetSTDIN(StringExtractorGDBRemote &packet);
970b57cec5SDimitry Andric 
980b57cec5SDimitry Andric   PacketResult Handle_QSetSTDOUT(StringExtractorGDBRemote &packet);
990b57cec5SDimitry Andric 
1000b57cec5SDimitry Andric   PacketResult Handle_QSetSTDERR(StringExtractorGDBRemote &packet);
1010b57cec5SDimitry Andric 
1020b57cec5SDimitry Andric   PacketResult Handle_qLaunchSuccess(StringExtractorGDBRemote &packet);
1030b57cec5SDimitry Andric 
1040b57cec5SDimitry Andric   PacketResult Handle_QEnvironment(StringExtractorGDBRemote &packet);
1050b57cec5SDimitry Andric 
1060b57cec5SDimitry Andric   PacketResult Handle_QEnvironmentHexEncoded(StringExtractorGDBRemote &packet);
1070b57cec5SDimitry Andric 
1080b57cec5SDimitry Andric   PacketResult Handle_QLaunchArch(StringExtractorGDBRemote &packet);
1090b57cec5SDimitry Andric 
1100b57cec5SDimitry Andric   static void CreateProcessInfoResponse(const ProcessInstanceInfo &proc_info,
1110b57cec5SDimitry Andric                                         StreamString &response);
1120b57cec5SDimitry Andric 
1130b57cec5SDimitry Andric   static void CreateProcessInfoResponse_DebugServerStyle(
1140b57cec5SDimitry Andric       const ProcessInstanceInfo &proc_info, StreamString &response);
1150b57cec5SDimitry Andric 
1160b57cec5SDimitry Andric   template <typename T>
RegisterMemberFunctionHandler(StringExtractorGDBRemote::ServerPacketType packet_type,PacketResult (T::* handler)(StringExtractorGDBRemote & packet))1170b57cec5SDimitry Andric   void RegisterMemberFunctionHandler(
1180b57cec5SDimitry Andric       StringExtractorGDBRemote::ServerPacketType packet_type,
1190b57cec5SDimitry Andric       PacketResult (T::*handler)(StringExtractorGDBRemote &packet)) {
1200b57cec5SDimitry Andric     RegisterPacketHandler(packet_type,
1210b57cec5SDimitry Andric                           [this, handler](StringExtractorGDBRemote packet,
1220b57cec5SDimitry Andric                                           Status &error, bool &interrupt,
1230b57cec5SDimitry Andric                                           bool &quit) {
1240b57cec5SDimitry Andric                             return (static_cast<T *>(this)->*handler)(packet);
1250b57cec5SDimitry Andric                           });
1260b57cec5SDimitry Andric   }
1270b57cec5SDimitry Andric 
1280b57cec5SDimitry Andric   /// Launch a process with the current launch settings.
1290b57cec5SDimitry Andric   ///
1300b57cec5SDimitry Andric   /// This method supports running an lldb-gdbserver or similar
1310b57cec5SDimitry Andric   /// server in a situation where the startup code has been provided
1320b57cec5SDimitry Andric   /// with all the information for a child process to be launched.
1330b57cec5SDimitry Andric   ///
1340b57cec5SDimitry Andric   /// \return
1350b57cec5SDimitry Andric   ///     An Status object indicating the success or failure of the
1360b57cec5SDimitry Andric   ///     launch.
1370b57cec5SDimitry Andric   virtual Status LaunchProcess() = 0;
1380b57cec5SDimitry Andric 
1390b57cec5SDimitry Andric   virtual FileSpec FindModuleFile(const std::string &module_path,
1400b57cec5SDimitry Andric                                   const ArchSpec &arch);
1410b57cec5SDimitry Andric 
142fe6060f1SDimitry Andric   // Process client_features (qSupported) and return an array of server features
143fe6060f1SDimitry Andric   // to be returned in response.
144fe6060f1SDimitry Andric   virtual std::vector<std::string>
145fe6060f1SDimitry Andric   HandleFeatures(llvm::ArrayRef<llvm::StringRef> client_features);
146fe6060f1SDimitry Andric 
1470b57cec5SDimitry Andric private:
1480b57cec5SDimitry Andric   ModuleSpec GetModuleInfo(llvm::StringRef module_path, llvm::StringRef triple);
1490b57cec5SDimitry Andric };
1500b57cec5SDimitry Andric 
1510b57cec5SDimitry Andric } // namespace process_gdb_remote
1520b57cec5SDimitry Andric } // namespace lldb_private
1530b57cec5SDimitry Andric 
1545ffd83dbSDimitry Andric #endif // LLDB_SOURCE_PLUGINS_PROCESS_GDB_REMOTE_GDBREMOTECOMMUNICATIONSERVERCOMMON_H
155