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