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