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