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/Host/FileSystem.h"
16 #include "lldb/Utility/FileSpec.h"
18 #include "lldb/Utility/XcodeSDK.h"
19 #include "llvm/ADT/StringRef.h"
20 #include "llvm/Support/FileSystem.h"
21 
22 #include <string>
23 #include <tuple>
24 
25 class PlatformDarwin : public PlatformPOSIX {
26 public:
27  PlatformDarwin(bool is_host);
28 
29  ~PlatformDarwin() override;
30 
32  const lldb_private::FileSpec &destination,
33  uint32_t uid = UINT32_MAX,
34  uint32_t gid = UINT32_MAX) override;
35 
36  // lldb_private::Platform functions
39  const lldb_private::ModuleSpec &sym_spec,
40  lldb_private::FileSpec &sym_file) override;
41 
42  lldb_private::FileSpecList LocateExecutableScriptingResources(
44  lldb_private::Stream *feedback_stream) override;
45 
47  GetSharedModule(const lldb_private::ModuleSpec &module_spec,
48  lldb_private::Process *process, lldb::ModuleSP &module_sp,
49  const lldb_private::FileSpecList *module_search_paths_ptr,
51  bool *did_create_ptr) override;
52 
54  lldb_private::Target &target,
55  lldb_private::BreakpointSite *bp_site) override;
56 
57  lldb::BreakpointSP
59 
61  lldb_private::Target &target, const lldb::ModuleSP &module_sp) override;
62 
65 
68 
70  lldb_private::ProcessLaunchInfo &launch_info) override;
71 
72  lldb::ProcessSP DebugProcess(lldb_private::ProcessLaunchInfo &launch_info,
73  lldb_private::Debugger &debugger,
74  lldb_private::Target &target,
75  lldb_private::Status &error) override;
76 
77  void CalculateTrapHandlerSymbolNames() override;
78 
79  llvm::VersionTuple
80  GetOSVersion(lldb_private::Process *process = nullptr) override;
81 
82  bool SupportsModules() override { return true; }
83 
86 
87  lldb_private::FileSpec LocateExecutable(const char *basename) override;
88 
90  LaunchProcess(lldb_private::ProcessLaunchInfo &launch_info) override;
91 
92  static std::tuple<llvm::VersionTuple, llvm::StringRef>
93  ParseVersionBuildDir(llvm::StringRef str);
94 
95  llvm::Expected<lldb_private::StructuredData::DictionarySP>
97 
98  /// Return the toolchain directory the current LLDB instance is located in.
100 
101  /// Return the command line tools directory the current LLDB instance is
102  /// located in.
104 
105 protected:
107  uint64_t version; // unsigned long
108  uint64_t message; // char *
109  uint64_t signature_string; // char *
110  uint64_t backtrace; // char *
111  uint64_t message2; // char *
112  uint64_t thread; // uint64_t
113  uint64_t dialog_mode; // unsigned int
114  uint64_t abort_cause; // unsigned int
115  };
116 
117  /// Extract the `__crash_info` annotations from each of of the target's
118  /// modules.
119  ///
120  /// If the platform have a crashed processes with a `__crash_info` section,
121  /// extract the section to gather the messages annotations and the abort
122  /// cause.
123  ///
124  /// \param[in] process
125  /// The crashed process.
126  ///
127  /// \return
128  /// A structured data array containing at each entry in each entry, the
129  /// module spec, its UUID, the crash messages and the abort cause.
130  /// \b nullptr if process has no crash information annotations.
133 
135 
137 
139  const lldb_private::ModuleSpec &module_spec, lldb::ModuleSP &module_sp,
140  const lldb_private::FileSpecList *module_search_paths_ptr,
141  llvm::SmallVectorImpl<lldb::ModuleSP> *old_modules, bool *did_create_ptr);
142 
146  };
147 
149  DirectoryEnumerator(void *baton, llvm::sys::fs::file_type file_type,
150  llvm::StringRef path);
151 
154  const lldb_private::FileSpec &sdks_spec);
155 
158 
160  lldb_private::Target *target, std::vector<std::string> &options,
162 
164  const lldb_private::ModuleSpec &module_spec,
165  lldb_private::Process *process, lldb::ModuleSP &module_sp,
166  const lldb_private::FileSpecList *module_search_paths_ptr,
167  llvm::SmallVectorImpl<lldb::ModuleSP> *old_modules, bool *did_create_ptr);
168 
169  static std::string FindComponentInPath(llvm::StringRef path,
170  llvm::StringRef component);
171 
173  llvm::StringMap<std::string> m_sdk_path;
174  std::mutex m_sdk_path_mutex;
175 
176 private:
177  PlatformDarwin(const PlatformDarwin &) = delete;
178  const PlatformDarwin &operator=(const PlatformDarwin &) = delete;
179 };
180 
181 #endif // LLDB_SOURCE_PLUGINS_PLATFORM_MACOSX_PLATFORMDARWIN_H
PlatformDarwin::DirectoryEnumerator
static lldb_private::FileSystem::EnumerateDirectoryResult DirectoryEnumerator(void *baton, llvm::sys::fs::file_type file_type, llvm::StringRef path)
Definition: PlatformDarwin.cpp:1271
PlatformDarwin::FindSDKInXcodeForModules
static lldb_private::FileSpec FindSDKInXcodeForModules(lldb_private::XcodeSDK::Type sdk_type, const lldb_private::FileSpec &sdks_spec)
Definition: PlatformDarwin.cpp:1284
lldb_private::ArchSpec
Definition: ArchSpec.h:33
FileSystem.h
StructuredData.h
PlatformDarwin::~PlatformDarwin
~PlatformDarwin() override
Destructor.
PlatformDarwin::x86GetSupportedArchitectureAtIndex
bool x86GetSupportedArchitectureAtIndex(uint32_t idx, lldb_private::ArchSpec &arch)
Definition: PlatformDarwin.cpp:517
ProcessLaunchInfo.h
PlatformDarwin::ReadLibdispatchOffsetsAddress
void ReadLibdispatchOffsetsAddress(lldb_private::Process *process)
PlatformDarwin::CrashInfoAnnotations
Definition: PlatformDarwin.h:106
PlatformDarwin::SetThreadCreationBreakpoint
lldb::BreakpointSP SetThreadCreationBreakpoint(lldb_private::Target &target) override
Definition: PlatformDarwin.cpp:1173
lldb_private::Process
Definition: Process.h:342
PlatformDarwin::LocateExecutable
lldb_private::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:1652
PlatformDarwin::GetSDKDirectoryForModules
static lldb_private::FileSpec GetSDKDirectoryForModules(lldb_private::XcodeSDK::Type sdk_type)
Definition: PlatformDarwin.cpp:1310
lldb_private::Module
Definition: Module.h:84
PlatformDarwin::ARMGetSupportedArchitectureAtIndex
bool ARMGetSupportedArchitectureAtIndex(uint32_t idx, lldb_private::ArchSpec &arch)
The architecture selection rules for arm processors These cpu subtypes have distinct names (e....
Definition: PlatformDarwin.cpp:561
lldb_private::Stream
Definition: Stream.h:28
PlatformDarwin::GetCurrentCommandLineToolsDirectory
static lldb_private::FileSpec GetCurrentCommandLineToolsDirectory()
Return the command line tools directory the current LLDB instance is located in.
Definition: PlatformDarwin.cpp:1821
lldb_private::Target
Definition: Target.h:454
PlatformDarwin::SDKEnumeratorInfo::found_path
lldb_private::FileSpec found_path
Definition: PlatformDarwin.h:144
PlatformDarwin::SDKEnumeratorInfo
Definition: PlatformDarwin.h:143
XcodeSDK.h
PlatformDarwin
Definition: PlatformDarwin.h:25
PlatformDarwin::GetSharedModule
lldb_private::Status GetSharedModule(const lldb_private::ModuleSpec &module_spec, lldb_private::Process *process, lldb::ModuleSP &module_sp, const lldb_private::FileSpecList *module_search_paths_ptr, llvm::SmallVectorImpl< lldb::ModuleSP > *old_modules, bool *did_create_ptr) override
Definition: PlatformDarwin.cpp:366
PlatformDarwin::PlatformDarwin
PlatformDarwin(bool is_host)
Default Constructor.
Definition: PlatformDarwin.cpp:51
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
PlatformDarwin::PutFile
lldb_private::Status PutFile(const lldb_private::FileSpec &source, const lldb_private::FileSpec &destination, uint32_t uid=UINT32_MAX, uint32_t gid=UINT32_MAX) override
Definition: PlatformDarwin.cpp:60
PlatformDarwin::CrashInfoAnnotations::thread
uint64_t thread
Definition: PlatformDarwin.h:112
lldb_private::ProcessLaunchInfo
Definition: ProcessLaunchInfo.h:31
PlatformDarwin::CrashInfoAnnotations::abort_cause
uint64_t abort_cause
Definition: PlatformDarwin.h:114
PlatformDarwin::AddClangModuleCompilationOptionsForSDKType
void AddClangModuleCompilationOptionsForSDKType(lldb_private::Target *target, std::vector< std::string > &options, lldb_private::XcodeSDK::Type sdk_type)
Definition: PlatformDarwin.cpp:1510
PlatformDarwin::CalculateTrapHandlerSymbolNames
void CalculateTrapHandlerSymbolNames() override
Ask the Platform subclass to fill in the list of trap handler names.
Definition: PlatformDarwin.cpp:1253
PlatformDarwin::m_developer_directory
std::string m_developer_directory
Definition: PlatformDarwin.h:172
PlatformDarwin::operator=
const PlatformDarwin & operator=(const PlatformDarwin &)=delete
lldb_private::FileSystem::EnumerateDirectoryResult
EnumerateDirectoryResult
Definition: FileSystem.h:162
lldb_private::ConstString
Definition: ConstString.h:40
PlatformDarwin::m_sdk_path
llvm::StringMap< std::string > m_sdk_path
Definition: PlatformDarwin.h:173
PlatformDarwin::ResolveSymbolFile
lldb_private::Status ResolveSymbolFile(lldb_private::Target &target, const lldb_private::ModuleSpec &sym_spec, lldb_private::FileSpec &sym_file) override
Find a symbol file given a symbol file module specification.
Definition: PlatformDarwin.cpp:194
lldb_private::Debugger
Definition: Debugger.h:70
PlatformDarwin::LocateExecutableScriptingResources
lldb_private::FileSpecList LocateExecutableScriptingResources(lldb_private::Target *target, lldb_private::Module &module, lldb_private::Stream *feedback_stream) override
Definition: PlatformDarwin.cpp:70
string
string(SUBSTRING ${p} 10 -1 pStripped) if($
Definition: Plugins/CMakeLists.txt:39
PlatformDarwin::ExtractCrashInfoAnnotations
lldb_private::StructuredData::ArraySP ExtractCrashInfoAnnotations(lldb_private::Process &process)
Extract the __crash_info annotations from each of of the target's modules.
Definition: PlatformDarwin.cpp:1407
PlatformDarwin::SupportsModules
bool SupportsModules() override
Definition: PlatformDarwin.h:82
PlatformDarwin::FindBundleBinaryInExecSearchPaths
lldb_private::Status FindBundleBinaryInExecSearchPaths(const lldb_private::ModuleSpec &module_spec, lldb_private::Process *process, lldb::ModuleSP &module_sp, const lldb_private::FileSpecList *module_search_paths_ptr, llvm::SmallVectorImpl< lldb::ModuleSP > *old_modules, bool *did_create_ptr)
Definition: PlatformDarwin.cpp:1725
PlatformDarwin::m_sdk_path_mutex
std::mutex m_sdk_path_mutex
Definition: PlatformDarwin.h:174
lldb_private::ModuleSpec
Definition: ModuleSpec.h:26
lldb_private::Status
Definition: Status.h:44
PlatformDarwin::GetFullNameForDylib
lldb_private::ConstString GetFullNameForDylib(lldb_private::ConstString basename) override
Definition: PlatformDarwin.cpp:1612
PlatformDarwin::ReadLibdispatchOffsets
void ReadLibdispatchOffsets(lldb_private::Process *process)
uint32_t
lldb_private::XcodeSDK::Type
Type
Different types of Xcode SDKs.
Definition: XcodeSDK.h:29
PlatformDarwin::GetSharedModuleWithLocalCache
virtual lldb_private::Status GetSharedModuleWithLocalCache(const lldb_private::ModuleSpec &module_spec, lldb::ModuleSP &module_sp, const lldb_private::FileSpecList *module_search_paths_ptr, llvm::SmallVectorImpl< lldb::ModuleSP > *old_modules, bool *did_create_ptr)
Definition: PlatformDarwin.cpp:221
PlatformDarwin::GetCurrentToolchainDirectory
static lldb_private::FileSpec GetCurrentToolchainDirectory()
Return the toolchain directory the current LLDB instance is located in.
Definition: PlatformDarwin.cpp:1815
UINT32_MAX
#define UINT32_MAX
Definition: lldb-defines.h:31
PlatformDarwin::CrashInfoAnnotations::version
uint64_t version
Definition: PlatformDarwin.h:107
PlatformDarwin::ModuleIsExcludedForUnconstrainedSearches
bool ModuleIsExcludedForUnconstrainedSearches(lldb_private::Target &target, const lldb::ModuleSP &module_sp) override
Definition: PlatformDarwin.cpp:504
PlatformDarwin::CrashInfoAnnotations::message
uint64_t message
Definition: PlatformDarwin.h:108
PlatformDarwin::CrashInfoAnnotations::signature_string
uint64_t signature_string
Definition: PlatformDarwin.h:109
PlatformDarwin::CrashInfoAnnotations::message2
uint64_t message2
Definition: PlatformDarwin.h:111
FileSpec.h
PlatformPOSIX.h
PlatformDarwin::FetchExtendedCrashInformation
llvm::Expected< lldb_private::StructuredData::DictionarySP > FetchExtendedCrashInformation(lldb_private::Process &process) override
Gather all of crash informations into a structured data dictionary.
Definition: PlatformDarwin.cpp:1388
ConstString.h
lldb_private::StructuredData::ArraySP
std::shared_ptr< Array > ArraySP
Definition: StructuredData.h:62
PlatformDarwin::ParseVersionBuildDir
static std::tuple< llvm::VersionTuple, llvm::StringRef > ParseVersionBuildDir(llvm::StringRef str)
Definition: PlatformDarwin.cpp:1370
PlatformDarwin::GetResumeCountForLaunchInfo
uint32_t GetResumeCountForLaunchInfo(lldb_private::ProcessLaunchInfo &launch_info) override
Definition: PlatformDarwin.cpp:1201
PlatformDarwin::GetSoftwareBreakpointTrapOpcode
size_t GetSoftwareBreakpointTrapOpcode(lldb_private::Target &target, lldb_private::BreakpointSite *bp_site) override
Definition: PlatformDarwin.cpp:447
llvm::SmallVectorImpl
Definition: Disassembler.h:42
PlatformDarwin::GetOSVersion
llvm::VersionTuple GetOSVersion(lldb_private::Process *process=nullptr) override
Get the OS version from a connected platform.
Definition: PlatformDarwin.cpp:1621
PlatformDarwin::LaunchProcess
lldb_private::Status LaunchProcess(lldb_private::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:1705
PlatformDarwin::DebugProcess
lldb::ProcessSP DebugProcess(lldb_private::ProcessLaunchInfo &launch_info, lldb_private::Debugger &debugger, lldb_private::Target &target, lldb_private::Status &error) override
Subclasses do not need to implement this function as it uses the Platform::LaunchProcess() followed b...
Definition: PlatformDarwin.cpp:1229
PlatformDarwin::CrashInfoAnnotations::dialog_mode
uint64_t dialog_mode
Definition: PlatformDarwin.h:113
PlatformDarwin::SDKEnumeratorInfo::sdk_type
lldb_private::XcodeSDK::Type sdk_type
Definition: PlatformDarwin.h:145
PlatformDarwin::FindComponentInPath
static std::string FindComponentInPath(llvm::StringRef path, llvm::StringRef component)
Definition: PlatformDarwin.cpp:1800
PlatformDarwin::CrashInfoAnnotations::backtrace
uint64_t backtrace
Definition: PlatformDarwin.h:110