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 /// Search CU for the SDK path the CUs was compiled against.
477 ///
478 /// \param[in] unit The CU
479 ///
480 /// \returns A parsed XcodeSDK object if successful, an Error otherwise.
481 virtual llvm::Expected<XcodeSDK> GetSDKPathFromDebugInfo(CompileUnit &unit) {
482 return llvm::createStringError(
483 llvm::formatv("{0} not implemented for '{1}' platform.",
484 LLVM_PRETTY_FUNCTION, GetName()));
485 }
486
487 /// Returns the full path of the most appropriate SDK for the
488 /// specified compile unit. This function gets this path by parsing
489 /// debug-info (see \ref `GetSDKPathFromDebugInfo`).
490 ///
491 /// \param[in] unit The CU to scan.
492 ///
493 /// \returns If successful, returns the full path to an
494 /// Xcode SDK.
495 virtual llvm::Expected<std::string>
497 return llvm::createStringError(
498 llvm::formatv("{0} not implemented for '{1}' platform.",
499 LLVM_PRETTY_FUNCTION, GetName()));
500 }
501
502 bool IsHost() const {
503 return m_is_host; // Is this the default host platform?
504 }
505
506 bool IsRemote() const { return !m_is_host; }
507
508 virtual bool IsConnected() const {
509 // Remote subclasses should override this function
510 return IsHost();
511 }
512
514
515 void SetSystemArchitecture(const ArchSpec &arch) {
516 m_system_arch = arch;
517 if (IsHost())
519 }
520
521 /// If the triple contains not specify the vendor, os, and environment
522 /// parts, we "augment" these using information from the platform and return
523 /// the resulting ArchSpec object.
524 ArchSpec GetAugmentedArchSpec(llvm::StringRef triple);
525
526 // Used for column widths
528
529 // Used for column widths
531
532 const std::string &GetSDKRootDirectory() const { return m_sdk_sysroot; }
533
534 void SetSDKRootDirectory(std::string dir) { m_sdk_sysroot = std::move(dir); }
535
536 const std::string &GetSDKBuild() const { return m_sdk_build; }
537
538 void SetSDKBuild(std::string sdk_build) {
539 m_sdk_build = std::move(sdk_build);
540 }
541
542 // Override this to return true if your platform supports Clang modules. You
543 // may also need to override AddClangModuleCompilationOptions to pass the
544 // right Clang flags for your platform.
545 virtual bool SupportsModules() { return false; }
546
547 // Appends the platform-specific options required to find the modules for the
548 // current platform.
549 virtual void
551 std::vector<std::string> &options);
552
554
555 bool SetWorkingDirectory(const FileSpec &working_dir);
556
557 // There may be modules that we don't want to find by default for operations
558 // like "setting breakpoint by name". The platform will return "true" from
559 // this call if the passed in module happens to be one of these.
560
561 virtual bool
563 const lldb::ModuleSP &module_sp) {
564 return false;
565 }
566
567 virtual Status MakeDirectory(const FileSpec &file_spec, uint32_t permissions);
568
569 virtual Status GetFilePermissions(const FileSpec &file_spec,
570 uint32_t &file_permissions);
571
572 virtual Status SetFilePermissions(const FileSpec &file_spec,
573 uint32_t file_permissions);
574
575 virtual lldb::user_id_t OpenFile(const FileSpec &file_spec,
576 File::OpenOptions flags, uint32_t mode,
577 Status &error);
578
579 virtual bool CloseFile(lldb::user_id_t fd, Status &error);
580
581 virtual lldb::user_id_t GetFileSize(const FileSpec &file_spec);
582
584 bool only_dir) {}
585
586 virtual uint64_t ReadFile(lldb::user_id_t fd, uint64_t offset, void *dst,
587 uint64_t dst_len, Status &error);
588
589 virtual uint64_t WriteFile(lldb::user_id_t fd, uint64_t offset,
590 const void *src, uint64_t src_len, Status &error);
591
592 virtual Status GetFile(const FileSpec &source, const FileSpec &destination);
593
594 virtual Status PutFile(const FileSpec &source, const FileSpec &destination,
595 uint32_t uid = UINT32_MAX, uint32_t gid = UINT32_MAX);
596
597 virtual Status
598 CreateSymlink(const FileSpec &src, // The name of the link is in src
599 const FileSpec &dst); // The symlink points to dst
600
601 /// Install a file or directory to the remote system.
602 ///
603 /// Install is similar to Platform::PutFile(), but it differs in that if an
604 /// application/framework/shared library is installed on a remote platform
605 /// and the remote platform requires something to be done to register the
606 /// application/framework/shared library, then this extra registration can
607 /// be done.
608 ///
609 /// \param[in] src
610 /// The source file/directory to install on the remote system.
611 ///
612 /// \param[in] dst
613 /// The destination file/directory where \a src will be installed.
614 /// If \a dst has no filename specified, then its filename will
615 /// be set from \a src. It \a dst has no directory specified, it
616 /// will use the platform working directory. If \a dst has a
617 /// directory specified, but the directory path is relative, the
618 /// platform working directory will be prepended to the relative
619 /// directory.
620 ///
621 /// \return
622 /// An error object that describes anything that went wrong.
623 virtual Status Install(const FileSpec &src, const FileSpec &dst);
624
625 virtual Environment GetEnvironment();
626
627 virtual bool GetFileExists(const lldb_private::FileSpec &file_spec);
628
629 virtual Status Unlink(const FileSpec &file_spec);
630
631 virtual MmapArgList GetMmapArgumentList(const ArchSpec &arch,
632 lldb::addr_t addr,
633 lldb::addr_t length,
634 unsigned prot, unsigned flags,
635 lldb::addr_t fd, lldb::addr_t offset);
636
637 virtual bool GetSupportsRSync() { return m_supports_rsync; }
638
639 virtual void SetSupportsRSync(bool flag) { m_supports_rsync = flag; }
640
641 virtual const char *GetRSyncOpts() { return m_rsync_opts.c_str(); }
642
643 virtual void SetRSyncOpts(const char *opts) { m_rsync_opts.assign(opts); }
644
645 virtual const char *GetRSyncPrefix() { return m_rsync_prefix.c_str(); }
646
647 virtual void SetRSyncPrefix(const char *prefix) {
648 m_rsync_prefix.assign(prefix);
649 }
650
651 virtual bool GetSupportsSSH() { return m_supports_ssh; }
652
653 virtual void SetSupportsSSH(bool flag) { m_supports_ssh = flag; }
654
655 virtual const char *GetSSHOpts() { return m_ssh_opts.c_str(); }
656
657 virtual void SetSSHOpts(const char *opts) { m_ssh_opts.assign(opts); }
658
660
661 virtual void SetIgnoresRemoteHostname(bool flag) {
663 }
664
667 return nullptr;
668 }
669
671 llvm::StringRef command,
672 const FileSpec &working_dir, // Pass empty FileSpec to use the current
673 // working directory
674 int *status_ptr, // Pass nullptr if you don't want the process exit status
675 int *signo_ptr, // Pass nullptr if you don't want the signal that caused
676 // the process to exit
677 std::string
678 *command_output, // Pass nullptr if you don't want the command output
679 const Timeout<std::micro> &timeout);
680
682 llvm::StringRef shell, llvm::StringRef command,
683 const FileSpec &working_dir, // Pass empty FileSpec to use the current
684 // working directory
685 int *status_ptr, // Pass nullptr if you don't want the process exit status
686 int *signo_ptr, // Pass nullptr if you don't want the signal that caused
687 // the process to exit
688 std::string
689 *command_output, // Pass nullptr if you don't want the command output
690 const Timeout<std::micro> &timeout);
691
692 virtual void SetLocalCacheDirectory(const char *local);
693
694 virtual const char *GetLocalCacheDirectory();
695
696 virtual std::string GetPlatformSpecificConnectionInformation() { return ""; }
697
698 virtual llvm::ErrorOr<llvm::MD5::MD5Result>
699 CalculateMD5(const FileSpec &file_spec);
700
701 virtual uint32_t GetResumeCountForLaunchInfo(ProcessLaunchInfo &launch_info) {
702 return 1;
703 }
704
706
708
709 /// Locate a queue name 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 name and
716 /// provide 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 name of the queue, if there is one. An empty string
726 /// means that this thread is not associated with a dispatch
727 /// queue.
728 virtual std::string
730 return "";
731 }
732
733 /// Locate a queue ID given a thread's qaddr
734 ///
735 /// On a system using libdispatch ("Grand Central Dispatch") style queues, a
736 /// thread may be associated with a GCD queue or not, and a queue may be
737 /// associated with multiple threads. The process/thread must provide a way
738 /// to find the "dispatch_qaddr" for each thread, and from that
739 /// dispatch_qaddr this Platform method will locate the queue ID and provide
740 /// that.
741 ///
742 /// \param[in] process
743 /// A process is required for reading memory.
744 ///
745 /// \param[in] dispatch_qaddr
746 /// The dispatch_qaddr for this thread.
747 ///
748 /// \return
749 /// The queue_id for this thread, if this thread is associated
750 /// with a dispatch queue. Else LLDB_INVALID_QUEUE_ID is returned.
751 virtual lldb::queue_id_t
754 }
755
756 /// Provide a list of trap handler function names for this platform
757 ///
758 /// The unwinder needs to treat trap handlers specially -- the stack frame
759 /// may not be aligned correctly for a trap handler (the kernel often won't
760 /// perturb the stack pointer, or won't re-align it properly, in the process
761 /// of calling the handler) and the frame above the handler needs to be
762 /// treated by the unwinder's "frame 0" rules instead of its "middle of the
763 /// stack frame" rules.
764 ///
765 /// In a user process debugging scenario, the list of trap handlers is
766 /// typically just "_sigtramp".
767 ///
768 /// The Platform base class provides the m_trap_handlers ivar but it does
769 /// not populate it. Subclasses should add the names of the asynchronous
770 /// signal handler routines as needed. For most Unix platforms, add
771 /// _sigtramp.
772 ///
773 /// \return
774 /// A list of symbol names. The list may be empty.
775 virtual const std::vector<ConstString> &GetTrapHandlerSymbolNames();
776
777 /// Try to get a specific unwind plan for a named trap handler.
778 /// The default is not to have specific unwind plans for trap handlers.
779 ///
780 /// \param[in] triple
781 /// Triple of the current target.
782 ///
783 /// \param[in] name
784 /// Name of the trap handler function.
785 ///
786 /// \return
787 /// A specific unwind plan for that trap handler, or an empty
788 /// shared pointer. The latter means there is no specific plan,
789 /// unwind as normal.
790 virtual lldb::UnwindPlanSP
791 GetTrapHandlerUnwindPlan(const llvm::Triple &triple, ConstString name) {
792 return {};
793 }
794
795 /// Find a support executable that may not live within in the standard
796 /// locations related to LLDB.
797 ///
798 /// Executable might exist within the Platform SDK directories, or in
799 /// standard tool directories within the current IDE that is running LLDB.
800 ///
801 /// \param[in] basename
802 /// The basename of the executable to locate in the current
803 /// platform.
804 ///
805 /// \return
806 /// A FileSpec pointing to the executable on disk, or an invalid
807 /// FileSpec if the executable cannot be found.
808 virtual FileSpec LocateExecutable(const char *basename) { return FileSpec(); }
809
810 /// Allow the platform to set preferred memory cache line size. If non-zero
811 /// (and the user has not set cache line size explicitly), this value will
812 /// be used as the cache line size for memory reads.
813 virtual uint32_t GetDefaultMemoryCacheLineSize() { return 0; }
814
815 /// Load a shared library into this process.
816 ///
817 /// Try and load a shared library into the current process. This call might
818 /// fail in the dynamic loader plug-in says it isn't safe to try and load
819 /// shared libraries at the moment.
820 ///
821 /// \param[in] process
822 /// The process to load the image.
823 ///
824 /// \param[in] local_file
825 /// The file spec that points to the shared library that you want
826 /// to load if the library is located on the host. The library will
827 /// be copied over to the location specified by remote_file or into
828 /// the current working directory with the same filename if the
829 /// remote_file isn't specified.
830 ///
831 /// \param[in] remote_file
832 /// If local_file is specified then the location where the library
833 /// should be copied over from the host. If local_file isn't
834 /// specified, then the path for the shared library on the target
835 /// what you want to load.
836 ///
837 /// \param[out] error
838 /// An error object that gets filled in with any errors that
839 /// might occur when trying to load the shared library.
840 ///
841 /// \return
842 /// A token that represents the shared library that can be
843 /// later used to unload the shared library. A value of
844 /// LLDB_INVALID_IMAGE_TOKEN will be returned if the shared
845 /// library can't be opened.
846 uint32_t LoadImage(lldb_private::Process *process,
847 const lldb_private::FileSpec &local_file,
848 const lldb_private::FileSpec &remote_file,
850
851 /// Load a shared library specified by base name into this process,
852 /// looking by hand along a set of paths.
853 ///
854 /// \param[in] process
855 /// The process to load the image.
856 ///
857 /// \param[in] library_name
858 /// The name of the library to look for. If library_name is an
859 /// absolute path, the basename will be extracted and searched for
860 /// along the paths. This emulates the behavior of the loader when
861 /// given an install name and a set (e.g. DYLD_LIBRARY_PATH provided) of
862 /// alternate paths.
863 ///
864 /// \param[in] paths
865 /// The list of paths to use to search for the library. First
866 /// match wins.
867 ///
868 /// \param[out] error
869 /// An error object that gets filled in with any errors that
870 /// might occur when trying to load the shared library.
871 ///
872 /// \param[out] loaded_path
873 /// If non-null, the path to the dylib that was successfully loaded
874 /// is stored in this path.
875 ///
876 /// \return
877 /// A token that represents the shared library which can be
878 /// passed to UnloadImage. A value of
879 /// LLDB_INVALID_IMAGE_TOKEN will be returned if the shared
880 /// library can't be opened.
882 const lldb_private::FileSpec &library_name,
883 const std::vector<std::string> &paths,
885 lldb_private::FileSpec *loaded_path);
886
887 virtual uint32_t DoLoadImage(lldb_private::Process *process,
888 const lldb_private::FileSpec &remote_file,
889 const std::vector<std::string> *paths,
891 lldb_private::FileSpec *loaded_path = nullptr);
892
894 uint32_t image_token);
895
896 /// Connect to all processes waiting for a debugger to attach
897 ///
898 /// If the platform have a list of processes waiting for a debugger to
899 /// connect to them then connect to all of these pending processes.
900 ///
901 /// \param[in] debugger
902 /// The debugger used for the connect.
903 ///
904 /// \param[out] error
905 /// If an error occurred during the connect then this object will
906 /// contain the error message.
907 ///
908 /// \return
909 /// The number of processes we are successfully connected to.
910 virtual size_t ConnectToWaitingProcesses(lldb_private::Debugger &debugger,
912
913 /// Gather all of crash informations into a structured data dictionary.
914 ///
915 /// If the platform have a crashed process with crash information entries,
916 /// gather all the entries into an structured data dictionary or return a
917 /// nullptr. This dictionary is generic and extensible, as it contains an
918 /// array for each different type of crash information.
919 ///
920 /// \param[in] process
921 /// The crashed process.
922 ///
923 /// \return
924 /// A structured data dictionary containing at each entry, the crash
925 /// information type as the entry key and the matching an array as the
926 /// entry value. \b nullptr if not implemented or if the process has no
927 /// crash information entry. \b error if an error occured.
928 virtual llvm::Expected<StructuredData::DictionarySP>
930 return nullptr;
931 }
932
933 /// Detect a binary in memory that will determine which Platform and
934 /// DynamicLoader should be used in this target/process, and update
935 /// the Platform/DynamicLoader.
936 /// The binary will be loaded into the Target, or will be registered with
937 /// the DynamicLoader so that it will be loaded at a later stage. Returns
938 /// true to indicate that this is a platform binary and has been
939 /// loaded/registered, no further action should be taken by the caller.
940 ///
941 /// \param[in] process
942 /// Process read memory from, a Process must be provided.
943 ///
944 /// \param[in] addr
945 /// Address of a binary in memory.
946 ///
947 /// \param[in] notify
948 /// Whether ModulesDidLoad should be called, if a binary is loaded.
949 /// Caller may prefer to call ModulesDidLoad for multiple binaries
950 /// that were loaded at the same time.
951 ///
952 /// \return
953 /// Returns true if the binary was loaded in the target (or will be
954 /// via a DynamicLoader). Returns false if the binary was not
955 /// loaded/registered, and the caller must load it into the target.
957 bool notify) {
958 return false;
959 }
960
961 virtual CompilerType GetSiginfoType(const llvm::Triple &triple);
962
964
965 typedef std::function<Status(const ModuleSpec &module_spec,
966 FileSpec &module_file_spec,
967 FileSpec &symbol_file_spec)>
969
970 /// Set locate module callback. This allows users to implement their own
971 /// module cache system. For example, to leverage artifacts of build system,
972 /// to bypass pulling files from remote platform, or to search symbol files
973 /// from symbol servers.
975
977
978protected:
979 /// Create a list of ArchSpecs with the given OS and a architectures. The
980 /// vendor field is left as an "unspecified unknown".
981 static std::vector<ArchSpec>
982 CreateArchList(llvm::ArrayRef<llvm::Triple::ArchType> archs,
983 llvm::Triple::OSType os);
984
985 /// Private implementation of connecting to a process. If the stream is set
986 /// we connect synchronously.
987 lldb::ProcessSP DoConnectProcess(llvm::StringRef connect_url,
988 llvm::StringRef plugin_name,
989 Debugger &debugger, Stream *stream,
990 Target *target, Status &error);
992 // Set to true when we are able to actually set the OS version while being
993 // connected. For remote platforms, we might set the version ahead of time
994 // before we actually connect and this version might change when we actually
995 // connect to a remote platform. For the host platform this will be set to
996 // the once we call HostInfo::GetOSVersion().
999 std::string
1000 m_sdk_sysroot; // the root location of where the SDK files are all located
1001 std::string m_sdk_build;
1002 FileSpec m_working_dir; // The working directory which is used when installing
1003 // modules that have no install path set
1004 std::string m_hostname;
1005 llvm::VersionTuple m_os_version;
1006 ArchSpec
1007 m_system_arch; // The architecture of the kernel or the remote platform
1008 typedef std::map<uint32_t, ConstString> IDToNameMap;
1009 // Mutex for modifying Platform data structures that should only be used for
1010 // non-reentrant code
1011 std::mutex m_mutex;
1015 std::string m_rsync_opts;
1016 std::string m_rsync_prefix;
1018 std::string m_ssh_opts;
1021 std::vector<ConstString> m_trap_handlers;
1023 const std::unique_ptr<ModuleCache> m_module_cache;
1025
1026 /// Ask the Platform subclass to fill in the list of trap handler names
1027 ///
1028 /// For most Unix user process environments, this will be a single function
1029 /// name, _sigtramp. More specialized environments may have additional
1030 /// handler names. The unwinder code needs to know when a trap handler is
1031 /// on the stack because the unwind rules for the frame that caused the trap
1032 /// are different.
1033 ///
1034 /// The base class Platform ivar m_trap_handlers should be updated by the
1035 /// Platform subclass when this method is called. If there are no
1036 /// predefined trap handlers, this method may be a no-op.
1038
1039 Status GetCachedExecutable(ModuleSpec &module_spec, lldb::ModuleSP &module_sp,
1040 const FileSpecList *module_search_paths_ptr);
1041
1042 virtual Status DownloadModuleSlice(const FileSpec &src_file_spec,
1043 const uint64_t src_offset,
1044 const uint64_t src_size,
1045 const FileSpec &dst_file_spec);
1046
1047 virtual Status DownloadSymbolFile(const lldb::ModuleSP &module_sp,
1048 const FileSpec &dst_file_spec);
1049
1050 virtual const char *GetCacheHostname();
1051
1052private:
1053 typedef std::function<Status(const ModuleSpec &)> ModuleResolver;
1054
1055 Status GetRemoteSharedModule(const ModuleSpec &module_spec, Process *process,
1056 lldb::ModuleSP &module_sp,
1057 const ModuleResolver &module_resolver,
1058 bool *did_create_ptr);
1059
1060 bool GetCachedSharedModule(const ModuleSpec &module_spec,
1061 lldb::ModuleSP &module_sp, bool *did_create_ptr);
1062
1064};
1065
1067public:
1068 PlatformList() = default;
1069
1070 ~PlatformList() = default;
1071
1072 void Append(const lldb::PlatformSP &platform_sp, bool set_selected) {
1073 std::lock_guard<std::recursive_mutex> guard(m_mutex);
1074 m_platforms.push_back(platform_sp);
1075 if (set_selected)
1077 }
1078
1079 size_t GetSize() {
1080 std::lock_guard<std::recursive_mutex> guard(m_mutex);
1081 return m_platforms.size();
1082 }
1083
1085 lldb::PlatformSP platform_sp;
1086 {
1087 std::lock_guard<std::recursive_mutex> guard(m_mutex);
1088 if (idx < m_platforms.size())
1089 platform_sp = m_platforms[idx];
1090 }
1091 return platform_sp;
1092 }
1093
1094 /// Select the active platform.
1095 ///
1096 /// In order to debug remotely, other platform's can be remotely connected
1097 /// to and set as the selected platform for any subsequent debugging. This
1098 /// allows connection to remote targets and allows the ability to discover
1099 /// process info, launch and attach to remote processes.
1101 std::lock_guard<std::recursive_mutex> guard(m_mutex);
1102 if (!m_selected_platform_sp && !m_platforms.empty())
1104
1106 }
1107
1108 void SetSelectedPlatform(const lldb::PlatformSP &platform_sp) {
1109 if (platform_sp) {
1110 std::lock_guard<std::recursive_mutex> guard(m_mutex);
1111 const size_t num_platforms = m_platforms.size();
1112 for (size_t idx = 0; idx < num_platforms; ++idx) {
1113 if (m_platforms[idx].get() == platform_sp.get()) {
1115 return;
1116 }
1117 }
1118 m_platforms.push_back(platform_sp);
1120 }
1121 }
1122
1123 lldb::PlatformSP GetOrCreate(llvm::StringRef name);
1125 const ArchSpec &process_host_arch,
1126 ArchSpec *platform_arch_ptr, Status &error);
1128 const ArchSpec &process_host_arch,
1129 ArchSpec *platform_arch_ptr);
1130
1131 /// Get the platform for the given list of architectures.
1132 ///
1133 /// The algorithm works a follows:
1134 ///
1135 /// 1. Returns the selected platform if it matches any of the architectures.
1136 /// 2. Returns the host platform if it matches any of the architectures.
1137 /// 3. Returns the platform that matches all the architectures.
1138 ///
1139 /// If none of the above apply, this function returns a default platform. The
1140 /// candidates output argument differentiates between either no platforms
1141 /// supporting the given architecture or multiple platforms supporting the
1142 /// given architecture.
1143 lldb::PlatformSP GetOrCreate(llvm::ArrayRef<ArchSpec> archs,
1144 const ArchSpec &process_host_arch,
1145 std::vector<lldb::PlatformSP> &candidates);
1146
1147 lldb::PlatformSP Create(llvm::StringRef name);
1148
1149 /// Detect a binary in memory that will determine which Platform and
1150 /// DynamicLoader should be used in this target/process, and update
1151 /// the Platform/DynamicLoader.
1152 /// The binary will be loaded into the Target, or will be registered with
1153 /// the DynamicLoader so that it will be loaded at a later stage. Returns
1154 /// true to indicate that this is a platform binary and has been
1155 /// loaded/registered, no further action should be taken by the caller.
1156 ///
1157 /// \param[in] process
1158 /// Process read memory from, a Process must be provided.
1159 ///
1160 /// \param[in] addr
1161 /// Address of a binary in memory.
1162 ///
1163 /// \param[in] notify
1164 /// Whether ModulesDidLoad should be called, if a binary is loaded.
1165 /// Caller may prefer to call ModulesDidLoad for multiple binaries
1166 /// that were loaded at the same time.
1167 ///
1168 /// \return
1169 /// Returns true if the binary was loaded in the target (or will be
1170 /// via a DynamicLoader). Returns false if the binary was not
1171 /// loaded/registered, and the caller must load it into the target.
1173 bool notify);
1174
1175protected:
1176 typedef std::vector<lldb::PlatformSP> collection;
1177 mutable std::recursive_mutex m_mutex;
1180
1181private:
1182 PlatformList(const PlatformList &) = delete;
1183 const PlatformList &operator=(const PlatformList &) = delete;
1184};
1185
1187public:
1189
1190 ~OptionGroupPlatformRSync() override = default;
1191
1193 SetOptionValue(uint32_t option_idx, llvm::StringRef option_value,
1194 ExecutionContext *execution_context) override;
1195
1196 void OptionParsingStarting(ExecutionContext *execution_context) override;
1197
1198 llvm::ArrayRef<OptionDefinition> GetDefinitions() override;
1199
1200 // Instance variables to hold the values for command options.
1201
1203 std::string m_rsync_opts;
1204 std::string m_rsync_prefix;
1206
1207private:
1211};
1212
1214public:
1216
1217 ~OptionGroupPlatformSSH() override = default;
1218
1220 SetOptionValue(uint32_t option_idx, llvm::StringRef option_value,
1221 ExecutionContext *execution_context) override;
1222
1223 void OptionParsingStarting(ExecutionContext *execution_context) override;
1224
1225 llvm::ArrayRef<OptionDefinition> GetDefinitions() override;
1226
1227 // Instance variables to hold the values for command options.
1228
1229 bool m_ssh;
1230 std::string m_ssh_opts;
1231
1232private:
1236};
1237
1239public:
1241
1242 ~OptionGroupPlatformCaching() override = default;
1243
1245 SetOptionValue(uint32_t option_idx, llvm::StringRef option_value,
1246 ExecutionContext *execution_context) override;
1247
1248 void OptionParsingStarting(ExecutionContext *execution_context) override;
1249
1250 llvm::ArrayRef<OptionDefinition> GetDefinitions() override;
1251
1252 // Instance variables to hold the values for command options.
1253
1254 std::string m_cache_dir;
1255
1256private:
1260};
1261
1262} // namespace lldb_private
1263
1264#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:359
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.
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:89
lldb_private::Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_value, ExecutionContext *execution_context) override
Definition: Platform.cpp:1414
void OptionParsingStarting(ExecutionContext *execution_context) override
Definition: Platform.cpp:1409
~OptionGroupPlatformCaching() override=default
llvm::ArrayRef< OptionDefinition > GetDefinitions() override
Definition: Platform.cpp:1405
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:1335
void OptionParsingStarting(ExecutionContext *execution_context) override
Definition: Platform.cpp:1326
llvm::ArrayRef< OptionDefinition > GetDefinitions() override
Definition: Platform.cpp:1322
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:1382
~OptionGroupPlatformSSH() override=default
OptionGroupPlatformSSH(const OptionGroupPlatformSSH &)=delete
llvm::ArrayRef< OptionDefinition > GetDefinitions() override
Definition: Platform.cpp:1371
const OptionGroupPlatformSSH & operator=(const OptionGroupPlatformSSH &)=delete
void OptionParsingStarting(ExecutionContext *execution_context) override
Definition: Platform.cpp:1375
PlatformList(const PlatformList &)=delete
const PlatformList & operator=(const PlatformList &)=delete
lldb::PlatformSP GetAtIndex(uint32_t idx)
Definition: Platform.h:1084
lldb::PlatformSP m_selected_platform_sp
Definition: Platform.h:1179
std::recursive_mutex m_mutex
Definition: Platform.h:1177
std::vector< lldb::PlatformSP > collection
Definition: Platform.h:1176
void Append(const lldb::PlatformSP &platform_sp, bool set_selected)
Definition: Platform.h:1072
lldb::PlatformSP Create(llvm::StringRef name)
Definition: Platform.cpp:2228
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:2235
lldb::PlatformSP GetSelectedPlatform()
Select the active platform.
Definition: Platform.h:1100
void SetSelectedPlatform(const lldb::PlatformSP &platform_sp)
Definition: Platform.h:1108
lldb::PlatformSP GetOrCreate(llvm::StringRef name)
Definition: Platform.cpp:2107
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:471
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:1699
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:800
std::map< uint32_t, ConstString > IDToNameMap
Definition: Platform.h:1008
ProcessInstanceInfoList GetAllProcesses()
Definition: Platform.cpp:926
virtual bool GetFileExists(const lldb_private::FileSpec &file_spec)
Definition: Platform.cpp:1219
virtual bool CloseFile(lldb::user_id_t fd, Status &error)
Definition: Platform.cpp:650
const std::string & GetSDKBuild() const
Definition: Platform.h:536
virtual bool IsConnected() const
Definition: Platform.h:508
void SetLocateModuleCallback(LocateModuleCallback callback)
Set locate module callback.
Definition: Platform.cpp:2099
virtual lldb::user_id_t OpenFile(const FileSpec &file_spec, File::OpenOptions flags, uint32_t mode, Status &error)
Definition: Platform.cpp:642
virtual void SetSupportsSSH(bool flag)
Definition: Platform.h:653
virtual const char * GetHostname()
Definition: Platform.cpp:692
void SetSystemArchitecture(const ArchSpec &arch)
Definition: Platform.h:515
std::vector< ConstString > m_trap_handlers
Definition: Platform.h:1021
size_t GetMaxUserIDNameLength() const
Definition: Platform.h:527
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:1231
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:645
virtual uint32_t FindProcesses(const ProcessInstanceInfoMatch &match_info, ProcessInstanceInfoList &proc_infos)
Attach to an existing process by process name.
Definition: Platform.cpp:916
virtual size_t GetSoftwareBreakpointTrapOpcode(Target &target, BreakpointSite *bp_site)
Definition: Platform.cpp:1954
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:736
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:1002
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:1016
llvm::VersionTuple m_os_version
Definition: Platform.h:1005
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:532
virtual Status GetFilePermissions(const FileSpec &file_spec, uint32_t &file_permissions)
Definition: Platform.cpp:612
virtual void SetIgnoresRemoteHostname(bool flag)
Definition: Platform.h:661
virtual Status MakeDirectory(const FileSpec &file_spec, uint32_t permissions)
Definition: Platform.cpp:599
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:686
virtual Status PutFile(const FileSpec &source, const FileSpec &destination, uint32_t uid=UINT32_MAX, uint32_t gid=UINT32_MAX)
Definition: Platform.cpp:1120
virtual const std::vector< ConstString > & GetTrapHandlerSymbolNames()
Provide a list of trap handler function names for this platform.
Definition: Platform.cpp:1439
virtual llvm::Expected< XcodeSDK > GetSDKPathFromDebugInfo(CompileUnit &unit)
Search CU for the SDK path the CUs was compiled against.
Definition: Platform.h:481
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:701
~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:530
bool m_system_arch_set_while_connected
Definition: Platform.h:998
static lldb::PlatformSP Create(llvm::StringRef name)
Definition: Platform.cpp:216
virtual Status DisconnectRemote()
Definition: Platform.cpp:893
virtual void SetSupportsRSync(bool flag)
Definition: Platform.h:639
static lldb::PlatformSP GetHostPlatform()
Get the native host platform plug-in.
Definition: Platform.cpp:134
std::string m_local_cache_directory
Definition: Platform.h:1020
virtual bool GetSupportsSSH()
Definition: Platform.h:651
virtual lldb::BreakpointSP SetThreadCreationBreakpoint(Target &target)
Definition: Platform.cpp:1367
lldb::UnixSignalsSP GetUnixSignals()
Definition: Platform.cpp:1799
virtual lldb::user_id_t GetFileSize(const FileSpec &file_spec)
Definition: Platform.cpp:656
Status GetCachedExecutable(ModuleSpec &module_spec, lldb::ModuleSP &module_sp, const FileSpecList *module_search_paths_ptr)
Definition: Platform.cpp:1451
bool SetWorkingDirectory(const FileSpec &working_dir)
Definition: Platform.cpp:584
std::string m_sdk_build
Definition: Platform.h:1001
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:808
const ArchSpec & GetSystemArchitecture()
Definition: Platform.cpp:817
virtual void SetSSHOpts(const char *opts)
Definition: Platform.h:657
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:496
virtual const char * GetLocalCacheDirectory()
Definition: Platform.cpp:1289
virtual llvm::StringRef GetDescription()=0
void SetSDKBuild(std::string sdk_build)
Definition: Platform.h:538
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:752
virtual Status Unlink(const FileSpec &file_spec)
Definition: Platform.cpp:1225
virtual const char * GetRSyncOpts()
Definition: Platform.h:641
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:1805
virtual bool SetRemoteWorkingDirectory(const FileSpec &working_dir)
Definition: Platform.cpp:705
virtual std::optional< std::string > GetRemoteOSKernelDescription()
Definition: Platform.h:228
LocateModuleCallback m_locate_module_callback
Definition: Platform.h:1024
virtual std::string GetQueueNameForThreadQAddress(Process *process, lldb::addr_t dispatch_qaddr)
Locate a queue name given a thread's qaddr.
Definition: Platform.h:729
virtual void SetLocalCacheDirectory(const char *local)
Definition: Platform.cpp:1285
virtual CompilerType GetSiginfoType(const llvm::Triple &triple)
Definition: Platform.cpp:2091
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:1732
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:929
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:1876
virtual void SetRSyncOpts(const char *opts)
Definition: Platform.h:643
virtual Status DownloadSymbolFile(const lldb::ModuleSP &module_sp, const FileSpec &dst_file_spec)
Definition: Platform.cpp:1780
bool SetOSVersion(llvm::VersionTuple os_version)
Definition: Platform.cpp:713
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:934
virtual Status KillProcess(const lldb::pid_t pid)
Kill process on a platform.
Definition: Platform.cpp:990
virtual Status CreateSymlink(const FileSpec &src, const FileSpec &dst)
Definition: Platform.cpp:1211
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:1948
virtual void SetRSyncPrefix(const char *prefix)
Definition: Platform.h:647
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:1843
virtual bool SupportsModules()
Definition: Platform.h:545
virtual Status UnloadImage(lldb_private::Process *process, uint32_t image_token)
Definition: Platform.cpp:1870
virtual uint32_t GetDefaultMemoryCacheLineSize()
Allow the platform to set preferred memory cache line size.
Definition: Platform.h:813
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:1099
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:791
virtual bool GetRemoteOSVersion()
Definition: Platform.h:222
virtual lldb_private::OptionGroupOptions * GetConnectionOptions(CommandInterpreter &interpreter)
Definition: Platform.h:666
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:1085
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:956
std::string m_hostname
Definition: Platform.h:1004
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:676
void CallLocateModuleCallbackIfSet(const ModuleSpec &module_spec, lldb::ModuleSP &module_sp, FileSpec &symbol_file_spec, bool *did_create_ptr)
Definition: Platform.cpp:1593
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:1891
const std::unique_ptr< ModuleCache > m_module_cache
Definition: Platform.h:1023
virtual std::string GetPlatformSpecificConnectionInformation()
Definition: Platform.h:696
LocateModuleCallback GetLocateModuleCallback() const
Definition: Platform.cpp:2103
Status GetRemoteSharedModule(const ModuleSpec &module_spec, Process *process, lldb::ModuleSP &module_sp, const ModuleResolver &module_resolver, bool *did_create_ptr)
Definition: Platform.cpp:1470
virtual bool GetIgnoresRemoteHostname()
Definition: Platform.h:659
bool IsRemote() const
Definition: Platform.h:506
void SetSDKRootDirectory(std::string dir)
Definition: Platform.h:534
bool m_os_version_set_while_connected
Definition: Platform.h:997
virtual Status GetFile(const FileSpec &source, const FileSpec &destination)
Definition: Platform.cpp:1206
virtual bool GetSupportsRSync()
Definition: Platform.h:637
FileSpec GetModuleCacheRoot()
Definition: Platform.cpp:1786
virtual uint32_t GetResumeCountForLaunchInfo(ProcessLaunchInfo &launch_info)
Definition: Platform.h:701
virtual const char * GetCacheHostname()
Definition: Platform.cpp:1792
virtual Status SetFilePermissions(const FileSpec &file_spec, uint32_t file_permissions)
Definition: Platform.cpp:628
virtual bool GetProcessInfo(lldb::pid_t pid, ProcessInstanceInfo &proc_info)
Definition: Platform.cpp:907
bool IsHost() const
Definition: Platform.h:502
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:1245
std::function< Status(const ModuleSpec &)> ModuleResolver
Definition: Platform.h:1053
virtual Environment GetEnvironment()
Definition: Platform.cpp:1433
virtual const lldb::UnixSignalsSP & GetRemoteUnixSignals()
Definition: Platform.cpp:1794
virtual bool ModuleIsExcludedForUnconstrainedSearches(Target &target, const lldb::ModuleSP &module_sp)
Definition: Platform.h:562
std::string m_rsync_opts
Definition: Platform.h:1015
virtual void AutoCompleteDiskFileOrDirectory(CompletionRequest &request, bool only_dir)
Definition: Platform.h:583
virtual Status ConnectRemote(Args &args)
Definition: Platform.cpp:880
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:1853
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:2095
virtual bool ResolveRemotePath(const FileSpec &platform_path, FileSpec &resolved_platform_path)
Resolves the FileSpec to a (possibly) remote path.
Definition: Platform.cpp:810
std::function< Status(const ModuleSpec &module_spec, FileSpec &module_file_spec, FileSpec &symbol_file_spec)> LocateModuleCallback
Definition: Platform.h:968
std::string m_sdk_sysroot
Definition: Platform.h:1000
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:1018
virtual llvm::ErrorOr< llvm::MD5::MD5Result > CalculateMD5(const FileSpec &file_spec)
Definition: Platform.cpp:1279
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:983
virtual lldb::ProcessSP ConnectProcessSynchronous(llvm::StringRef connect_url, llvm::StringRef plugin_name, Debugger &debugger, Stream &stream, Target *target, Status &error)
Definition: Platform.cpp:1884
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:666
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:655
virtual llvm::StringRef GetPluginName()=0
A plug-in interface definition class for debugging a process.
Definition: Process.h:343
An error handling class.
Definition: Status.h:118
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:480
std::shared_ptr< lldb_private::Platform > PlatformSP
Definition: lldb-forward.h:388
std::shared_ptr< lldb_private::Breakpoint > BreakpointSP
Definition: lldb-forward.h:321
std::shared_ptr< lldb_private::Process > ProcessSP
Definition: lldb-forward.h:389
uint64_t pid_t
Definition: lldb-types.h:83
std::shared_ptr< lldb_private::UnwindPlan > UnwindPlanSP
Definition: lldb-forward.h:483
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:373
uint64_t queue_id_t
Definition: lldb-types.h:90