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
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] process
308 /// A Process.
309 ///
310 /// \param[out] module_sp
311 /// A Module that matches the ModuleSpec, if one is found.
312 ///
313 /// \param[in] module_search_paths_ptr
314 /// Locations to possibly look for a binary that matches the ModuleSpec.
315 ///
316 /// \param[out] old_modules
317 /// Existing Modules in the Process' Target 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
331 GetSharedModule(const ModuleSpec &module_spec, Process *process,
332 lldb::ModuleSP &module_sp,
334 bool *did_create_ptr);
335
336 void CallLocateModuleCallbackIfSet(const ModuleSpec &module_spec,
337 lldb::ModuleSP &module_sp,
338 FileSpec &symbol_file_spec,
339 bool *did_create_ptr);
340
341 virtual bool GetModuleSpec(const FileSpec &module_file_spec,
342 const ArchSpec &arch, ModuleSpec &module_spec);
343
344 virtual Status ConnectRemote(Args &args);
345
346 virtual Status DisconnectRemote();
347
348 /// Get the platform's supported architectures in the order in which they
349 /// should be searched.
350 ///
351 /// \param[in] process_host_arch
352 /// The process host architecture if it's known. An invalid ArchSpec
353 /// represents that the process host architecture is unknown.
354 virtual std::vector<ArchSpec>
355 GetSupportedArchitectures(const ArchSpec &process_host_arch) = 0;
356
357 virtual size_t GetSoftwareBreakpointTrapOpcode(Target &target,
358 BreakpointSite *bp_site);
359
360 /// Launch a new process on a platform, not necessarily for debugging, it
361 /// could be just for running the process.
362 virtual Status LaunchProcess(ProcessLaunchInfo &launch_info);
363
364 /// Perform expansion of the command-line for this launch info This can
365 /// potentially involve wildcard expansion
366 /// environment variable replacement, and whatever other
367 /// argument magic the platform defines as part of its typical
368 /// user experience
369 virtual Status ShellExpandArguments(ProcessLaunchInfo &launch_info);
370
371 /// Kill process on a platform.
372 virtual Status KillProcess(const lldb::pid_t pid);
373
374 /// Lets a platform answer if it is compatible with a given architecture and
375 /// the target triple contained within.
376 virtual bool IsCompatibleArchitecture(const ArchSpec &arch,
377 const ArchSpec &process_host_arch,
379 ArchSpec *compatible_arch_ptr);
380
381 /// Not all platforms will support debugging a process by spawning somehow
382 /// halted for a debugger (specified using the "eLaunchFlagDebug" launch
383 /// flag) and then attaching. If your platform doesn't support this,
384 /// override this function and return false.
385 virtual bool CanDebugProcess() { return true; }
386
387 /// Subclasses do not need to implement this function as it uses the
388 /// Platform::LaunchProcess() followed by Platform::Attach (). Remote
389 /// platforms will want to subclass this function in order to be able to
390 /// intercept STDIO and possibly launch a separate process that will debug
391 /// the debuggee.
393 Debugger &debugger, Target &target,
394 Status &error);
395
396 virtual lldb::ProcessSP ConnectProcess(llvm::StringRef connect_url,
397 llvm::StringRef plugin_name,
398 Debugger &debugger, Target *target,
399 Status &error);
400
401 virtual lldb::ProcessSP
402 ConnectProcessSynchronous(llvm::StringRef connect_url,
403 llvm::StringRef plugin_name, Debugger &debugger,
404 Stream &stream, Target *target, Status &error);
405
406 /// Attach to an existing process using a process ID.
407 ///
408 /// Each platform subclass needs to implement this function and attempt to
409 /// attach to the process with the process ID of \a pid. The platform
410 /// subclass should return an appropriate ProcessSP subclass that is
411 /// attached to the process, or an empty shared pointer with an appropriate
412 /// error.
413 ///
414 /// \return
415 /// An appropriate ProcessSP containing a valid shared pointer
416 /// to the default Process subclass for the platform that is
417 /// attached to the process, or an empty shared pointer with an
418 /// appropriate error fill into the \a error object.
420 Debugger &debugger,
421 Target *target, // Can be nullptr, if nullptr
422 // create a new target, else
423 // use existing one
424 Status &error) = 0;
425
426 /// Attach to an existing process by process name.
427 ///
428 /// This function is not meant to be overridden by Process subclasses. It
429 /// will first call Process::WillAttach (const char *) and if that returns
430 /// \b true, Process::DoAttach (const char *) will be called to actually do
431 /// the attach. If DoAttach returns \b true, then Process::DidAttach() will
432 /// be called.
433 ///
434 /// \param[in] process_name
435 /// A process name to match against the current process list.
436 ///
437 /// \return
438 /// Returns \a pid if attaching was successful, or
439 /// LLDB_INVALID_PROCESS_ID if attaching fails.
440 // virtual lldb::ProcessSP
441 // Attach (const char *process_name,
442 // bool wait_for_launch,
443 // Status &error) = 0;
444
445 // The base class Platform will take care of the host platform. Subclasses
446 // will need to fill in the remote case.
447 virtual uint32_t FindProcesses(const ProcessInstanceInfoMatch &match_info,
448 ProcessInstanceInfoList &proc_infos);
449
451
452 virtual bool GetProcessInfo(lldb::pid_t pid, ProcessInstanceInfo &proc_info);
453
454 // Set a breakpoint on all functions that can end up creating a thread for
455 // this platform. This is needed when running expressions and also for
456 // process control.
458
459 // Given a target, find the local SDK directory if one exists on the current
460 // host.
465
466 /// Search each CU associated with the specified 'module' for
467 /// the SDK paths the CUs were compiled against. In the presence
468 /// of different SDKs, we try to pick the most appropriate one
469 /// using \ref XcodeSDK::Merge.
470 ///
471 /// \param[in] module Module whose debug-info CUs to parse for
472 /// which SDK they were compiled against.
473 ///
474 /// \returns If successful, returns a pair of a parsed XcodeSDK
475 /// object and a boolean that is 'true' if we encountered
476 /// a conflicting combination of SDKs when parsing the CUs
477 /// (e.g., a public and internal SDK).
478 virtual llvm::Expected<std::pair<XcodeSDK, bool>>
480 return llvm::make_error<UnimplementedError>(
481 llvm::formatv("{0} not implemented for '{1}' platform.",
482 LLVM_PRETTY_FUNCTION, GetName()));
483 }
484
485 /// Returns the full path of the most appropriate SDK for the
486 /// specified 'module'. This function gets this path by parsing
487 /// debug-info (see \ref `GetSDKPathFromDebugInfo`).
488 ///
489 /// \param[in] module Module whose debug-info to parse for
490 /// which SDK it was compiled against.
491 ///
492 /// \returns If successful, returns the full path to an
493 /// Xcode SDK.
494 virtual llvm::Expected<std::string>
496 return llvm::make_error<UnimplementedError>(
497 llvm::formatv("{0} not implemented for '{1}' platform.",
498 LLVM_PRETTY_FUNCTION, GetName()));
499 }
500
501 /// Search CU for the SDK path the CUs was compiled against.
502 ///
503 /// \param[in] unit The CU
504 ///
505 /// \returns A parsed XcodeSDK object if successful, an Error otherwise.
506 virtual llvm::Expected<XcodeSDK>
508 return llvm::make_error<UnimplementedError>(
509 llvm::formatv("{0} not implemented for '{1}' platform.",
510 LLVM_PRETTY_FUNCTION, GetName()));
511 }
512
513 /// Returns the full path of the most appropriate SDK for the
514 /// specified compile unit. This function gets this path by parsing
515 /// debug-info (see \ref `GetSDKPathFromDebugInfo`).
516 ///
517 /// \param[in] unit The CU to scan.
518 ///
519 /// \returns If successful, returns the full path to an
520 /// Xcode SDK.
521 virtual llvm::Expected<std::string>
523 return llvm::make_error<UnimplementedError>(
524 llvm::formatv("{0} not implemented for '{1}' platform.",
525 LLVM_PRETTY_FUNCTION, GetName()));
526 }
527
528 bool IsHost() const {
529 return m_is_host; // Is this the default host platform?
530 }
531
532 bool IsRemote() const { return !m_is_host; }
533
534 virtual bool IsConnected() const {
535 // Remote subclasses should override this function
536 return IsHost();
537 }
538
540
541 void SetSystemArchitecture(const ArchSpec &arch) {
542 m_system_arch = arch;
543 if (IsHost())
545 }
546
547 /// If the triple contains not specify the vendor, os, and environment
548 /// parts, we "augment" these using information from the platform and return
549 /// the resulting ArchSpec object.
550 ArchSpec GetAugmentedArchSpec(llvm::StringRef triple);
551
552 // Used for column widths
554
555 // Used for column widths
557
558 const std::string &GetSDKRootDirectory() const { return m_sdk_sysroot; }
559
560 void SetSDKRootDirectory(std::string dir) { m_sdk_sysroot = std::move(dir); }
561
562 const std::string &GetSDKBuild() const { return m_sdk_build; }
563
564 void SetSDKBuild(std::string sdk_build) {
565 m_sdk_build = std::move(sdk_build);
566 }
567
568 // Override this to return true if your platform supports Clang modules. You
569 // may also need to override AddClangModuleCompilationOptions to pass the
570 // right Clang flags for your platform.
571 virtual bool SupportsModules() { return false; }
572
573 // Appends the platform-specific options required to find the modules for the
574 // current platform.
575 virtual void
577 std::vector<std::string> &options);
578
580
581 bool SetWorkingDirectory(const FileSpec &working_dir);
582
583 // There may be modules that we don't want to find by default for operations
584 // like "setting breakpoint by name". The platform will return "true" from
585 // this call if the passed in module happens to be one of these.
586
587 virtual bool
589 const lldb::ModuleSP &module_sp) {
590 return false;
591 }
592
593 virtual Status MakeDirectory(const FileSpec &file_spec, uint32_t permissions);
594
595 virtual Status GetFilePermissions(const FileSpec &file_spec,
596 uint32_t &file_permissions);
597
598 virtual Status SetFilePermissions(const FileSpec &file_spec,
599 uint32_t file_permissions);
600
601 virtual lldb::user_id_t OpenFile(const FileSpec &file_spec,
602 File::OpenOptions flags, uint32_t mode,
603 Status &error);
604
605 virtual bool CloseFile(lldb::user_id_t fd, Status &error);
606
607 virtual lldb::user_id_t GetFileSize(const FileSpec &file_spec);
608
610 bool only_dir) {}
611
612 virtual uint64_t ReadFile(lldb::user_id_t fd, uint64_t offset, void *dst,
613 uint64_t dst_len, Status &error);
614
615 virtual uint64_t WriteFile(lldb::user_id_t fd, uint64_t offset,
616 const void *src, uint64_t src_len, Status &error);
617
618 virtual Status GetFile(const FileSpec &source, const FileSpec &destination);
619
620 virtual Status PutFile(const FileSpec &source, const FileSpec &destination,
621 uint32_t uid = UINT32_MAX, uint32_t gid = UINT32_MAX);
622
623 virtual Status
624 CreateSymlink(const FileSpec &src, // The name of the link is in src
625 const FileSpec &dst); // The symlink points to dst
626
627 /// Install a file or directory to the remote system.
628 ///
629 /// Install is similar to Platform::PutFile(), but it differs in that if an
630 /// application/framework/shared library is installed on a remote platform
631 /// and the remote platform requires something to be done to register the
632 /// application/framework/shared library, then this extra registration can
633 /// be done.
634 ///
635 /// \param[in] src
636 /// The source file/directory to install on the remote system.
637 ///
638 /// \param[in] dst
639 /// The destination file/directory where \a src will be installed.
640 /// If \a dst has no filename specified, then its filename will
641 /// be set from \a src. It \a dst has no directory specified, it
642 /// will use the platform working directory. If \a dst has a
643 /// directory specified, but the directory path is relative, the
644 /// platform working directory will be prepended to the relative
645 /// directory.
646 ///
647 /// \return
648 /// An error object that describes anything that went wrong.
649 virtual Status Install(const FileSpec &src, const FileSpec &dst);
650
651 virtual Environment GetEnvironment();
652
653 virtual bool GetFileExists(const lldb_private::FileSpec &file_spec);
654
655 virtual Status Unlink(const FileSpec &file_spec);
656
657 virtual MmapArgList GetMmapArgumentList(const ArchSpec &arch,
658 lldb::addr_t addr,
659 lldb::addr_t length,
660 unsigned prot, unsigned flags,
661 lldb::addr_t fd, lldb::addr_t offset);
662
663 virtual bool GetSupportsRSync() { return m_supports_rsync; }
664
665 virtual void SetSupportsRSync(bool flag) { m_supports_rsync = flag; }
666
667 virtual const char *GetRSyncOpts() { return m_rsync_opts.c_str(); }
668
669 virtual void SetRSyncOpts(const char *opts) { m_rsync_opts.assign(opts); }
670
671 virtual const char *GetRSyncPrefix() { return m_rsync_prefix.c_str(); }
672
673 virtual void SetRSyncPrefix(const char *prefix) {
674 m_rsync_prefix.assign(prefix);
675 }
676
677 virtual bool GetSupportsSSH() { return m_supports_ssh; }
678
679 virtual void SetSupportsSSH(bool flag) { m_supports_ssh = flag; }
680
681 virtual const char *GetSSHOpts() { return m_ssh_opts.c_str(); }
682
683 virtual void SetSSHOpts(const char *opts) { m_ssh_opts.assign(opts); }
684
686
687 virtual void SetIgnoresRemoteHostname(bool flag) {
689 }
690
693 return nullptr;
694 }
695
697 llvm::StringRef command,
698 const FileSpec &working_dir, // Pass empty FileSpec to use the current
699 // working directory
700 int *status_ptr, // Pass nullptr if you don't want the process exit status
701 int *signo_ptr, // Pass nullptr if you don't want the signal that caused
702 // the process to exit
703 std::string
704 *command_output, // Pass nullptr if you don't want the command output
705 std::string
706 *separated_error_output, // Pass nullptr to have error and command
707 // output combined in command_output.
708 const Timeout<std::micro> &timeout);
709
711 llvm::StringRef shell, llvm::StringRef command,
712 const FileSpec &working_dir, // Pass empty FileSpec to use the current
713 // working directory
714 int *status_ptr, // Pass nullptr if you don't want the process exit status
715 int *signo_ptr, // Pass nullptr if you don't want the signal that caused
716 // the process to exit
717 std::string
718 *command_output, // Pass nullptr if you don't want the command output
719 std::string
720 *separated_error_output, // Pass nullptr to have error and command
721 // output combined in command_output.
722 const Timeout<std::micro> &timeout);
723
724 virtual void SetLocalCacheDirectory(const char *local);
725
726 virtual const char *GetLocalCacheDirectory();
727
728 virtual std::string GetPlatformSpecificConnectionInformation() { return ""; }
729
730 virtual llvm::ErrorOr<llvm::MD5::MD5Result>
731 CalculateMD5(const FileSpec &file_spec);
732
733 virtual uint32_t GetResumeCountForLaunchInfo(ProcessLaunchInfo &launch_info) {
734 return 1;
735 }
736
738
740
741 /// Locate a queue name given a thread's qaddr
742 ///
743 /// On a system using libdispatch ("Grand Central Dispatch") style queues, a
744 /// thread may be associated with a GCD queue or not, and a queue may be
745 /// associated with multiple threads. The process/thread must provide a way
746 /// to find the "dispatch_qaddr" for each thread, and from that
747 /// dispatch_qaddr this Platform method will locate the queue name and
748 /// provide that.
749 ///
750 /// \param[in] process
751 /// A process is required for reading memory.
752 ///
753 /// \param[in] dispatch_qaddr
754 /// The dispatch_qaddr for this thread.
755 ///
756 /// \return
757 /// The name of the queue, if there is one. An empty string
758 /// means that this thread is not associated with a dispatch
759 /// queue.
760 virtual std::string
762 return "";
763 }
764
765 /// Locate a queue ID given a thread's qaddr
766 ///
767 /// On a system using libdispatch ("Grand Central Dispatch") style queues, a
768 /// thread may be associated with a GCD queue or not, and a queue may be
769 /// associated with multiple threads. The process/thread must provide a way
770 /// to find the "dispatch_qaddr" for each thread, and from that
771 /// dispatch_qaddr this Platform method will locate the queue ID and provide
772 /// that.
773 ///
774 /// \param[in] process
775 /// A process is required for reading memory.
776 ///
777 /// \param[in] dispatch_qaddr
778 /// The dispatch_qaddr for this thread.
779 ///
780 /// \return
781 /// The queue_id for this thread, if this thread is associated
782 /// with a dispatch queue. Else LLDB_INVALID_QUEUE_ID is returned.
783 virtual lldb::queue_id_t
786 }
787
788 /// Provide a list of trap handler function names for this platform
789 ///
790 /// The unwinder needs to treat trap handlers specially -- the stack frame
791 /// may not be aligned correctly for a trap handler (the kernel often won't
792 /// perturb the stack pointer, or won't re-align it properly, in the process
793 /// of calling the handler) and the frame above the handler needs to be
794 /// treated by the unwinder's "frame 0" rules instead of its "middle of the
795 /// stack frame" rules.
796 ///
797 /// In a user process debugging scenario, the list of trap handlers is
798 /// typically just "_sigtramp".
799 ///
800 /// The Platform base class provides the m_trap_handlers ivar but it does
801 /// not populate it. Subclasses should add the names of the asynchronous
802 /// signal handler routines as needed. For most Unix platforms, add
803 /// _sigtramp.
804 ///
805 /// \return
806 /// A list of symbol names. The list may be empty.
807 virtual const std::vector<ConstString> &GetTrapHandlerSymbolNames();
808
809 /// Try to get a specific unwind plan for a named trap handler.
810 /// The default is not to have specific unwind plans for trap handlers.
811 ///
812 /// \param[in] arch
813 /// Architecture of the current target.
814 ///
815 /// \param[in] name
816 /// Name of the trap handler function.
817 ///
818 /// \return
819 /// A specific unwind plan for that trap handler, or an empty
820 /// shared pointer. The latter means there is no specific plan,
821 /// unwind as normal.
823 ConstString name) {
824 return {};
825 }
826
827 /// Find a support executable that may not live within in the standard
828 /// locations related to LLDB.
829 ///
830 /// Executable might exist within the Platform SDK directories, or in
831 /// standard tool directories within the current IDE that is running LLDB.
832 ///
833 /// \param[in] basename
834 /// The basename of the executable to locate in the current
835 /// platform.
836 ///
837 /// \return
838 /// A FileSpec pointing to the executable on disk, or an invalid
839 /// FileSpec if the executable cannot be found.
840 virtual FileSpec LocateExecutable(const char *basename) { return FileSpec(); }
841
842 /// Allow the platform to set preferred memory cache line size. If non-zero
843 /// (and the user has not set cache line size explicitly), this value will
844 /// be used as the cache line size for memory reads.
845 virtual uint32_t GetDefaultMemoryCacheLineSize() { return 0; }
846
847 /// Load a shared library into this process.
848 ///
849 /// Try and load a shared library into the current process. This call might
850 /// fail in the dynamic loader plug-in says it isn't safe to try and load
851 /// shared libraries at the moment.
852 ///
853 /// \param[in] process
854 /// The process to load the image.
855 ///
856 /// \param[in] local_file
857 /// The file spec that points to the shared library that you want
858 /// to load if the library is located on the host. The library will
859 /// be copied over to the location specified by remote_file or into
860 /// the current working directory with the same filename if the
861 /// remote_file isn't specified.
862 ///
863 /// \param[in] remote_file
864 /// If local_file is specified then the location where the library
865 /// should be copied over from the host. If local_file isn't
866 /// specified, then the path for the shared library on the target
867 /// what you want to load.
868 ///
869 /// \param[out] error
870 /// An error object that gets filled in with any errors that
871 /// might occur when trying to load the shared library.
872 ///
873 /// \return
874 /// A token that represents the shared library that can be
875 /// later used to unload the shared library. A value of
876 /// LLDB_INVALID_IMAGE_TOKEN will be returned if the shared
877 /// library can't be opened.
878 uint32_t LoadImage(lldb_private::Process *process,
879 const lldb_private::FileSpec &local_file,
880 const lldb_private::FileSpec &remote_file,
882
883 /// Load a shared library specified by base name into this process,
884 /// looking by hand along a set of paths.
885 ///
886 /// \param[in] process
887 /// The process to load the image.
888 ///
889 /// \param[in] library_name
890 /// The name of the library to look for. If library_name is an
891 /// absolute path, the basename will be extracted and searched for
892 /// along the paths. This emulates the behavior of the loader when
893 /// given an install name and a set (e.g. DYLD_LIBRARY_PATH provided) of
894 /// alternate paths.
895 ///
896 /// \param[in] paths
897 /// The list of paths to use to search for the library. First
898 /// match wins.
899 ///
900 /// \param[out] error
901 /// An error object that gets filled in with any errors that
902 /// might occur when trying to load the shared library.
903 ///
904 /// \param[out] loaded_path
905 /// If non-null, the path to the dylib that was successfully loaded
906 /// is stored in this path.
907 ///
908 /// \return
909 /// A token that represents the shared library which can be
910 /// passed to UnloadImage. A value of
911 /// LLDB_INVALID_IMAGE_TOKEN will be returned if the shared
912 /// library can't be opened.
914 const lldb_private::FileSpec &library_name,
915 const std::vector<std::string> &paths,
917 lldb_private::FileSpec *loaded_path);
918
919 virtual uint32_t DoLoadImage(lldb_private::Process *process,
920 const lldb_private::FileSpec &remote_file,
921 const std::vector<std::string> *paths,
923 lldb_private::FileSpec *loaded_path = nullptr);
924
926 uint32_t image_token);
927
928 /// Connect to all processes waiting for a debugger to attach
929 ///
930 /// If the platform have a list of processes waiting for a debugger to
931 /// connect to them then connect to all of these pending processes.
932 ///
933 /// \param[in] debugger
934 /// The debugger used for the connect.
935 ///
936 /// \param[out] error
937 /// If an error occurred during the connect then this object will
938 /// contain the error message.
939 ///
940 /// \return
941 /// The number of processes we are successfully connected to.
942 virtual size_t ConnectToWaitingProcesses(lldb_private::Debugger &debugger,
944
945 /// Gather all of crash informations into a structured data dictionary.
946 ///
947 /// If the platform have a crashed process with crash information entries,
948 /// gather all the entries into an structured data dictionary or return a
949 /// nullptr. This dictionary is generic and extensible, as it contains an
950 /// array for each different type of crash information.
951 ///
952 /// \param[in] process
953 /// The crashed process.
954 ///
955 /// \return
956 /// A structured data dictionary containing at each entry, the crash
957 /// information type as the entry key and the matching an array as the
958 /// entry value. \b nullptr if not implemented or if the process has no
959 /// crash information entry. \b error if an error occurred.
960 virtual llvm::Expected<StructuredData::DictionarySP>
962 return nullptr;
963 }
964
965 /// Detect a binary in memory that will determine which Platform and
966 /// DynamicLoader should be used in this target/process, and update
967 /// the Platform/DynamicLoader.
968 /// The binary will be loaded into the Target, or will be registered with
969 /// the DynamicLoader so that it will be loaded at a later stage. Returns
970 /// true to indicate that this is a platform binary and has been
971 /// loaded/registered, no further action should be taken by the caller.
972 ///
973 /// \param[in] process
974 /// Process read memory from, a Process must be provided.
975 ///
976 /// \param[in] addr
977 /// Address of a binary in memory.
978 ///
979 /// \param[in] notify
980 /// Whether ModulesDidLoad should be called, if a binary is loaded.
981 /// Caller may prefer to call ModulesDidLoad for multiple binaries
982 /// that were loaded at the same time.
983 ///
984 /// \return
985 /// Returns true if the binary was loaded in the target (or will be
986 /// via a DynamicLoader). Returns false if the binary was not
987 /// loaded/registered, and the caller must load it into the target.
989 bool notify) {
990 return false;
991 }
992
993 virtual CompilerType GetSiginfoType(const llvm::Triple &triple);
994
995 virtual lldb::StopInfoSP GetStopInfoFromSiginfo(Thread &thread) { return {}; }
996
998
999 typedef std::function<Status(const ModuleSpec &module_spec,
1000 FileSpec &module_file_spec,
1001 FileSpec &symbol_file_spec)>
1003
1004 /// Set locate module callback. This allows users to implement their own
1005 /// module cache system. For example, to leverage artifacts of build system,
1006 /// to bypass pulling files from remote platform, or to search symbol files
1007 /// from symbol servers.
1009
1011
1012 /// Returns a \c FileSpecList of safe paths to auto-load scripting resources
1013 /// from for a particular platform.
1014 virtual llvm::Expected<FileSpecList>
1015 GetSafeAutoLoadPaths(const Target &target) const {
1016 return FileSpecList();
1017 }
1018
1019protected:
1020 /// Create a list of ArchSpecs with the given OS and a architectures. The
1021 /// vendor field is left as an "unspecified unknown".
1022 static std::vector<ArchSpec>
1023 CreateArchList(llvm::ArrayRef<llvm::Triple::ArchType> archs,
1024 llvm::Triple::OSType os);
1025
1026 /// Private implementation of connecting to a process. If the stream is set
1027 /// we connect synchronously.
1028 lldb::ProcessSP DoConnectProcess(llvm::StringRef connect_url,
1029 llvm::StringRef plugin_name,
1030 Debugger &debugger, Stream *stream,
1031 Target *target, Status &error);
1033 // Set to true when we are able to actually set the OS version while being
1034 // connected. For remote platforms, we might set the version ahead of time
1035 // before we actually connect and this version might change when we actually
1036 // connect to a remote platform. For the host platform this will be set to
1037 // the once we call HostInfo::GetOSVersion().
1040 std::string
1041 m_sdk_sysroot; // the root location of where the SDK files are all located
1042 std::string m_sdk_build;
1043 FileSpec m_working_dir; // The working directory which is used when installing
1044 // modules that have no install path set
1045 std::string m_hostname;
1046 llvm::VersionTuple m_os_version;
1047 ArchSpec
1048 m_system_arch; // The architecture of the kernel or the remote platform
1049 typedef std::map<uint32_t, ConstString> IDToNameMap;
1050 // Mutex for modifying Platform data structures that should only be used for
1051 // non-reentrant code
1052 std::mutex m_mutex;
1056 std::string m_rsync_opts;
1057 std::string m_rsync_prefix;
1059 std::string m_ssh_opts;
1062 std::vector<ConstString> m_trap_handlers;
1064 const std::unique_ptr<ModuleCache> m_module_cache;
1066
1067 /// Ask the Platform subclass to fill in the list of trap handler names
1068 ///
1069 /// For most Unix user process environments, this will be a single function
1070 /// name, _sigtramp. More specialized environments may have additional
1071 /// handler names. The unwinder code needs to know when a trap handler is
1072 /// on the stack because the unwind rules for the frame that caused the trap
1073 /// are different.
1074 ///
1075 /// The base class Platform ivar m_trap_handlers should be updated by the
1076 /// Platform subclass when this method is called. If there are no
1077 /// predefined trap handlers, this method may be a no-op.
1079
1081 lldb::ModuleSP &module_sp);
1082
1083 virtual Status DownloadModuleSlice(const FileSpec &src_file_spec,
1084 const uint64_t src_offset,
1085 const uint64_t src_size,
1086 const FileSpec &dst_file_spec);
1087
1088 virtual Status DownloadSymbolFile(const lldb::ModuleSP &module_sp,
1089 const FileSpec &dst_file_spec);
1090
1091 virtual const char *GetCacheHostname();
1092
1093 /// If we did some replacements of reserved characters, and a
1094 /// file with the untampered name exists, then warn the user
1095 /// that the file as-is shall not be loaded.
1097 Stream &os,
1099 const FileSpec &original_fspec, const FileSpec &fspec);
1100
1101 /// Returns the \c LoadScriptFromSymFile of scripting resource associated
1102 /// with the specified module \c FileSpec. If the load style wasn't explicitly
1103 /// set for a module, returns the target-wide default.
1105 GetScriptLoadStyleForModule(const FileSpec &module_fspec,
1106 const Target &target);
1107
1108private:
1109 typedef std::function<Status(const ModuleSpec &)> ModuleResolver;
1110
1111 Status GetRemoteSharedModule(const ModuleSpec &module_spec, Process *process,
1112 lldb::ModuleSP &module_sp,
1113 const ModuleResolver &module_resolver,
1114 bool *did_create_ptr);
1115
1116 bool GetCachedSharedModule(const ModuleSpec &module_spec,
1117 lldb::ModuleSP &module_sp, bool *did_create_ptr);
1118
1120};
1121
1123public:
1124 PlatformList() = default;
1125
1126 ~PlatformList() = default;
1127
1128 void Append(const lldb::PlatformSP &platform_sp, bool set_selected) {
1129 std::lock_guard<std::recursive_mutex> guard(m_mutex);
1130 m_platforms.push_back(platform_sp);
1131 if (set_selected)
1133 }
1134
1135 size_t GetSize() {
1136 std::lock_guard<std::recursive_mutex> guard(m_mutex);
1137 return m_platforms.size();
1138 }
1139
1141 lldb::PlatformSP platform_sp;
1142 {
1143 std::lock_guard<std::recursive_mutex> guard(m_mutex);
1144 if (idx < m_platforms.size())
1145 platform_sp = m_platforms[idx];
1146 }
1147 return platform_sp;
1148 }
1149
1150 /// Select the active platform.
1151 ///
1152 /// In order to debug remotely, other platform's can be remotely connected
1153 /// to and set as the selected platform for any subsequent debugging. This
1154 /// allows connection to remote targets and allows the ability to discover
1155 /// process info, launch and attach to remote processes.
1157 std::lock_guard<std::recursive_mutex> guard(m_mutex);
1158 if (!m_selected_platform_sp && !m_platforms.empty())
1160
1162 }
1163
1164 void SetSelectedPlatform(const lldb::PlatformSP &platform_sp) {
1165 if (platform_sp) {
1166 std::lock_guard<std::recursive_mutex> guard(m_mutex);
1167 const size_t num_platforms = m_platforms.size();
1168 for (size_t idx = 0; idx < num_platforms; ++idx) {
1169 if (m_platforms[idx].get() == platform_sp.get()) {
1171 return;
1172 }
1173 }
1174 m_platforms.push_back(platform_sp);
1176 }
1177 }
1178
1179 lldb::PlatformSP GetOrCreate(llvm::StringRef name);
1181 const ArchSpec &process_host_arch,
1182 ArchSpec *platform_arch_ptr, Status &error);
1184 const ArchSpec &process_host_arch,
1185 ArchSpec *platform_arch_ptr);
1186
1187 /// Get the platform for the given list of architectures.
1188 ///
1189 /// The algorithm works a follows:
1190 ///
1191 /// 1. Returns the selected platform if it matches any of the architectures.
1192 /// 2. Returns the host platform if it matches any of the architectures.
1193 /// 3. Returns the platform that matches all the architectures.
1194 ///
1195 /// If none of the above apply, this function returns a default platform. The
1196 /// candidates output argument differentiates between either no platforms
1197 /// supporting the given architecture or multiple platforms supporting the
1198 /// given architecture.
1199 lldb::PlatformSP GetOrCreate(llvm::ArrayRef<ArchSpec> archs,
1200 const ArchSpec &process_host_arch,
1201 std::vector<lldb::PlatformSP> &candidates);
1202
1203 lldb::PlatformSP Create(llvm::StringRef name);
1204
1205 /// Detect a binary in memory that will determine which Platform and
1206 /// DynamicLoader should be used in this target/process, and update
1207 /// the Platform/DynamicLoader.
1208 /// The binary will be loaded into the Target, or will be registered with
1209 /// the DynamicLoader so that it will be loaded at a later stage. Returns
1210 /// true to indicate that this is a platform binary and has been
1211 /// loaded/registered, no further action should be taken by the caller.
1212 ///
1213 /// \param[in] process
1214 /// Process read memory from, a Process must be provided.
1215 ///
1216 /// \param[in] addr
1217 /// Address of a binary in memory.
1218 ///
1219 /// \param[in] notify
1220 /// Whether ModulesDidLoad should be called, if a binary is loaded.
1221 /// Caller may prefer to call ModulesDidLoad for multiple binaries
1222 /// that were loaded at the same time.
1223 ///
1224 /// \return
1225 /// Returns true if the binary was loaded in the target (or will be
1226 /// via a DynamicLoader). Returns false if the binary was not
1227 /// loaded/registered, and the caller must load it into the target.
1229 bool notify);
1230
1231protected:
1232 typedef std::vector<lldb::PlatformSP> collection;
1233 mutable std::recursive_mutex m_mutex;
1236
1237private:
1238 PlatformList(const PlatformList &) = delete;
1239 const PlatformList &operator=(const PlatformList &) = delete;
1240};
1241
1243public:
1245
1246 ~OptionGroupPlatformRSync() override = default;
1247
1249 SetOptionValue(uint32_t option_idx, llvm::StringRef option_value,
1250 ExecutionContext *execution_context) override;
1251
1252 void OptionParsingStarting(ExecutionContext *execution_context) override;
1253
1254 llvm::ArrayRef<OptionDefinition> GetDefinitions() override;
1255
1256 // Instance variables to hold the values for command options.
1257
1259 std::string m_rsync_opts;
1260 std::string m_rsync_prefix;
1262
1263private:
1267};
1268
1270public:
1272
1273 ~OptionGroupPlatformSSH() override = default;
1274
1276 SetOptionValue(uint32_t option_idx, llvm::StringRef option_value,
1277 ExecutionContext *execution_context) override;
1278
1279 void OptionParsingStarting(ExecutionContext *execution_context) override;
1280
1281 llvm::ArrayRef<OptionDefinition> GetDefinitions() override;
1282
1283 // Instance variables to hold the values for command options.
1284
1285 bool m_ssh;
1286 std::string m_ssh_opts;
1287
1288private:
1292};
1293
1295public:
1297
1298 ~OptionGroupPlatformCaching() override = default;
1299
1301 SetOptionValue(uint32_t option_idx, llvm::StringRef option_value,
1302 ExecutionContext *execution_context) override;
1303
1304 void OptionParsingStarting(ExecutionContext *execution_context) override;
1305
1306 llvm::ArrayRef<OptionDefinition> GetDefinitions() override;
1307
1308 // Instance variables to hold the values for command options.
1309
1310 std::string m_cache_dir;
1311
1312private:
1316};
1317
1318} // namespace lldb_private
1319
1320#endif // LLDB_TARGET_PLATFORM_H
static llvm::raw_ostream & error(Stream &strm)
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:57
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:90
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:1140
lldb::PlatformSP m_selected_platform_sp
Definition Platform.h:1235
std::recursive_mutex m_mutex
Definition Platform.h:1233
std::vector< lldb::PlatformSP > collection
Definition Platform.h:1232
void Append(const lldb::PlatformSP &platform_sp, bool set_selected)
Definition Platform.h:1128
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:1156
void SetSelectedPlatform(const lldb::PlatformSP &platform_sp)
Definition Platform.h:1164
lldb::PlatformSP GetOrCreate(llvm::StringRef name)
FileSpec GetModuleCacheDirectory() const
Definition Platform.cpp:113
bool SetUseModuleCache(bool use_module_cache)
Definition Platform.cpp:109
void SetDefaultModuleCacheDirectory(const FileSpec &dir_spec)
Definition Platform.cpp:122
bool SetModuleCacheDirectory(const FileSpec &dir_spec)
Definition Platform.cpp:117
static llvm::StringRef GetSettingName()
Definition Platform.cpp:79
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:564
virtual Status GetFileWithUUID(const FileSpec &platform_file, const UUID *uuid_ptr, FileSpec &local_file)
Locate a file for a platform.
Definition Platform.cpp:155
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:889
std::map< uint32_t, ConstString > IDToNameMap
Definition Platform.h:1049
ProcessInstanceInfoList GetAllProcesses()
virtual bool GetFileExists(const lldb_private::FileSpec &file_spec)
virtual bool CloseFile(lldb::user_id_t fd, Status &error)
Definition Platform.cpp:742
const std::string & GetSDKBuild() const
Definition Platform.h:562
virtual llvm::Expected< XcodeSDK > GetSDKPathFromDebugInfo(CompileUnit &)
Search CU for the SDK path the CUs was compiled against.
Definition Platform.h:507
virtual bool IsConnected() const
Definition Platform.h:534
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:734
virtual void SetSupportsSSH(bool flag)
Definition Platform.h:679
virtual const char * GetHostname()
Definition Platform.cpp:784
void SetSystemArchitecture(const ArchSpec &arch)
Definition Platform.h:541
std::vector< ConstString > m_trap_handlers
Definition Platform.h:1062
size_t GetMaxUserIDNameLength() const
Definition Platform.h:553
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:479
virtual const char * GetRSyncPrefix()
Definition Platform.h:671
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:995
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:142
virtual void CalculateTrapHandlerSymbolNames()=0
Ask the Platform subclass to fill in the list of trap handler names.
virtual Status GetSharedModule(const ModuleSpec &module_spec, Process *process, lldb::ModuleSP &module_sp, llvm::SmallVectorImpl< lldb::ModuleSP > *old_modules, bool *did_create_ptr)
Definition Platform.cpp:258
virtual bool IsSymbolFileTrusted(Module &module)
Returns true if the module's symbol file (e.g.
Definition Platform.cpp:162
std::string m_rsync_prefix
Definition Platform.h:1057
llvm::VersionTuple m_os_version
Definition Platform.h:1046
virtual llvm::Expected< std::string > ResolveSDKPathFromDebugInfo(Module &module)
Returns the full path of the most appropriate SDK for the specified 'module'.
Definition Platform.h:495
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:827
const std::string & GetSDKRootDirectory() const
Definition Platform.h:558
virtual Status GetFilePermissions(const FileSpec &file_spec, uint32_t &file_permissions)
Definition Platform.cpp:704
virtual void SetIgnoresRemoteHostname(bool flag)
Definition Platform.h:687
virtual Status MakeDirectory(const FileSpec &file_spec, uint32_t permissions)
Definition Platform.cpp:691
FileSpec GetWorkingDirectory()
Definition Platform.cpp:453
virtual void AddClangModuleCompilationOptions(Target *target, std::vector< std::string > &options)
Definition Platform.cpp:444
virtual UserIDResolver & GetUserIDResolver()
Definition Platform.cpp:778
virtual Status PutFile(const FileSpec &source, const FileSpec &destination, uint32_t uid=UINT32_MAX, uint32_t gid=UINT32_MAX)
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:320
virtual ConstString GetFullNameForDylib(ConstString basename)
Definition Platform.cpp:793
~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:556
bool m_system_arch_set_while_connected
Definition Platform.h:1039
Platform(bool is_host_platform)
Default Constructor.
Definition Platform.cpp:327
static lldb::PlatformSP Create(llvm::StringRef name)
Definition Platform.cpp:309
virtual Status DisconnectRemote()
Definition Platform.cpp:982
virtual void SetSupportsRSync(bool flag)
Definition Platform.h:665
static lldb::PlatformSP GetHostPlatform()
Get the native host platform plug-in.
Definition Platform.cpp:138
std::string m_local_cache_directory
Definition Platform.h:1061
virtual bool GetSupportsSSH()
Definition Platform.h:677
virtual lldb::BreakpointSP SetThreadCreationBreakpoint(Target &target)
lldb::UnixSignalsSP GetUnixSignals()
virtual lldb::user_id_t GetFileSize(const FileSpec &file_spec)
Definition Platform.cpp:748
bool SetWorkingDirectory(const FileSpec &working_dir)
Definition Platform.cpp:676
std::string m_sdk_build
Definition Platform.h:1042
static void SetHostPlatform(const lldb::PlatformSP &platform_sp)
Definition Platform.cpp:149
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:840
const ArchSpec & GetSystemArchitecture()
Definition Platform.cpp:906
virtual void SetSSHOpts(const char *opts)
Definition Platform.h:683
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:522
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:238
virtual llvm::StringRef GetDescription()=0
void SetSDKBuild(std::string sdk_build)
Definition Platform.h:564
virtual lldb::UnwindPlanSP GetTrapHandlerUnwindPlan(const ArchSpec &arch, ConstString name)
Try to get a specific unwind plan for a named trap handler.
Definition Platform.h:822
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:784
virtual Status Unlink(const FileSpec &file_spec)
virtual const char * GetRSyncOpts()
Definition Platform.h:667
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:797
virtual std::optional< std::string > GetRemoteOSKernelDescription()
Definition Platform.h:230
LocateModuleCallback m_locate_module_callback
Definition Platform.h:1065
virtual std::string GetQueueNameForThreadQAddress(Process *process, lldb::addr_t dispatch_qaddr)
Locate a queue name given a thread's qaddr.
Definition Platform.h:761
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:390
virtual llvm::Expected< StructuredData::DictionarySP > FetchExtendedCrashInformation(lldb_private::Process &process)
Gather all of crash informations into a structured data dictionary.
Definition Platform.h:961
virtual void GetStatus(Stream &strm)
Report the current status for this platform.
Definition Platform.cpp:341
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:669
virtual Status DownloadSymbolFile(const lldb::ModuleSP &module_sp, const FileSpec &dst_file_spec)
bool SetOSVersion(llvm::VersionTuple os_version)
Definition Platform.cpp:805
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:1015
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:140
std::optional< std::string > GetOSBuildString()
Definition Platform.cpp:432
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:673
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:571
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:845
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:692
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:988
std::string m_hostname
Definition Platform.h:1045
static PlatformProperties & GetGlobalPlatformProperties()
Definition Platform.cpp:144
virtual uint64_t WriteFile(lldb::user_id_t fd, uint64_t offset, const void *src, uint64_t src_len, Status &error)
Definition Platform.cpp:768
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:1064
virtual std::string GetPlatformSpecificConnectionInformation()
Definition Platform.h:728
LocateModuleCallback GetLocateModuleCallback() const
Status GetRemoteSharedModule(const ModuleSpec &module_spec, Process *process, lldb::ModuleSP &module_sp, const ModuleResolver &module_resolver, bool *did_create_ptr)
virtual bool GetIgnoresRemoteHostname()
Definition Platform.h:685
bool IsRemote() const
Definition Platform.h:532
void SetSDKRootDirectory(std::string dir)
Definition Platform.h:560
bool m_os_version_set_while_connected
Definition Platform.h:1038
virtual Status GetFile(const FileSpec &source, const FileSpec &destination)
virtual bool GetSupportsRSync()
Definition Platform.h:663
FileSpec GetModuleCacheRoot()
virtual uint32_t GetResumeCountForLaunchInfo(ProcessLaunchInfo &launch_info)
Definition Platform.h:733
virtual const char * GetCacheHostname()
virtual Status SetFilePermissions(const FileSpec &file_spec, uint32_t file_permissions)
Definition Platform.cpp:720
virtual bool GetProcessInfo(lldb::pid_t pid, ProcessInstanceInfo &proc_info)
Definition Platform.cpp:996
bool IsHost() const
Definition Platform.h:528
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:231
std::function< Status(const ModuleSpec &)> ModuleResolver
Definition Platform.h:1109
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:165
virtual Environment GetEnvironment()
virtual const lldb::UnixSignalsSP & GetRemoteUnixSignals()
virtual bool ModuleIsExcludedForUnconstrainedSearches(Target &target, const lldb::ModuleSP &module_sp)
Definition Platform.h:588
std::string m_rsync_opts
Definition Platform.h:1056
virtual void AutoCompleteDiskFileOrDirectory(CompletionRequest &request, bool only_dir)
Definition Platform.h:609
virtual Status ConnectRemote(Args &args)
Definition Platform.cpp:969
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:899
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:1002
std::string m_sdk_sysroot
Definition Platform.h:1041
virtual bool CanDebugProcess()
Not all platforms will support debugging a process by spawning somehow halted for a debugger (specifi...
Definition Platform.h:385
std::string m_ssh_opts
Definition Platform.h:1059
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:65
virtual uint64_t ReadFile(lldb::user_id_t fd, uint64_t offset, void *dst, uint64_t dst_len, Status &error)
Definition Platform.cpp:758
virtual bool GetModuleSpec(const FileSpec &module_file_spec, const ArchSpec &arch, ModuleSpec &module_spec)
Definition Platform.cpp:299
virtual lldb_private::ConstString GetSDKDirectory(lldb_private::Target &target)
Definition Platform.h:462
std::optional< std::string > GetOSKernelDescription()
Definition Platform.cpp:438
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:176
virtual const char * GetSSHOpts()
Definition Platform.h:681
virtual llvm::StringRef GetPluginName()=0
A plug-in interface definition class for debugging a process.
Definition Process.h:355
Holds an lldb_private::Module name and a "sanitized" version of it for the purposes of loading a scri...
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:57
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:83
std::shared_ptr< lldb_private::UnwindPlan > UnwindPlanSP
uint64_t user_id_t
Definition lldb-types.h:82
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:91