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