1 //===-- PlatformPOSIX.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_PlatformPOSIX_h_
11 #define liblldb_PlatformPOSIX_h_
12 
13 // C Includes
14 // C++ Includes
15 #include <map>
16 #include <memory>
17 
18 // Other libraries and framework includes
19 // Project includes
20 #include "lldb/Interpreter/Options.h"
21 #include "lldb/Target/Platform.h"
22 
23 class PlatformPOSIX : public lldb_private::Platform
24 {
25 public:
26     PlatformPOSIX(bool is_host);
27 
28     ~PlatformPOSIX() override;
29 
30     //------------------------------------------------------------
31     // lldb_private::Platform functions
32     //------------------------------------------------------------
33 
34     bool
35     GetModuleSpec (const lldb_private::FileSpec& module_file_spec,
36                    const lldb_private::ArchSpec& arch,
37                    lldb_private::ModuleSpec &module_spec) override;
38 
39     lldb_private::OptionGroupOptions*
40     GetConnectionOptions(lldb_private::CommandInterpreter &interpreter) override;
41 
42     const char *
43     GetHostname () override;
44 
45     const char *
46     GetUserName (uint32_t uid) override;
47 
48     const char *
49     GetGroupName (uint32_t gid) override;
50 
51     lldb_private::Error
52     PutFile (const lldb_private::FileSpec& source,
53              const lldb_private::FileSpec& destination,
54              uint32_t uid = UINT32_MAX,
55              uint32_t gid = UINT32_MAX) override;
56 
57     lldb::user_id_t
58     OpenFile (const lldb_private::FileSpec& file_spec,
59               uint32_t flags,
60               uint32_t mode,
61               lldb_private::Error &error) override;
62 
63     bool
64     CloseFile (lldb::user_id_t fd,
65                lldb_private::Error &error) override;
66 
67     uint64_t
68     ReadFile (lldb::user_id_t fd,
69               uint64_t offset,
70               void *dst,
71               uint64_t dst_len,
72               lldb_private::Error &error) override;
73 
74     uint64_t
75     WriteFile (lldb::user_id_t fd,
76                uint64_t offset,
77                const void* src,
78                uint64_t src_len,
79                lldb_private::Error &error) override;
80 
81     lldb::user_id_t
82     GetFileSize (const lldb_private::FileSpec& file_spec) override;
83 
84     lldb_private::Error
85     CreateSymlink(const lldb_private::FileSpec &src,
86                   const lldb_private::FileSpec &dst) override;
87 
88     lldb_private::Error
89     GetFile(const lldb_private::FileSpec &source,
90             const lldb_private::FileSpec &destination) override;
91 
92     lldb_private::FileSpec
93     GetRemoteWorkingDirectory() override;
94 
95     bool
96     SetRemoteWorkingDirectory(const lldb_private::FileSpec &working_dir) override;
97 
98     bool
99     GetRemoteOSVersion () override;
100 
101     bool
102     GetRemoteOSBuildString (std::string &s) override;
103 
104     bool
105     GetRemoteOSKernelDescription (std::string &s) override;
106 
107     lldb_private::ArchSpec
108     GetRemoteSystemArchitecture () override;
109 
110     const lldb::UnixSignalsSP &
111     GetRemoteUnixSignals() override;
112 
113     size_t
114     GetEnvironment (lldb_private::StringList &environment) override;
115 
116     bool
117     IsConnected () const override;
118 
119     lldb_private::Error
120     RunShellCommand(const char *command,                       // Shouldn't be nullptr
121                     const lldb_private::FileSpec &working_dir, // Pass empty FileSpec to use the current working directory
122                     int *status_ptr,                           // Pass nullptr if you don't want the process exit status
123                     int *signo_ptr,                            // Pass nullptr if you don't want the signal that caused the process to exit
124                     std::string *command_output,               // Pass nullptr if you don't want the command output
125                     uint32_t timeout_sec) override;            // Timeout in seconds to wait for shell program to finish
126 
127     lldb_private::Error
128     MakeDirectory(const lldb_private::FileSpec &file_spec, uint32_t mode) override;
129 
130     lldb_private::Error
131     GetFilePermissions(const lldb_private::FileSpec &file_spec, uint32_t &file_permissions) override;
132 
133     lldb_private::Error
134     SetFilePermissions(const lldb_private::FileSpec &file_spec, uint32_t file_permissions) override;
135 
136     bool
137     GetFileExists (const lldb_private::FileSpec& file_spec) override;
138 
139     lldb_private::Error
140     Unlink(const lldb_private::FileSpec &file_spec) override;
141 
142     lldb_private::Error
143     LaunchProcess (lldb_private::ProcessLaunchInfo &launch_info) override;
144 
145     lldb_private::Error
146     KillProcess (const lldb::pid_t pid) override;
147 
148     lldb::ProcessSP
149     Attach (lldb_private::ProcessAttachInfo &attach_info,
150             lldb_private::Debugger &debugger,
151             lldb_private::Target *target,       // Can be nullptr, if nullptr create a new target, else use existing one
152             lldb_private::Error &error) override;
153 
154     lldb::ProcessSP
155     DebugProcess (lldb_private::ProcessLaunchInfo &launch_info,
156                   lldb_private::Debugger &debugger,
157                   lldb_private::Target *target,       // Can be nullptr, if nullptr create a new target, else use existing one
158                   lldb_private::Error &error) override;
159 
160     std::string
161     GetPlatformSpecificConnectionInformation() override;
162 
163     bool
164     CalculateMD5 (const lldb_private::FileSpec& file_spec,
165                   uint64_t &low,
166                   uint64_t &high) override;
167 
168     void
169     CalculateTrapHandlerSymbolNames () override;
170 
171     lldb_private::Error
172     ConnectRemote (lldb_private::Args& args) override;
173 
174     lldb_private::Error
175     DisconnectRemote () override;
176 
177     uint32_t
178     DoLoadImage (lldb_private::Process* process,
179                  const lldb_private::FileSpec& remote_file,
180                  lldb_private::Error& error) override;
181 
182     lldb_private::Error
183     UnloadImage (lldb_private::Process* process, uint32_t image_token) override;
184 
185     lldb::ProcessSP
186     ConnectProcess (const char* connect_url,
187                     const char* plugin_name,
188                     lldb_private::Debugger &debugger,
189                     lldb_private::Target *target,
190                     lldb_private::Error &error) override;
191 
192     size_t
193     ConnectToWaitingProcesses(lldb_private::Debugger& debugger, lldb_private::Error& error) override;
194 
195 protected:
196     std::unique_ptr<lldb_private::OptionGroupPlatformRSync> m_option_group_platform_rsync;
197     std::unique_ptr<lldb_private::OptionGroupPlatformSSH> m_option_group_platform_ssh;
198     std::unique_ptr<lldb_private::OptionGroupPlatformCaching> m_option_group_platform_caching;
199 
200     std::map<lldb_private::CommandInterpreter*,std::unique_ptr<lldb_private::OptionGroupOptions>> m_options;
201     lldb::PlatformSP m_remote_platform_sp; // Allow multiple ways to connect to a remote POSIX-compliant OS
202 
203     lldb_private::Error
204     EvaluateLibdlExpression(lldb_private::Process* process,
205                             const char *expr_cstr,
206                             const char *expr_prefix,
207                             lldb::ValueObjectSP& result_valobj_sp);
208 
209     virtual const char*
210     GetLibdlFunctionDeclarations() const;
211 
212 private:
213     DISALLOW_COPY_AND_ASSIGN (PlatformPOSIX);
214 };
215 
216 #endif // liblldb_PlatformPOSIX_h_
217