1 //===-- PlatformDarwin.h ----------------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef LLDB_SOURCE_PLUGINS_PLATFORM_MACOSX_PLATFORMDARWIN_H
10 #define LLDB_SOURCE_PLUGINS_PLATFORM_MACOSX_PLATFORMDARWIN_H
12 #include "Plugins/Platform/POSIX/PlatformPOSIX.h"
13 #include "lldb/Host/FileSystem.h"
14 #include "lldb/Host/ProcessLaunchInfo.h"
15 #include "lldb/Utility/ArchSpec.h"
16 #include "lldb/Utility/ConstString.h"
17 #include "lldb/Utility/FileSpec.h"
18 #include "lldb/Utility/FileSpecList.h"
19 #include "lldb/Utility/Status.h"
20 #include "lldb/Utility/StructuredData.h"
21 #include "lldb/Utility/XcodeSDK.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"
35 namespace lldb_private
{
41 class ProcessLaunchInfo
;
45 class PlatformDarwin
: public PlatformPOSIX
{
47 using PlatformPOSIX::PlatformPOSIX
;
49 ~PlatformDarwin() override
;
51 static lldb::PlatformSP
CreateInstance(bool force
, const ArchSpec
*arch
);
53 static void DebuggerInitialize(lldb_private::Debugger
&debugger
);
55 static void Initialize();
57 static void Terminate();
59 static llvm::StringRef
GetPluginNameStatic() { return "darwin"; }
61 static llvm::StringRef
GetDescriptionStatic();
63 Status
PutFile(const FileSpec
&source
, const FileSpec
&destination
,
64 uint32_t uid
= UINT32_MAX
, uint32_t gid
= UINT32_MAX
) override
;
67 Status
ResolveSymbolFile(Target
&target
, const ModuleSpec
&sym_spec
,
68 FileSpec
&sym_file
) override
;
71 LocateExecutableScriptingResources(Target
*target
, Module
&module
,
72 Stream
&feedback_stream
) override
;
74 Status
GetSharedModule(const ModuleSpec
&module_spec
, Process
*process
,
75 lldb::ModuleSP
&module_sp
,
76 const FileSpecList
*module_search_paths_ptr
,
77 llvm::SmallVectorImpl
<lldb::ModuleSP
> *old_modules
,
78 bool *did_create_ptr
) override
;
80 size_t GetSoftwareBreakpointTrapOpcode(Target
&target
,
81 BreakpointSite
*bp_site
) override
;
83 lldb::BreakpointSP
SetThreadCreationBreakpoint(Target
&target
) override
;
85 bool ModuleIsExcludedForUnconstrainedSearches(
86 Target
&target
, const lldb::ModuleSP
&module_sp
) override
;
89 ARMGetSupportedArchitectures(std::vector
<ArchSpec
> &archs
,
90 std::optional
<llvm::Triple::OSType
> os
= {});
92 void x86GetSupportedArchitectures(std::vector
<ArchSpec
> &archs
);
94 uint32_t GetResumeCountForLaunchInfo(ProcessLaunchInfo
&launch_info
) override
;
96 lldb::ProcessSP
DebugProcess(ProcessLaunchInfo
&launch_info
,
97 Debugger
&debugger
, Target
&target
,
98 Status
&error
) override
;
100 void CalculateTrapHandlerSymbolNames() override
;
102 llvm::VersionTuple
GetOSVersion(Process
*process
= nullptr) override
;
104 bool SupportsModules() override
{ return true; }
106 ConstString
GetFullNameForDylib(ConstString basename
) override
;
108 FileSpec
LocateExecutable(const char *basename
) override
;
110 Status
LaunchProcess(ProcessLaunchInfo
&launch_info
) override
;
112 Args
GetExtraStartupCommands() override
;
114 static std::tuple
<llvm::VersionTuple
, llvm::StringRef
>
115 ParseVersionBuildDir(llvm::StringRef str
);
117 llvm::Expected
<StructuredData::DictionarySP
>
118 FetchExtendedCrashInformation(Process
&process
) override
;
120 /// Return the toolchain directory the current LLDB instance is located in.
121 static FileSpec
GetCurrentToolchainDirectory();
123 /// Return the command line tools directory the current LLDB instance is
125 static FileSpec
GetCurrentCommandLineToolsDirectory();
127 llvm::Expected
<std::pair
<XcodeSDK
, bool>>
128 GetSDKPathFromDebugInfo(Module
&module
) override
;
130 llvm::Expected
<std::string
>
131 ResolveSDKPathFromDebugInfo(Module
&module
) override
;
133 llvm::Expected
<XcodeSDK
> GetSDKPathFromDebugInfo(CompileUnit
&unit
) override
;
135 llvm::Expected
<std::string
>
136 ResolveSDKPathFromDebugInfo(CompileUnit
&unit
) override
;
139 static const char *GetCompatibleArch(ArchSpec::Core core
, size_t idx
);
141 struct CrashInfoAnnotations
{
142 uint64_t version
; // unsigned long
143 uint64_t message
; // char *
144 uint64_t signature_string
; // char *
145 uint64_t backtrace
; // char *
146 uint64_t message2
; // char *
147 uint64_t thread
; // uint64_t
148 uint64_t dialog_mode
; // unsigned int
149 uint64_t abort_cause
; // unsigned int
152 /// Extract the `__crash_info` annotations from each of the target's
155 /// If the platform have a crashed processes with a `__crash_info` section,
156 /// extract the section to gather the messages annotations and the abort
159 /// \param[in] process
160 /// The crashed process.
163 /// A structured data array containing at each entry in each entry, the
164 /// module spec, its UUID, the crash messages and the abort cause.
165 /// \b nullptr if process has no crash information annotations.
166 StructuredData::ArraySP
ExtractCrashInfoAnnotations(Process
&process
);
168 /// Extract the `Application Specific Information` messages from a crash
170 StructuredData::DictionarySP
ExtractAppSpecificInfo(Process
&process
);
172 void ReadLibdispatchOffsetsAddress(Process
*process
);
174 void ReadLibdispatchOffsets(Process
*process
);
176 virtual bool CheckLocalSharedCache() const { return IsHost(); }
178 struct SDKEnumeratorInfo
{
180 XcodeSDK::Type sdk_type
;
183 static FileSystem::EnumerateDirectoryResult
184 DirectoryEnumerator(void *baton
, llvm::sys::fs::file_type file_type
,
185 llvm::StringRef path
);
187 static FileSpec
FindSDKInXcodeForModules(XcodeSDK::Type sdk_type
,
188 const FileSpec
&sdks_spec
);
190 static FileSpec
GetSDKDirectoryForModules(XcodeSDK::Type sdk_type
);
193 AddClangModuleCompilationOptionsForSDKType(Target
*target
,
194 std::vector
<std::string
> &options
,
195 XcodeSDK::Type sdk_type
);
197 Status
FindBundleBinaryInExecSearchPaths(
198 const ModuleSpec
&module_spec
, Process
*process
,
199 lldb::ModuleSP
&module_sp
, const FileSpecList
*module_search_paths_ptr
,
200 llvm::SmallVectorImpl
<lldb::ModuleSP
> *old_modules
, bool *did_create_ptr
);
202 static std::string
FindComponentInPath(llvm::StringRef path
,
203 llvm::StringRef component
);
205 // The OSType where lldb is running.
206 static llvm::Triple::OSType
GetHostOSType();
208 std::string m_developer_directory
;
209 llvm::StringMap
<std::string
> m_sdk_path
;
210 std::mutex m_sdk_path_mutex
;
213 PlatformDarwin(const PlatformDarwin
&) = delete;
214 const PlatformDarwin
&operator=(const PlatformDarwin
&) = delete;
217 } // namespace lldb_private
219 #endif // LLDB_SOURCE_PLUGINS_PLATFORM_MACOSX_PLATFORMDARWIN_H