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