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 
13 #include "lldb/Core/FileSpecList.h"
14 #include "lldb/Host/FileSystem.h"
16 #include "lldb/Utility/ArchSpec.h"
18 #include "lldb/Utility/FileSpec.h"
19 #include "lldb/Utility/Status.h"
21 #include "lldb/Utility/XcodeSDK.h"
22 #include "lldb/lldb-forward.h"
23 #include "llvm/ADT/Optional.h"
24 #include "llvm/ADT/SmallVector.h"
25 #include "llvm/ADT/StringMap.h"
26 #include "llvm/ADT/StringRef.h"
27 #include "llvm/ADT/Triple.h"
28 #include "llvm/Support/Error.h"
29 #include "llvm/Support/VersionTuple.h"
30 
31 #include <mutex>
32 #include <string>
33 #include <vector>
34 
35 namespace lldb_private {
36 class BreakpointSite;
37 class Debugger;
38 class Module;
39 class ModuleSpec;
40 class Process;
41 class ProcessLaunchInfo;
42 class Stream;
43 class Target;
44 
45 class PlatformDarwin : public PlatformPOSIX {
46 public:
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  FileSpecList
72  Stream *feedback_stream) override;
73 
74  Status GetSharedModule(const ModuleSpec &module_spec, Process *process,
75  lldb::ModuleSP &module_sp,
76  const FileSpecList *module_search_paths_ptr,
78  bool *did_create_ptr) override;
79 
81  BreakpointSite *bp_site) override;
82 
83  lldb::BreakpointSP SetThreadCreationBreakpoint(Target &target) override;
84 
86  Target &target, const lldb::ModuleSP &module_sp) override;
87 
88  void
89  ARMGetSupportedArchitectures(std::vector<ArchSpec> &archs,
90  llvm::Optional<llvm::Triple::OSType> os = {});
91 
92  void x86GetSupportedArchitectures(std::vector<ArchSpec> &archs);
93 
94  uint32_t GetResumeCountForLaunchInfo(ProcessLaunchInfo &launch_info) override;
95 
96  lldb::ProcessSP DebugProcess(ProcessLaunchInfo &launch_info,
97  Debugger &debugger, Target &target,
98  Status &error) override;
99 
100  void CalculateTrapHandlerSymbolNames() override;
101 
102  llvm::VersionTuple GetOSVersion(Process *process = nullptr) override;
103 
104  bool SupportsModules() override { return true; }
105 
106  ConstString GetFullNameForDylib(ConstString basename) override;
107 
108  FileSpec LocateExecutable(const char *basename) override;
109 
110  Status LaunchProcess(ProcessLaunchInfo &launch_info) override;
111 
112  Args GetExtraStartupCommands() override;
113 
114  static std::tuple<llvm::VersionTuple, llvm::StringRef>
115  ParseVersionBuildDir(llvm::StringRef str);
116 
117  llvm::Expected<StructuredData::DictionarySP>
118  FetchExtendedCrashInformation(Process &process) override;
119 
120  /// Return the toolchain directory the current LLDB instance is located in.
122 
123  /// Return the command line tools directory the current LLDB instance is
124  /// located in.
126 
127 protected:
128  static const char *GetCompatibleArch(ArchSpec::Core core, size_t idx);
129 
131  uint64_t version; // unsigned long
132  uint64_t message; // char *
133  uint64_t signature_string; // char *
134  uint64_t backtrace; // char *
135  uint64_t message2; // char *
136  uint64_t thread; // uint64_t
137  uint64_t dialog_mode; // unsigned int
138  uint64_t abort_cause; // unsigned int
139  };
140 
141  /// Extract the `__crash_info` annotations from each of of the target's
142  /// modules.
143  ///
144  /// If the platform have a crashed processes with a `__crash_info` section,
145  /// extract the section to gather the messages annotations and the abort
146  /// cause.
147  ///
148  /// \param[in] process
149  /// The crashed process.
150  ///
151  /// \return
152  /// A structured data array containing at each entry in each entry, the
153  /// module spec, its UUID, the crash messages and the abort cause.
154  /// \b nullptr if process has no crash information annotations.
156 
157  void ReadLibdispatchOffsetsAddress(Process *process);
158 
159  void ReadLibdispatchOffsets(Process *process);
160 
161  virtual bool CheckLocalSharedCache() const { return IsHost(); }
162 
166  };
167 
169  DirectoryEnumerator(void *baton, llvm::sys::fs::file_type file_type,
170  llvm::StringRef path);
171 
173  const FileSpec &sdks_spec);
174 
176 
177  void
179  std::vector<std::string> &options,
180  XcodeSDK::Type sdk_type);
181 
183  const ModuleSpec &module_spec, Process *process,
184  lldb::ModuleSP &module_sp, const FileSpecList *module_search_paths_ptr,
185  llvm::SmallVectorImpl<lldb::ModuleSP> *old_modules, bool *did_create_ptr);
186 
187  static std::string FindComponentInPath(llvm::StringRef path,
188  llvm::StringRef component);
189 
190  // The OSType where lldb is running.
191  static llvm::Triple::OSType GetHostOSType();
192 
194  llvm::StringMap<std::string> m_sdk_path;
195  std::mutex m_sdk_path_mutex;
196 
197 private:
198  PlatformDarwin(const PlatformDarwin &) = delete;
199  const PlatformDarwin &operator=(const PlatformDarwin &) = delete;
200 };
201 
202 } // namespace lldb_private
203 
204 #endif // LLDB_SOURCE_PLUGINS_PLATFORM_MACOSX_PLATFORMDARWIN_H
lldb_private::PlatformDarwin::FindComponentInPath
static std::string FindComponentInPath(llvm::StringRef path, llvm::StringRef component)
Definition: PlatformDarwin.cpp:1270
lldb_private::PlatformDarwin::CalculateTrapHandlerSymbolNames
void CalculateTrapHandlerSymbolNames() override
Ask the Platform subclass to fill in the list of trap handler names.
Definition: PlatformDarwin.cpp:724
lldb_private::ArchSpec
Definition: ArchSpec.h:33
lldb_private::PlatformDarwin::x86GetSupportedArchitectures
void x86GetSupportedArchitectures(std::vector< ArchSpec > &archs)
Definition: PlatformDarwin.cpp:483
lldb_private::PlatformDarwin::~PlatformDarwin
~PlatformDarwin() override
Destructor.
FileSystem.h
lldb_private::PlatformDarwin::DebugProcess
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...
Definition: PlatformDarwin.cpp:701
lldb_private::PlatformDarwin::CrashInfoAnnotations::abort_cause
uint64_t abort_cause
Definition: PlatformDarwin.h:138
lldb_private::PlatformDarwin::SDKEnumeratorInfo
Definition: PlatformDarwin.h:163
lldb_private::PlatformDarwin::CrashInfoAnnotations::message2
uint64_t message2
Definition: PlatformDarwin.h:135
lldb_private::PlatformDarwin::GetSDKDirectoryForModules
static FileSpec GetSDKDirectoryForModules(XcodeSDK::Type sdk_type)
Definition: PlatformDarwin.cpp:781
StructuredData.h
lldb_private::PlatformDarwin::ParseVersionBuildDir
static std::tuple< llvm::VersionTuple, llvm::StringRef > ParseVersionBuildDir(llvm::StringRef str)
Definition: PlatformDarwin.cpp:841
ProcessLaunchInfo.h
lldb_private::PlatformDarwin::PlatformDarwin
PlatformDarwin(const PlatformDarwin &)=delete
lldb_private::Process
Definition: Process.h:338
lldb_private::PlatformDarwin::CreateInstance
static lldb::PlatformSP CreateInstance(bool force, const ArchSpec *arch)
Definition: PlatformDarwin.cpp:108
lldb_private::PlatformDarwin::GetExtraStartupCommands
Args GetExtraStartupCommands() override
Definition: PlatformDarwin.cpp:174
lldb_private::PlatformDarwin::ARMGetSupportedArchitectures
void ARMGetSupportedArchitectures(std::vector< ArchSpec > &archs, llvm::Optional< llvm::Triple::OSType > os={})
The architecture selection rules for arm processors These cpu subtypes have distinct names (e....
Definition: PlatformDarwin.cpp:603
lldb_private::PlatformDarwin::SDKEnumeratorInfo::sdk_type
XcodeSDK::Type sdk_type
Definition: PlatformDarwin.h:165
lldb_private::PlatformDarwin::GetCompatibleArch
static const char * GetCompatibleArch(ArchSpec::Core core, size_t idx)
lldb_private::PlatformDarwin::CrashInfoAnnotations::version
uint64_t version
Definition: PlatformDarwin.h:131
lldb_private::Module
Definition: Module.h:85
lldb_private::CompilerContextKind::Module
@ Module
lldb_private::PlatformDarwin::ReadLibdispatchOffsets
void ReadLibdispatchOffsets(Process *process)
lldb_private::Stream
Definition: Stream.h:28
lldb_private::Args
Definition: Args.h:33
lldb_private::PlatformDarwin::GetFullNameForDylib
ConstString GetFullNameForDylib(ConstString basename) override
Definition: PlatformDarwin.cpp:1082
lldb_private::Target
Definition: Target.h:473
lldb_private::PlatformDarwin::PutFile
Status PutFile(const FileSpec &source, const FileSpec &destination, uint32_t uid=UINT32_MAX, uint32_t gid=UINT32_MAX) override
Definition: PlatformDarwin.cpp:187
lldb_private::PlatformDarwin::ResolveSymbolFile
Status ResolveSymbolFile(Target &target, const ModuleSpec &sym_spec, FileSpec &sym_file) override
Find a symbol file given a symbol file module specification.
Definition: PlatformDarwin.cpp:321
lldb_private::PlatformDarwin::m_sdk_path
llvm::StringMap< std::string > m_sdk_path
Definition: PlatformDarwin.h:194
lldb_private::PlatformDarwin::m_sdk_path_mutex
std::mutex m_sdk_path_mutex
Definition: PlatformDarwin.h:195
XcodeSDK.h
lldb_private::ArchSpec::Core
Core
Definition: ArchSpec.h:112
lldb_private::PlatformDarwin::LocateExecutable
FileSpec LocateExecutable(const char *basename) override
Find a support executable that may not live within in the standard locations related to LLDB.
Definition: PlatformDarwin.cpp:1122
lldb_private::PlatformDarwin::Initialize
static void Initialize()
Definition: PlatformDarwin.cpp:83
lldb_private::PlatformDarwin::GetPluginNameStatic
static llvm::StringRef GetPluginNameStatic()
Definition: PlatformDarwin.h:59
lldb_private::FileSpec
Definition: FileSpec.h:56
error
static llvm::raw_ostream & error(Stream &strm)
Definition: CommandReturnObject.cpp:17
PlatformPOSIX
Definition: PlatformPOSIX.h:18
lldb_private::BreakpointSite
Definition: BreakpointSite.h:35
lldb_private::ProcessLaunchInfo
Definition: ProcessLaunchInfo.h:31
lldb_private::PlatformDarwin::Terminate
static void Terminate()
Definition: PlatformDarwin.cpp:94
PlatformPOSIX::PlatformPOSIX
PlatformPOSIX(bool is_host)
Default Constructor.
Definition: PlatformPOSIX.cpp:41
lldb_private::PlatformDarwin::CheckLocalSharedCache
virtual bool CheckLocalSharedCache() const
Definition: PlatformDarwin.h:161
lldb_private::PlatformDarwin::GetSoftwareBreakpointTrapOpcode
size_t GetSoftwareBreakpointTrapOpcode(Target &target, BreakpointSite *bp_site) override
Definition: PlatformDarwin.cpp:413
lldb_private::PlatformDarwin::m_developer_directory
std::string m_developer_directory
Definition: PlatformDarwin.h:193
lldb_private::LLDBLog::Process
@ Process
lldb_private::PlatformDarwin::CrashInfoAnnotations::signature_string
uint64_t signature_string
Definition: PlatformDarwin.h:133
lldb_private::FileSystem::EnumerateDirectoryResult
EnumerateDirectoryResult
Definition: FileSystem.h:166
FileSpecList.h
lldb_private::ConstString
Definition: ConstString.h:40
lldb_private::PlatformDarwin::GetResumeCountForLaunchInfo
uint32_t GetResumeCountForLaunchInfo(ProcessLaunchInfo &launch_info) override
Definition: PlatformDarwin.cpp:673
lldb_private::Debugger
Definition: Debugger.h:74
string
string(SUBSTRING ${p} 10 -1 pStripped) if($
Definition: Plugins/CMakeLists.txt:40
lldb_private::PlatformDarwin::GetSharedModule
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) override
Definition: PlatformDarwin.cpp:332
lldb_private::PlatformDarwin::LocateExecutableScriptingResources
FileSpecList LocateExecutableScriptingResources(Target *target, Module &module, Stream *feedback_stream) override
Definition: PlatformDarwin.cpp:197
lldb_private::PlatformDarwin::FetchExtendedCrashInformation
llvm::Expected< StructuredData::DictionarySP > FetchExtendedCrashInformation(Process &process) override
Gather all of crash informations into a structured data dictionary.
Definition: PlatformDarwin.cpp:859
lldb_private::PlatformDarwin::GetDescriptionStatic
static llvm::StringRef GetDescriptionStatic()
Definition: PlatformDarwin.cpp:104
lldb_private::ModuleSpec
Definition: ModuleSpec.h:27
lldb_private::Status
Definition: Status.h:44
lldb_private::PlatformDarwin::AddClangModuleCompilationOptionsForSDKType
void AddClangModuleCompilationOptionsForSDKType(Target *target, std::vector< std::string > &options, XcodeSDK::Type sdk_type)
Definition: PlatformDarwin.cpp:981
uint32_t
lldb_private::PlatformDarwin::CrashInfoAnnotations::backtrace
uint64_t backtrace
Definition: PlatformDarwin.h:134
lldb_private::XcodeSDK::Type
Type
Different types of Xcode SDKs.
Definition: XcodeSDK.h:29
lldb_private::PlatformDarwin::DirectoryEnumerator
static FileSystem::EnumerateDirectoryResult DirectoryEnumerator(void *baton, llvm::sys::fs::file_type file_type, llvm::StringRef path)
Definition: PlatformDarwin.cpp:742
ArchSpec.h
UINT32_MAX
#define UINT32_MAX
Definition: lldb-defines.h:19
lldb_private::PlatformDarwin::LaunchProcess
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...
Definition: PlatformDarwin.cpp:1175
lldb_private::PlatformDarwin::FindBundleBinaryInExecSearchPaths
Status FindBundleBinaryInExecSearchPaths(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: PlatformDarwin.cpp:1195
lldb_private::PlatformDarwin::GetHostOSType
static llvm::Triple::OSType GetHostOSType()
Definition: PlatformDarwin.cpp:1297
lldb_private::PlatformDarwin::ReadLibdispatchOffsetsAddress
void ReadLibdispatchOffsetsAddress(Process *process)
lldb_private::PlatformDarwin::ExtractCrashInfoAnnotations
StructuredData::ArraySP ExtractCrashInfoAnnotations(Process &process)
Extract the __crash_info annotations from each of of the target's modules.
Definition: PlatformDarwin.cpp:878
lldb_private::PlatformDarwin::DebuggerInitialize
static void DebuggerInitialize(lldb_private::Debugger &debugger)
Definition: PlatformDarwin.cpp:159
lldb_private::PlatformDarwin::CrashInfoAnnotations
Definition: PlatformDarwin.h:130
lldb_private::PlatformDarwin::ModuleIsExcludedForUnconstrainedSearches
bool ModuleIsExcludedForUnconstrainedSearches(Target &target, const lldb::ModuleSP &module_sp) override
Definition: PlatformDarwin.cpp:470
lldb_private::PlatformDarwin::CrashInfoAnnotations::dialog_mode
uint64_t dialog_mode
Definition: PlatformDarwin.h:137
lldb-forward.h
lldb_private::PlatformDarwin::SupportsModules
bool SupportsModules() override
Definition: PlatformDarwin.h:104
Status.h
lldb_private::PlatformDarwin::CrashInfoAnnotations::thread
uint64_t thread
Definition: PlatformDarwin.h:136
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::PlatformDarwin::GetCurrentToolchainDirectory
static FileSpec GetCurrentToolchainDirectory()
Return the toolchain directory the current LLDB instance is located in.
Definition: PlatformDarwin.cpp:1285
lldb_private::LLDBLog::Target
@ Target
lldb_private::PlatformDarwin::GetCurrentCommandLineToolsDirectory
static FileSpec GetCurrentCommandLineToolsDirectory()
Return the command line tools directory the current LLDB instance is located in.
Definition: PlatformDarwin.cpp:1291
FileSpec.h
PlatformPOSIX.h
ConstString.h
lldb_private::PlatformDarwin::SetThreadCreationBreakpoint
lldb::BreakpointSP SetThreadCreationBreakpoint(Target &target) override
Definition: PlatformDarwin.cpp:645
lldb_private::PlatformDarwin::CrashInfoAnnotations::message
uint64_t message
Definition: PlatformDarwin.h:132
lldb_private::StructuredData::ArraySP
std::shared_ptr< Array > ArraySP
Definition: StructuredData.h:62
lldb_private::PlatformDarwin::SDKEnumeratorInfo::found_path
FileSpec found_path
Definition: PlatformDarwin.h:164
llvm::SmallVectorImpl
Definition: Disassembler.h:42
lldb_private::Platform::IsHost
bool IsHost() const
Definition: Platform.h:420
lldb_private::PlatformDarwin::operator=
const PlatformDarwin & operator=(const PlatformDarwin &)=delete
lldb_private::PlatformDarwin::FindSDKInXcodeForModules
static FileSpec FindSDKInXcodeForModules(XcodeSDK::Type sdk_type, const FileSpec &sdks_spec)
Definition: PlatformDarwin.cpp:755
lldb_private::PlatformDarwin
Definition: PlatformDarwin.h:45
lldb_private::PlatformDarwin::GetOSVersion
llvm::VersionTuple GetOSVersion(Process *process=nullptr) override
Get the OS version from a connected platform.
Definition: PlatformDarwin.cpp:1091