xref: /NextBSD/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.h (revision 84d351007654069f9643c8e4b4802a7f5f08ee42)
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_qEcho (StringExtractorGDBRemote &packet);
114 
115     PacketResult
116     Handle_qModuleInfo (StringExtractorGDBRemote &packet);
117 
118     PacketResult
119     Handle_qPlatform_shell (StringExtractorGDBRemote &packet);
120 
121     PacketResult
122     Handle_qPlatform_mkdir (StringExtractorGDBRemote &packet);
123 
124     PacketResult
125     Handle_qPlatform_chmod (StringExtractorGDBRemote &packet);
126 
127     PacketResult
128     Handle_qSupported (StringExtractorGDBRemote &packet);
129 
130     PacketResult
131     Handle_QThreadSuffixSupported (StringExtractorGDBRemote &packet);
132 
133     PacketResult
134     Handle_QListThreadsInStopReply (StringExtractorGDBRemote &packet);
135 
136     PacketResult
137     Handle_QSetDetachOnError (StringExtractorGDBRemote &packet);
138 
139     PacketResult
140     Handle_QStartNoAckMode (StringExtractorGDBRemote &packet);
141 
142     PacketResult
143     Handle_QSetSTDIN (StringExtractorGDBRemote &packet);
144 
145     PacketResult
146     Handle_QSetSTDOUT (StringExtractorGDBRemote &packet);
147 
148     PacketResult
149     Handle_QSetSTDERR (StringExtractorGDBRemote &packet);
150 
151     PacketResult
152     Handle_qLaunchSuccess (StringExtractorGDBRemote &packet);
153 
154     PacketResult
155     Handle_QEnvironment (StringExtractorGDBRemote &packet);
156 
157     PacketResult
158     Handle_QEnvironmentHexEncoded (StringExtractorGDBRemote &packet);
159 
160     PacketResult
161     Handle_QLaunchArch (StringExtractorGDBRemote &packet);
162 
163     bool
164     KillSpawnedProcess (lldb::pid_t pid);
165 
166     static void
167     CreateProcessInfoResponse (const ProcessInstanceInfo &proc_info,
168                                StreamString &response);
169 
170     static void
171     CreateProcessInfoResponse_DebugServerStyle (const ProcessInstanceInfo &proc_info,
172                                                 StreamString &response);
173 
174     template <typename T>
175     void
RegisterMemberFunctionHandler(StringExtractorGDBRemote::ServerPacketType packet_type,PacketResult (T::* handler)(StringExtractorGDBRemote & packet))176     RegisterMemberFunctionHandler (StringExtractorGDBRemote::ServerPacketType packet_type,
177                                    PacketResult (T::*handler) (StringExtractorGDBRemote& packet))
178     {
179         RegisterPacketHandler(packet_type,
180                               [this, handler] (StringExtractorGDBRemote packet,
181                                                Error &error,
182                                                bool &interrupt,
183                                                bool &quit)
184                               {
185                                   return (static_cast<T*>(this)->*handler) (packet);
186                               });
187     }
188 
189     bool
GetThreadSuffixSupported()190     GetThreadSuffixSupported () override
191     {
192         return true;
193     }
194 
195     //------------------------------------------------------------------
196     /// Launch a process with the current launch settings.
197     ///
198     /// This method supports running an lldb-gdbserver or similar
199     /// server in a situation where the startup code has been provided
200     /// with all the information for a child process to be launched.
201     ///
202     /// @return
203     ///     An Error object indicating the success or failure of the
204     ///     launch.
205     //------------------------------------------------------------------
206     virtual Error
207     LaunchProcess () = 0;
208 
209     virtual FileSpec
210     FindModuleFile (const std::string& module_path, const ArchSpec& arch);
211 };
212 
213 } // namespace process_gdb_remote
214 } // namespace lldb_private
215 
216 #endif  // liblldb_GDBRemoteCommunicationServerCommon_h_
217