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