LLDB mainline
PlatformDarwinKernel.h
Go to the documentation of this file.
1//===-- PlatformDarwinKernel.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_PLATFORMDARWINKERNEL_H
10#define LLDB_SOURCE_PLUGINS_PLATFORM_MACOSX_PLATFORMDARWINKERNEL_H
11
12#include "PlatformDarwin.h"
16#include "lldb/Utility/Status.h"
17#include "lldb/Utility/UUID.h"
18#include "lldb/lldb-forward.h"
20#include "llvm/ADT/SmallVector.h"
21#include "llvm/ADT/StringRef.h"
22#include "llvm/Support/Error.h"
23#include "llvm/Support/FileSystem.h"
24
25#include <vector>
26
27namespace lldb_private {
28class ArchSpec;
29class Debugger;
30class FileSpecList;
31class ModuleSpec;
32class Process;
33class Stream;
34
35#if defined(__APPLE__) // This Plugin uses the Mac-specific
36 // source/Host/macosx/cfcpp utilities
37
39public:
40 static lldb::PlatformSP CreateInstance(bool force, const ArchSpec *arch);
41
42 static void DebuggerInitialize(Debugger &debugger);
43
44 static void Initialize();
45
46 static void Terminate();
47
48 static llvm::StringRef GetPluginNameStatic() { return "darwin-kernel"; }
49
50 static llvm::StringRef GetDescriptionStatic();
51
52 PlatformDarwinKernel(LazyBool is_ios_debug_session);
53
54 ~PlatformDarwinKernel() override;
55
56 llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
57
58 llvm::StringRef GetDescription() override { return GetDescriptionStatic(); }
59
60 void GetStatus(Stream &strm) override;
61
62 Status GetSharedModule(const ModuleSpec &module_spec, Target &target,
63 lldb::ModuleSP &module_sp,
64 llvm::SmallVectorImpl<lldb::ModuleSP> *old_modules,
65 bool *did_create_ptr) override;
66
67 std::vector<ArchSpec>
68 GetSupportedArchitectures(const ArchSpec &process_host_arch) override;
69
70 bool SupportsModules() override { return false; }
71
72 void CalculateTrapHandlerSymbolNames() override;
73
74protected:
75 // Map from kext bundle ID ("com.apple.filesystems.exfat") to FileSpec for
76 // the kext bundle on the host
77 // ("/System/Library/Extensions/exfat.kext/Contents/Info.plist").
78 typedef std::multimap<ConstString, FileSpec> BundleIDToKextMap;
79
80 typedef std::vector<FileSpec> KernelBinaryCollection;
81
82 // Array of directories that were searched for kext bundles (used only for
83 // reporting to user).
84 typedef std::vector<FileSpec> DirectoriesSearchedCollection;
85 typedef DirectoriesSearchedCollection::iterator DirectoriesSearchedIterator;
86
87 // Populate m_search_directories and m_search_directories_no_recursing
88 // vectors of directories.
89 void CollectKextAndKernelDirectories();
90
91 void GetUserSpecifiedDirectoriesToSearch();
92
93 static void AddRootSubdirsToSearchPaths(PlatformDarwinKernel *thisp,
94 const std::string &dir);
95
96 void AddSDKSubdirsToSearchPaths(const std::string &dir);
97
99 FindKDKandSDKDirectoriesInDirectory(void *baton, llvm::sys::fs::file_type ft,
100 llvm::StringRef path);
101
102 void SearchForKextsAndKernelsRecursively();
103
105 GetKernelsAndKextsInDirectoryWithRecursion(void *baton,
106 llvm::sys::fs::file_type ft,
107 llvm::StringRef path);
108
110 GetKernelsAndKextsInDirectoryNoRecursion(void *baton,
111 llvm::sys::fs::file_type ft,
112 llvm::StringRef path);
113
115 GetKernelsAndKextsInDirectoryHelper(void *baton, llvm::sys::fs::file_type ft,
116 llvm::StringRef path, bool recurse);
117
118 static std::vector<FileSpec>
119 SearchForExecutablesRecursively(const std::string &dir);
120
121 static void AddKextToMap(PlatformDarwinKernel *thisp,
122 const FileSpec &file_spec);
123
124 // Returns true if there is a .dSYM bundle next to the kext, or next to the
125 // binary inside the kext.
126 static bool KextHasdSYMSibling(const FileSpec &kext_bundle_filepath);
127
128 // Returns true if there is a .dSYM bundle next to the kernel
129 static bool KernelHasdSYMSibling(const FileSpec &kernel_filepath);
130
131 // Returns true if there is a .dSYM bundle with NO kernel binary next to it
132 static bool
133 KerneldSYMHasNoSiblingBinary(const FileSpec &kernel_dsym_filepath);
134
135 // Given a dsym_bundle argument ('.../foo.dSYM'), return a FileSpec
136 // with the binary inside it ('.../foo.dSYM/Contents/Resources/DWARF/foo').
137 // A dSYM bundle may have multiple DWARF binaries in them, so a vector
138 // of matches is returned.
139 static std::vector<FileSpec>
140 GetDWARFBinaryInDSYMBundle(const FileSpec &dsym_bundle);
141
142 llvm::Expected<lldb::ModuleSP>
143 GetSharedModuleKext(const ModuleSpec &module_spec, Target &target,
144 llvm::SmallVectorImpl<lldb::ModuleSP> *old_modules,
145 bool *did_create_ptr);
146
147 llvm::Expected<lldb::ModuleSP>
148 GetSharedModuleKernel(const ModuleSpec &module_spec, Target &target,
149 llvm::SmallVectorImpl<lldb::ModuleSP> *old_modules,
150 bool *did_create_ptr);
151
152 /// Search the kext index for a bundle ID with a matching UUID.
153 lldb::ModuleSP FindKextInIndex(const ModuleSpec &module_spec);
154
155 /// Search the kernel index for a binary with a matching UUID, and for its
156 /// symbols.
157 lldb::ModuleSP FindKernelInIndex(const ModuleSpec &module_spec,
158 const FileSpecList &search_paths);
159
160 lldb::ModuleSP ExamineKextForMatchingUUID(const FileSpec &kext_bundle_path,
161 const UUID &uuid,
162 const ArchSpec &arch);
163
164 bool LoadPlatformBinaryAndSetup(Process *process, lldb::addr_t addr,
165 bool notify) override;
166
167 void UpdateKextandKernelsLocalScan();
168
169 // Most of the ivars are assembled under FileSystem::EnumerateDirectory calls
170 // where the function being called for each file/directory must be static.
171 // We'll pass a this pointer as a baton and access the ivars directly.
172 // Toss-up whether this should just be a struct at this point.
173
174public:
175 /// Multimap of CFBundleID to FileSpec on local filesystem, kexts with dSYMs
176 /// next to them.
177 BundleIDToKextMap m_name_to_kext_path_map_with_dsyms;
178
179 /// Multimap of CFBundleID to FileSpec on local filesystem, kexts without
180 /// dSYMs next to them.
181 BundleIDToKextMap m_name_to_kext_path_map_without_dsyms;
182
183 /// List of directories we search for kexts/kernels.
184 DirectoriesSearchedCollection m_search_directories;
185
186 /// List of directories we search for kexts/kernels, no recursion.
187 DirectoriesSearchedCollection m_search_directories_no_recursing;
188
189 /// List of kernel binaries we found on local filesystem, without dSYMs next
190 /// to them.
191 KernelBinaryCollection m_kernel_binaries_with_dsyms;
192
193 /// List of kernel binaries we found on local filesystem, with dSYMs next to
194 /// them.
195 KernelBinaryCollection m_kernel_binaries_without_dsyms;
196
197 /// List of kernel dsyms with no binaries next to them.
198 KernelBinaryCollection m_kernel_dsyms_no_binaries;
199
200 /// List of kernel .dSYM.yaa files.
201 KernelBinaryCollection m_kernel_dsyms_yaas;
202
203 LazyBool m_ios_debug_session;
204
205 std::once_flag m_kext_scan_flag;
206
207 PlatformDarwinKernel(const PlatformDarwinKernel &) = delete;
208 const PlatformDarwinKernel &operator=(const PlatformDarwinKernel &) = delete;
209};
210
211#else // __APPLE__
212
213// Since DynamicLoaderDarwinKernel is compiled in for all systems, and relies
214// on PlatformDarwinKernel for the plug-in name, we compile just the plug-in
215// name in here to avoid issues. We are tracking an internal bug to resolve
216// this issue by either not compiling in DynamicLoaderDarwinKernel for
217// non-apple builds, or to make PlatformDarwinKernel build on all systems.
218//
219// PlatformDarwinKernel is currently not compiled on other platforms due to the
220// use of the Mac-specific source/Host/macosx/cfcpp utilities.
221
223public:
224 static llvm::StringRef GetPluginNameStatic() { return "darwin-kernel"; }
225};
226
227#endif // __APPLE__
228
229} // namespace lldb_private
230
231#endif // LLDB_SOURCE_PLUGINS_PLATFORM_MACOSX_PLATFORMDARWINKERNEL_H
An architecture specification class.
Definition ArchSpec.h:32
A class to manage flag bits.
Definition Debugger.h:100
A file collection class.
static llvm::StringRef GetPluginNameStatic()
A plug-in interface definition class for debugging a process.
Definition Process.h:367
A stream class that can stream formatted output to a file.
Definition Stream.h:28
A class that represents a running process on the host machine.
std::shared_ptr< lldb_private::Platform > PlatformSP
uint64_t addr_t
Definition lldb-types.h:80
std::shared_ptr< lldb_private::Module > ModuleSP