1//===-- GDBRemoteCommunicationServerCommon.h --------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLDB_SOURCE_PLUGINS_PROCESS_GDB_REMOTE_GDBREMOTECOMMUNICATIONSERVERCOMMON_H
10#define LLDB_SOURCE_PLUGINS_PROCESS_GDB_REMOTE_GDBREMOTECOMMUNICATIONSERVERCOMMON_H
11
12#include <string>
13
14#include "lldb/Host/ProcessLaunchInfo.h"
15#include "lldb/lldb-private-forward.h"
16
17#include "GDBRemoteCommunicationServer.h"
18
19class StringExtractorGDBRemote;
20
21namespace lldb_private {
22namespace process_gdb_remote {
23
24class ProcessGDBRemote;
25
26class GDBRemoteCommunicationServerCommon : public GDBRemoteCommunicationServer {
27public:
28 GDBRemoteCommunicationServerCommon();
29
30 ~GDBRemoteCommunicationServerCommon() override;
31
32protected:
33 ProcessLaunchInfo m_process_launch_info;
34 Status m_process_launch_error;
35 ProcessInstanceInfoList m_proc_infos;
36 uint32_t m_proc_infos_index;
37
38 PacketResult Handle_A(StringExtractorGDBRemote &packet);
39
40 PacketResult Handle_qHostInfo(StringExtractorGDBRemote &packet);
41
42 PacketResult Handle_qProcessInfoPID(StringExtractorGDBRemote &packet);
43
44 PacketResult Handle_qfProcessInfo(StringExtractorGDBRemote &packet);
45
46 PacketResult Handle_qsProcessInfo(StringExtractorGDBRemote &packet);
47
48 PacketResult Handle_qUserName(StringExtractorGDBRemote &packet);
49
50 PacketResult Handle_qGroupName(StringExtractorGDBRemote &packet);
51
52 PacketResult Handle_qSpeedTest(StringExtractorGDBRemote &packet);
53
54 PacketResult Handle_vFile_Open(StringExtractorGDBRemote &packet);
55
56 PacketResult Handle_vFile_Close(StringExtractorGDBRemote &packet);
57
58 PacketResult Handle_vFile_pRead(StringExtractorGDBRemote &packet);
59
60 PacketResult Handle_vFile_pWrite(StringExtractorGDBRemote &packet);
61
62 PacketResult Handle_vFile_Size(StringExtractorGDBRemote &packet);
63
64 PacketResult Handle_vFile_Mode(StringExtractorGDBRemote &packet);
65
66 PacketResult Handle_vFile_Exists(StringExtractorGDBRemote &packet);
67
68 PacketResult Handle_vFile_symlink(StringExtractorGDBRemote &packet);
69
70 PacketResult Handle_vFile_unlink(StringExtractorGDBRemote &packet);
71
72 PacketResult Handle_vFile_FStat(StringExtractorGDBRemote &packet);
73
74 PacketResult Handle_vFile_Stat(StringExtractorGDBRemote &packet);
75
76 PacketResult Handle_vFile_MD5(StringExtractorGDBRemote &packet);
77
78 PacketResult Handle_qEcho(StringExtractorGDBRemote &packet);
79
80 PacketResult Handle_qModuleInfo(StringExtractorGDBRemote &packet);
81
82 PacketResult Handle_jModulesInfo(StringExtractorGDBRemote &packet);
83
84 PacketResult Handle_qPlatform_shell(StringExtractorGDBRemote &packet);
85
86 PacketResult Handle_qPlatform_mkdir(StringExtractorGDBRemote &packet);
87
88 PacketResult Handle_qPlatform_chmod(StringExtractorGDBRemote &packet);
89
90 PacketResult Handle_qSupported(StringExtractorGDBRemote &packet);
91
92 PacketResult Handle_QSetDetachOnError(StringExtractorGDBRemote &packet);
93
94 PacketResult Handle_QStartNoAckMode(StringExtractorGDBRemote &packet);
95
96 PacketResult Handle_QSetSTDIN(StringExtractorGDBRemote &packet);
97
98 PacketResult Handle_QSetSTDOUT(StringExtractorGDBRemote &packet);
99
100 PacketResult Handle_QSetSTDERR(StringExtractorGDBRemote &packet);
101
102 PacketResult Handle_qLaunchSuccess(StringExtractorGDBRemote &packet);
103
104 PacketResult Handle_QEnvironment(StringExtractorGDBRemote &packet);
105
106 PacketResult Handle_QEnvironmentHexEncoded(StringExtractorGDBRemote &packet);
107
108 PacketResult Handle_QLaunchArch(StringExtractorGDBRemote &packet);
109
110 static void CreateProcessInfoResponse(const ProcessInstanceInfo &proc_info,
111 StreamString &response);
112
113 static void CreateProcessInfoResponse_DebugServerStyle(
114 const ProcessInstanceInfo &proc_info, StreamString &response);
115
116 template <typename T>
117 void RegisterMemberFunctionHandler(
118 StringExtractorGDBRemote::ServerPacketType packet_type,
119 PacketResult (T::*handler)(StringExtractorGDBRemote &packet)) {
120 RegisterPacketHandler(packet_type,
121 handler: [this, handler](StringExtractorGDBRemote packet,
122 Status &error, bool &interrupt,
123 bool &quit) {
124 return (static_cast<T *>(this)->*handler)(packet);
125 });
126 }
127
128 /// Launch a process with the current launch settings.
129 ///
130 /// This method supports running an lldb-gdbserver or similar
131 /// server in a situation where the startup code has been provided
132 /// with all the information for a child process to be launched.
133 ///
134 /// \return
135 /// An Status object indicating the success or failure of the
136 /// launch.
137 virtual Status LaunchProcess() = 0;
138
139 virtual FileSpec FindModuleFile(const std::string &module_path,
140 const ArchSpec &arch);
141
142 // Process client_features (qSupported) and return an array of server features
143 // to be returned in response.
144 virtual std::vector<std::string>
145 HandleFeatures(llvm::ArrayRef<llvm::StringRef> client_features);
146
147private:
148 ModuleSpec GetModuleInfo(llvm::StringRef module_path, llvm::StringRef triple);
149};
150
151} // namespace process_gdb_remote
152} // namespace lldb_private
153
154#endif // LLDB_SOURCE_PLUGINS_PROCESS_GDB_REMOTE_GDBREMOTECOMMUNICATIONSERVERCOMMON_H
155

source code of lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.h