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