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