1 //===-- GDBRemoteCommunicationServerCommon.h --------------------*- C++ -*-===// 2 // 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 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef LLDB_SOURCE_PLUGINS_PROCESS_GDB_REMOTE_GDBREMOTECOMMUNICATIONSERVERCOMMON_H 10 #define LLDB_SOURCE_PLUGINS_PROCESS_GDB_REMOTE_GDBREMOTECOMMUNICATIONSERVERCOMMON_H 11 12 #include <string> 13 14 #include "lldb/Host/ProcessLaunchInfo.h" 15 #include "lldb/lldb-private-forward.h" 16 17 #include "GDBRemoteCommunicationServer.h" 18 #include "GDBRemoteCommunicationServerCommon.h" 19 20 class StringExtractorGDBRemote; 21 22 namespace lldb_private { 23 namespace process_gdb_remote { 24 25 class ProcessGDBRemote; 26 27 class GDBRemoteCommunicationServerCommon : public GDBRemoteCommunicationServer { 28 public: 29 GDBRemoteCommunicationServerCommon(const char *comm_name, 30 const char *listener_name); 31 32 ~GDBRemoteCommunicationServerCommon() override; 33 34 protected: 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; 41 42 PacketResult Handle_A(StringExtractorGDBRemote &packet); 43 44 PacketResult Handle_qHostInfo(StringExtractorGDBRemote &packet); 45 46 PacketResult Handle_qProcessInfoPID(StringExtractorGDBRemote &packet); 47 48 PacketResult Handle_qfProcessInfo(StringExtractorGDBRemote &packet); 49 50 PacketResult Handle_qsProcessInfo(StringExtractorGDBRemote &packet); 51 52 PacketResult Handle_qUserName(StringExtractorGDBRemote &packet); 53 54 PacketResult Handle_qGroupName(StringExtractorGDBRemote &packet); 55 56 PacketResult Handle_qSpeedTest(StringExtractorGDBRemote &packet); 57 58 PacketResult Handle_vFile_Open(StringExtractorGDBRemote &packet); 59 60 PacketResult Handle_vFile_Close(StringExtractorGDBRemote &packet); 61 62 PacketResult Handle_vFile_pRead(StringExtractorGDBRemote &packet); 63 64 PacketResult Handle_vFile_pWrite(StringExtractorGDBRemote &packet); 65 66 PacketResult Handle_vFile_Size(StringExtractorGDBRemote &packet); 67 68 PacketResult Handle_vFile_Mode(StringExtractorGDBRemote &packet); 69 70 PacketResult Handle_vFile_Exists(StringExtractorGDBRemote &packet); 71 72 PacketResult Handle_vFile_symlink(StringExtractorGDBRemote &packet); 73 74 PacketResult Handle_vFile_unlink(StringExtractorGDBRemote &packet); 75 76 PacketResult Handle_vFile_Stat(StringExtractorGDBRemote &packet); 77 78 PacketResult Handle_vFile_MD5(StringExtractorGDBRemote &packet); 79 80 PacketResult Handle_qEcho(StringExtractorGDBRemote &packet); 81 82 PacketResult Handle_qModuleInfo(StringExtractorGDBRemote &packet); 83 84 PacketResult Handle_jModulesInfo(StringExtractorGDBRemote &packet); 85 86 PacketResult Handle_qPlatform_shell(StringExtractorGDBRemote &packet); 87 88 PacketResult Handle_qPlatform_mkdir(StringExtractorGDBRemote &packet); 89 90 PacketResult Handle_qPlatform_chmod(StringExtractorGDBRemote &packet); 91 92 PacketResult Handle_qSupported(StringExtractorGDBRemote &packet); 93 94 PacketResult Handle_QThreadSuffixSupported(StringExtractorGDBRemote &packet); 95 96 PacketResult Handle_QListThreadsInStopReply(StringExtractorGDBRemote &packet); 97 98 PacketResult Handle_QSetDetachOnError(StringExtractorGDBRemote &packet); 99 100 PacketResult Handle_QStartNoAckMode(StringExtractorGDBRemote &packet); 101 102 PacketResult Handle_QSetSTDIN(StringExtractorGDBRemote &packet); 103 104 PacketResult Handle_QSetSTDOUT(StringExtractorGDBRemote &packet); 105 106 PacketResult Handle_QSetSTDERR(StringExtractorGDBRemote &packet); 107 108 PacketResult Handle_qLaunchSuccess(StringExtractorGDBRemote &packet); 109 110 PacketResult Handle_QEnvironment(StringExtractorGDBRemote &packet); 111 112 PacketResult Handle_QEnvironmentHexEncoded(StringExtractorGDBRemote &packet); 113 114 PacketResult Handle_QLaunchArch(StringExtractorGDBRemote &packet); 115 116 static void CreateProcessInfoResponse(const ProcessInstanceInfo &proc_info, 117 StreamString &response); 118 119 static void CreateProcessInfoResponse_DebugServerStyle( 120 const ProcessInstanceInfo &proc_info, StreamString &response); 121 122 template <typename T> RegisterMemberFunctionHandler(StringExtractorGDBRemote::ServerPacketType packet_type,PacketResult (T::* handler)(StringExtractorGDBRemote & packet))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, 129 bool &quit) { 130 return (static_cast<T *>(this)->*handler)(packet); 131 }); 132 } 133 134 /// Launch a process with the current launch settings. 135 /// 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. 139 /// 140 /// \return 141 /// An Status object indicating the success or failure of the 142 /// launch. 143 virtual Status LaunchProcess() = 0; 144 145 virtual FileSpec FindModuleFile(const std::string &module_path, 146 const ArchSpec &arch); 147 148 private: 149 ModuleSpec GetModuleInfo(llvm::StringRef module_path, llvm::StringRef triple); 150 }; 151 152 } // namespace process_gdb_remote 153 } // namespace lldb_private 154 155 #endif // LLDB_SOURCE_PLUGINS_PROCESS_GDB_REMOTE_GDBREMOTECOMMUNICATIONSERVERCOMMON_H 156