LLDB mainline
PlatformDarwin.h
Go to the documentation of this file.
1//===-- PlatformDarwin.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_SOURCE_PLUGINS_PLATFORM_MACOSX_PLATFORMDARWIN_H
10#define LLDB_SOURCE_PLUGINS_PLATFORM_MACOSX_PLATFORMDARWIN_H
11
19#include "lldb/Utility/Status.h"
22#include "lldb/lldb-forward.h"
23#include "llvm/ADT/SmallVector.h"
24#include "llvm/ADT/StringMap.h"
25#include "llvm/ADT/StringRef.h"
26#include "llvm/Support/Error.h"
27#include "llvm/Support/VersionTuple.h"
28#include "llvm/TargetParser/Triple.h"
29
30#include <mutex>
31#include <optional>
32#include <string>
33#include <vector>
34
35namespace lldb_private {
36class BreakpointSite;
37class Debugger;
38class Module;
39class ModuleSpec;
40class Process;
42class Stream;
43class Target;
44
46public:
48
49 ~PlatformDarwin() override;
50
51 static lldb::PlatformSP CreateInstance(bool force, const ArchSpec *arch);
52
53 static void DebuggerInitialize(lldb_private::Debugger &debugger);
54
55 static void Initialize();
56
57 static void Terminate();
58
59 static llvm::StringRef GetPluginNameStatic() { return "darwin"; }
60
61 static llvm::StringRef GetDescriptionStatic();
62
63 Status PutFile(const FileSpec &source, const FileSpec &destination,
64 uint32_t uid = UINT32_MAX, uint32_t gid = UINT32_MAX) override;
65
66 // Platform functions
67 Status ResolveSymbolFile(Target &target, const ModuleSpec &sym_spec,
68 FileSpec &sym_file) override;
69
70 llvm::SmallDenseMap<FileSpec, LoadScriptFromSymFile>
72 Target *target, Module &module_spec, Stream &feedback_stream) override;
73
74 bool IsSymbolFileTrusted(Module &module) override;
75
76 Status GetSharedModule(const ModuleSpec &module_spec, Target &target,
77 lldb::ModuleSP &module_sp,
79 bool *did_create_ptr) override;
80
82 const ModuleSpec &module_spec, Target &target, lldb::ModuleSP &module_sp,
83 llvm::SmallVectorImpl<lldb::ModuleSP> *old_modules, bool *did_create_ptr);
84
86 BreakpointSite *bp_site) override;
87
89
91 Target &target, const lldb::ModuleSP &module_sp) override;
92
93 void
94 ARMGetSupportedArchitectures(std::vector<ArchSpec> &archs,
95 std::optional<llvm::Triple::OSType> os = {});
96
97 void x86GetSupportedArchitectures(std::vector<ArchSpec> &archs);
98
99 uint32_t GetResumeCountForLaunchInfo(ProcessLaunchInfo &launch_info) override;
100
101 lldb::ProcessSP DebugProcess(ProcessLaunchInfo &launch_info,
102 Debugger &debugger, Target &target,
103 Status &error) override;
104
105 void CalculateTrapHandlerSymbolNames() override;
106
107 llvm::VersionTuple GetOSVersion(Process *process = nullptr) override;
108
109 bool SupportsModules() override { return true; }
110
111 std::string GetFullNameForDylib(llvm::StringRef basename) override;
112
113 FileSpec LocateExecutable(const char *basename) override;
114
115 Status LaunchProcess(ProcessLaunchInfo &launch_info) override;
116
117 Args GetExtraStartupCommands() override;
118
119 static std::tuple<llvm::VersionTuple, llvm::StringRef>
120 ParseVersionBuildDir(llvm::StringRef str);
121
122 llvm::Expected<StructuredData::DictionarySP>
123 FetchExtendedCrashInformation(Process &process) override;
124
125 /// The generic implementation parses the SDKs out of debug info, but only
126 /// Darwin SDKs come in public and internal flavors, so detecting a conflict
127 /// between the two is done here.
128 llvm::Expected<std::pair<XcodeSDKAndSysroot, bool>>
129 GetSDKPathFromDebugInfo(Module &module) override;
131
132 llvm::Expected<std::string>
133 ResolveSDKPathFromDebugInfo(Module &module) override;
134
135 llvm::Expected<std::string>
137
138 /// Resolve an XcodeSDK to an on-disk path under a Progress event.
139 static llvm::Expected<FileSpec> ResolveXcodeSDK(const XcodeSDK &sdk);
140
141 /// Same, but prefer the sysroot the SDK was used from when it exists on
142 /// this machine.
143 static llvm::Expected<FileSpec>
145
146 /// Helper function for \c LocateExecutableScriptingResources
147 /// which gathers FileSpecs for executable scripts (currently
148 /// just Python) from a .dSYM Python directory.
149 ///
150 /// \param[out] feedback_stream Any warnings/errors are printed into this
151 /// stream.
152 ///
153 /// \param[in] module_spec FileSpec of the Module for which to locate
154 /// scripting resources.
155 ///
156 /// \param[in] target Target which owns the ScriptInterpreter which is
157 /// eventually used for loading the scripting resources.
158 ///
159 /// \param[in] symfile_spec FileSpec for the SymbolFile inside the Module's
160 /// dSYM directory. The scripting resources are loaded from the adjacent
161 /// Resources directory in the same dSYM.
162 /// E.g., \c /path/to/.dSYM/Contents/Resources/DWARF/a.out
163 ///
164 static llvm::SmallDenseMap<FileSpec, LoadScriptFromSymFile>
166 FileSpec module_spec,
167 const Target &target,
168 const FileSpec &symfile_spec);
169
170 llvm::Expected<FileSpecList>
171 GetSafeAutoLoadPaths(const Target &target) const override;
172
173protected:
174 static const char *GetCompatibleArch(ArchSpec::Core core, size_t idx);
175
177 uint64_t version; // unsigned long
178 uint64_t message; // char *
179 uint64_t signature_string; // char *
180 uint64_t backtrace; // char *
181 uint64_t message2; // char *
182 uint64_t thread; // uint64_t
183 uint64_t dialog_mode; // unsigned int
184 uint64_t abort_cause; // unsigned int
185 };
186
187 /// Extract the `__crash_info` annotations from each of the target's
188 /// modules.
189 ///
190 /// If the platform have a crashed processes with a `__crash_info` section,
191 /// extract the section to gather the messages annotations and the abort
192 /// cause.
193 ///
194 /// \param[in] process
195 /// The crashed process.
196 ///
197 /// \return
198 /// A structured data array containing at each entry in each entry, the
199 /// module spec, its UUID, the crash messages and the abort cause.
200 /// \b nullptr if process has no crash information annotations.
202
203 /// Extract the `Application Specific Information` messages from a crash
204 /// report.
206
208
210
211 virtual bool CheckLocalSharedCache() const { return IsHost(); }
212
217
219 DirectoryEnumerator(void *baton, llvm::sys::fs::file_type file_type,
220 llvm::StringRef path);
221
223 const FileSpec &sdks_spec);
224
226
227 void
229 std::vector<std::string> &options,
230 XcodeSDK::Type sdk_type);
231
233 const ModuleSpec &module_spec, Target &target, lldb::ModuleSP &module_sp,
234 llvm::SmallVectorImpl<lldb::ModuleSP> *old_modules, bool *did_create_ptr);
235
236 // The OSType where lldb is running.
237 static llvm::Triple::OSType GetHostOSType();
238
240 llvm::StringMap<std::string> m_sdk_path;
242
243private:
245 const PlatformDarwin &operator=(const PlatformDarwin &) = delete;
246};
247
248} // namespace lldb_private
249
250#endif // LLDB_SOURCE_PLUGINS_PLATFORM_MACOSX_PLATFORMDARWIN_H
static llvm::raw_ostream & error(Stream &strm)
PlatformPOSIX(bool is_host)
Default Constructor.
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
A class to manage flag bits.
Definition Debugger.h:100
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:91
void ReadLibdispatchOffsets(Process *process)
StructuredData::ArraySP ExtractCrashInfoAnnotations(Process &process)
Extract the __crash_info annotations from each of the target's modules.
bool IsSymbolFileTrusted(Module &module) override
Returns true if the module's symbol file (e.g.
llvm::Expected< StructuredData::DictionarySP > FetchExtendedCrashInformation(Process &process) override
Gather all of crash informations into a structured data dictionary.
~PlatformDarwin() override
Destructor.
static FileSpec GetSDKDirectoryForModules(XcodeSDK::Type sdk_type)
Status ResolveSymbolFile(Target &target, const ModuleSpec &sym_spec, FileSpec &sym_file) override
Find a symbol file given a symbol file module specification.
llvm::Expected< std::pair< XcodeSDKAndSysroot, bool > > GetSDKPathFromDebugInfo(Module &module) override
The generic implementation parses the SDKs out of debug info, but only Darwin SDKs come in public and...
void CalculateTrapHandlerSymbolNames() override
Ask the Platform subclass to fill in the list of trap handler names.
Status GetModuleFromSharedCaches(const ModuleSpec &module_spec, Target &target, lldb::ModuleSP &module_sp, llvm::SmallVectorImpl< lldb::ModuleSP > *old_modules, bool *did_create_ptr)
static std::tuple< llvm::VersionTuple, llvm::StringRef > ParseVersionBuildDir(llvm::StringRef str)
static lldb::PlatformSP CreateInstance(bool force, const ArchSpec *arch)
Status FindBundleBinaryInExecSearchPaths(const ModuleSpec &module_spec, Target &target, lldb::ModuleSP &module_sp, llvm::SmallVectorImpl< lldb::ModuleSP > *old_modules, bool *did_create_ptr)
llvm::VersionTuple GetOSVersion(Process *process=nullptr) override
Get the OS version from a connected platform.
void ReadLibdispatchOffsetsAddress(Process *process)
PlatformPOSIX(bool is_host)
Default Constructor.
static FileSystem::EnumerateDirectoryResult DirectoryEnumerator(void *baton, llvm::sys::fs::file_type file_type, llvm::StringRef path)
static FileSpec FindSDKInXcodeForModules(XcodeSDK::Type sdk_type, const FileSpec &sdks_spec)
Status GetSharedModule(const ModuleSpec &module_spec, Target &target, lldb::ModuleSP &module_sp, llvm::SmallVectorImpl< lldb::ModuleSP > *old_modules, bool *did_create_ptr) override
static void DebuggerInitialize(lldb_private::Debugger &debugger)
static llvm::StringRef GetPluginNameStatic()
static llvm::Triple::OSType GetHostOSType()
virtual bool CheckLocalSharedCache() const
StructuredData::DictionarySP ExtractAppSpecificInfo(Process &process)
Extract the Application Specific Information messages from a crash report.
static llvm::Expected< FileSpec > ResolveXcodeSDK(const XcodeSDK &sdk)
Resolve an XcodeSDK to an on-disk path under a Progress event.
lldb::ProcessSP DebugProcess(ProcessLaunchInfo &launch_info, Debugger &debugger, Target &target, Status &error) override
Subclasses do not need to implement this function as it uses the Platform::LaunchProcess() followed b...
lldb::BreakpointSP SetThreadCreationBreakpoint(Target &target) override
static llvm::StringRef GetDescriptionStatic()
llvm::StringMap< std::string > m_sdk_path
Status LaunchProcess(ProcessLaunchInfo &launch_info) override
Launch a new process on a platform, not necessarily for debugging, it could be just for running the p...
const PlatformDarwin & operator=(const PlatformDarwin &)=delete
static const char * GetCompatibleArch(ArchSpec::Core core, size_t idx)
uint32_t GetResumeCountForLaunchInfo(ProcessLaunchInfo &launch_info) override
llvm::Expected< std::string > ResolveSDKPathFromDebugInfo(Module &module) override
Returns the full path of the most appropriate SDK for the specified 'module'.
size_t GetSoftwareBreakpointTrapOpcode(Target &target, BreakpointSite *bp_site) override
std::string GetFullNameForDylib(llvm::StringRef basename) override
void AddClangModuleCompilationOptionsForSDKType(Target *target, std::vector< std::string > &options, XcodeSDK::Type sdk_type)
Args GetExtraStartupCommands() override
Status PutFile(const FileSpec &source, const FileSpec &destination, uint32_t uid=UINT32_MAX, uint32_t gid=UINT32_MAX) override
static llvm::SmallDenseMap< FileSpec, LoadScriptFromSymFile > LocateExecutableScriptingResourcesFromDSYM(Stream &feedback_stream, FileSpec module_spec, const Target &target, const FileSpec &symfile_spec)
Helper function for LocateExecutableScriptingResources which gathers FileSpecs for executable scripts...
FileSpec LocateExecutable(const char *basename) override
Find a support executable that may not live within in the standard locations related to LLDB.
void x86GetSupportedArchitectures(std::vector< ArchSpec > &archs)
llvm::SmallDenseMap< FileSpec, LoadScriptFromSymFile > LocateExecutableScriptingResourcesForPlatform(Target *target, Module &module_spec, Stream &feedback_stream) override
Locate the platform-specific scripting resource given a module specification.
llvm::Expected< FileSpecList > GetSafeAutoLoadPaths(const Target &target) const override
Returns a FileSpecList of safe paths to auto-load scripting resources from for a particular platform.
bool ModuleIsExcludedForUnconstrainedSearches(Target &target, const lldb::ModuleSP &module_sp) override
void ARMGetSupportedArchitectures(std::vector< ArchSpec > &archs, std::optional< llvm::Triple::OSType > os={})
The architecture selection rules for arm processors These cpu subtypes have distinct names (e....
PlatformDarwin(const PlatformDarwin &)=delete
virtual llvm::Expected< std::pair< XcodeSDKAndSysroot, bool > > GetSDKPathFromDebugInfo(Module &module)
Search each CU associated with the specified 'module' for the SDK paths the CUs were compiled against...
bool IsHost() const
Definition Platform.h:557
A plug-in interface definition class for debugging a process.
Definition Process.h:368
An error handling class.
Definition Status.h:118
A stream class that can stream formatted output to a file.
Definition Stream.h:28
std::shared_ptr< Dictionary > DictionarySP
std::shared_ptr< Array > ArraySP
An abstraction which groups an XcodeSDK with the sysroot it was used from.
Definition XcodeSDK.h:101
An abstraction for Xcode-style SDKs that works like ArchSpec.
Definition XcodeSDK.h:25
Type
Different types of Xcode SDKs.
Definition XcodeSDK.h:30
#define UINT32_MAX
A class that represents a running process on the host machine.
std::shared_ptr< lldb_private::Platform > PlatformSP
std::shared_ptr< lldb_private::Breakpoint > BreakpointSP
std::shared_ptr< lldb_private::Process > ProcessSP
std::shared_ptr< lldb_private::Module > ModuleSP