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