1 //===-- RemoteAwarePlatform.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_TARGET_REMOTEAWAREPLATFORM_H
10 #define LLDB_TARGET_REMOTEAWAREPLATFORM_H
11 
12 #include "lldb/Target/Platform.h"
13 #include <optional>
14 
15 namespace lldb_private {
16 
17 /// A base class for platforms which automatically want to be able to forward
18 /// operations to a remote platform instance (such as PlatformRemoteGDBServer).
19 class RemoteAwarePlatform : public Platform {
20 public:
21   using Platform::Platform;
22 
23   bool GetModuleSpec(const FileSpec &module_file_spec, const ArchSpec &arch,
24                      ModuleSpec &module_spec) override;
25 
26   Status
27   ResolveExecutable(const ModuleSpec &module_spec, lldb::ModuleSP &module_sp,
28                     const FileSpecList *module_search_paths_ptr) override;
29 
30   lldb::user_id_t OpenFile(const FileSpec &file_spec, File::OpenOptions flags,
31                            uint32_t mode, Status &error) override;
32 
33   bool CloseFile(lldb::user_id_t fd, Status &error) override;
34 
35   uint64_t ReadFile(lldb::user_id_t fd, uint64_t offset, void *dst,
36                     uint64_t dst_len, Status &error) override;
37 
38   uint64_t WriteFile(lldb::user_id_t fd, uint64_t offset, const void *src,
39                      uint64_t src_len, Status &error) override;
40 
41   lldb::user_id_t GetFileSize(const FileSpec &file_spec) override;
42 
43   Status CreateSymlink(const FileSpec &src, const FileSpec &dst) override;
44 
45   bool GetFileExists(const FileSpec &file_spec) override;
46 
47   Status Unlink(const FileSpec &file_spec) override;
48 
49   FileSpec GetRemoteWorkingDirectory() override;
50 
51   bool SetRemoteWorkingDirectory(const FileSpec &working_dir) override;
52 
53   Status MakeDirectory(const FileSpec &file_spec, uint32_t mode) override;
54 
55   Status GetFilePermissions(const FileSpec &file_spec,
56                             uint32_t &file_permissions) override;
57 
58   Status SetFilePermissions(const FileSpec &file_spec,
59                             uint32_t file_permissions) override;
60 
61   bool CalculateMD5(const FileSpec &file_spec, uint64_t &low,
62                     uint64_t &high) override;
63 
64   Status GetFileWithUUID(const FileSpec &platform_file, const UUID *uuid,
65                          FileSpec &local_file) override;
66 
67   bool GetRemoteOSVersion() override;
68   std::optional<std::string> GetRemoteOSBuildString() override;
69   std::optional<std::string> GetRemoteOSKernelDescription() override;
70   ArchSpec GetRemoteSystemArchitecture() override;
71 
72   Status RunShellCommand(llvm::StringRef command, const FileSpec &working_dir,
73                          int *status_ptr, int *signo_ptr,
74                          std::string *command_output,
75                          const Timeout<std::micro> &timeout) override;
76 
77   Status RunShellCommand(llvm::StringRef interpreter, llvm::StringRef command,
78                          const FileSpec &working_dir, int *status_ptr,
79                          int *signo_ptr, std::string *command_output,
80                          const Timeout<std::micro> &timeout) override;
81 
82   const char *GetHostname() override;
83   UserIDResolver &GetUserIDResolver() override;
84   lldb_private::Environment GetEnvironment() override;
85 
86   bool IsConnected() const override;
87 
88   bool GetProcessInfo(lldb::pid_t pid, ProcessInstanceInfo &proc_info) override;
89   uint32_t FindProcesses(const ProcessInstanceInfoMatch &match_info,
90                          ProcessInstanceInfoList &process_infos) override;
91 
92   lldb::ProcessSP ConnectProcess(llvm::StringRef connect_url,
93                                  llvm::StringRef plugin_name,
94                                  Debugger &debugger, Target *target,
95                                  Status &error) override;
96 
97   Status LaunchProcess(ProcessLaunchInfo &launch_info) override;
98 
99   Status KillProcess(const lldb::pid_t pid) override;
100 
101   size_t ConnectToWaitingProcesses(Debugger &debugger,
102                                    Status &error) override;
103 
104 protected:
105   lldb::PlatformSP m_remote_platform_sp;
106 };
107 
108 } // namespace lldb_private
109 
110 #endif // LLDB_TARGET_REMOTEAWAREPLATFORM_H
111