Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 1 | //===-- GDBRemoteCommunicationServer.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_GDBRemoteCommunicationServer_h_ |
| 11 | #define liblldb_GDBRemoteCommunicationServer_h_ |
| 12 | |
| 13 | // C Includes |
| 14 | // C++ Includes |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 15 | #include <vector> |
| 16 | #include <set> |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 17 | // Other libraries and framework includes |
| 18 | // Project includes |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 19 | #include "lldb/Host/Mutex.h" |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 20 | #include "lldb/Target/Process.h" |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 21 | #include "GDBRemoteCommunication.h" |
| 22 | |
| 23 | class ProcessGDBRemote; |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 24 | class StringExtractorGDBRemote; |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 25 | |
| 26 | class GDBRemoteCommunicationServer : public GDBRemoteCommunication |
| 27 | { |
| 28 | public: |
| 29 | enum |
| 30 | { |
| 31 | eBroadcastBitRunPacketSent = kLoUserBroadcastBit |
| 32 | }; |
| 33 | //------------------------------------------------------------------ |
| 34 | // Constructors and Destructors |
| 35 | //------------------------------------------------------------------ |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 36 | GDBRemoteCommunicationServer(bool is_platform); |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 37 | |
| 38 | virtual |
| 39 | ~GDBRemoteCommunicationServer(); |
| 40 | |
| 41 | bool |
Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 42 | GetPacketAndSendResponse (uint32_t timeout_usec, |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 43 | lldb_private::Error &error, |
Greg Clayton | d314e81 | 2011-03-23 00:09:55 +0000 | [diff] [blame] | 44 | bool &interrupt, |
| 45 | bool &quit); |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 46 | |
| 47 | virtual bool |
| 48 | GetThreadSuffixSupported () |
| 49 | { |
| 50 | return true; |
| 51 | } |
| 52 | |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 53 | // After connecting, do a little handshake with the client to make sure |
| 54 | // we are at least communicating |
| 55 | bool |
| 56 | HandshakeWithClient (lldb_private::Error *error_ptr); |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 57 | |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 58 | // Set both ports to zero to let the platform automatically bind to |
| 59 | // a port chosen by the OS. |
| 60 | void |
| 61 | SetPortRange (uint16_t lo_port_num, uint16_t hi_port_num) |
| 62 | { |
| 63 | m_lo_port_num = lo_port_num; |
| 64 | m_hi_port_num = hi_port_num; |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 65 | m_next_port = m_lo_port_num; |
| 66 | m_use_port_range = true; |
| 67 | } |
| 68 | |
| 69 | // If we are using a port range, get and update the next port to be used variable. |
| 70 | // Otherwise, just return 0. |
| 71 | uint16_t |
| 72 | GetAndUpdateNextPort () |
| 73 | { |
| 74 | if (!m_use_port_range) |
| 75 | return 0; |
| 76 | uint16_t val = m_next_port; |
| 77 | if (++m_next_port > m_hi_port_num) |
| 78 | m_next_port = m_lo_port_num; |
| 79 | return val; |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 80 | } |
| 81 | |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 82 | protected: |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 83 | //typedef std::map<uint16_t, lldb::pid_t> PortToPIDMap; |
| 84 | |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 85 | lldb::thread_t m_async_thread; |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 86 | lldb_private::ProcessLaunchInfo m_process_launch_info; |
| 87 | lldb_private::Error m_process_launch_error; |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 88 | std::set<lldb::pid_t> m_spawned_pids; |
| 89 | lldb_private::Mutex m_spawned_pids_mutex; |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 90 | lldb_private::ProcessInstanceInfoList m_proc_infos; |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 91 | uint32_t m_proc_infos_index; |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 92 | uint16_t m_lo_port_num; |
| 93 | uint16_t m_hi_port_num; |
| 94 | //PortToPIDMap m_port_to_pid_map; |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 95 | uint16_t m_next_port; |
| 96 | bool m_use_port_range; |
| 97 | |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 98 | |
| 99 | size_t |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 100 | SendUnimplementedResponse (const char *packet); |
| 101 | |
| 102 | size_t |
| 103 | SendErrorResponse (uint8_t error); |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 104 | |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 105 | size_t |
| 106 | SendOKResponse (); |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 107 | |
| 108 | bool |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 109 | Handle_A (StringExtractorGDBRemote &packet); |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 110 | |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 111 | bool |
| 112 | Handle_qLaunchSuccess (StringExtractorGDBRemote &packet); |
| 113 | |
| 114 | bool |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 115 | Handle_qHostInfo (StringExtractorGDBRemote &packet); |
| 116 | |
| 117 | bool |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 118 | Handle_qLaunchGDBServer (StringExtractorGDBRemote &packet); |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 119 | |
| 120 | bool |
| 121 | Handle_qKillSpawnedProcess (StringExtractorGDBRemote &packet); |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 122 | |
| 123 | bool |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 124 | Handle_qPlatform_IO_MkDir (StringExtractorGDBRemote &packet); |
| 125 | |
| 126 | bool |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 127 | Handle_qProcessInfoPID (StringExtractorGDBRemote &packet); |
| 128 | |
| 129 | bool |
| 130 | Handle_qfProcessInfo (StringExtractorGDBRemote &packet); |
| 131 | |
| 132 | bool |
| 133 | Handle_qsProcessInfo (StringExtractorGDBRemote &packet); |
| 134 | |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 135 | bool |
| 136 | Handle_qC (StringExtractorGDBRemote &packet); |
| 137 | |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 138 | bool |
| 139 | Handle_qUserName (StringExtractorGDBRemote &packet); |
| 140 | |
| 141 | bool |
| 142 | Handle_qGroupName (StringExtractorGDBRemote &packet); |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 143 | |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 144 | bool |
Greg Clayton | 9b1e1cd | 2011-04-04 18:18:57 +0000 | [diff] [blame] | 145 | Handle_qSpeedTest (StringExtractorGDBRemote &packet); |
| 146 | |
| 147 | bool |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 148 | Handle_QEnvironment (StringExtractorGDBRemote &packet); |
| 149 | |
| 150 | bool |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 151 | Handle_QLaunchArch (StringExtractorGDBRemote &packet); |
| 152 | |
| 153 | bool |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 154 | Handle_QSetDisableASLR (StringExtractorGDBRemote &packet); |
| 155 | |
| 156 | bool |
| 157 | Handle_QSetWorkingDir (StringExtractorGDBRemote &packet); |
| 158 | |
| 159 | bool |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 160 | Handle_QStartNoAckMode (StringExtractorGDBRemote &packet); |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 161 | |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 162 | bool |
| 163 | Handle_QSetSTDIN (StringExtractorGDBRemote &packet); |
| 164 | |
| 165 | bool |
| 166 | Handle_QSetSTDOUT (StringExtractorGDBRemote &packet); |
| 167 | |
| 168 | bool |
| 169 | Handle_QSetSTDERR (StringExtractorGDBRemote &packet); |
| 170 | |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 171 | bool |
| 172 | Handle_vFile_Open (StringExtractorGDBRemote &packet); |
| 173 | |
| 174 | bool |
| 175 | Handle_vFile_Close (StringExtractorGDBRemote &packet); |
| 176 | |
| 177 | bool |
| 178 | Handle_vFile_pRead (StringExtractorGDBRemote &packet); |
| 179 | |
| 180 | bool |
| 181 | Handle_vFile_pWrite (StringExtractorGDBRemote &packet); |
| 182 | |
| 183 | bool |
| 184 | Handle_vFile_Size (StringExtractorGDBRemote &packet); |
| 185 | |
| 186 | bool |
| 187 | Handle_vFile_Mode (StringExtractorGDBRemote &packet); |
| 188 | |
| 189 | bool |
| 190 | Handle_vFile_Exists (StringExtractorGDBRemote &packet); |
| 191 | |
| 192 | bool |
| 193 | Handle_vFile_Stat (StringExtractorGDBRemote &packet); |
| 194 | |
| 195 | bool |
| 196 | Handle_vFile_MD5 (StringExtractorGDBRemote &packet); |
| 197 | |
| 198 | bool |
| 199 | Handle_qPlatform_RunCommand (StringExtractorGDBRemote &packet); |
| 200 | |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 201 | private: |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 202 | bool |
| 203 | DebugserverProcessReaped (lldb::pid_t pid); |
| 204 | |
| 205 | static bool |
| 206 | ReapDebugserverProcess (void *callback_baton, |
| 207 | lldb::pid_t pid, |
| 208 | bool exited, |
| 209 | int signal, |
| 210 | int status); |
| 211 | |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 212 | //------------------------------------------------------------------ |
| 213 | // For GDBRemoteCommunicationServer only |
| 214 | //------------------------------------------------------------------ |
| 215 | DISALLOW_COPY_AND_ASSIGN (GDBRemoteCommunicationServer); |
| 216 | }; |
| 217 | |
| 218 | #endif // liblldb_GDBRemoteCommunicationServer_h_ |