Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:42:54

0001 //===-- Platform.h ----------------------------------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLDB_TARGET_PLATFORM_H
0010 #define LLDB_TARGET_PLATFORM_H
0011 
0012 #include <functional>
0013 #include <map>
0014 #include <memory>
0015 #include <mutex>
0016 #include <optional>
0017 #include <string>
0018 #include <vector>
0019 
0020 #include "lldb/Core/PluginInterface.h"
0021 #include "lldb/Core/UserSettingsController.h"
0022 #include "lldb/Host/File.h"
0023 #include "lldb/Interpreter/Options.h"
0024 #include "lldb/Utility/ArchSpec.h"
0025 #include "lldb/Utility/ConstString.h"
0026 #include "lldb/Utility/FileSpec.h"
0027 #include "lldb/Utility/StructuredData.h"
0028 #include "lldb/Utility/Timeout.h"
0029 #include "lldb/Utility/UserIDResolver.h"
0030 #include "lldb/Utility/XcodeSDK.h"
0031 #include "lldb/lldb-private-forward.h"
0032 #include "lldb/lldb-public.h"
0033 
0034 #include "llvm/Support/Compiler.h"
0035 #include "llvm/Support/Error.h"
0036 #include "llvm/Support/VersionTuple.h"
0037 
0038 namespace lldb_private {
0039 
0040 class ProcessInstanceInfo;
0041 class ProcessInstanceInfoMatch;
0042 typedef std::vector<ProcessInstanceInfo> ProcessInstanceInfoList;
0043 
0044 class ModuleCache;
0045 enum MmapFlags { eMmapFlagsPrivate = 1, eMmapFlagsAnon = 2 };
0046 
0047 class PlatformProperties : public Properties {
0048 public:
0049   PlatformProperties();
0050 
0051   static llvm::StringRef GetSettingName();
0052 
0053   bool GetUseModuleCache() const;
0054   bool SetUseModuleCache(bool use_module_cache);
0055 
0056   FileSpec GetModuleCacheDirectory() const;
0057   bool SetModuleCacheDirectory(const FileSpec &dir_spec);
0058 
0059 private:
0060   void SetDefaultModuleCacheDirectory(const FileSpec &dir_spec);
0061 };
0062 
0063 typedef llvm::SmallVector<lldb::addr_t, 6> MmapArgList;
0064 
0065 /// \class Platform Platform.h "lldb/Target/Platform.h"
0066 /// A plug-in interface definition class for debug platform that
0067 /// includes many platform abilities such as:
0068 ///     \li getting platform information such as supported architectures,
0069 ///         supported binary file formats and more
0070 ///     \li launching new processes
0071 ///     \li attaching to existing processes
0072 ///     \li download/upload files
0073 ///     \li execute shell commands
0074 ///     \li listing and getting info for existing processes
0075 ///     \li attaching and possibly debugging the platform's kernel
0076 class Platform : public PluginInterface {
0077 public:
0078   /// Default Constructor
0079   Platform(bool is_host_platform);
0080 
0081   /// The destructor is virtual since this class is designed to be inherited
0082   /// from by the plug-in instance.
0083   ~Platform() override;
0084 
0085   static void Initialize();
0086 
0087   static void Terminate();
0088 
0089   static PlatformProperties &GetGlobalPlatformProperties();
0090 
0091   /// Get the native host platform plug-in.
0092   ///
0093   /// There should only be one of these for each host that LLDB runs upon that
0094   /// should be statically compiled in and registered using preprocessor
0095   /// macros or other similar build mechanisms in a
0096   /// PlatformSubclass::Initialize() function.
0097   ///
0098   /// This platform will be used as the default platform when launching or
0099   /// attaching to processes unless another platform is specified.
0100   static lldb::PlatformSP GetHostPlatform();
0101 
0102   static const char *GetHostPlatformName();
0103 
0104   static void SetHostPlatform(const lldb::PlatformSP &platform_sp);
0105 
0106   static lldb::PlatformSP Create(llvm::StringRef name);
0107 
0108   /// Augments the triple either with information from platform or the host
0109   /// system (if platform is null).
0110   static ArchSpec GetAugmentedArchSpec(Platform *platform,
0111                                        llvm::StringRef triple);
0112 
0113   /// Set the target's executable based off of the existing architecture
0114   /// information in \a target given a path to an executable \a exe_file.
0115   ///
0116   /// Each platform knows the architectures that it supports and can select
0117   /// the correct architecture slice within \a exe_file by inspecting the
0118   /// architecture in \a target. If the target had an architecture specified,
0119   /// then in can try and obey that request and optionally fail if the
0120   /// architecture doesn't match up. If no architecture is specified, the
0121   /// platform should select the default architecture from \a exe_file. Any
0122   /// application bundles or executable wrappers can also be inspected for the
0123   /// actual application binary within the bundle that should be used.
0124   ///
0125   /// \return
0126   ///     Returns \b true if this Platform plug-in was able to find
0127   ///     a suitable executable, \b false otherwise.
0128   virtual Status ResolveExecutable(const ModuleSpec &module_spec,
0129                                    lldb::ModuleSP &exe_module_sp,
0130                                    const FileSpecList *module_search_paths_ptr);
0131 
0132   /// Find a symbol file given a symbol file module specification.
0133   ///
0134   /// Each platform might have tricks to find symbol files for an executable
0135   /// given information in a symbol file ModuleSpec. Some platforms might also
0136   /// support symbol files that are bundles and know how to extract the right
0137   /// symbol file given a bundle.
0138   ///
0139   /// \param[in] target
0140   ///     The target in which we are trying to resolve the symbol file.
0141   ///     The target has a list of modules that we might be able to
0142   ///     use in order to help find the right symbol file. If the
0143   ///     "m_file" or "m_platform_file" entries in the \a sym_spec
0144   ///     are filled in, then we might be able to locate a module in
0145   ///     the target, extract its UUID and locate a symbol file.
0146   ///     If just the "m_uuid" is specified, then we might be able
0147   ///     to find the module in the target that matches that UUID
0148   ///     and pair the symbol file along with it. If just "m_symbol_file"
0149   ///     is specified, we can use a variety of tricks to locate the
0150   ///     symbols in an SDK, PDK, or other development kit location.
0151   ///
0152   /// \param[in] sym_spec
0153   ///     A module spec that describes some information about the
0154   ///     symbol file we are trying to resolve. The ModuleSpec might
0155   ///     contain the following:
0156   ///     m_file - A full or partial path to an executable from the
0157   ///              target (might be empty).
0158   ///     m_platform_file - Another executable hint that contains
0159   ///                       the path to the file as known on the
0160   ///                       local/remote platform.
0161   ///     m_symbol_file - A full or partial path to a symbol file
0162   ///                     or symbol bundle that should be used when
0163   ///                     trying to resolve the symbol file.
0164   ///     m_arch - The architecture we are looking for when resolving
0165   ///              the symbol file.
0166   ///     m_uuid - The UUID of the executable and symbol file. This
0167   ///              can often be used to match up an executable with
0168   ///              a symbol file, or resolve an symbol file in a
0169   ///              symbol file bundle.
0170   ///
0171   /// \param[out] sym_file
0172   ///     The resolved symbol file spec if the returned error
0173   ///     indicates success.
0174   ///
0175   /// \return
0176   ///     Returns an error that describes success or failure.
0177   virtual Status ResolveSymbolFile(Target &target, const ModuleSpec &sym_spec,
0178                                    FileSpec &sym_file);
0179 
0180   /// Resolves the FileSpec to a (possibly) remote path. Remote platforms must
0181   /// override this to resolve to a path on the remote side.
0182   virtual bool ResolveRemotePath(const FileSpec &platform_path,
0183                                  FileSpec &resolved_platform_path);
0184 
0185   /// Get the OS version from a connected platform.
0186   ///
0187   /// Some platforms might not be connected to a remote platform, but can
0188   /// figure out the OS version for a process. This is common for simulator
0189   /// platforms that will run native programs on the current host, but the
0190   /// simulator might be simulating a different OS. The \a process parameter
0191   /// might be specified to help to determine the OS version.
0192   virtual llvm::VersionTuple GetOSVersion(Process *process = nullptr);
0193 
0194   bool SetOSVersion(llvm::VersionTuple os_version);
0195 
0196   std::optional<std::string> GetOSBuildString();
0197 
0198   std::optional<std::string> GetOSKernelDescription();
0199 
0200   // Returns the name of the platform
0201   llvm::StringRef GetName() { return GetPluginName(); }
0202 
0203   virtual const char *GetHostname();
0204 
0205   virtual ConstString GetFullNameForDylib(ConstString basename);
0206 
0207   virtual llvm::StringRef GetDescription() = 0;
0208 
0209   /// Report the current status for this platform.
0210   ///
0211   /// The returned string usually involves returning the OS version (if
0212   /// available), and any SDK directory that might be being used for local
0213   /// file caching, and if connected a quick blurb about what this platform is
0214   /// connected to.
0215   virtual void GetStatus(Stream &strm);
0216 
0217   // Subclasses must be able to fetch the current OS version
0218   //
0219   // Remote classes must be connected for this to succeed. Local subclasses
0220   // don't need to override this function as it will just call the
0221   // HostInfo::GetOSVersion().
0222   virtual bool GetRemoteOSVersion() { return false; }
0223 
0224   virtual std::optional<std::string> GetRemoteOSBuildString() {
0225     return std::nullopt;
0226   }
0227 
0228   virtual std::optional<std::string> GetRemoteOSKernelDescription() {
0229     return std::nullopt;
0230   }
0231 
0232   // Remote Platform subclasses need to override this function
0233   virtual ArchSpec GetRemoteSystemArchitecture() {
0234     return ArchSpec(); // Return an invalid architecture
0235   }
0236 
0237   virtual FileSpec GetRemoteWorkingDirectory() { return m_working_dir; }
0238 
0239   virtual bool SetRemoteWorkingDirectory(const FileSpec &working_dir);
0240 
0241   virtual UserIDResolver &GetUserIDResolver();
0242 
0243   /// Locate a file for a platform.
0244   ///
0245   /// The default implementation of this function will return the same file
0246   /// patch in \a local_file as was in \a platform_file.
0247   ///
0248   /// \param[in] platform_file
0249   ///     The platform file path to locate and cache locally.
0250   ///
0251   /// \param[in] uuid_ptr
0252   ///     If we know the exact UUID of the file we are looking for, it
0253   ///     can be specified. If it is not specified, we might now know
0254   ///     the exact file. The UUID is usually some sort of MD5 checksum
0255   ///     for the file and is sometimes known by dynamic linkers/loaders.
0256   ///     If the UUID is known, it is best to supply it to platform
0257   ///     file queries to ensure we are finding the correct file, not
0258   ///     just a file at the correct path.
0259   ///
0260   /// \param[out] local_file
0261   ///     A locally cached version of the platform file. For platforms
0262   ///     that describe the current host computer, this will just be
0263   ///     the same file. For remote platforms, this file might come from
0264   ///     and SDK directory, or might need to be sync'ed over to the
0265   ///     current machine for efficient debugging access.
0266   ///
0267   /// \return
0268   ///     An error object.
0269   virtual Status GetFileWithUUID(const FileSpec &platform_file,
0270                                  const UUID *uuid_ptr, FileSpec &local_file);
0271 
0272   // Locate the scripting resource given a module specification.
0273   //
0274   // Locating the file should happen only on the local computer or using the
0275   // current computers global settings.
0276   virtual FileSpecList
0277   LocateExecutableScriptingResources(Target *target, Module &module,
0278                                      Stream &feedback_stream);
0279 
0280   /// \param[in] module_spec
0281   ///     The ModuleSpec of a binary to find.
0282   ///
0283   /// \param[in] process
0284   ///     A Process.
0285   ///
0286   /// \param[out] module_sp
0287   ///     A Module that matches the ModuleSpec, if one is found.
0288   ///
0289   /// \param[in] module_search_paths_ptr
0290   ///     Locations to possibly look for a binary that matches the ModuleSpec.
0291   ///
0292   /// \param[out] old_modules
0293   ///     Existing Modules in the Process' Target image list which match
0294   ///     the FileSpec.
0295   ///
0296   /// \param[out] did_create_ptr
0297   ///     Optional boolean, nullptr may be passed for this argument.
0298   ///     If this method is returning a *new* ModuleSP, this
0299   ///     will be set to true.
0300   ///     If this method is returning a ModuleSP that is already in the
0301   ///     Target's image list, it will be false.
0302   ///
0303   /// \return
0304   ///     The Status object for any errors found while searching for
0305   ///     the binary.
0306   virtual Status GetSharedModule(
0307       const ModuleSpec &module_spec, Process *process,
0308       lldb::ModuleSP &module_sp, const FileSpecList *module_search_paths_ptr,
0309       llvm::SmallVectorImpl<lldb::ModuleSP> *old_modules, bool *did_create_ptr);
0310 
0311   void CallLocateModuleCallbackIfSet(const ModuleSpec &module_spec,
0312                                      lldb::ModuleSP &module_sp,
0313                                      FileSpec &symbol_file_spec,
0314                                      bool *did_create_ptr);
0315 
0316   virtual bool GetModuleSpec(const FileSpec &module_file_spec,
0317                              const ArchSpec &arch, ModuleSpec &module_spec);
0318 
0319   virtual Status ConnectRemote(Args &args);
0320 
0321   virtual Status DisconnectRemote();
0322 
0323   /// Get the platform's supported architectures in the order in which they
0324   /// should be searched.
0325   ///
0326   /// \param[in] process_host_arch
0327   ///     The process host architecture if it's known. An invalid ArchSpec
0328   ///     represents that the process host architecture is unknown.
0329   virtual std::vector<ArchSpec>
0330   GetSupportedArchitectures(const ArchSpec &process_host_arch) = 0;
0331 
0332   virtual size_t GetSoftwareBreakpointTrapOpcode(Target &target,
0333                                                  BreakpointSite *bp_site);
0334 
0335   /// Launch a new process on a platform, not necessarily for debugging, it
0336   /// could be just for running the process.
0337   virtual Status LaunchProcess(ProcessLaunchInfo &launch_info);
0338 
0339   /// Perform expansion of the command-line for this launch info This can
0340   /// potentially involve wildcard expansion
0341   /// environment variable replacement, and whatever other
0342   /// argument magic the platform defines as part of its typical
0343   /// user experience
0344   virtual Status ShellExpandArguments(ProcessLaunchInfo &launch_info);
0345 
0346   /// Kill process on a platform.
0347   virtual Status KillProcess(const lldb::pid_t pid);
0348 
0349   /// Lets a platform answer if it is compatible with a given architecture and
0350   /// the target triple contained within.
0351   virtual bool IsCompatibleArchitecture(const ArchSpec &arch,
0352                                         const ArchSpec &process_host_arch,
0353                                         ArchSpec::MatchType match,
0354                                         ArchSpec *compatible_arch_ptr);
0355 
0356   /// Not all platforms will support debugging a process by spawning somehow
0357   /// halted for a debugger (specified using the "eLaunchFlagDebug" launch
0358   /// flag) and then attaching. If your platform doesn't support this,
0359   /// override this function and return false.
0360   virtual bool CanDebugProcess() { return true; }
0361 
0362   /// Subclasses do not need to implement this function as it uses the
0363   /// Platform::LaunchProcess() followed by Platform::Attach (). Remote
0364   /// platforms will want to subclass this function in order to be able to
0365   /// intercept STDIO and possibly launch a separate process that will debug
0366   /// the debuggee.
0367   virtual lldb::ProcessSP DebugProcess(ProcessLaunchInfo &launch_info,
0368                                        Debugger &debugger, Target &target,
0369                                        Status &error);
0370 
0371   virtual lldb::ProcessSP ConnectProcess(llvm::StringRef connect_url,
0372                                          llvm::StringRef plugin_name,
0373                                          Debugger &debugger, Target *target,
0374                                          Status &error);
0375 
0376   virtual lldb::ProcessSP
0377   ConnectProcessSynchronous(llvm::StringRef connect_url,
0378                             llvm::StringRef plugin_name, Debugger &debugger,
0379                             Stream &stream, Target *target, Status &error);
0380 
0381   /// Attach to an existing process using a process ID.
0382   ///
0383   /// Each platform subclass needs to implement this function and attempt to
0384   /// attach to the process with the process ID of \a pid. The platform
0385   /// subclass should return an appropriate ProcessSP subclass that is
0386   /// attached to the process, or an empty shared pointer with an appropriate
0387   /// error.
0388   ///
0389   /// \return
0390   ///     An appropriate ProcessSP containing a valid shared pointer
0391   ///     to the default Process subclass for the platform that is
0392   ///     attached to the process, or an empty shared pointer with an
0393   ///     appropriate error fill into the \a error object.
0394   virtual lldb::ProcessSP Attach(ProcessAttachInfo &attach_info,
0395                                  Debugger &debugger,
0396                                  Target *target, // Can be nullptr, if nullptr
0397                                                  // create a new target, else
0398                                                  // use existing one
0399                                  Status &error) = 0;
0400 
0401   /// Attach to an existing process by process name.
0402   ///
0403   /// This function is not meant to be overridden by Process subclasses. It
0404   /// will first call Process::WillAttach (const char *) and if that returns
0405   /// \b true, Process::DoAttach (const char *) will be called to actually do
0406   /// the attach. If DoAttach returns \b true, then Process::DidAttach() will
0407   /// be called.
0408   ///
0409   /// \param[in] process_name
0410   ///     A process name to match against the current process list.
0411   ///
0412   /// \return
0413   ///     Returns \a pid if attaching was successful, or
0414   ///     LLDB_INVALID_PROCESS_ID if attaching fails.
0415   //        virtual lldb::ProcessSP
0416   //        Attach (const char *process_name,
0417   //                bool wait_for_launch,
0418   //                Status &error) = 0;
0419 
0420   // The base class Platform will take care of the host platform. Subclasses
0421   // will need to fill in the remote case.
0422   virtual uint32_t FindProcesses(const ProcessInstanceInfoMatch &match_info,
0423                                  ProcessInstanceInfoList &proc_infos);
0424 
0425   ProcessInstanceInfoList GetAllProcesses();
0426 
0427   virtual bool GetProcessInfo(lldb::pid_t pid, ProcessInstanceInfo &proc_info);
0428 
0429   // Set a breakpoint on all functions that can end up creating a thread for
0430   // this platform. This is needed when running expressions and also for
0431   // process control.
0432   virtual lldb::BreakpointSP SetThreadCreationBreakpoint(Target &target);
0433 
0434   // Given a target, find the local SDK directory if one exists on the current
0435   // host.
0436   virtual lldb_private::ConstString
0437   GetSDKDirectory(lldb_private::Target &target) {
0438     return lldb_private::ConstString();
0439   }
0440 
0441   /// Search each CU associated with the specified 'module' for
0442   /// the SDK paths the CUs were compiled against. In the presence
0443   /// of different SDKs, we try to pick the most appropriate one
0444   /// using \ref XcodeSDK::Merge.
0445   ///
0446   /// \param[in] module Module whose debug-info CUs to parse for
0447   ///                   which SDK they were compiled against.
0448   ///
0449   /// \returns If successful, returns a pair of a parsed XcodeSDK
0450   ///          object and a boolean that is 'true' if we encountered
0451   ///          a conflicting combination of SDKs when parsing the CUs
0452   ///          (e.g., a public and internal SDK).
0453   virtual llvm::Expected<std::pair<XcodeSDK, bool>>
0454   GetSDKPathFromDebugInfo(Module &module) {
0455     return llvm::createStringError(
0456         llvm::formatv("{0} not implemented for '{1}' platform.",
0457                       LLVM_PRETTY_FUNCTION, GetName()));
0458   }
0459 
0460   /// Returns the full path of the most appropriate SDK for the
0461   /// specified 'module'. This function gets this path by parsing
0462   /// debug-info (see \ref `GetSDKPathFromDebugInfo`).
0463   ///
0464   /// \param[in] module Module whose debug-info to parse for
0465   ///                   which SDK it was compiled against.
0466   ///
0467   /// \returns If successful, returns the full path to an
0468   ///          Xcode SDK.
0469   virtual llvm::Expected<std::string>
0470   ResolveSDKPathFromDebugInfo(Module &module) {
0471     return llvm::createStringError(
0472         llvm::formatv("{0} not implemented for '{1}' platform.",
0473                       LLVM_PRETTY_FUNCTION, GetName()));
0474   }
0475 
0476   /// Search CU for the SDK path the CUs was compiled against.
0477   ///
0478   /// \param[in] unit The CU
0479   ///
0480   /// \returns A parsed XcodeSDK object if successful, an Error otherwise. 
0481   virtual llvm::Expected<XcodeSDK> GetSDKPathFromDebugInfo(CompileUnit &unit) {
0482     return llvm::createStringError(
0483         llvm::formatv("{0} not implemented for '{1}' platform.",
0484                       LLVM_PRETTY_FUNCTION, GetName()));
0485   }
0486 
0487   /// Returns the full path of the most appropriate SDK for the
0488   /// specified compile unit. This function gets this path by parsing
0489   /// debug-info (see \ref `GetSDKPathFromDebugInfo`).
0490   ///
0491   /// \param[in] unit The CU to scan.
0492   ///
0493   /// \returns If successful, returns the full path to an
0494   ///          Xcode SDK.
0495   virtual llvm::Expected<std::string>
0496   ResolveSDKPathFromDebugInfo(CompileUnit &unit) {
0497     return llvm::createStringError(
0498         llvm::formatv("{0} not implemented for '{1}' platform.",
0499                       LLVM_PRETTY_FUNCTION, GetName()));
0500   }
0501 
0502   bool IsHost() const {
0503     return m_is_host; // Is this the default host platform?
0504   }
0505 
0506   bool IsRemote() const { return !m_is_host; }
0507 
0508   virtual bool IsConnected() const {
0509     // Remote subclasses should override this function
0510     return IsHost();
0511   }
0512 
0513   const ArchSpec &GetSystemArchitecture();
0514 
0515   void SetSystemArchitecture(const ArchSpec &arch) {
0516     m_system_arch = arch;
0517     if (IsHost())
0518       m_os_version_set_while_connected = m_system_arch.IsValid();
0519   }
0520 
0521   /// If the triple contains not specify the vendor, os, and environment
0522   /// parts, we "augment" these using information from the platform and return
0523   /// the resulting ArchSpec object.
0524   ArchSpec GetAugmentedArchSpec(llvm::StringRef triple);
0525 
0526   // Used for column widths
0527   size_t GetMaxUserIDNameLength() const { return m_max_uid_name_len; }
0528 
0529   // Used for column widths
0530   size_t GetMaxGroupIDNameLength() const { return m_max_gid_name_len; }
0531 
0532   const std::string &GetSDKRootDirectory() const { return m_sdk_sysroot; }
0533 
0534   void SetSDKRootDirectory(std::string dir) { m_sdk_sysroot = std::move(dir); }
0535 
0536   const std::string &GetSDKBuild() const { return m_sdk_build; }
0537 
0538   void SetSDKBuild(std::string sdk_build) {
0539     m_sdk_build = std::move(sdk_build);
0540   }
0541 
0542   // Override this to return true if your platform supports Clang modules. You
0543   // may also need to override AddClangModuleCompilationOptions to pass the
0544   // right Clang flags for your platform.
0545   virtual bool SupportsModules() { return false; }
0546 
0547   // Appends the platform-specific options required to find the modules for the
0548   // current platform.
0549   virtual void
0550   AddClangModuleCompilationOptions(Target *target,
0551                                    std::vector<std::string> &options);
0552 
0553   FileSpec GetWorkingDirectory();
0554 
0555   bool SetWorkingDirectory(const FileSpec &working_dir);
0556 
0557   // There may be modules that we don't want to find by default for operations
0558   // like "setting breakpoint by name". The platform will return "true" from
0559   // this call if the passed in module happens to be one of these.
0560 
0561   virtual bool
0562   ModuleIsExcludedForUnconstrainedSearches(Target &target,
0563                                            const lldb::ModuleSP &module_sp) {
0564     return false;
0565   }
0566 
0567   virtual Status MakeDirectory(const FileSpec &file_spec, uint32_t permissions);
0568 
0569   virtual Status GetFilePermissions(const FileSpec &file_spec,
0570                                     uint32_t &file_permissions);
0571 
0572   virtual Status SetFilePermissions(const FileSpec &file_spec,
0573                                     uint32_t file_permissions);
0574 
0575   virtual lldb::user_id_t OpenFile(const FileSpec &file_spec,
0576                                    File::OpenOptions flags, uint32_t mode,
0577                                    Status &error);
0578 
0579   virtual bool CloseFile(lldb::user_id_t fd, Status &error);
0580 
0581   virtual lldb::user_id_t GetFileSize(const FileSpec &file_spec);
0582 
0583   virtual void AutoCompleteDiskFileOrDirectory(CompletionRequest &request,
0584                                                bool only_dir) {}
0585 
0586   virtual uint64_t ReadFile(lldb::user_id_t fd, uint64_t offset, void *dst,
0587                             uint64_t dst_len, Status &error);
0588 
0589   virtual uint64_t WriteFile(lldb::user_id_t fd, uint64_t offset,
0590                              const void *src, uint64_t src_len, Status &error);
0591 
0592   virtual Status GetFile(const FileSpec &source, const FileSpec &destination);
0593 
0594   virtual Status PutFile(const FileSpec &source, const FileSpec &destination,
0595                          uint32_t uid = UINT32_MAX, uint32_t gid = UINT32_MAX);
0596 
0597   virtual Status
0598   CreateSymlink(const FileSpec &src,  // The name of the link is in src
0599                 const FileSpec &dst); // The symlink points to dst
0600 
0601   /// Install a file or directory to the remote system.
0602   ///
0603   /// Install is similar to Platform::PutFile(), but it differs in that if an
0604   /// application/framework/shared library is installed on a remote platform
0605   /// and the remote platform requires something to be done to register the
0606   /// application/framework/shared library, then this extra registration can
0607   /// be done.
0608   ///
0609   /// \param[in] src
0610   ///     The source file/directory to install on the remote system.
0611   ///
0612   /// \param[in] dst
0613   ///     The destination file/directory where \a src will be installed.
0614   ///     If \a dst has no filename specified, then its filename will
0615   ///     be set from \a src. It \a dst has no directory specified, it
0616   ///     will use the platform working directory. If \a dst has a
0617   ///     directory specified, but the directory path is relative, the
0618   ///     platform working directory will be prepended to the relative
0619   ///     directory.
0620   ///
0621   /// \return
0622   ///     An error object that describes anything that went wrong.
0623   virtual Status Install(const FileSpec &src, const FileSpec &dst);
0624 
0625   virtual Environment GetEnvironment();
0626 
0627   virtual bool GetFileExists(const lldb_private::FileSpec &file_spec);
0628 
0629   virtual Status Unlink(const FileSpec &file_spec);
0630 
0631   virtual MmapArgList GetMmapArgumentList(const ArchSpec &arch,
0632                                           lldb::addr_t addr,
0633                                           lldb::addr_t length,
0634                                           unsigned prot, unsigned flags,
0635                                           lldb::addr_t fd, lldb::addr_t offset);
0636 
0637   virtual bool GetSupportsRSync() { return m_supports_rsync; }
0638 
0639   virtual void SetSupportsRSync(bool flag) { m_supports_rsync = flag; }
0640 
0641   virtual const char *GetRSyncOpts() { return m_rsync_opts.c_str(); }
0642 
0643   virtual void SetRSyncOpts(const char *opts) { m_rsync_opts.assign(opts); }
0644 
0645   virtual const char *GetRSyncPrefix() { return m_rsync_prefix.c_str(); }
0646 
0647   virtual void SetRSyncPrefix(const char *prefix) {
0648     m_rsync_prefix.assign(prefix);
0649   }
0650 
0651   virtual bool GetSupportsSSH() { return m_supports_ssh; }
0652 
0653   virtual void SetSupportsSSH(bool flag) { m_supports_ssh = flag; }
0654 
0655   virtual const char *GetSSHOpts() { return m_ssh_opts.c_str(); }
0656 
0657   virtual void SetSSHOpts(const char *opts) { m_ssh_opts.assign(opts); }
0658 
0659   virtual bool GetIgnoresRemoteHostname() { return m_ignores_remote_hostname; }
0660 
0661   virtual void SetIgnoresRemoteHostname(bool flag) {
0662     m_ignores_remote_hostname = flag;
0663   }
0664 
0665   virtual lldb_private::OptionGroupOptions *
0666   GetConnectionOptions(CommandInterpreter &interpreter) {
0667     return nullptr;
0668   }
0669 
0670   virtual lldb_private::Status RunShellCommand(
0671       llvm::StringRef command,
0672       const FileSpec &working_dir, // Pass empty FileSpec to use the current
0673                                    // working directory
0674       int *status_ptr, // Pass nullptr if you don't want the process exit status
0675       int *signo_ptr,  // Pass nullptr if you don't want the signal that caused
0676                        // the process to exit
0677       std::string
0678           *command_output, // Pass nullptr if you don't want the command output
0679       const Timeout<std::micro> &timeout);
0680 
0681   virtual lldb_private::Status RunShellCommand(
0682       llvm::StringRef shell, llvm::StringRef command,
0683       const FileSpec &working_dir, // Pass empty FileSpec to use the current
0684                                    // working directory
0685       int *status_ptr, // Pass nullptr if you don't want the process exit status
0686       int *signo_ptr,  // Pass nullptr if you don't want the signal that caused
0687                        // the process to exit
0688       std::string
0689           *command_output, // Pass nullptr if you don't want the command output
0690       const Timeout<std::micro> &timeout);
0691 
0692   virtual void SetLocalCacheDirectory(const char *local);
0693 
0694   virtual const char *GetLocalCacheDirectory();
0695 
0696   virtual std::string GetPlatformSpecificConnectionInformation() { return ""; }
0697 
0698   virtual llvm::ErrorOr<llvm::MD5::MD5Result>
0699   CalculateMD5(const FileSpec &file_spec);
0700 
0701   virtual uint32_t GetResumeCountForLaunchInfo(ProcessLaunchInfo &launch_info) {
0702     return 1;
0703   }
0704 
0705   virtual const lldb::UnixSignalsSP &GetRemoteUnixSignals();
0706 
0707   lldb::UnixSignalsSP GetUnixSignals();
0708 
0709   /// Locate a queue name given a thread's qaddr
0710   ///
0711   /// On a system using libdispatch ("Grand Central Dispatch") style queues, a
0712   /// thread may be associated with a GCD queue or not, and a queue may be
0713   /// associated with multiple threads. The process/thread must provide a way
0714   /// to find the "dispatch_qaddr" for each thread, and from that
0715   /// dispatch_qaddr this Platform method will locate the queue name and
0716   /// provide that.
0717   ///
0718   /// \param[in] process
0719   ///     A process is required for reading memory.
0720   ///
0721   /// \param[in] dispatch_qaddr
0722   ///     The dispatch_qaddr for this thread.
0723   ///
0724   /// \return
0725   ///     The name of the queue, if there is one.  An empty string
0726   ///     means that this thread is not associated with a dispatch
0727   ///     queue.
0728   virtual std::string
0729   GetQueueNameForThreadQAddress(Process *process, lldb::addr_t dispatch_qaddr) {
0730     return "";
0731   }
0732 
0733   /// Locate a queue ID given a thread's qaddr
0734   ///
0735   /// On a system using libdispatch ("Grand Central Dispatch") style queues, a
0736   /// thread may be associated with a GCD queue or not, and a queue may be
0737   /// associated with multiple threads. The process/thread must provide a way
0738   /// to find the "dispatch_qaddr" for each thread, and from that
0739   /// dispatch_qaddr this Platform method will locate the queue ID and provide
0740   /// that.
0741   ///
0742   /// \param[in] process
0743   ///     A process is required for reading memory.
0744   ///
0745   /// \param[in] dispatch_qaddr
0746   ///     The dispatch_qaddr for this thread.
0747   ///
0748   /// \return
0749   ///     The queue_id for this thread, if this thread is associated
0750   ///     with a dispatch queue.  Else LLDB_INVALID_QUEUE_ID is returned.
0751   virtual lldb::queue_id_t
0752   GetQueueIDForThreadQAddress(Process *process, lldb::addr_t dispatch_qaddr) {
0753     return LLDB_INVALID_QUEUE_ID;
0754   }
0755 
0756   /// Provide a list of trap handler function names for this platform
0757   ///
0758   /// The unwinder needs to treat trap handlers specially -- the stack frame
0759   /// may not be aligned correctly for a trap handler (the kernel often won't
0760   /// perturb the stack pointer, or won't re-align it properly, in the process
0761   /// of calling the handler) and the frame above the handler needs to be
0762   /// treated by the unwinder's "frame 0" rules instead of its "middle of the
0763   /// stack frame" rules.
0764   ///
0765   /// In a user process debugging scenario, the list of trap handlers is
0766   /// typically just "_sigtramp".
0767   ///
0768   /// The Platform base class provides the m_trap_handlers ivar but it does
0769   /// not populate it.  Subclasses should add the names of the asynchronous
0770   /// signal handler routines as needed.  For most Unix platforms, add
0771   /// _sigtramp.
0772   ///
0773   /// \return
0774   ///     A list of symbol names.  The list may be empty.
0775   virtual const std::vector<ConstString> &GetTrapHandlerSymbolNames();
0776 
0777   /// Try to get a specific unwind plan for a named trap handler.
0778   /// The default is not to have specific unwind plans for trap handlers.
0779   ///
0780   /// \param[in] triple
0781   ///     Triple of the current target.
0782   ///
0783   /// \param[in] name
0784   ///     Name of the trap handler function.
0785   ///
0786   /// \return
0787   ///     A specific unwind plan for that trap handler, or an empty
0788   ///     shared pointer. The latter means there is no specific plan,
0789   ///     unwind as normal.
0790   virtual lldb::UnwindPlanSP
0791   GetTrapHandlerUnwindPlan(const llvm::Triple &triple, ConstString name) {
0792     return {};
0793   }
0794 
0795   /// Find a support executable that may not live within in the standard
0796   /// locations related to LLDB.
0797   ///
0798   /// Executable might exist within the Platform SDK directories, or in
0799   /// standard tool directories within the current IDE that is running LLDB.
0800   ///
0801   /// \param[in] basename
0802   ///     The basename of the executable to locate in the current
0803   ///     platform.
0804   ///
0805   /// \return
0806   ///     A FileSpec pointing to the executable on disk, or an invalid
0807   ///     FileSpec if the executable cannot be found.
0808   virtual FileSpec LocateExecutable(const char *basename) { return FileSpec(); }
0809 
0810   /// Allow the platform to set preferred memory cache line size. If non-zero
0811   /// (and the user has not set cache line size explicitly), this value will
0812   /// be used as the cache line size for memory reads.
0813   virtual uint32_t GetDefaultMemoryCacheLineSize() { return 0; }
0814 
0815   /// Load a shared library into this process.
0816   ///
0817   /// Try and load a shared library into the current process. This call might
0818   /// fail in the dynamic loader plug-in says it isn't safe to try and load
0819   /// shared libraries at the moment.
0820   ///
0821   /// \param[in] process
0822   ///     The process to load the image.
0823   ///
0824   /// \param[in] local_file
0825   ///     The file spec that points to the shared library that you want
0826   ///     to load if the library is located on the host. The library will
0827   ///     be copied over to the location specified by remote_file or into
0828   ///     the current working directory with the same filename if the
0829   ///     remote_file isn't specified.
0830   ///
0831   /// \param[in] remote_file
0832   ///     If local_file is specified then the location where the library
0833   ///     should be copied over from the host. If local_file isn't
0834   ///     specified, then the path for the shared library on the target
0835   ///     what you want to load.
0836   ///
0837   /// \param[out] error
0838   ///     An error object that gets filled in with any errors that
0839   ///     might occur when trying to load the shared library.
0840   ///
0841   /// \return
0842   ///     A token that represents the shared library that can be
0843   ///     later used to unload the shared library. A value of
0844   ///     LLDB_INVALID_IMAGE_TOKEN will be returned if the shared
0845   ///     library can't be opened.
0846   uint32_t LoadImage(lldb_private::Process *process,
0847                      const lldb_private::FileSpec &local_file,
0848                      const lldb_private::FileSpec &remote_file,
0849                      lldb_private::Status &error);
0850 
0851   /// Load a shared library specified by base name into this process,
0852   /// looking by hand along a set of paths.
0853   ///
0854   /// \param[in] process
0855   ///     The process to load the image.
0856   ///
0857   /// \param[in] library_name
0858   ///     The name of the library to look for.  If library_name is an
0859   ///     absolute path, the basename will be extracted and searched for
0860   ///     along the paths.  This emulates the behavior of the loader when
0861   ///     given an install name and a set (e.g. DYLD_LIBRARY_PATH provided) of
0862   ///     alternate paths.
0863   ///
0864   /// \param[in] paths
0865   ///     The list of paths to use to search for the library.  First
0866   ///     match wins.
0867   ///
0868   /// \param[out] error
0869   ///     An error object that gets filled in with any errors that
0870   ///     might occur when trying to load the shared library.
0871   ///
0872   /// \param[out] loaded_path
0873   ///      If non-null, the path to the dylib that was successfully loaded
0874   ///      is stored in this path.
0875   ///
0876   /// \return
0877   ///     A token that represents the shared library which can be
0878   ///     passed to UnloadImage. A value of
0879   ///     LLDB_INVALID_IMAGE_TOKEN will be returned if the shared
0880   ///     library can't be opened.
0881   uint32_t LoadImageUsingPaths(lldb_private::Process *process,
0882                                const lldb_private::FileSpec &library_name,
0883                                const std::vector<std::string> &paths,
0884                                lldb_private::Status &error,
0885                                lldb_private::FileSpec *loaded_path);
0886 
0887   virtual uint32_t DoLoadImage(lldb_private::Process *process,
0888                                const lldb_private::FileSpec &remote_file,
0889                                const std::vector<std::string> *paths,
0890                                lldb_private::Status &error,
0891                                lldb_private::FileSpec *loaded_path = nullptr);
0892 
0893   virtual Status UnloadImage(lldb_private::Process *process,
0894                              uint32_t image_token);
0895 
0896   /// Connect to all processes waiting for a debugger to attach
0897   ///
0898   /// If the platform have a list of processes waiting for a debugger to
0899   /// connect to them then connect to all of these pending processes.
0900   ///
0901   /// \param[in] debugger
0902   ///     The debugger used for the connect.
0903   ///
0904   /// \param[out] error
0905   ///     If an error occurred during the connect then this object will
0906   ///     contain the error message.
0907   ///
0908   /// \return
0909   ///     The number of processes we are successfully connected to.
0910   virtual size_t ConnectToWaitingProcesses(lldb_private::Debugger &debugger,
0911                                            lldb_private::Status &error);
0912 
0913   /// Gather all of crash informations into a structured data dictionary.
0914   ///
0915   /// If the platform have a crashed process with crash information entries,
0916   /// gather all the entries into an structured data dictionary or return a
0917   /// nullptr. This dictionary is generic and extensible, as it contains an
0918   /// array for each different type of crash information.
0919   ///
0920   /// \param[in] process
0921   ///     The crashed process.
0922   ///
0923   /// \return
0924   ///     A structured data dictionary containing at each entry, the crash
0925   ///     information type as the entry key and the matching  an array as the
0926   ///     entry value. \b nullptr if not implemented or  if the process has no
0927   ///     crash information entry. \b error if an error occured.
0928   virtual llvm::Expected<StructuredData::DictionarySP>
0929   FetchExtendedCrashInformation(lldb_private::Process &process) {
0930     return nullptr;
0931   }
0932 
0933   /// Detect a binary in memory that will determine which Platform and
0934   /// DynamicLoader should be used in this target/process, and update
0935   /// the Platform/DynamicLoader.
0936   /// The binary will be loaded into the Target, or will be registered with
0937   /// the DynamicLoader so that it will be loaded at a later stage.  Returns
0938   /// true to indicate that this is a platform binary and has been
0939   /// loaded/registered, no further action should be taken by the caller.
0940   ///
0941   /// \param[in] process
0942   ///     Process read memory from, a Process must be provided.
0943   ///
0944   /// \param[in] addr
0945   ///     Address of a binary in memory.
0946   ///
0947   /// \param[in] notify
0948   ///     Whether ModulesDidLoad should be called, if a binary is loaded.
0949   ///     Caller may prefer to call ModulesDidLoad for multiple binaries
0950   ///     that were loaded at the same time.
0951   ///
0952   /// \return
0953   ///     Returns true if the binary was loaded in the target (or will be
0954   ///     via a DynamicLoader).  Returns false if the binary was not
0955   ///     loaded/registered, and the caller must load it into the target.
0956   virtual bool LoadPlatformBinaryAndSetup(Process *process, lldb::addr_t addr,
0957                                           bool notify) {
0958     return false;
0959   }
0960 
0961   virtual CompilerType GetSiginfoType(const llvm::Triple &triple);
0962 
0963   virtual Args GetExtraStartupCommands();
0964 
0965   typedef std::function<Status(const ModuleSpec &module_spec,
0966                                FileSpec &module_file_spec,
0967                                FileSpec &symbol_file_spec)>
0968       LocateModuleCallback;
0969 
0970   /// Set locate module callback. This allows users to implement their own
0971   /// module cache system. For example, to leverage artifacts of build system,
0972   /// to bypass pulling files from remote platform, or to search symbol files
0973   /// from symbol servers.
0974   void SetLocateModuleCallback(LocateModuleCallback callback);
0975 
0976   LocateModuleCallback GetLocateModuleCallback() const;
0977 
0978 protected:
0979   /// Create a list of ArchSpecs with the given OS and a architectures. The
0980   /// vendor field is left as an "unspecified unknown".
0981   static std::vector<ArchSpec>
0982   CreateArchList(llvm::ArrayRef<llvm::Triple::ArchType> archs,
0983                  llvm::Triple::OSType os);
0984 
0985   /// Private implementation of connecting to a process. If the stream is set
0986   /// we connect synchronously.
0987   lldb::ProcessSP DoConnectProcess(llvm::StringRef connect_url,
0988                                    llvm::StringRef plugin_name,
0989                                    Debugger &debugger, Stream *stream,
0990                                    Target *target, Status &error);
0991   bool m_is_host;
0992   // Set to true when we are able to actually set the OS version while being
0993   // connected. For remote platforms, we might set the version ahead of time
0994   // before we actually connect and this version might change when we actually
0995   // connect to a remote platform. For the host platform this will be set to
0996   // the once we call HostInfo::GetOSVersion().
0997   bool m_os_version_set_while_connected;
0998   bool m_system_arch_set_while_connected;
0999   std::string
1000       m_sdk_sysroot; // the root location of where the SDK files are all located
1001   std::string m_sdk_build;
1002   FileSpec m_working_dir; // The working directory which is used when installing
1003                           // modules that have no install path set
1004   std::string m_hostname;
1005   llvm::VersionTuple m_os_version;
1006   ArchSpec
1007       m_system_arch; // The architecture of the kernel or the remote platform
1008   typedef std::map<uint32_t, ConstString> IDToNameMap;
1009   // Mutex for modifying Platform data structures that should only be used for
1010   // non-reentrant code
1011   std::mutex m_mutex;
1012   size_t m_max_uid_name_len;
1013   size_t m_max_gid_name_len;
1014   bool m_supports_rsync;
1015   std::string m_rsync_opts;
1016   std::string m_rsync_prefix;
1017   bool m_supports_ssh;
1018   std::string m_ssh_opts;
1019   bool m_ignores_remote_hostname;
1020   std::string m_local_cache_directory;
1021   std::vector<ConstString> m_trap_handlers;
1022   bool m_calculated_trap_handlers;
1023   const std::unique_ptr<ModuleCache> m_module_cache;
1024   LocateModuleCallback m_locate_module_callback;
1025 
1026   /// Ask the Platform subclass to fill in the list of trap handler names
1027   ///
1028   /// For most Unix user process environments, this will be a single function
1029   /// name, _sigtramp.  More specialized environments may have additional
1030   /// handler names.  The unwinder code needs to know when a trap handler is
1031   /// on the stack because the unwind rules for the frame that caused the trap
1032   /// are different.
1033   ///
1034   /// The base class Platform ivar m_trap_handlers should be updated by the
1035   /// Platform subclass when this method is called.  If there are no
1036   /// predefined trap handlers, this method may be a no-op.
1037   virtual void CalculateTrapHandlerSymbolNames() = 0;
1038 
1039   Status GetCachedExecutable(ModuleSpec &module_spec, lldb::ModuleSP &module_sp,
1040                              const FileSpecList *module_search_paths_ptr);
1041 
1042   virtual Status DownloadModuleSlice(const FileSpec &src_file_spec,
1043                                      const uint64_t src_offset,
1044                                      const uint64_t src_size,
1045                                      const FileSpec &dst_file_spec);
1046 
1047   virtual Status DownloadSymbolFile(const lldb::ModuleSP &module_sp,
1048                                     const FileSpec &dst_file_spec);
1049 
1050   virtual const char *GetCacheHostname();
1051 
1052 private:
1053   typedef std::function<Status(const ModuleSpec &)> ModuleResolver;
1054 
1055   Status GetRemoteSharedModule(const ModuleSpec &module_spec, Process *process,
1056                                lldb::ModuleSP &module_sp,
1057                                const ModuleResolver &module_resolver,
1058                                bool *did_create_ptr);
1059 
1060   bool GetCachedSharedModule(const ModuleSpec &module_spec,
1061                              lldb::ModuleSP &module_sp, bool *did_create_ptr);
1062 
1063   FileSpec GetModuleCacheRoot();
1064 };
1065 
1066 class PlatformList {
1067 public:
1068   PlatformList() = default;
1069 
1070   ~PlatformList() = default;
1071 
1072   void Append(const lldb::PlatformSP &platform_sp, bool set_selected) {
1073     std::lock_guard<std::recursive_mutex> guard(m_mutex);
1074     m_platforms.push_back(platform_sp);
1075     if (set_selected)
1076       m_selected_platform_sp = m_platforms.back();
1077   }
1078 
1079   size_t GetSize() {
1080     std::lock_guard<std::recursive_mutex> guard(m_mutex);
1081     return m_platforms.size();
1082   }
1083 
1084   lldb::PlatformSP GetAtIndex(uint32_t idx) {
1085     lldb::PlatformSP platform_sp;
1086     {
1087       std::lock_guard<std::recursive_mutex> guard(m_mutex);
1088       if (idx < m_platforms.size())
1089         platform_sp = m_platforms[idx];
1090     }
1091     return platform_sp;
1092   }
1093 
1094   /// Select the active platform.
1095   ///
1096   /// In order to debug remotely, other platform's can be remotely connected
1097   /// to and set as the selected platform for any subsequent debugging. This
1098   /// allows connection to remote targets and allows the ability to discover
1099   /// process info, launch and attach to remote processes.
1100   lldb::PlatformSP GetSelectedPlatform() {
1101     std::lock_guard<std::recursive_mutex> guard(m_mutex);
1102     if (!m_selected_platform_sp && !m_platforms.empty())
1103       m_selected_platform_sp = m_platforms.front();
1104 
1105     return m_selected_platform_sp;
1106   }
1107 
1108   void SetSelectedPlatform(const lldb::PlatformSP &platform_sp) {
1109     if (platform_sp) {
1110       std::lock_guard<std::recursive_mutex> guard(m_mutex);
1111       const size_t num_platforms = m_platforms.size();
1112       for (size_t idx = 0; idx < num_platforms; ++idx) {
1113         if (m_platforms[idx].get() == platform_sp.get()) {
1114           m_selected_platform_sp = m_platforms[idx];
1115           return;
1116         }
1117       }
1118       m_platforms.push_back(platform_sp);
1119       m_selected_platform_sp = m_platforms.back();
1120     }
1121   }
1122 
1123   lldb::PlatformSP GetOrCreate(llvm::StringRef name);
1124   lldb::PlatformSP GetOrCreate(const ArchSpec &arch,
1125                                const ArchSpec &process_host_arch,
1126                                ArchSpec *platform_arch_ptr, Status &error);
1127   lldb::PlatformSP GetOrCreate(const ArchSpec &arch,
1128                                const ArchSpec &process_host_arch,
1129                                ArchSpec *platform_arch_ptr);
1130 
1131   /// Get the platform for the given list of architectures.
1132   ///
1133   /// The algorithm works a follows:
1134   ///
1135   /// 1. Returns the selected platform if it matches any of the architectures.
1136   /// 2. Returns the host platform if it matches any of the architectures.
1137   /// 3. Returns the platform that matches all the architectures.
1138   ///
1139   /// If none of the above apply, this function returns a default platform. The
1140   /// candidates output argument differentiates between either no platforms
1141   /// supporting the given architecture or multiple platforms supporting the
1142   /// given architecture.
1143   lldb::PlatformSP GetOrCreate(llvm::ArrayRef<ArchSpec> archs,
1144                                const ArchSpec &process_host_arch,
1145                                std::vector<lldb::PlatformSP> &candidates);
1146 
1147   lldb::PlatformSP Create(llvm::StringRef name);
1148 
1149   /// Detect a binary in memory that will determine which Platform and
1150   /// DynamicLoader should be used in this target/process, and update
1151   /// the Platform/DynamicLoader.
1152   /// The binary will be loaded into the Target, or will be registered with
1153   /// the DynamicLoader so that it will be loaded at a later stage.  Returns
1154   /// true to indicate that this is a platform binary and has been
1155   /// loaded/registered, no further action should be taken by the caller.
1156   ///
1157   /// \param[in] process
1158   ///     Process read memory from, a Process must be provided.
1159   ///
1160   /// \param[in] addr
1161   ///     Address of a binary in memory.
1162   ///
1163   /// \param[in] notify
1164   ///     Whether ModulesDidLoad should be called, if a binary is loaded.
1165   ///     Caller may prefer to call ModulesDidLoad for multiple binaries
1166   ///     that were loaded at the same time.
1167   ///
1168   /// \return
1169   ///     Returns true if the binary was loaded in the target (or will be
1170   ///     via a DynamicLoader).  Returns false if the binary was not
1171   ///     loaded/registered, and the caller must load it into the target.
1172   bool LoadPlatformBinaryAndSetup(Process *process, lldb::addr_t addr,
1173                                   bool notify);
1174 
1175 protected:
1176   typedef std::vector<lldb::PlatformSP> collection;
1177   mutable std::recursive_mutex m_mutex;
1178   collection m_platforms;
1179   lldb::PlatformSP m_selected_platform_sp;
1180 
1181 private:
1182   PlatformList(const PlatformList &) = delete;
1183   const PlatformList &operator=(const PlatformList &) = delete;
1184 };
1185 
1186 class OptionGroupPlatformRSync : public lldb_private::OptionGroup {
1187 public:
1188   OptionGroupPlatformRSync() = default;
1189 
1190   ~OptionGroupPlatformRSync() override = default;
1191 
1192   lldb_private::Status
1193   SetOptionValue(uint32_t option_idx, llvm::StringRef option_value,
1194                  ExecutionContext *execution_context) override;
1195 
1196   void OptionParsingStarting(ExecutionContext *execution_context) override;
1197 
1198   llvm::ArrayRef<OptionDefinition> GetDefinitions() override;
1199 
1200   // Instance variables to hold the values for command options.
1201 
1202   bool m_rsync;
1203   std::string m_rsync_opts;
1204   std::string m_rsync_prefix;
1205   bool m_ignores_remote_hostname;
1206 
1207 private:
1208   OptionGroupPlatformRSync(const OptionGroupPlatformRSync &) = delete;
1209   const OptionGroupPlatformRSync &
1210   operator=(const OptionGroupPlatformRSync &) = delete;
1211 };
1212 
1213 class OptionGroupPlatformSSH : public lldb_private::OptionGroup {
1214 public:
1215   OptionGroupPlatformSSH() = default;
1216 
1217   ~OptionGroupPlatformSSH() override = default;
1218 
1219   lldb_private::Status
1220   SetOptionValue(uint32_t option_idx, llvm::StringRef option_value,
1221                  ExecutionContext *execution_context) override;
1222 
1223   void OptionParsingStarting(ExecutionContext *execution_context) override;
1224 
1225   llvm::ArrayRef<OptionDefinition> GetDefinitions() override;
1226 
1227   // Instance variables to hold the values for command options.
1228 
1229   bool m_ssh;
1230   std::string m_ssh_opts;
1231 
1232 private:
1233   OptionGroupPlatformSSH(const OptionGroupPlatformSSH &) = delete;
1234   const OptionGroupPlatformSSH &
1235   operator=(const OptionGroupPlatformSSH &) = delete;
1236 };
1237 
1238 class OptionGroupPlatformCaching : public lldb_private::OptionGroup {
1239 public:
1240   OptionGroupPlatformCaching() = default;
1241 
1242   ~OptionGroupPlatformCaching() override = default;
1243 
1244   lldb_private::Status
1245   SetOptionValue(uint32_t option_idx, llvm::StringRef option_value,
1246                  ExecutionContext *execution_context) override;
1247 
1248   void OptionParsingStarting(ExecutionContext *execution_context) override;
1249 
1250   llvm::ArrayRef<OptionDefinition> GetDefinitions() override;
1251 
1252   // Instance variables to hold the values for command options.
1253 
1254   std::string m_cache_dir;
1255 
1256 private:
1257   OptionGroupPlatformCaching(const OptionGroupPlatformCaching &) = delete;
1258   const OptionGroupPlatformCaching &
1259   operator=(const OptionGroupPlatformCaching &) = delete;
1260 };
1261 
1262 } // namespace lldb_private
1263 
1264 #endif // LLDB_TARGET_PLATFORM_H