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 source/Host/macosx/cfcpp utilities
16
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
26class PlatformDarwinKernel : public PlatformDarwin
27{
28public:
29
30    //------------------------------------------------------------
31    // Class Functions
32    //------------------------------------------------------------
33    static lldb_private::Platform*
34    CreateInstance (bool force, const lldb_private::ArchSpec *arch);
35
36    static void
37    DebuggerInitialize (lldb_private::Debugger &debugger);
38
39    static void
40    Initialize ();
41
42    static void
43    Terminate ();
44
45    static lldb_private::ConstString
46    GetPluginNameStatic ();
47
48    static const char *
49    GetDescriptionStatic();
50
51    //------------------------------------------------------------
52    // Class Methods
53    //------------------------------------------------------------
54    PlatformDarwinKernel (lldb_private::LazyBool is_ios_debug_session);
55
56    virtual
57    ~PlatformDarwinKernel();
58
59    //------------------------------------------------------------
60    // lldb_private::PluginInterface functions
61    //------------------------------------------------------------
62    virtual lldb_private::ConstString
63    GetPluginName()
64    {
65        return GetPluginNameStatic();
66    }
67
68    virtual uint32_t
69    GetPluginVersion()
70    {
71        return 1;
72    }
73
74    //------------------------------------------------------------
75    // lldb_private::Platform functions
76    //------------------------------------------------------------
77    virtual const char *
78    GetDescription ()
79    {
80        return GetDescriptionStatic();
81    }
82
83    virtual void
84    GetStatus (lldb_private::Stream &strm);
85
86    virtual lldb_private::Error
87    GetSharedModule (const lldb_private::ModuleSpec &module_spec,
88                     lldb::ModuleSP &module_sp,
89                     const lldb_private::FileSpecList *module_search_paths_ptr,
90                     lldb::ModuleSP *old_module_sp_ptr,
91                     bool *did_create_ptr);
92
93    virtual bool
94    GetSupportedArchitectureAtIndex (uint32_t idx,
95                                     lldb_private::ArchSpec &arch);
96
97protected:
98
99    // Map from kext bundle ID ("com.apple.filesystems.exfat") to FileSpec for the kext bundle on
100    // the host ("/System/Library/Extensions/exfat.kext/Contents/Info.plist").
101    typedef std::multimap<lldb_private::ConstString, lldb_private::FileSpec> BundleIDToKextMap;
102    typedef BundleIDToKextMap::iterator BundleIDToKextIterator;
103
104
105    // Array of directories that were searched for kext bundles (used only for reporting to user)
106    typedef std::vector<lldb_private::FileSpec> DirectoriesSearchedCollection;
107    typedef DirectoriesSearchedCollection::iterator DirectoriesSearchedIterator;
108
109
110    static lldb_private::FileSpec::EnumerateDirectoryResult
111    GetKextDirectoriesInSDK (void *baton,
112                             lldb_private::FileSpec::FileType file_type,
113                             const lldb_private::FileSpec &file_spec);
114
115    static lldb_private::FileSpec::EnumerateDirectoryResult
116    GetKextsInDirectory (void *baton,
117                         lldb_private::FileSpec::FileType file_type,
118                         const lldb_private::FileSpec &file_spec);
119
120    void
121    SearchForKexts();
122
123    // Directories where we may find iOS SDKs with kext bundles in them
124    void
125    GetiOSSDKDirectoriesToSearch (std::vector<lldb_private::FileSpec> &directories);
126
127    // Directories where we may find Mac OS X SDKs with kext bundles in them
128    void
129    GetMacSDKDirectoriesToSearch (std::vector<lldb_private::FileSpec> &directories);
130
131    // Directories where we may find Mac OS X or iOS SDKs with kext bundles in them
132    void
133    GetGenericSDKDirectoriesToSearch (std::vector<lldb_private::FileSpec> &directories);
134
135    // Directories where we may find iOS kext bundles
136    void
137    GetiOSDirectoriesToSearch (std::vector<lldb_private::FileSpec> &directories);
138
139    // Directories where we may find MacOSX kext bundles
140    void
141    GetMacDirectoriesToSearch (std::vector<lldb_private::FileSpec> &directories);
142
143    // Directories where we may find iOS or MacOSX kext bundles
144    void
145    GetGenericDirectoriesToSearch (std::vector<lldb_private::FileSpec> &directories);
146
147    // Directories specified via the "kext-directories" setting - maybe KDK/SDKs, may be plain directories
148    void
149    GetUserSpecifiedDirectoriesToSearch (std::vector<lldb_private::FileSpec> &directories);
150
151    // Search through a vector of SDK FileSpecs, add any directories that may contain kexts
152    // to the vector of kext dir FileSpecs
153    void
154    SearchSDKsForKextDirectories (std::vector<lldb_private::FileSpec> sdk_dirs, std::vector<lldb_private::FileSpec> &kext_dirs);
155
156    // Search through all of the directories passed in, find all .kext bundles in those directories,
157    // get the CFBundleIDs out of the Info.plists and add the bundle ID and kext path to m_name_to_kext_path_map.
158    void
159    IndexKextsInDirectories (std::vector<lldb_private::FileSpec> kext_dirs);
160
161    lldb_private::Error
162    ExamineKextForMatchingUUID (const lldb_private::FileSpec &kext_bundle_path, const lldb_private::UUID &uuid, const lldb_private::ArchSpec &arch, lldb::ModuleSP &exe_module_sp);
163
164private:
165
166    BundleIDToKextMap m_name_to_kext_path_map;
167    DirectoriesSearchedCollection m_directories_searched;
168    lldb_private::LazyBool m_ios_debug_session;
169
170    DISALLOW_COPY_AND_ASSIGN (PlatformDarwinKernel);
171
172};
173
174#else   // __APPLE__
175
176// Since DynamicLoaderDarwinKernel is compiled in for all systems, and relies on
177// PlatformDarwinKernel for the plug-in name, we compile just the plug-in name in
178// here to avoid issues. We are tracking an internal bug to resolve this issue by
179// either not compiling in DynamicLoaderDarwinKernel for non-apple builds, or to make
180// PlatformDarwinKernel build on all systems. PlatformDarwinKernel is currently not
181// compiled on other platforms due to the use of the Mac-specific
182// source/Host/macosx/cfcpp utilities.
183
184class PlatformDarwinKernel
185{
186    static lldb_private::ConstString
187    GetPluginNameStatic ();
188};
189
190#endif  // __APPLE__
191
192#endif  // liblldb_PlatformDarwinKernel_h_
193