/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h
Line | Count | Source |
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 | | |
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" |
29 | | |
30 | | #include <mutex> |
31 | | #include <optional> |
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: |
47 | | using PlatformPOSIX::PlatformPOSIX; |
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 | 3.94k | 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 |
71 | | LocateExecutableScriptingResources(Target *target, Module &module, |
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, |
77 | | llvm::SmallVectorImpl<lldb::ModuleSP> *old_modules, |
78 | | bool *did_create_ptr) override; |
79 | | |
80 | | size_t GetSoftwareBreakpointTrapOpcode(Target &target, |
81 | | BreakpointSite *bp_site) override; |
82 | | |
83 | | lldb::BreakpointSP SetThreadCreationBreakpoint(Target &target) override; |
84 | | |
85 | | bool ModuleIsExcludedForUnconstrainedSearches( |
86 | | Target &target, const lldb::ModuleSP &module_sp) override; |
87 | | |
88 | | void |
89 | | ARMGetSupportedArchitectures(std::vector<ArchSpec> &archs, |
90 | | std::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 | 1.23k | 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. |
121 | | static FileSpec GetCurrentToolchainDirectory(); |
122 | | |
123 | | /// Return the command line tools directory the current LLDB instance is |
124 | | /// located in. |
125 | | static FileSpec GetCurrentCommandLineToolsDirectory(); |
126 | | |
127 | | /// Search each CU associated with the specified 'module' for |
128 | | /// the SDK paths the CUs were compiled against. In the presence |
129 | | /// of different SDKs, we try to pick the most appropriate one |
130 | | /// using \ref XcodeSDK::Merge. |
131 | | /// |
132 | | /// \param[in] module Module whose debug-info CUs to parse for |
133 | | /// which SDK they were compiled against. |
134 | | /// |
135 | | /// \returns If successful, returns a pair of a parsed XcodeSDK |
136 | | /// object and a boolean that is 'true' if we encountered |
137 | | /// a conflicting combination of SDKs when parsing the CUs |
138 | | /// (e.g., a public and internal SDK). |
139 | | static llvm::Expected<std::pair<XcodeSDK, bool>> |
140 | | GetSDKPathFromDebugInfo(Module &module); |
141 | | |
142 | | /// Returns the full path of the most appropriate SDK for the |
143 | | /// specified 'module'. This function gets this path by parsing |
144 | | /// debug-info (see \ref `GetSDKPathFromDebugInfo`). |
145 | | /// |
146 | | /// \param[in] module Module whose debug-info to parse for |
147 | | /// which SDK it was compiled against. |
148 | | /// |
149 | | /// \returns If successful, returns the full path to an |
150 | | /// Xcode SDK. |
151 | | static llvm::Expected<std::string> |
152 | | ResolveSDKPathFromDebugInfo(Module &module); |
153 | | |
154 | | protected: |
155 | | static const char *GetCompatibleArch(ArchSpec::Core core, size_t idx); |
156 | | |
157 | | struct CrashInfoAnnotations { |
158 | | uint64_t version; // unsigned long |
159 | | uint64_t message; // char * |
160 | | uint64_t signature_string; // char * |
161 | | uint64_t backtrace; // char * |
162 | | uint64_t message2; // char * |
163 | | uint64_t thread; // uint64_t |
164 | | uint64_t dialog_mode; // unsigned int |
165 | | uint64_t abort_cause; // unsigned int |
166 | | }; |
167 | | |
168 | | /// Extract the `__crash_info` annotations from each of the target's |
169 | | /// modules. |
170 | | /// |
171 | | /// If the platform have a crashed processes with a `__crash_info` section, |
172 | | /// extract the section to gather the messages annotations and the abort |
173 | | /// cause. |
174 | | /// |
175 | | /// \param[in] process |
176 | | /// The crashed process. |
177 | | /// |
178 | | /// \return |
179 | | /// A structured data array containing at each entry in each entry, the |
180 | | /// module spec, its UUID, the crash messages and the abort cause. |
181 | | /// \b nullptr if process has no crash information annotations. |
182 | | StructuredData::ArraySP ExtractCrashInfoAnnotations(Process &process); |
183 | | |
184 | | /// Extract the `Application Specific Information` messages from a crash |
185 | | /// report. |
186 | | StructuredData::DictionarySP ExtractAppSpecificInfo(Process &process); |
187 | | |
188 | | void ReadLibdispatchOffsetsAddress(Process *process); |
189 | | |
190 | | void ReadLibdispatchOffsets(Process *process); |
191 | | |
192 | 115k | virtual bool CheckLocalSharedCache() const { return IsHost(); } |
193 | | |
194 | | struct SDKEnumeratorInfo { |
195 | | FileSpec found_path; |
196 | | XcodeSDK::Type sdk_type; |
197 | | }; |
198 | | |
199 | | static FileSystem::EnumerateDirectoryResult |
200 | | DirectoryEnumerator(void *baton, llvm::sys::fs::file_type file_type, |
201 | | llvm::StringRef path); |
202 | | |
203 | | static FileSpec FindSDKInXcodeForModules(XcodeSDK::Type sdk_type, |
204 | | const FileSpec &sdks_spec); |
205 | | |
206 | | static FileSpec GetSDKDirectoryForModules(XcodeSDK::Type sdk_type); |
207 | | |
208 | | void |
209 | | AddClangModuleCompilationOptionsForSDKType(Target *target, |
210 | | std::vector<std::string> &options, |
211 | | XcodeSDK::Type sdk_type); |
212 | | |
213 | | Status FindBundleBinaryInExecSearchPaths( |
214 | | const ModuleSpec &module_spec, Process *process, |
215 | | lldb::ModuleSP &module_sp, const FileSpecList *module_search_paths_ptr, |
216 | | llvm::SmallVectorImpl<lldb::ModuleSP> *old_modules, bool *did_create_ptr); |
217 | | |
218 | | static std::string FindComponentInPath(llvm::StringRef path, |
219 | | llvm::StringRef component); |
220 | | |
221 | | // The OSType where lldb is running. |
222 | | static llvm::Triple::OSType GetHostOSType(); |
223 | | |
224 | | std::string m_developer_directory; |
225 | | llvm::StringMap<std::string> m_sdk_path; |
226 | | std::mutex m_sdk_path_mutex; |
227 | | |
228 | | private: |
229 | | PlatformDarwin(const PlatformDarwin &) = delete; |
230 | | const PlatformDarwin &operator=(const PlatformDarwin &) = delete; |
231 | | }; |
232 | | |
233 | | } // namespace lldb_private |
234 | | |
235 | | #endif // LLDB_SOURCE_PLUGINS_PLATFORM_MACOSX_PLATFORMDARWIN_H |