summaryrefslogtreecommitdiffstats
path: root/lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.h
blob: 1ba26803ce65c4d7cdfa71c9ebafe2864fecb5a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
//===-- PlatformDarwinKernel.h ----------------------------------*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#ifndef liblldb_PlatformDarwinKernel_h_
#define liblldb_PlatformDarwinKernel_h_

#include "lldb/Core/ConstString.h"

#if defined (__APPLE__)  // This Plugin uses the Mac-specific source/Host/macosx/cfcpp utilities


// C Includes
// C++ Includes
// Other libraries and framework includes
#include "lldb/Host/FileSpec.h"

// Project includes
#include "PlatformDarwin.h"

class PlatformDarwinKernel : public PlatformDarwin
{
public:

    //------------------------------------------------------------
    // Class Functions
    //------------------------------------------------------------
    static lldb::PlatformSP
    CreateInstance (bool force, const lldb_private::ArchSpec *arch);

    static void
    DebuggerInitialize (lldb_private::Debugger &debugger);

    static void
    Initialize ();

    static void
    Terminate ();

    static lldb_private::ConstString
    GetPluginNameStatic ();

    static const char *
    GetDescriptionStatic();

    //------------------------------------------------------------
    // Class Methods
    //------------------------------------------------------------
    PlatformDarwinKernel (lldb_private::LazyBool is_ios_debug_session);

    virtual
    ~PlatformDarwinKernel();

    //------------------------------------------------------------
    // lldb_private::PluginInterface functions
    //------------------------------------------------------------
    lldb_private::ConstString
    GetPluginName() override
    {
        return GetPluginNameStatic();
    }

    virtual uint32_t
    GetPluginVersion()  override
    {
        return 1;
    }

    //------------------------------------------------------------
    // lldb_private::Platform functions
    //------------------------------------------------------------
    const char *
    GetDescription () override
    {
        return GetDescriptionStatic();
    }

    void
    GetStatus (lldb_private::Stream &strm) override;

    lldb_private::Error
    GetSharedModule (const lldb_private::ModuleSpec &module_spec,
                     lldb::ModuleSP &module_sp,
                     const lldb_private::FileSpecList *module_search_paths_ptr,
                     lldb::ModuleSP *old_module_sp_ptr,
                     bool *did_create_ptr)  override;

    bool
    GetSupportedArchitectureAtIndex (uint32_t idx, 
                                     lldb_private::ArchSpec &arch) override;
    
    bool
    SupportsModules() override { return false; }

    void
    CalculateTrapHandlerSymbolNames () override;


protected:

    // Map from kext bundle ID ("com.apple.filesystems.exfat") to FileSpec for the kext bundle on 
    // the host ("/System/Library/Extensions/exfat.kext/Contents/Info.plist").
    typedef std::multimap<lldb_private::ConstString, lldb_private::FileSpec> BundleIDToKextMap;
    typedef BundleIDToKextMap::iterator BundleIDToKextIterator;

    
    // Array of directories that were searched for kext bundles (used only for reporting to user)
    typedef std::vector<lldb_private::FileSpec> DirectoriesSearchedCollection;
    typedef DirectoriesSearchedCollection::iterator DirectoriesSearchedIterator;


    static lldb_private::FileSpec::EnumerateDirectoryResult
    GetKextDirectoriesInSDK (void *baton,
                             lldb_private::FileSpec::FileType file_type,
                             const lldb_private::FileSpec &file_spec);

    static lldb_private::FileSpec::EnumerateDirectoryResult 
    GetKextsInDirectory (void *baton,
                         lldb_private::FileSpec::FileType file_type,
                         const lldb_private::FileSpec &file_spec);

    void
    SearchForKexts();

    // Directories where we may find iOS SDKs with kext bundles in them
    void
    GetiOSSDKDirectoriesToSearch (std::vector<lldb_private::FileSpec> &directories);

    // Directories where we may find Mac OS X SDKs with kext bundles in them
    void
    GetMacSDKDirectoriesToSearch (std::vector<lldb_private::FileSpec> &directories);

    // Directories where we may find Mac OS X or iOS SDKs with kext bundles in them
    void
    GetGenericSDKDirectoriesToSearch (std::vector<lldb_private::FileSpec> &directories);

    // Directories where we may find iOS kext bundles
    void
    GetiOSDirectoriesToSearch (std::vector<lldb_private::FileSpec> &directories);

    // Directories where we may find MacOSX kext bundles
    void
    GetMacDirectoriesToSearch (std::vector<lldb_private::FileSpec> &directories);

    // Directories where we may find iOS or MacOSX kext bundles
    void
    GetGenericDirectoriesToSearch (std::vector<lldb_private::FileSpec> &directories);

    // Directories specified via the "kext-directories" setting - maybe KDK/SDKs, may be plain directories
    void
    GetUserSpecifiedDirectoriesToSearch (std::vector<lldb_private::FileSpec> &directories);

    // Search through a vector of SDK FileSpecs, add any directories that may contain kexts
    // to the vector of kext dir FileSpecs
    void
    SearchSDKsForKextDirectories (std::vector<lldb_private::FileSpec> sdk_dirs, std::vector<lldb_private::FileSpec> &kext_dirs);

    // Search through all of the directories passed in, find all .kext bundles in those directories,
    // get the CFBundleIDs out of the Info.plists and add the bundle ID and kext path to m_name_to_kext_path_map.
    void
    IndexKextsInDirectories (std::vector<lldb_private::FileSpec> kext_dirs);

    lldb_private::Error
    ExamineKextForMatchingUUID (const lldb_private::FileSpec &kext_bundle_path, const lldb_private::UUID &uuid, const lldb_private::ArchSpec &arch, lldb::ModuleSP &exe_module_sp);

private:

    BundleIDToKextMap m_name_to_kext_path_map; 
    DirectoriesSearchedCollection m_directories_searched;
    lldb_private::LazyBool m_ios_debug_session;

    DISALLOW_COPY_AND_ASSIGN (PlatformDarwinKernel);

};

#else   // __APPLE__

// Since DynamicLoaderDarwinKernel is compiled in for all systems, and relies on
// PlatformDarwinKernel for the plug-in name, we compile just the plug-in name in
// here to avoid issues. We are tracking an internal bug to resolve this issue by
// either not compiling in DynamicLoaderDarwinKernel for non-apple builds, or to make
// PlatformDarwinKernel build on all systems. PlatformDarwinKernel is currently not
// compiled on other platforms due to the use of the Mac-specific
// source/Host/macosx/cfcpp utilities.

class PlatformDarwinKernel
{
    static lldb_private::ConstString
    GetPluginNameStatic ();
};

#endif  // __APPLE__

#endif  // liblldb_PlatformDarwinKernel_h_
OpenPOWER on IntegriCloud