blob: 64f6f8de1a2102eddf9c3ea8cc81bbdf68aedf2c [file] [log] [blame]
Greg Clayton576d8832011-03-22 04:00:09 +00001//===-- 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 Maleae0f8f572013-08-26 23:57:52 +000015#include <vector>
16#include <set>
Greg Clayton576d8832011-03-22 04:00:09 +000017// Other libraries and framework includes
18// Project includes
Daniel Maleae0f8f572013-08-26 23:57:52 +000019#include "lldb/Host/Mutex.h"
Greg Clayton32e0a752011-03-30 18:16:51 +000020#include "lldb/Target/Process.h"
Greg Clayton576d8832011-03-22 04:00:09 +000021#include "GDBRemoteCommunication.h"
22
23class ProcessGDBRemote;
Greg Clayton32e0a752011-03-30 18:16:51 +000024class StringExtractorGDBRemote;
Greg Clayton576d8832011-03-22 04:00:09 +000025
26class GDBRemoteCommunicationServer : public GDBRemoteCommunication
27{
28public:
29 enum
30 {
31 eBroadcastBitRunPacketSent = kLoUserBroadcastBit
32 };
33 //------------------------------------------------------------------
34 // Constructors and Destructors
35 //------------------------------------------------------------------
Greg Clayton8b82f082011-04-12 05:54:46 +000036 GDBRemoteCommunicationServer(bool is_platform);
Greg Clayton576d8832011-03-22 04:00:09 +000037
38 virtual
39 ~GDBRemoteCommunicationServer();
40
41 bool
Greg Clayton73bf5db2011-06-17 01:22:15 +000042 GetPacketAndSendResponse (uint32_t timeout_usec,
Greg Clayton1cb64962011-03-24 04:28:38 +000043 lldb_private::Error &error,
Greg Claytond314e812011-03-23 00:09:55 +000044 bool &interrupt,
45 bool &quit);
Greg Clayton576d8832011-03-22 04:00:09 +000046
47 virtual bool
48 GetThreadSuffixSupported ()
49 {
50 return true;
51 }
52
Greg Clayton1cb64962011-03-24 04:28:38 +000053 // 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 Clayton576d8832011-03-22 04:00:09 +000057
Greg Clayton8b82f082011-04-12 05:54:46 +000058 // 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 Maleae0f8f572013-08-26 23:57:52 +000065 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 Clayton8b82f082011-04-12 05:54:46 +000080 }
81
Greg Clayton576d8832011-03-22 04:00:09 +000082protected:
Greg Clayton8b82f082011-04-12 05:54:46 +000083 //typedef std::map<uint16_t, lldb::pid_t> PortToPIDMap;
84
Greg Clayton576d8832011-03-22 04:00:09 +000085 lldb::thread_t m_async_thread;
Greg Clayton8b82f082011-04-12 05:54:46 +000086 lldb_private::ProcessLaunchInfo m_process_launch_info;
87 lldb_private::Error m_process_launch_error;
Daniel Maleae0f8f572013-08-26 23:57:52 +000088 std::set<lldb::pid_t> m_spawned_pids;
89 lldb_private::Mutex m_spawned_pids_mutex;
Greg Clayton8b82f082011-04-12 05:54:46 +000090 lldb_private::ProcessInstanceInfoList m_proc_infos;
Greg Clayton32e0a752011-03-30 18:16:51 +000091 uint32_t m_proc_infos_index;
Greg Clayton8b82f082011-04-12 05:54:46 +000092 uint16_t m_lo_port_num;
93 uint16_t m_hi_port_num;
94 //PortToPIDMap m_port_to_pid_map;
Daniel Maleae0f8f572013-08-26 23:57:52 +000095 uint16_t m_next_port;
96 bool m_use_port_range;
97
Greg Clayton576d8832011-03-22 04:00:09 +000098
99 size_t
Greg Clayton32e0a752011-03-30 18:16:51 +0000100 SendUnimplementedResponse (const char *packet);
101
102 size_t
103 SendErrorResponse (uint8_t error);
Greg Clayton576d8832011-03-22 04:00:09 +0000104
Greg Clayton1cb64962011-03-24 04:28:38 +0000105 size_t
106 SendOKResponse ();
Greg Clayton576d8832011-03-22 04:00:09 +0000107
108 bool
Greg Clayton8b82f082011-04-12 05:54:46 +0000109 Handle_A (StringExtractorGDBRemote &packet);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000110
Greg Clayton8b82f082011-04-12 05:54:46 +0000111 bool
112 Handle_qLaunchSuccess (StringExtractorGDBRemote &packet);
113
114 bool
Greg Clayton32e0a752011-03-30 18:16:51 +0000115 Handle_qHostInfo (StringExtractorGDBRemote &packet);
116
117 bool
Greg Clayton8b82f082011-04-12 05:54:46 +0000118 Handle_qLaunchGDBServer (StringExtractorGDBRemote &packet);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000119
120 bool
121 Handle_qKillSpawnedProcess (StringExtractorGDBRemote &packet);
Greg Clayton8b82f082011-04-12 05:54:46 +0000122
123 bool
Daniel Maleae0f8f572013-08-26 23:57:52 +0000124 Handle_qPlatform_IO_MkDir (StringExtractorGDBRemote &packet);
125
126 bool
Greg Clayton32e0a752011-03-30 18:16:51 +0000127 Handle_qProcessInfoPID (StringExtractorGDBRemote &packet);
128
129 bool
130 Handle_qfProcessInfo (StringExtractorGDBRemote &packet);
131
132 bool
133 Handle_qsProcessInfo (StringExtractorGDBRemote &packet);
134
Greg Clayton8b82f082011-04-12 05:54:46 +0000135 bool
136 Handle_qC (StringExtractorGDBRemote &packet);
137
Greg Clayton32e0a752011-03-30 18:16:51 +0000138 bool
139 Handle_qUserName (StringExtractorGDBRemote &packet);
140
141 bool
142 Handle_qGroupName (StringExtractorGDBRemote &packet);
Greg Clayton576d8832011-03-22 04:00:09 +0000143
Greg Clayton1cb64962011-03-24 04:28:38 +0000144 bool
Greg Clayton9b1e1cd2011-04-04 18:18:57 +0000145 Handle_qSpeedTest (StringExtractorGDBRemote &packet);
146
147 bool
Greg Clayton8b82f082011-04-12 05:54:46 +0000148 Handle_QEnvironment (StringExtractorGDBRemote &packet);
149
150 bool
Daniel Maleae0f8f572013-08-26 23:57:52 +0000151 Handle_QLaunchArch (StringExtractorGDBRemote &packet);
152
153 bool
Greg Clayton8b82f082011-04-12 05:54:46 +0000154 Handle_QSetDisableASLR (StringExtractorGDBRemote &packet);
155
156 bool
157 Handle_QSetWorkingDir (StringExtractorGDBRemote &packet);
158
159 bool
Greg Clayton32e0a752011-03-30 18:16:51 +0000160 Handle_QStartNoAckMode (StringExtractorGDBRemote &packet);
Greg Clayton1cb64962011-03-24 04:28:38 +0000161
Greg Clayton8b82f082011-04-12 05:54:46 +0000162 bool
163 Handle_QSetSTDIN (StringExtractorGDBRemote &packet);
164
165 bool
166 Handle_QSetSTDOUT (StringExtractorGDBRemote &packet);
167
168 bool
169 Handle_QSetSTDERR (StringExtractorGDBRemote &packet);
170
Daniel Maleae0f8f572013-08-26 23:57:52 +0000171 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 Clayton576d8832011-03-22 04:00:09 +0000201private:
Daniel Maleae0f8f572013-08-26 23:57:52 +0000202 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 Clayton576d8832011-03-22 04:00:09 +0000212 //------------------------------------------------------------------
213 // For GDBRemoteCommunicationServer only
214 //------------------------------------------------------------------
215 DISALLOW_COPY_AND_ASSIGN (GDBRemoteCommunicationServer);
216};
217
218#endif // liblldb_GDBRemoteCommunicationServer_h_