/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/include/lldb/Target/Platform.h
Line | Count | Source (jump to first uncovered line) |
1 | | //===-- Platform.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_PLATFORM_H |
10 | | #define LLDB_TARGET_PLATFORM_H |
11 | | |
12 | | #include <functional> |
13 | | #include <map> |
14 | | #include <memory> |
15 | | #include <mutex> |
16 | | #include <optional> |
17 | | #include <string> |
18 | | #include <vector> |
19 | | |
20 | | #include "lldb/Core/PluginInterface.h" |
21 | | #include "lldb/Core/UserSettingsController.h" |
22 | | #include "lldb/Host/File.h" |
23 | | #include "lldb/Interpreter/Options.h" |
24 | | #include "lldb/Utility/ArchSpec.h" |
25 | | #include "lldb/Utility/ConstString.h" |
26 | | #include "lldb/Utility/FileSpec.h" |
27 | | #include "lldb/Utility/StructuredData.h" |
28 | | #include "lldb/Utility/Timeout.h" |
29 | | #include "lldb/Utility/UserIDResolver.h" |
30 | | #include "lldb/lldb-private-forward.h" |
31 | | #include "lldb/lldb-public.h" |
32 | | #include "llvm/Support/VersionTuple.h" |
33 | | |
34 | | namespace lldb_private { |
35 | | |
36 | | class ProcessInstanceInfo; |
37 | | class ProcessInstanceInfoMatch; |
38 | | typedef std::vector<ProcessInstanceInfo> ProcessInstanceInfoList; |
39 | | |
40 | | class ModuleCache; |
41 | | enum MmapFlags { eMmapFlagsPrivate = 1, eMmapFlagsAnon = 2 }; |
42 | | |
43 | | class PlatformProperties : public Properties { |
44 | | public: |
45 | | PlatformProperties(); |
46 | | |
47 | | static llvm::StringRef GetSettingName(); |
48 | | |
49 | | bool GetUseModuleCache() const; |
50 | | bool SetUseModuleCache(bool use_module_cache); |
51 | | |
52 | | FileSpec GetModuleCacheDirectory() const; |
53 | | bool SetModuleCacheDirectory(const FileSpec &dir_spec); |
54 | | |
55 | | private: |
56 | | void SetDefaultModuleCacheDirectory(const FileSpec &dir_spec); |
57 | | }; |
58 | | |
59 | | typedef llvm::SmallVector<lldb::addr_t, 6> MmapArgList; |
60 | | |
61 | | /// \class Platform Platform.h "lldb/Target/Platform.h" |
62 | | /// A plug-in interface definition class for debug platform that |
63 | | /// includes many platform abilities such as: |
64 | | /// \li getting platform information such as supported architectures, |
65 | | /// supported binary file formats and more |
66 | | /// \li launching new processes |
67 | | /// \li attaching to existing processes |
68 | | /// \li download/upload files |
69 | | /// \li execute shell commands |
70 | | /// \li listing and getting info for existing processes |
71 | | /// \li attaching and possibly debugging the platform's kernel |
72 | | class Platform : public PluginInterface { |
73 | | public: |
74 | | /// Default Constructor |
75 | | Platform(bool is_host_platform); |
76 | | |
77 | | /// The destructor is virtual since this class is designed to be inherited |
78 | | /// from by the plug-in instance. |
79 | | ~Platform() override; |
80 | | |
81 | | static void Initialize(); |
82 | | |
83 | | static void Terminate(); |
84 | | |
85 | | static PlatformProperties &GetGlobalPlatformProperties(); |
86 | | |
87 | | /// Get the native host platform plug-in. |
88 | | /// |
89 | | /// There should only be one of these for each host that LLDB runs upon that |
90 | | /// should be statically compiled in and registered using preprocessor |
91 | | /// macros or other similar build mechanisms in a |
92 | | /// PlatformSubclass::Initialize() function. |
93 | | /// |
94 | | /// This platform will be used as the default platform when launching or |
95 | | /// attaching to processes unless another platform is specified. |
96 | | static lldb::PlatformSP GetHostPlatform(); |
97 | | |
98 | | static const char *GetHostPlatformName(); |
99 | | |
100 | | static void SetHostPlatform(const lldb::PlatformSP &platform_sp); |
101 | | |
102 | | static lldb::PlatformSP Create(llvm::StringRef name); |
103 | | |
104 | | /// Augments the triple either with information from platform or the host |
105 | | /// system (if platform is null). |
106 | | static ArchSpec GetAugmentedArchSpec(Platform *platform, |
107 | | llvm::StringRef triple); |
108 | | |
109 | | /// Find a platform plugin for a given process. |
110 | | /// |
111 | | /// Scans the installed Platform plug-ins and tries to find an instance that |
112 | | /// can be used for \a process |
113 | | /// |
114 | | /// \param[in] process |
115 | | /// The process for which to try and locate a platform |
116 | | /// plug-in instance. |
117 | | /// |
118 | | /// \param[in] plugin_name |
119 | | /// An optional name of a specific platform plug-in that |
120 | | /// should be used. If nullptr, pick the best plug-in. |
121 | | // static lldb::PlatformSP |
122 | | // FindPlugin (Process *process, ConstString plugin_name); |
123 | | |
124 | | /// Set the target's executable based off of the existing architecture |
125 | | /// information in \a target given a path to an executable \a exe_file. |
126 | | /// |
127 | | /// Each platform knows the architectures that it supports and can select |
128 | | /// the correct architecture slice within \a exe_file by inspecting the |
129 | | /// architecture in \a target. If the target had an architecture specified, |
130 | | /// then in can try and obey that request and optionally fail if the |
131 | | /// architecture doesn't match up. If no architecture is specified, the |
132 | | /// platform should select the default architecture from \a exe_file. Any |
133 | | /// application bundles or executable wrappers can also be inspected for the |
134 | | /// actual application binary within the bundle that should be used. |
135 | | /// |
136 | | /// \return |
137 | | /// Returns \b true if this Platform plug-in was able to find |
138 | | /// a suitable executable, \b false otherwise. |
139 | | virtual Status ResolveExecutable(const ModuleSpec &module_spec, |
140 | | lldb::ModuleSP &module_sp, |
141 | | const FileSpecList *module_search_paths_ptr); |
142 | | |
143 | | /// Find a symbol file given a symbol file module specification. |
144 | | /// |
145 | | /// Each platform might have tricks to find symbol files for an executable |
146 | | /// given information in a symbol file ModuleSpec. Some platforms might also |
147 | | /// support symbol files that are bundles and know how to extract the right |
148 | | /// symbol file given a bundle. |
149 | | /// |
150 | | /// \param[in] target |
151 | | /// The target in which we are trying to resolve the symbol file. |
152 | | /// The target has a list of modules that we might be able to |
153 | | /// use in order to help find the right symbol file. If the |
154 | | /// "m_file" or "m_platform_file" entries in the \a sym_spec |
155 | | /// are filled in, then we might be able to locate a module in |
156 | | /// the target, extract its UUID and locate a symbol file. |
157 | | /// If just the "m_uuid" is specified, then we might be able |
158 | | /// to find the module in the target that matches that UUID |
159 | | /// and pair the symbol file along with it. If just "m_symbol_file" |
160 | | /// is specified, we can use a variety of tricks to locate the |
161 | | /// symbols in an SDK, PDK, or other development kit location. |
162 | | /// |
163 | | /// \param[in] sym_spec |
164 | | /// A module spec that describes some information about the |
165 | | /// symbol file we are trying to resolve. The ModuleSpec might |
166 | | /// contain the following: |
167 | | /// m_file - A full or partial path to an executable from the |
168 | | /// target (might be empty). |
169 | | /// m_platform_file - Another executable hint that contains |
170 | | /// the path to the file as known on the |
171 | | /// local/remote platform. |
172 | | /// m_symbol_file - A full or partial path to a symbol file |
173 | | /// or symbol bundle that should be used when |
174 | | /// trying to resolve the symbol file. |
175 | | /// m_arch - The architecture we are looking for when resolving |
176 | | /// the symbol file. |
177 | | /// m_uuid - The UUID of the executable and symbol file. This |
178 | | /// can often be used to match up an executable with |
179 | | /// a symbol file, or resolve an symbol file in a |
180 | | /// symbol file bundle. |
181 | | /// |
182 | | /// \param[out] sym_file |
183 | | /// The resolved symbol file spec if the returned error |
184 | | /// indicates success. |
185 | | /// |
186 | | /// \return |
187 | | /// Returns an error that describes success or failure. |
188 | | virtual Status ResolveSymbolFile(Target &target, const ModuleSpec &sym_spec, |
189 | | FileSpec &sym_file); |
190 | | |
191 | | /// Resolves the FileSpec to a (possibly) remote path. Remote platforms must |
192 | | /// override this to resolve to a path on the remote side. |
193 | | virtual bool ResolveRemotePath(const FileSpec &platform_path, |
194 | | FileSpec &resolved_platform_path); |
195 | | |
196 | | /// Get the OS version from a connected platform. |
197 | | /// |
198 | | /// Some platforms might not be connected to a remote platform, but can |
199 | | /// figure out the OS version for a process. This is common for simulator |
200 | | /// platforms that will run native programs on the current host, but the |
201 | | /// simulator might be simulating a different OS. The \a process parameter |
202 | | /// might be specified to help to determine the OS version. |
203 | | virtual llvm::VersionTuple GetOSVersion(Process *process = nullptr); |
204 | | |
205 | | bool SetOSVersion(llvm::VersionTuple os_version); |
206 | | |
207 | | std::optional<std::string> GetOSBuildString(); |
208 | | |
209 | | std::optional<std::string> GetOSKernelDescription(); |
210 | | |
211 | | // Returns the name of the platform |
212 | 131 | llvm::StringRef GetName() { return GetPluginName(); } |
213 | | |
214 | | virtual const char *GetHostname(); |
215 | | |
216 | | virtual ConstString GetFullNameForDylib(ConstString basename); |
217 | | |
218 | | virtual llvm::StringRef GetDescription() = 0; |
219 | | |
220 | | /// Report the current status for this platform. |
221 | | /// |
222 | | /// The returned string usually involves returning the OS version (if |
223 | | /// available), and any SDK directory that might be being used for local |
224 | | /// file caching, and if connected a quick blurb about what this platform is |
225 | | /// connected to. |
226 | | virtual void GetStatus(Stream &strm); |
227 | | |
228 | | // Subclasses must be able to fetch the current OS version |
229 | | // |
230 | | // Remote classes must be connected for this to succeed. Local subclasses |
231 | | // don't need to override this function as it will just call the |
232 | | // HostInfo::GetOSVersion(). |
233 | 0 | virtual bool GetRemoteOSVersion() { return false; } |
234 | | |
235 | 0 | virtual std::optional<std::string> GetRemoteOSBuildString() { |
236 | 0 | return std::nullopt; |
237 | 0 | } |
238 | | |
239 | 0 | virtual std::optional<std::string> GetRemoteOSKernelDescription() { |
240 | 0 | return std::nullopt; |
241 | 0 | } |
242 | | |
243 | | // Remote Platform subclasses need to override this function |
244 | 0 | virtual ArchSpec GetRemoteSystemArchitecture() { |
245 | 0 | return ArchSpec(); // Return an invalid architecture |
246 | 0 | } |
247 | | |
248 | 37 | virtual FileSpec GetRemoteWorkingDirectory() { return m_working_dir; } |
249 | | |
250 | | virtual bool SetRemoteWorkingDirectory(const FileSpec &working_dir); |
251 | | |
252 | | virtual UserIDResolver &GetUserIDResolver(); |
253 | | |
254 | | /// Locate a file for a platform. |
255 | | /// |
256 | | /// The default implementation of this function will return the same file |
257 | | /// patch in \a local_file as was in \a platform_file. |
258 | | /// |
259 | | /// \param[in] platform_file |
260 | | /// The platform file path to locate and cache locally. |
261 | | /// |
262 | | /// \param[in] uuid_ptr |
263 | | /// If we know the exact UUID of the file we are looking for, it |
264 | | /// can be specified. If it is not specified, we might now know |
265 | | /// the exact file. The UUID is usually some sort of MD5 checksum |
266 | | /// for the file and is sometimes known by dynamic linkers/loaders. |
267 | | /// If the UUID is known, it is best to supply it to platform |
268 | | /// file queries to ensure we are finding the correct file, not |
269 | | /// just a file at the correct path. |
270 | | /// |
271 | | /// \param[out] local_file |
272 | | /// A locally cached version of the platform file. For platforms |
273 | | /// that describe the current host computer, this will just be |
274 | | /// the same file. For remote platforms, this file might come from |
275 | | /// and SDK directory, or might need to be sync'ed over to the |
276 | | /// current machine for efficient debugging access. |
277 | | /// |
278 | | /// \return |
279 | | /// An error object. |
280 | | virtual Status GetFileWithUUID(const FileSpec &platform_file, |
281 | | const UUID *uuid_ptr, FileSpec &local_file); |
282 | | |
283 | | // Locate the scripting resource given a module specification. |
284 | | // |
285 | | // Locating the file should happen only on the local computer or using the |
286 | | // current computers global settings. |
287 | | virtual FileSpecList |
288 | | LocateExecutableScriptingResources(Target *target, Module &module, |
289 | | Stream &feedback_stream); |
290 | | |
291 | | virtual Status GetSharedModule( |
292 | | const ModuleSpec &module_spec, Process *process, |
293 | | lldb::ModuleSP &module_sp, const FileSpecList *module_search_paths_ptr, |
294 | | llvm::SmallVectorImpl<lldb::ModuleSP> *old_modules, bool *did_create_ptr); |
295 | | |
296 | | void CallLocateModuleCallbackIfSet(const ModuleSpec &module_spec, |
297 | | lldb::ModuleSP &module_sp, |
298 | | FileSpec &symbol_file_spec, |
299 | | bool *did_create_ptr); |
300 | | |
301 | | virtual bool GetModuleSpec(const FileSpec &module_file_spec, |
302 | | const ArchSpec &arch, ModuleSpec &module_spec); |
303 | | |
304 | | virtual Status ConnectRemote(Args &args); |
305 | | |
306 | | virtual Status DisconnectRemote(); |
307 | | |
308 | | /// Get the platform's supported architectures in the order in which they |
309 | | /// should be searched. |
310 | | /// |
311 | | /// \param[in] process_host_arch |
312 | | /// The process host architecture if it's known. An invalid ArchSpec |
313 | | /// represents that the process host architecture is unknown. |
314 | | virtual std::vector<ArchSpec> |
315 | | GetSupportedArchitectures(const ArchSpec &process_host_arch) = 0; |
316 | | |
317 | | virtual size_t GetSoftwareBreakpointTrapOpcode(Target &target, |
318 | | BreakpointSite *bp_site); |
319 | | |
320 | | /// Launch a new process on a platform, not necessarily for debugging, it |
321 | | /// could be just for running the process. |
322 | | virtual Status LaunchProcess(ProcessLaunchInfo &launch_info); |
323 | | |
324 | | /// Perform expansion of the command-line for this launch info This can |
325 | | /// potentially involve wildcard expansion |
326 | | /// environment variable replacement, and whatever other |
327 | | /// argument magic the platform defines as part of its typical |
328 | | /// user experience |
329 | | virtual Status ShellExpandArguments(ProcessLaunchInfo &launch_info); |
330 | | |
331 | | /// Kill process on a platform. |
332 | | virtual Status KillProcess(const lldb::pid_t pid); |
333 | | |
334 | | /// Lets a platform answer if it is compatible with a given architecture and |
335 | | /// the target triple contained within. |
336 | | virtual bool IsCompatibleArchitecture(const ArchSpec &arch, |
337 | | const ArchSpec &process_host_arch, |
338 | | ArchSpec::MatchType match, |
339 | | ArchSpec *compatible_arch_ptr); |
340 | | |
341 | | /// Not all platforms will support debugging a process by spawning somehow |
342 | | /// halted for a debugger (specified using the "eLaunchFlagDebug" launch |
343 | | /// flag) and then attaching. If your platform doesn't support this, |
344 | | /// override this function and return false. |
345 | 2.13k | virtual bool CanDebugProcess() { return true; } |
346 | | |
347 | | /// Subclasses do not need to implement this function as it uses the |
348 | | /// Platform::LaunchProcess() followed by Platform::Attach (). Remote |
349 | | /// platforms will want to subclass this function in order to be able to |
350 | | /// intercept STDIO and possibly launch a separate process that will debug |
351 | | /// the debuggee. |
352 | | virtual lldb::ProcessSP DebugProcess(ProcessLaunchInfo &launch_info, |
353 | | Debugger &debugger, Target &target, |
354 | | Status &error); |
355 | | |
356 | | virtual lldb::ProcessSP ConnectProcess(llvm::StringRef connect_url, |
357 | | llvm::StringRef plugin_name, |
358 | | Debugger &debugger, Target *target, |
359 | | Status &error); |
360 | | |
361 | | virtual lldb::ProcessSP |
362 | | ConnectProcessSynchronous(llvm::StringRef connect_url, |
363 | | llvm::StringRef plugin_name, Debugger &debugger, |
364 | | Stream &stream, Target *target, Status &error); |
365 | | |
366 | | /// Attach to an existing process using a process ID. |
367 | | /// |
368 | | /// Each platform subclass needs to implement this function and attempt to |
369 | | /// attach to the process with the process ID of \a pid. The platform |
370 | | /// subclass should return an appropriate ProcessSP subclass that is |
371 | | /// attached to the process, or an empty shared pointer with an appropriate |
372 | | /// error. |
373 | | /// |
374 | | /// \return |
375 | | /// An appropriate ProcessSP containing a valid shared pointer |
376 | | /// to the default Process subclass for the platform that is |
377 | | /// attached to the process, or an empty shared pointer with an |
378 | | /// appropriate error fill into the \a error object. |
379 | | virtual lldb::ProcessSP Attach(ProcessAttachInfo &attach_info, |
380 | | Debugger &debugger, |
381 | | Target *target, // Can be nullptr, if nullptr |
382 | | // create a new target, else |
383 | | // use existing one |
384 | | Status &error) = 0; |
385 | | |
386 | | /// Attach to an existing process by process name. |
387 | | /// |
388 | | /// This function is not meant to be overridden by Process subclasses. It |
389 | | /// will first call Process::WillAttach (const char *) and if that returns |
390 | | /// \b true, Process::DoAttach (const char *) will be called to actually do |
391 | | /// the attach. If DoAttach returns \b true, then Process::DidAttach() will |
392 | | /// be called. |
393 | | /// |
394 | | /// \param[in] process_name |
395 | | /// A process name to match against the current process list. |
396 | | /// |
397 | | /// \return |
398 | | /// Returns \a pid if attaching was successful, or |
399 | | /// LLDB_INVALID_PROCESS_ID if attaching fails. |
400 | | // virtual lldb::ProcessSP |
401 | | // Attach (const char *process_name, |
402 | | // bool wait_for_launch, |
403 | | // Status &error) = 0; |
404 | | |
405 | | // The base class Platform will take care of the host platform. Subclasses |
406 | | // will need to fill in the remote case. |
407 | | virtual uint32_t FindProcesses(const ProcessInstanceInfoMatch &match_info, |
408 | | ProcessInstanceInfoList &proc_infos); |
409 | | |
410 | | virtual bool GetProcessInfo(lldb::pid_t pid, ProcessInstanceInfo &proc_info); |
411 | | |
412 | | // Set a breakpoint on all functions that can end up creating a thread for |
413 | | // this platform. This is needed when running expressions and also for |
414 | | // process control. |
415 | | virtual lldb::BreakpointSP SetThreadCreationBreakpoint(Target &target); |
416 | | |
417 | | // Given a target, find the local SDK directory if one exists on the current |
418 | | // host. |
419 | | virtual lldb_private::ConstString |
420 | 0 | GetSDKDirectory(lldb_private::Target &target) { |
421 | 0 | return lldb_private::ConstString(); |
422 | 0 | } |
423 | | |
424 | 0 | const std::string &GetRemoteURL() const { return m_remote_url; } |
425 | | |
426 | 170k | bool IsHost() const { |
427 | 170k | return m_is_host; // Is this the default host platform? |
428 | 170k | } |
429 | | |
430 | 114k | bool IsRemote() const { return !m_is_host; } |
431 | | |
432 | 2.38k | virtual bool IsConnected() const { |
433 | | // Remote subclasses should override this function |
434 | 2.38k | return IsHost(); |
435 | 2.38k | } |
436 | | |
437 | | const ArchSpec &GetSystemArchitecture(); |
438 | | |
439 | 3.94k | void SetSystemArchitecture(const ArchSpec &arch) { |
440 | 3.94k | m_system_arch = arch; |
441 | 3.94k | if (IsHost()) |
442 | 3.94k | m_os_version_set_while_connected = m_system_arch.IsValid(); |
443 | 3.94k | } |
444 | | |
445 | | /// If the triple contains not specify the vendor, os, and environment |
446 | | /// parts, we "augment" these using information from the platform and return |
447 | | /// the resulting ArchSpec object. |
448 | | ArchSpec GetAugmentedArchSpec(llvm::StringRef triple); |
449 | | |
450 | | // Used for column widths |
451 | 0 | size_t GetMaxUserIDNameLength() const { return m_max_uid_name_len; } |
452 | | |
453 | | // Used for column widths |
454 | 0 | size_t GetMaxGroupIDNameLength() const { return m_max_gid_name_len; } |
455 | | |
456 | 70 | const std::string &GetSDKRootDirectory() const { return m_sdk_sysroot; } |
457 | | |
458 | 19 | void SetSDKRootDirectory(std::string dir) { m_sdk_sysroot = std::move(dir); } |
459 | | |
460 | 2 | const std::string &GetSDKBuild() const { return m_sdk_build; } |
461 | | |
462 | 0 | void SetSDKBuild(std::string sdk_build) { |
463 | 0 | m_sdk_build = std::move(sdk_build); |
464 | 0 | } |
465 | | |
466 | | // Override this to return true if your platform supports Clang modules. You |
467 | | // may also need to override AddClangModuleCompilationOptions to pass the |
468 | | // right Clang flags for your platform. |
469 | 4 | virtual bool SupportsModules() { return false; } |
470 | | |
471 | | // Appends the platform-specific options required to find the modules for the |
472 | | // current platform. |
473 | | virtual void |
474 | | AddClangModuleCompilationOptions(Target *target, |
475 | | std::vector<std::string> &options); |
476 | | |
477 | | FileSpec GetWorkingDirectory(); |
478 | | |
479 | | bool SetWorkingDirectory(const FileSpec &working_dir); |
480 | | |
481 | | // There may be modules that we don't want to find by default for operations |
482 | | // like "setting breakpoint by name". The platform will return "true" from |
483 | | // this call if the passed in module happens to be one of these. |
484 | | |
485 | | virtual bool |
486 | | ModuleIsExcludedForUnconstrainedSearches(Target &target, |
487 | 0 | const lldb::ModuleSP &module_sp) { |
488 | 0 | return false; |
489 | 0 | } |
490 | | |
491 | | virtual Status MakeDirectory(const FileSpec &file_spec, uint32_t permissions); |
492 | | |
493 | | virtual Status GetFilePermissions(const FileSpec &file_spec, |
494 | | uint32_t &file_permissions); |
495 | | |
496 | | virtual Status SetFilePermissions(const FileSpec &file_spec, |
497 | | uint32_t file_permissions); |
498 | | |
499 | | virtual lldb::user_id_t OpenFile(const FileSpec &file_spec, |
500 | | File::OpenOptions flags, uint32_t mode, |
501 | | Status &error); |
502 | | |
503 | | virtual bool CloseFile(lldb::user_id_t fd, Status &error); |
504 | | |
505 | | virtual lldb::user_id_t GetFileSize(const FileSpec &file_spec); |
506 | | |
507 | | virtual void AutoCompleteDiskFileOrDirectory(CompletionRequest &request, |
508 | 0 | bool only_dir) {} |
509 | | |
510 | | virtual uint64_t ReadFile(lldb::user_id_t fd, uint64_t offset, void *dst, |
511 | | uint64_t dst_len, Status &error); |
512 | | |
513 | | virtual uint64_t WriteFile(lldb::user_id_t fd, uint64_t offset, |
514 | | const void *src, uint64_t src_len, Status &error); |
515 | | |
516 | | virtual Status GetFile(const FileSpec &source, const FileSpec &destination); |
517 | | |
518 | | virtual Status PutFile(const FileSpec &source, const FileSpec &destination, |
519 | | uint32_t uid = UINT32_MAX, uint32_t gid = UINT32_MAX); |
520 | | |
521 | | virtual Status |
522 | | CreateSymlink(const FileSpec &src, // The name of the link is in src |
523 | | const FileSpec &dst); // The symlink points to dst |
524 | | |
525 | | /// Install a file or directory to the remote system. |
526 | | /// |
527 | | /// Install is similar to Platform::PutFile(), but it differs in that if an |
528 | | /// application/framework/shared library is installed on a remote platform |
529 | | /// and the remote platform requires something to be done to register the |
530 | | /// application/framework/shared library, then this extra registration can |
531 | | /// be done. |
532 | | /// |
533 | | /// \param[in] src |
534 | | /// The source file/directory to install on the remote system. |
535 | | /// |
536 | | /// \param[in] dst |
537 | | /// The destination file/directory where \a src will be installed. |
538 | | /// If \a dst has no filename specified, then its filename will |
539 | | /// be set from \a src. It \a dst has no directory specified, it |
540 | | /// will use the platform working directory. If \a dst has a |
541 | | /// directory specified, but the directory path is relative, the |
542 | | /// platform working directory will be prepended to the relative |
543 | | /// directory. |
544 | | /// |
545 | | /// \return |
546 | | /// An error object that describes anything that went wrong. |
547 | | virtual Status Install(const FileSpec &src, const FileSpec &dst); |
548 | | |
549 | | virtual Environment GetEnvironment(); |
550 | | |
551 | | virtual bool GetFileExists(const lldb_private::FileSpec &file_spec); |
552 | | |
553 | | virtual Status Unlink(const FileSpec &file_spec); |
554 | | |
555 | | virtual MmapArgList GetMmapArgumentList(const ArchSpec &arch, |
556 | | lldb::addr_t addr, |
557 | | lldb::addr_t length, |
558 | | unsigned prot, unsigned flags, |
559 | | lldb::addr_t fd, lldb::addr_t offset); |
560 | | |
561 | 14 | virtual bool GetSupportsRSync() { return m_supports_rsync; } |
562 | | |
563 | 0 | virtual void SetSupportsRSync(bool flag) { m_supports_rsync = flag; } |
564 | | |
565 | 0 | virtual const char *GetRSyncOpts() { return m_rsync_opts.c_str(); } |
566 | | |
567 | 0 | virtual void SetRSyncOpts(const char *opts) { m_rsync_opts.assign(opts); } |
568 | | |
569 | 0 | virtual const char *GetRSyncPrefix() { return m_rsync_prefix.c_str(); } |
570 | | |
571 | 0 | virtual void SetRSyncPrefix(const char *prefix) { |
572 | 0 | m_rsync_prefix.assign(prefix); |
573 | 0 | } |
574 | | |
575 | 13 | virtual bool GetSupportsSSH() { return m_supports_ssh; } |
576 | | |
577 | 0 | virtual void SetSupportsSSH(bool flag) { m_supports_ssh = flag; } |
578 | | |
579 | 0 | virtual const char *GetSSHOpts() { return m_ssh_opts.c_str(); } |
580 | | |
581 | 0 | virtual void SetSSHOpts(const char *opts) { m_ssh_opts.assign(opts); } |
582 | | |
583 | 0 | virtual bool GetIgnoresRemoteHostname() { return m_ignores_remote_hostname; } |
584 | | |
585 | 0 | virtual void SetIgnoresRemoteHostname(bool flag) { |
586 | 0 | m_ignores_remote_hostname = flag; |
587 | 0 | } |
588 | | |
589 | | virtual lldb_private::OptionGroupOptions * |
590 | 12 | GetConnectionOptions(CommandInterpreter &interpreter) { |
591 | 12 | return nullptr; |
592 | 12 | } |
593 | | |
594 | | virtual lldb_private::Status RunShellCommand( |
595 | | llvm::StringRef command, |
596 | | const FileSpec &working_dir, // Pass empty FileSpec to use the current |
597 | | // working directory |
598 | | int *status_ptr, // Pass nullptr if you don't want the process exit status |
599 | | int *signo_ptr, // Pass nullptr if you don't want the signal that caused |
600 | | // the process to exit |
601 | | std::string |
602 | | *command_output, // Pass nullptr if you don't want the command output |
603 | | const Timeout<std::micro> &timeout); |
604 | | |
605 | | virtual lldb_private::Status RunShellCommand( |
606 | | llvm::StringRef shell, llvm::StringRef command, |
607 | | const FileSpec &working_dir, // Pass empty FileSpec to use the current |
608 | | // working directory |
609 | | int *status_ptr, // Pass nullptr if you don't want the process exit status |
610 | | int *signo_ptr, // Pass nullptr if you don't want the signal that caused |
611 | | // the process to exit |
612 | | std::string |
613 | | *command_output, // Pass nullptr if you don't want the command output |
614 | | const Timeout<std::micro> &timeout); |
615 | | |
616 | | virtual void SetLocalCacheDirectory(const char *local); |
617 | | |
618 | | virtual const char *GetLocalCacheDirectory(); |
619 | | |
620 | 13 | virtual std::string GetPlatformSpecificConnectionInformation() { return ""; } |
621 | | |
622 | | virtual bool CalculateMD5(const FileSpec &file_spec, uint64_t &low, |
623 | | uint64_t &high); |
624 | | |
625 | 0 | virtual uint32_t GetResumeCountForLaunchInfo(ProcessLaunchInfo &launch_info) { |
626 | 0 | return 1; |
627 | 0 | } |
628 | | |
629 | | virtual const lldb::UnixSignalsSP &GetRemoteUnixSignals(); |
630 | | |
631 | | lldb::UnixSignalsSP GetUnixSignals(); |
632 | | |
633 | | /// Locate a queue name given a thread's qaddr |
634 | | /// |
635 | | /// On a system using libdispatch ("Grand Central Dispatch") style queues, a |
636 | | /// thread may be associated with a GCD queue or not, and a queue may be |
637 | | /// associated with multiple threads. The process/thread must provide a way |
638 | | /// to find the "dispatch_qaddr" for each thread, and from that |
639 | | /// dispatch_qaddr this Platform method will locate the queue name and |
640 | | /// provide that. |
641 | | /// |
642 | | /// \param[in] process |
643 | | /// A process is required for reading memory. |
644 | | /// |
645 | | /// \param[in] dispatch_qaddr |
646 | | /// The dispatch_qaddr for this thread. |
647 | | /// |
648 | | /// \return |
649 | | /// The name of the queue, if there is one. An empty string |
650 | | /// means that this thread is not associated with a dispatch |
651 | | /// queue. |
652 | | virtual std::string |
653 | 0 | GetQueueNameForThreadQAddress(Process *process, lldb::addr_t dispatch_qaddr) { |
654 | 0 | return ""; |
655 | 0 | } |
656 | | |
657 | | /// Locate a queue ID given a thread's qaddr |
658 | | /// |
659 | | /// On a system using libdispatch ("Grand Central Dispatch") style queues, a |
660 | | /// thread may be associated with a GCD queue or not, and a queue may be |
661 | | /// associated with multiple threads. The process/thread must provide a way |
662 | | /// to find the "dispatch_qaddr" for each thread, and from that |
663 | | /// dispatch_qaddr this Platform method will locate the queue ID and provide |
664 | | /// that. |
665 | | /// |
666 | | /// \param[in] process |
667 | | /// A process is required for reading memory. |
668 | | /// |
669 | | /// \param[in] dispatch_qaddr |
670 | | /// The dispatch_qaddr for this thread. |
671 | | /// |
672 | | /// \return |
673 | | /// The queue_id for this thread, if this thread is associated |
674 | | /// with a dispatch queue. Else LLDB_INVALID_QUEUE_ID is returned. |
675 | | virtual lldb::queue_id_t |
676 | 0 | GetQueueIDForThreadQAddress(Process *process, lldb::addr_t dispatch_qaddr) { |
677 | 0 | return LLDB_INVALID_QUEUE_ID; |
678 | 0 | } |
679 | | |
680 | | /// Provide a list of trap handler function names for this platform |
681 | | /// |
682 | | /// The unwinder needs to treat trap handlers specially -- the stack frame |
683 | | /// may not be aligned correctly for a trap handler (the kernel often won't |
684 | | /// perturb the stack pointer, or won't re-align it properly, in the process |
685 | | /// of calling the handler) and the frame above the handler needs to be |
686 | | /// treated by the unwinder's "frame 0" rules instead of its "middle of the |
687 | | /// stack frame" rules. |
688 | | /// |
689 | | /// In a user process debugging scenario, the list of trap handlers is |
690 | | /// typically just "_sigtramp". |
691 | | /// |
692 | | /// The Platform base class provides the m_trap_handlers ivar but it does |
693 | | /// not populate it. Subclasses should add the names of the asynchronous |
694 | | /// signal handler routines as needed. For most Unix platforms, add |
695 | | /// _sigtramp. |
696 | | /// |
697 | | /// \return |
698 | | /// A list of symbol names. The list may be empty. |
699 | | virtual const std::vector<ConstString> &GetTrapHandlerSymbolNames(); |
700 | | |
701 | | /// Try to get a specific unwind plan for a named trap handler. |
702 | | /// The default is not to have specific unwind plans for trap handlers. |
703 | | /// |
704 | | /// \param[in] triple |
705 | | /// Triple of the current target. |
706 | | /// |
707 | | /// \param[in] name |
708 | | /// Name of the trap handler function. |
709 | | /// |
710 | | /// \return |
711 | | /// A specific unwind plan for that trap handler, or an empty |
712 | | /// shared pointer. The latter means there is no specific plan, |
713 | | /// unwind as normal. |
714 | | virtual lldb::UnwindPlanSP |
715 | 9 | GetTrapHandlerUnwindPlan(const llvm::Triple &triple, ConstString name) { |
716 | 9 | return {}; |
717 | 9 | } |
718 | | |
719 | | /// Find a support executable that may not live within in the standard |
720 | | /// locations related to LLDB. |
721 | | /// |
722 | | /// Executable might exist within the Platform SDK directories, or in |
723 | | /// standard tool directories within the current IDE that is running LLDB. |
724 | | /// |
725 | | /// \param[in] basename |
726 | | /// The basename of the executable to locate in the current |
727 | | /// platform. |
728 | | /// |
729 | | /// \return |
730 | | /// A FileSpec pointing to the executable on disk, or an invalid |
731 | | /// FileSpec if the executable cannot be found. |
732 | 0 | virtual FileSpec LocateExecutable(const char *basename) { return FileSpec(); } |
733 | | |
734 | | /// Allow the platform to set preferred memory cache line size. If non-zero |
735 | | /// (and the user has not set cache line size explicitly), this value will |
736 | | /// be used as the cache line size for memory reads. |
737 | 2.64k | virtual uint32_t GetDefaultMemoryCacheLineSize() { return 0; } |
738 | | |
739 | | /// Load a shared library into this process. |
740 | | /// |
741 | | /// Try and load a shared library into the current process. This call might |
742 | | /// fail in the dynamic loader plug-in says it isn't safe to try and load |
743 | | /// shared libraries at the moment. |
744 | | /// |
745 | | /// \param[in] process |
746 | | /// The process to load the image. |
747 | | /// |
748 | | /// \param[in] local_file |
749 | | /// The file spec that points to the shared library that you want |
750 | | /// to load if the library is located on the host. The library will |
751 | | /// be copied over to the location specified by remote_file or into |
752 | | /// the current working directory with the same filename if the |
753 | | /// remote_file isn't specified. |
754 | | /// |
755 | | /// \param[in] remote_file |
756 | | /// If local_file is specified then the location where the library |
757 | | /// should be copied over from the host. If local_file isn't |
758 | | /// specified, then the path for the shared library on the target |
759 | | /// what you want to load. |
760 | | /// |
761 | | /// \param[out] error |
762 | | /// An error object that gets filled in with any errors that |
763 | | /// might occur when trying to load the shared library. |
764 | | /// |
765 | | /// \return |
766 | | /// A token that represents the shared library that can be |
767 | | /// later used to unload the shared library. A value of |
768 | | /// LLDB_INVALID_IMAGE_TOKEN will be returned if the shared |
769 | | /// library can't be opened. |
770 | | uint32_t LoadImage(lldb_private::Process *process, |
771 | | const lldb_private::FileSpec &local_file, |
772 | | const lldb_private::FileSpec &remote_file, |
773 | | lldb_private::Status &error); |
774 | | |
775 | | /// Load a shared library specified by base name into this process, |
776 | | /// looking by hand along a set of paths. |
777 | | /// |
778 | | /// \param[in] process |
779 | | /// The process to load the image. |
780 | | /// |
781 | | /// \param[in] library_name |
782 | | /// The name of the library to look for. If library_name is an |
783 | | /// absolute path, the basename will be extracted and searched for |
784 | | /// along the paths. This emulates the behavior of the loader when |
785 | | /// given an install name and a set (e.g. DYLD_LIBRARY_PATH provided) of |
786 | | /// alternate paths. |
787 | | /// |
788 | | /// \param[in] paths |
789 | | /// The list of paths to use to search for the library. First |
790 | | /// match wins. |
791 | | /// |
792 | | /// \param[out] error |
793 | | /// An error object that gets filled in with any errors that |
794 | | /// might occur when trying to load the shared library. |
795 | | /// |
796 | | /// \param[out] loaded_path |
797 | | /// If non-null, the path to the dylib that was successfully loaded |
798 | | /// is stored in this path. |
799 | | /// |
800 | | /// \return |
801 | | /// A token that represents the shared library which can be |
802 | | /// passed to UnloadImage. A value of |
803 | | /// LLDB_INVALID_IMAGE_TOKEN will be returned if the shared |
804 | | /// library can't be opened. |
805 | | uint32_t LoadImageUsingPaths(lldb_private::Process *process, |
806 | | const lldb_private::FileSpec &library_name, |
807 | | const std::vector<std::string> &paths, |
808 | | lldb_private::Status &error, |
809 | | lldb_private::FileSpec *loaded_path); |
810 | | |
811 | | virtual uint32_t DoLoadImage(lldb_private::Process *process, |
812 | | const lldb_private::FileSpec &remote_file, |
813 | | const std::vector<std::string> *paths, |
814 | | lldb_private::Status &error, |
815 | | lldb_private::FileSpec *loaded_path = nullptr); |
816 | | |
817 | | virtual Status UnloadImage(lldb_private::Process *process, |
818 | | uint32_t image_token); |
819 | | |
820 | | /// Connect to all processes waiting for a debugger to attach |
821 | | /// |
822 | | /// If the platform have a list of processes waiting for a debugger to |
823 | | /// connect to them then connect to all of these pending processes. |
824 | | /// |
825 | | /// \param[in] debugger |
826 | | /// The debugger used for the connect. |
827 | | /// |
828 | | /// \param[out] error |
829 | | /// If an error occurred during the connect then this object will |
830 | | /// contain the error message. |
831 | | /// |
832 | | /// \return |
833 | | /// The number of processes we are successfully connected to. |
834 | | virtual size_t ConnectToWaitingProcesses(lldb_private::Debugger &debugger, |
835 | | lldb_private::Status &error); |
836 | | |
837 | | /// Gather all of crash informations into a structured data dictionary. |
838 | | /// |
839 | | /// If the platform have a crashed process with crash information entries, |
840 | | /// gather all the entries into an structured data dictionary or return a |
841 | | /// nullptr. This dictionary is generic and extensible, as it contains an |
842 | | /// array for each different type of crash information. |
843 | | /// |
844 | | /// \param[in] process |
845 | | /// The crashed process. |
846 | | /// |
847 | | /// \return |
848 | | /// A structured data dictionary containing at each entry, the crash |
849 | | /// information type as the entry key and the matching an array as the |
850 | | /// entry value. \b nullptr if not implemented or if the process has no |
851 | | /// crash information entry. \b error if an error occured. |
852 | | virtual llvm::Expected<StructuredData::DictionarySP> |
853 | 0 | FetchExtendedCrashInformation(lldb_private::Process &process) { |
854 | 0 | return nullptr; |
855 | 0 | } |
856 | | |
857 | | /// Detect a binary in memory that will determine which Platform and |
858 | | /// DynamicLoader should be used in this target/process, and update |
859 | | /// the Platform/DynamicLoader. |
860 | | /// The binary will be loaded into the Target, or will be registered with |
861 | | /// the DynamicLoader so that it will be loaded at a later stage. Returns |
862 | | /// true to indicate that this is a platform binary and has been |
863 | | /// loaded/registered, no further action should be taken by the caller. |
864 | | /// |
865 | | /// \param[in] process |
866 | | /// Process read memory from, a Process must be provided. |
867 | | /// |
868 | | /// \param[in] addr |
869 | | /// Address of a binary in memory. |
870 | | /// |
871 | | /// \param[in] notify |
872 | | /// Whether ModulesDidLoad should be called, if a binary is loaded. |
873 | | /// Caller may prefer to call ModulesDidLoad for multiple binaries |
874 | | /// that were loaded at the same time. |
875 | | /// |
876 | | /// \return |
877 | | /// Returns true if the binary was loaded in the target (or will be |
878 | | /// via a DynamicLoader). Returns false if the binary was not |
879 | | /// loaded/registered, and the caller must load it into the target. |
880 | | virtual bool LoadPlatformBinaryAndSetup(Process *process, lldb::addr_t addr, |
881 | 64 | bool notify) { |
882 | 64 | return false; |
883 | 64 | } |
884 | | |
885 | | virtual CompilerType GetSiginfoType(const llvm::Triple &triple); |
886 | | |
887 | | virtual Args GetExtraStartupCommands(); |
888 | | |
889 | | typedef std::function<Status(const ModuleSpec &module_spec, |
890 | | FileSpec &module_file_spec, |
891 | | FileSpec &symbol_file_spec)> |
892 | | LocateModuleCallback; |
893 | | |
894 | | /// Set locate module callback. This allows users to implement their own |
895 | | /// module cache system. For example, to leverage artifacts of build system, |
896 | | /// to bypass pulling files from remote platform, or to search symbol files |
897 | | /// from symbol servers. |
898 | | void SetLocateModuleCallback(LocateModuleCallback callback); |
899 | | |
900 | | LocateModuleCallback GetLocateModuleCallback() const; |
901 | | |
902 | | protected: |
903 | | /// Create a list of ArchSpecs with the given OS and a architectures. The |
904 | | /// vendor field is left as an "unspecified unknown". |
905 | | static std::vector<ArchSpec> |
906 | | CreateArchList(llvm::ArrayRef<llvm::Triple::ArchType> archs, |
907 | | llvm::Triple::OSType os); |
908 | | |
909 | | /// Private implementation of connecting to a process. If the stream is set |
910 | | /// we connect synchronously. |
911 | | lldb::ProcessSP DoConnectProcess(llvm::StringRef connect_url, |
912 | | llvm::StringRef plugin_name, |
913 | | Debugger &debugger, Stream *stream, |
914 | | Target *target, Status &error); |
915 | | bool m_is_host; |
916 | | // Set to true when we are able to actually set the OS version while being |
917 | | // connected. For remote platforms, we might set the version ahead of time |
918 | | // before we actually connect and this version might change when we actually |
919 | | // connect to a remote platform. For the host platform this will be set to |
920 | | // the once we call HostInfo::GetOSVersion(). |
921 | | bool m_os_version_set_while_connected; |
922 | | bool m_system_arch_set_while_connected; |
923 | | std::string |
924 | | m_sdk_sysroot; // the root location of where the SDK files are all located |
925 | | std::string m_sdk_build; |
926 | | FileSpec m_working_dir; // The working directory which is used when installing |
927 | | // modules that have no install path set |
928 | | std::string m_remote_url; |
929 | | std::string m_hostname; |
930 | | llvm::VersionTuple m_os_version; |
931 | | ArchSpec |
932 | | m_system_arch; // The architecture of the kernel or the remote platform |
933 | | typedef std::map<uint32_t, ConstString> IDToNameMap; |
934 | | // Mutex for modifying Platform data structures that should only be used for |
935 | | // non-reentrant code |
936 | | std::mutex m_mutex; |
937 | | size_t m_max_uid_name_len; |
938 | | size_t m_max_gid_name_len; |
939 | | bool m_supports_rsync; |
940 | | std::string m_rsync_opts; |
941 | | std::string m_rsync_prefix; |
942 | | bool m_supports_ssh; |
943 | | std::string m_ssh_opts; |
944 | | bool m_ignores_remote_hostname; |
945 | | std::string m_local_cache_directory; |
946 | | std::vector<ConstString> m_trap_handlers; |
947 | | bool m_calculated_trap_handlers; |
948 | | const std::unique_ptr<ModuleCache> m_module_cache; |
949 | | LocateModuleCallback m_locate_module_callback; |
950 | | |
951 | | /// Ask the Platform subclass to fill in the list of trap handler names |
952 | | /// |
953 | | /// For most Unix user process environments, this will be a single function |
954 | | /// name, _sigtramp. More specialized environments may have additional |
955 | | /// handler names. The unwinder code needs to know when a trap handler is |
956 | | /// on the stack because the unwind rules for the frame that caused the trap |
957 | | /// are different. |
958 | | /// |
959 | | /// The base class Platform ivar m_trap_handlers should be updated by the |
960 | | /// Platform subclass when this method is called. If there are no |
961 | | /// predefined trap handlers, this method may be a no-op. |
962 | | virtual void CalculateTrapHandlerSymbolNames() = 0; |
963 | | |
964 | | Status GetCachedExecutable(ModuleSpec &module_spec, lldb::ModuleSP &module_sp, |
965 | | const FileSpecList *module_search_paths_ptr); |
966 | | |
967 | | virtual Status DownloadModuleSlice(const FileSpec &src_file_spec, |
968 | | const uint64_t src_offset, |
969 | | const uint64_t src_size, |
970 | | const FileSpec &dst_file_spec); |
971 | | |
972 | | virtual Status DownloadSymbolFile(const lldb::ModuleSP &module_sp, |
973 | | const FileSpec &dst_file_spec); |
974 | | |
975 | | virtual const char *GetCacheHostname(); |
976 | | |
977 | | virtual Status |
978 | | ResolveRemoteExecutable(const ModuleSpec &module_spec, |
979 | | lldb::ModuleSP &exe_module_sp, |
980 | | const FileSpecList *module_search_paths_ptr); |
981 | | |
982 | | private: |
983 | | typedef std::function<Status(const ModuleSpec &)> ModuleResolver; |
984 | | |
985 | | Status GetRemoteSharedModule(const ModuleSpec &module_spec, Process *process, |
986 | | lldb::ModuleSP &module_sp, |
987 | | const ModuleResolver &module_resolver, |
988 | | bool *did_create_ptr); |
989 | | |
990 | | bool GetCachedSharedModule(const ModuleSpec &module_spec, |
991 | | lldb::ModuleSP &module_sp, bool *did_create_ptr); |
992 | | |
993 | | FileSpec GetModuleCacheRoot(); |
994 | | }; |
995 | | |
996 | | class PlatformList { |
997 | | public: |
998 | 6.10k | PlatformList() = default; |
999 | | |
1000 | 6.09k | ~PlatformList() = default; |
1001 | | |
1002 | 6.10k | void Append(const lldb::PlatformSP &platform_sp, bool set_selected) { |
1003 | 6.10k | std::lock_guard<std::recursive_mutex> guard(m_mutex); |
1004 | 6.10k | m_platforms.push_back(platform_sp); |
1005 | 6.10k | if (set_selected) |
1006 | 6.10k | m_selected_platform_sp = m_platforms.back(); |
1007 | 6.10k | } |
1008 | | |
1009 | 3 | size_t GetSize() { |
1010 | 3 | std::lock_guard<std::recursive_mutex> guard(m_mutex); |
1011 | 3 | return m_platforms.size(); |
1012 | 3 | } |
1013 | | |
1014 | 4 | lldb::PlatformSP GetAtIndex(uint32_t idx) { |
1015 | 4 | lldb::PlatformSP platform_sp; |
1016 | 4 | { |
1017 | 4 | std::lock_guard<std::recursive_mutex> guard(m_mutex); |
1018 | 4 | if (idx < m_platforms.size()) |
1019 | 4 | platform_sp = m_platforms[idx]; |
1020 | 4 | } |
1021 | 4 | return platform_sp; |
1022 | 4 | } |
1023 | | |
1024 | | /// Select the active platform. |
1025 | | /// |
1026 | | /// In order to debug remotely, other platform's can be remotely connected |
1027 | | /// to and set as the selected platform for any subsequent debugging. This |
1028 | | /// allows connection to remote targets and allows the ability to discover |
1029 | | /// process info, launch and attach to remote processes. |
1030 | 34.7k | lldb::PlatformSP GetSelectedPlatform() { |
1031 | 34.7k | std::lock_guard<std::recursive_mutex> guard(m_mutex); |
1032 | 34.7k | if (!m_selected_platform_sp && !m_platforms.empty()0 ) |
1033 | 0 | m_selected_platform_sp = m_platforms.front(); |
1034 | | |
1035 | 34.7k | return m_selected_platform_sp; |
1036 | 34.7k | } |
1037 | | |
1038 | 3.39k | void SetSelectedPlatform(const lldb::PlatformSP &platform_sp) { |
1039 | 3.39k | if (platform_sp) { |
1040 | 3.39k | std::lock_guard<std::recursive_mutex> guard(m_mutex); |
1041 | 3.39k | const size_t num_platforms = m_platforms.size(); |
1042 | 3.52k | for (size_t idx = 0; idx < num_platforms; ++idx135 ) { |
1043 | 3.52k | if (m_platforms[idx].get() == platform_sp.get()) { |
1044 | 3.38k | m_selected_platform_sp = m_platforms[idx]; |
1045 | 3.38k | return; |
1046 | 3.38k | } |
1047 | 3.52k | } |
1048 | 5 | m_platforms.push_back(platform_sp); |
1049 | 5 | m_selected_platform_sp = m_platforms.back(); |
1050 | 5 | } |
1051 | 3.39k | } |
1052 | | |
1053 | | lldb::PlatformSP GetOrCreate(llvm::StringRef name); |
1054 | | lldb::PlatformSP GetOrCreate(const ArchSpec &arch, |
1055 | | const ArchSpec &process_host_arch, |
1056 | | ArchSpec *platform_arch_ptr, Status &error); |
1057 | | lldb::PlatformSP GetOrCreate(const ArchSpec &arch, |
1058 | | const ArchSpec &process_host_arch, |
1059 | | ArchSpec *platform_arch_ptr); |
1060 | | |
1061 | | /// Get the platform for the given list of architectures. |
1062 | | /// |
1063 | | /// The algorithm works a follows: |
1064 | | /// |
1065 | | /// 1. Returns the selected platform if it matches any of the architectures. |
1066 | | /// 2. Returns the host platform if it matches any of the architectures. |
1067 | | /// 3. Returns the platform that matches all the architectures. |
1068 | | /// |
1069 | | /// If none of the above apply, this function returns a default platform. The |
1070 | | /// candidates output argument differentiates between either no platforms |
1071 | | /// supporting the given architecture or multiple platforms supporting the |
1072 | | /// given architecture. |
1073 | | lldb::PlatformSP GetOrCreate(llvm::ArrayRef<ArchSpec> archs, |
1074 | | const ArchSpec &process_host_arch, |
1075 | | std::vector<lldb::PlatformSP> &candidates); |
1076 | | |
1077 | | lldb::PlatformSP Create(llvm::StringRef name); |
1078 | | |
1079 | | /// Detect a binary in memory that will determine which Platform and |
1080 | | /// DynamicLoader should be used in this target/process, and update |
1081 | | /// the Platform/DynamicLoader. |
1082 | | /// The binary will be loaded into the Target, or will be registered with |
1083 | | /// the DynamicLoader so that it will be loaded at a later stage. Returns |
1084 | | /// true to indicate that this is a platform binary and has been |
1085 | | /// loaded/registered, no further action should be taken by the caller. |
1086 | | /// |
1087 | | /// \param[in] process |
1088 | | /// Process read memory from, a Process must be provided. |
1089 | | /// |
1090 | | /// \param[in] addr |
1091 | | /// Address of a binary in memory. |
1092 | | /// |
1093 | | /// \param[in] notify |
1094 | | /// Whether ModulesDidLoad should be called, if a binary is loaded. |
1095 | | /// Caller may prefer to call ModulesDidLoad for multiple binaries |
1096 | | /// that were loaded at the same time. |
1097 | | /// |
1098 | | /// \return |
1099 | | /// Returns true if the binary was loaded in the target (or will be |
1100 | | /// via a DynamicLoader). Returns false if the binary was not |
1101 | | /// loaded/registered, and the caller must load it into the target. |
1102 | | bool LoadPlatformBinaryAndSetup(Process *process, lldb::addr_t addr, |
1103 | | bool notify); |
1104 | | |
1105 | | protected: |
1106 | | typedef std::vector<lldb::PlatformSP> collection; |
1107 | | mutable std::recursive_mutex m_mutex; |
1108 | | collection m_platforms; |
1109 | | lldb::PlatformSP m_selected_platform_sp; |
1110 | | |
1111 | | private: |
1112 | | PlatformList(const PlatformList &) = delete; |
1113 | | const PlatformList &operator=(const PlatformList &) = delete; |
1114 | | }; |
1115 | | |
1116 | | class OptionGroupPlatformRSync : public lldb_private::OptionGroup { |
1117 | | public: |
1118 | 4.29k | OptionGroupPlatformRSync() = default; |
1119 | | |
1120 | 4.24k | ~OptionGroupPlatformRSync() override = default; |
1121 | | |
1122 | | lldb_private::Status |
1123 | | SetOptionValue(uint32_t option_idx, llvm::StringRef option_value, |
1124 | | ExecutionContext *execution_context) override; |
1125 | | |
1126 | | void OptionParsingStarting(ExecutionContext *execution_context) override; |
1127 | | |
1128 | | llvm::ArrayRef<OptionDefinition> GetDefinitions() override; |
1129 | | |
1130 | | // Instance variables to hold the values for command options. |
1131 | | |
1132 | | bool m_rsync; |
1133 | | std::string m_rsync_opts; |
1134 | | std::string m_rsync_prefix; |
1135 | | bool m_ignores_remote_hostname; |
1136 | | |
1137 | | private: |
1138 | | OptionGroupPlatformRSync(const OptionGroupPlatformRSync &) = delete; |
1139 | | const OptionGroupPlatformRSync & |
1140 | | operator=(const OptionGroupPlatformRSync &) = delete; |
1141 | | }; |
1142 | | |
1143 | | class OptionGroupPlatformSSH : public lldb_private::OptionGroup { |
1144 | | public: |
1145 | 4.29k | OptionGroupPlatformSSH() = default; |
1146 | | |
1147 | 4.24k | ~OptionGroupPlatformSSH() override = default; |
1148 | | |
1149 | | lldb_private::Status |
1150 | | SetOptionValue(uint32_t option_idx, llvm::StringRef option_value, |
1151 | | ExecutionContext *execution_context) override; |
1152 | | |
1153 | | void OptionParsingStarting(ExecutionContext *execution_context) override; |
1154 | | |
1155 | | llvm::ArrayRef<OptionDefinition> GetDefinitions() override; |
1156 | | |
1157 | | // Instance variables to hold the values for command options. |
1158 | | |
1159 | | bool m_ssh; |
1160 | | std::string m_ssh_opts; |
1161 | | |
1162 | | private: |
1163 | | OptionGroupPlatformSSH(const OptionGroupPlatformSSH &) = delete; |
1164 | | const OptionGroupPlatformSSH & |
1165 | | operator=(const OptionGroupPlatformSSH &) = delete; |
1166 | | }; |
1167 | | |
1168 | | class OptionGroupPlatformCaching : public lldb_private::OptionGroup { |
1169 | | public: |
1170 | 4.29k | OptionGroupPlatformCaching() = default; |
1171 | | |
1172 | 4.24k | ~OptionGroupPlatformCaching() override = default; |
1173 | | |
1174 | | lldb_private::Status |
1175 | | SetOptionValue(uint32_t option_idx, llvm::StringRef option_value, |
1176 | | ExecutionContext *execution_context) override; |
1177 | | |
1178 | | void OptionParsingStarting(ExecutionContext *execution_context) override; |
1179 | | |
1180 | | llvm::ArrayRef<OptionDefinition> GetDefinitions() override; |
1181 | | |
1182 | | // Instance variables to hold the values for command options. |
1183 | | |
1184 | | std::string m_cache_dir; |
1185 | | |
1186 | | private: |
1187 | | OptionGroupPlatformCaching(const OptionGroupPlatformCaching &) = delete; |
1188 | | const OptionGroupPlatformCaching & |
1189 | | operator=(const OptionGroupPlatformCaching &) = delete; |
1190 | | }; |
1191 | | |
1192 | | } // namespace lldb_private |
1193 | | |
1194 | | #endif // LLDB_TARGET_PLATFORM_H |