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