1 //===-- GDBRemoteCommunicationServerCommon.h --------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #ifndef liblldb_GDBRemoteCommunicationServerCommon_h_ 11 #define liblldb_GDBRemoteCommunicationServerCommon_h_ 12 13 // C Includes 14 // C++ Includes 15 #include <set> 16 17 // Other libraries and framework includes 18 #include "lldb/lldb-private-forward.h" 19 #include "lldb/Host/Mutex.h" 20 #include "lldb/Target/Process.h" 21 22 // Project includes 23 #include "GDBRemoteCommunicationServer.h" 24 #include "GDBRemoteCommunicationServerCommon.h" 25 26 class StringExtractorGDBRemote; 27 28 namespace lldb_private { 29 namespace process_gdb_remote { 30 31 class ProcessGDBRemote; 32 33 class GDBRemoteCommunicationServerCommon : 34 public GDBRemoteCommunicationServer 35 { 36 public: 37 GDBRemoteCommunicationServerCommon(const char *comm_name, const char *listener_name); 38 39 virtual 40 ~GDBRemoteCommunicationServerCommon(); 41 42 protected: 43 std::set<lldb::pid_t> m_spawned_pids; 44 Mutex m_spawned_pids_mutex; 45 ProcessLaunchInfo m_process_launch_info; 46 Error m_process_launch_error; 47 ProcessInstanceInfoList m_proc_infos; 48 uint32_t m_proc_infos_index; 49 bool m_thread_suffix_supported; 50 bool m_list_threads_in_stop_reply; 51 52 PacketResult 53 Handle_A (StringExtractorGDBRemote &packet); 54 55 PacketResult 56 Handle_qHostInfo (StringExtractorGDBRemote &packet); 57 58 PacketResult 59 Handle_qProcessInfoPID (StringExtractorGDBRemote &packet); 60 61 PacketResult 62 Handle_qfProcessInfo (StringExtractorGDBRemote &packet); 63 64 PacketResult 65 Handle_qsProcessInfo (StringExtractorGDBRemote &packet); 66 67 PacketResult 68 Handle_qUserName (StringExtractorGDBRemote &packet); 69 70 PacketResult 71 Handle_qGroupName (StringExtractorGDBRemote &packet); 72 73 PacketResult 74 Handle_qSpeedTest (StringExtractorGDBRemote &packet); 75 76 PacketResult 77 Handle_qKillSpawnedProcess (StringExtractorGDBRemote &packet); 78 79 PacketResult 80 Handle_vFile_Open (StringExtractorGDBRemote &packet); 81 82 PacketResult 83 Handle_vFile_Close (StringExtractorGDBRemote &packet); 84 85 PacketResult 86 Handle_vFile_pRead (StringExtractorGDBRemote &packet); 87 88 PacketResult 89 Handle_vFile_pWrite (StringExtractorGDBRemote &packet); 90 91 PacketResult 92 Handle_vFile_Size (StringExtractorGDBRemote &packet); 93 94 PacketResult 95 Handle_vFile_Mode (StringExtractorGDBRemote &packet); 96 97 PacketResult 98 Handle_vFile_Exists (StringExtractorGDBRemote &packet); 99 100 PacketResult 101 Handle_vFile_symlink (StringExtractorGDBRemote &packet); 102 103 PacketResult 104 Handle_vFile_unlink (StringExtractorGDBRemote &packet); 105 106 PacketResult 107 Handle_vFile_Stat (StringExtractorGDBRemote &packet); 108 109 PacketResult 110 Handle_vFile_MD5 (StringExtractorGDBRemote &packet); 111 112 PacketResult 113 Handle_qModuleInfo (StringExtractorGDBRemote &packet); 114 115 PacketResult 116 Handle_qPlatform_shell (StringExtractorGDBRemote &packet); 117 118 PacketResult 119 Handle_qPlatform_mkdir (StringExtractorGDBRemote &packet); 120 121 PacketResult 122 Handle_qPlatform_chmod (StringExtractorGDBRemote &packet); 123 124 PacketResult 125 Handle_qSupported (StringExtractorGDBRemote &packet); 126 127 PacketResult 128 Handle_QThreadSuffixSupported (StringExtractorGDBRemote &packet); 129 130 PacketResult 131 Handle_QListThreadsInStopReply (StringExtractorGDBRemote &packet); 132 133 PacketResult 134 Handle_QSetDetachOnError (StringExtractorGDBRemote &packet); 135 136 PacketResult 137 Handle_QStartNoAckMode (StringExtractorGDBRemote &packet); 138 139 PacketResult 140 Handle_QSetSTDIN (StringExtractorGDBRemote &packet); 141 142 PacketResult 143 Handle_QSetSTDOUT (StringExtractorGDBRemote &packet); 144 145 PacketResult 146 Handle_QSetSTDERR (StringExtractorGDBRemote &packet); 147 148 PacketResult 149 Handle_qLaunchSuccess (StringExtractorGDBRemote &packet); 150 151 PacketResult 152 Handle_QEnvironment (StringExtractorGDBRemote &packet); 153 154 PacketResult 155 Handle_QLaunchArch (StringExtractorGDBRemote &packet); 156 157 bool 158 KillSpawnedProcess (lldb::pid_t pid); 159 160 static void 161 CreateProcessInfoResponse (const ProcessInstanceInfo &proc_info, 162 StreamString &response); 163 164 static void 165 CreateProcessInfoResponse_DebugServerStyle (const ProcessInstanceInfo &proc_info, 166 StreamString &response); 167 168 template <typename T> 169 void 170 RegisterMemberFunctionHandler (StringExtractorGDBRemote::ServerPacketType packet_type, 171 PacketResult (T::*handler) (StringExtractorGDBRemote& packet)) 172 { 173 RegisterPacketHandler(packet_type, 174 [this, handler] (StringExtractorGDBRemote packet, 175 Error &error, 176 bool &interrupt, 177 bool &quit) 178 { 179 return (static_cast<T*>(this)->*handler) (packet); 180 }); 181 } 182 183 bool 184 GetThreadSuffixSupported () override 185 { 186 return true; 187 } 188 189 //------------------------------------------------------------------ 190 /// Launch a process with the current launch settings. 191 /// 192 /// This method supports running an lldb-gdbserver or similar 193 /// server in a situation where the startup code has been provided 194 /// with all the information for a child process to be launched. 195 /// 196 /// @return 197 /// An Error object indicating the success or failure of the 198 /// launch. 199 //------------------------------------------------------------------ 200 virtual Error 201 LaunchProcess () = 0; 202 203 virtual FileSpec 204 FindModuleFile (const std::string& module_path, const ArchSpec& arch); 205 }; 206 207 } // namespace process_gdb_remote 208 } // namespace lldb_private 209 210 #endif // liblldb_GDBRemoteCommunicationServerCommon_h_ 211