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