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