1 //===-- PlatformDarwinKernel.h ----------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_PlatformDarwinKernel_h_
11 #define liblldb_PlatformDarwinKernel_h_
13 #include "lldb/Core/ConstString.h"
15 #if defined (__APPLE__) // This Plugin uses the Mac-specific source/Host/macosx/cfcpp utilities
20 // Other libraries and framework includes
21 #include "lldb/Host/FileSpec.h"
24 #include "PlatformDarwin.h"
26 class PlatformDarwinKernel : public PlatformDarwin
30 //------------------------------------------------------------
32 //------------------------------------------------------------
33 static lldb::PlatformSP
34 CreateInstance (bool force, const lldb_private::ArchSpec *arch);
37 DebuggerInitialize (lldb_private::Debugger &debugger);
45 static lldb_private::ConstString
46 GetPluginNameStatic ();
49 GetDescriptionStatic();
51 //------------------------------------------------------------
53 //------------------------------------------------------------
54 PlatformDarwinKernel (lldb_private::LazyBool is_ios_debug_session);
57 ~PlatformDarwinKernel();
59 //------------------------------------------------------------
60 // lldb_private::PluginInterface functions
61 //------------------------------------------------------------
62 lldb_private::ConstString
63 GetPluginName() override
65 return GetPluginNameStatic();
69 GetPluginVersion() override
74 //------------------------------------------------------------
75 // lldb_private::Platform functions
76 //------------------------------------------------------------
78 GetDescription () override
80 return GetDescriptionStatic();
84 GetStatus (lldb_private::Stream &strm) override;
87 GetSharedModule (const lldb_private::ModuleSpec &module_spec,
88 lldb_private::Process *process,
89 lldb::ModuleSP &module_sp,
90 const lldb_private::FileSpecList *module_search_paths_ptr,
91 lldb::ModuleSP *old_module_sp_ptr,
92 bool *did_create_ptr) override;
95 GetSupportedArchitectureAtIndex (uint32_t idx,
96 lldb_private::ArchSpec &arch) override;
99 SupportsModules() override { return false; }
102 CalculateTrapHandlerSymbolNames () override;
106 // Map from kext bundle ID ("com.apple.filesystems.exfat") to FileSpec for the kext bundle on
107 // the host ("/System/Library/Extensions/exfat.kext/Contents/Info.plist").
108 typedef std::multimap<lldb_private::ConstString, lldb_private::FileSpec> BundleIDToKextMap;
109 typedef BundleIDToKextMap::iterator BundleIDToKextIterator;
111 typedef std::vector<lldb_private::FileSpec> KernelBinaryCollection;
113 // Array of directories that were searched for kext bundles (used only for reporting to user)
114 typedef std::vector<lldb_private::FileSpec> DirectoriesSearchedCollection;
115 typedef DirectoriesSearchedCollection::iterator DirectoriesSearchedIterator;
118 static lldb_private::FileSpec::EnumerateDirectoryResult
119 GetKextDirectoriesInSDK (void *baton,
120 lldb_private::FileSpec::FileType file_type,
121 const lldb_private::FileSpec &file_spec);
123 static lldb_private::FileSpec::EnumerateDirectoryResult
124 GetKextsInDirectory (void *baton,
125 lldb_private::FileSpec::FileType file_type,
126 const lldb_private::FileSpec &file_spec);
128 // Populate m_search_directories vector of directories
130 CollectKextAndKernelDirectories ();
132 // Directories where we may find iOS SDKs with kext bundles in them
134 GetiOSSDKDirectoriesToSearch (std::vector<lldb_private::FileSpec> &directories);
136 // Directories where we may find AppleTVOS SDKs with kext bundles in them
138 GetAppleTVOSSDKDirectoriesToSearch (std::vector<lldb_private::FileSpec> &directories);
140 // Directories where we may find WatchOS SDKs with kext bundles in them
142 GetWatchOSSDKDirectoriesToSearch (std::vector<lldb_private::FileSpec> &directories);
144 // Directories where we may find Mac OS X SDKs with kext bundles in them
146 GetMacSDKDirectoriesToSearch (std::vector<lldb_private::FileSpec> &directories);
148 // Directories where we may find Mac OS X or iOS SDKs with kext bundles in them
150 GetGenericSDKDirectoriesToSearch (std::vector<lldb_private::FileSpec> &directories);
152 // Directories where we may find iOS kext bundles
154 GetiOSDirectoriesToSearch (std::vector<lldb_private::FileSpec> &directories);
156 // Directories where we may find MacOSX kext bundles
158 GetMacDirectoriesToSearch (std::vector<lldb_private::FileSpec> &directories);
160 // Directories where we may find iOS or MacOSX kext bundles
162 GetGenericDirectoriesToSearch (std::vector<lldb_private::FileSpec> &directories);
164 // Directories specified via the "kext-directories" setting - maybe KDK/SDKs, may be plain directories
166 GetUserSpecifiedDirectoriesToSearch (std::vector<lldb_private::FileSpec> &directories);
169 GetCurrentDirectoryToSearch (std::vector<lldb_private::FileSpec> &directories);
171 // Directories where we may find kernels exclusively
173 GetKernelDirectoriesToSearch (std::vector<lldb_private::FileSpec> &directories);
175 // Search through a vector of SDK FileSpecs, add any directories that may contain kexts
176 // to the vector of kext dir FileSpecs
178 SearchSDKsForKextDirectories (std::vector<lldb_private::FileSpec> sdk_dirs, std::vector<lldb_private::FileSpec> &kext_dirs);
180 // Search through all of the directories passed in, find all .kext bundles in those directories,
181 // get the CFBundleIDs out of the Info.plists and add the bundle ID and kext path to m_name_to_kext_path_map.
183 IndexKextsInDirectories ();
185 // Search through all of the directories passed in, find all kernel binaries in those directories
186 // (look for "kernel*", "mach.*", assume those are kernels. False positives aren't a huge problem.)
188 IndexKernelsInDirectories ();
190 // Callback which iterates over all the files in a given directory, looking for kernel binaries
191 static lldb_private::FileSpec::EnumerateDirectoryResult
192 GetKernelsInDirectory (void *baton,
193 lldb_private::FileSpec::FileType file_type,
194 const lldb_private::FileSpec &file_spec);
197 ExamineKextForMatchingUUID (const lldb_private::FileSpec &kext_bundle_path, const lldb_private::UUID &uuid, const lldb_private::ArchSpec &arch, lldb::ModuleSP &exe_module_sp);
201 BundleIDToKextMap m_name_to_kext_path_map; // multimap of CFBundleID to FileSpec on local filesystem
202 DirectoriesSearchedCollection m_search_directories; // list of directories we search for kexts/kernels
203 KernelBinaryCollection m_kernel_binaries; // list of kernel binaries we found on local filesystem
204 lldb_private::LazyBool m_ios_debug_session;
206 DISALLOW_COPY_AND_ASSIGN (PlatformDarwinKernel);
212 // Since DynamicLoaderDarwinKernel is compiled in for all systems, and relies on
213 // PlatformDarwinKernel for the plug-in name, we compile just the plug-in name in
214 // here to avoid issues. We are tracking an internal bug to resolve this issue by
215 // either not compiling in DynamicLoaderDarwinKernel for non-apple builds, or to make
216 // PlatformDarwinKernel build on all systems. PlatformDarwinKernel is currently not
217 // compiled on other platforms due to the use of the Mac-specific
218 // source/Host/macosx/cfcpp utilities.
220 class PlatformDarwinKernel
222 static lldb_private::ConstString
223 GetPluginNameStatic ();
228 #endif // liblldb_PlatformDarwinKernel_h_