]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - source/Plugins/Platform/MacOSX/PlatformDarwinKernel.h
Vendor import of lldb trunk r256945:
[FreeBSD/FreeBSD.git] / source / Plugins / Platform / MacOSX / PlatformDarwinKernel.h
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
26 class PlatformDarwinKernel : public PlatformDarwin
27 {
28 public:
29
30     //------------------------------------------------------------
31     // Class Functions
32     //------------------------------------------------------------
33     static lldb::PlatformSP
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     lldb_private::ConstString
63     GetPluginName() override
64     {
65         return GetPluginNameStatic();
66     }
67
68     uint32_t
69     GetPluginVersion() override
70     {
71         return 1;
72     }
73
74     //------------------------------------------------------------
75     // lldb_private::Platform functions
76     //------------------------------------------------------------
77     const char *
78     GetDescription () override
79     {
80         return GetDescriptionStatic();
81     }
82
83     void
84     GetStatus (lldb_private::Stream &strm) override;
85
86     lldb_private::Error
87     GetSharedModule (const lldb_private::ModuleSpec &module_spec,
88                      lldb_private::Process *process,
89                      lldb::ModuleSP &module_sp,
90                      const lldb_private::FileSpecList *module_search_paths_ptr,
91                      lldb::ModuleSP *old_module_sp_ptr,
92                      bool *did_create_ptr) override;
93
94     bool
95     GetSupportedArchitectureAtIndex (uint32_t idx, 
96                                      lldb_private::ArchSpec &arch) override;
97     
98     bool
99     SupportsModules() override { return false; }
100
101     void
102     CalculateTrapHandlerSymbolNames () override;
103
104 protected:
105
106     // Map from kext bundle ID ("com.apple.filesystems.exfat") to FileSpec for the kext bundle on 
107     // the host ("/System/Library/Extensions/exfat.kext/Contents/Info.plist").
108     typedef std::multimap<lldb_private::ConstString, lldb_private::FileSpec> BundleIDToKextMap;
109     typedef BundleIDToKextMap::iterator BundleIDToKextIterator;
110
111     typedef std::vector<lldb_private::FileSpec> KernelBinaryCollection;
112     
113     // Array of directories that were searched for kext bundles (used only for reporting to user)
114     typedef std::vector<lldb_private::FileSpec> DirectoriesSearchedCollection;
115     typedef DirectoriesSearchedCollection::iterator DirectoriesSearchedIterator;
116
117
118     static lldb_private::FileSpec::EnumerateDirectoryResult
119     GetKextDirectoriesInSDK (void *baton,
120                              lldb_private::FileSpec::FileType file_type,
121                              const lldb_private::FileSpec &file_spec);
122
123     static lldb_private::FileSpec::EnumerateDirectoryResult 
124     GetKextsInDirectory (void *baton,
125                          lldb_private::FileSpec::FileType file_type,
126                          const lldb_private::FileSpec &file_spec);
127
128     // Populate m_search_directories vector of directories
129     void
130     CollectKextAndKernelDirectories ();
131
132     // Directories where we may find iOS SDKs with kext bundles in them
133     void
134     GetiOSSDKDirectoriesToSearch (std::vector<lldb_private::FileSpec> &directories);
135
136     // Directories where we may find AppleTVOS SDKs with kext bundles in them
137     void
138     GetAppleTVOSSDKDirectoriesToSearch (std::vector<lldb_private::FileSpec> &directories);
139     
140     // Directories where we may find WatchOS SDKs with kext bundles in them
141     void
142     GetWatchOSSDKDirectoriesToSearch (std::vector<lldb_private::FileSpec> &directories);
143
144     // Directories where we may find Mac OS X SDKs with kext bundles in them
145     void
146     GetMacSDKDirectoriesToSearch (std::vector<lldb_private::FileSpec> &directories);
147
148     // Directories where we may find Mac OS X or iOS SDKs with kext bundles in them
149     void
150     GetGenericSDKDirectoriesToSearch (std::vector<lldb_private::FileSpec> &directories);
151
152     // Directories where we may find iOS kext bundles
153     void
154     GetiOSDirectoriesToSearch (std::vector<lldb_private::FileSpec> &directories);
155
156     // Directories where we may find MacOSX kext bundles
157     void
158     GetMacDirectoriesToSearch (std::vector<lldb_private::FileSpec> &directories);
159
160     // Directories where we may find iOS or MacOSX kext bundles
161     void
162     GetGenericDirectoriesToSearch (std::vector<lldb_private::FileSpec> &directories);
163
164     // Directories specified via the "kext-directories" setting - maybe KDK/SDKs, may be plain directories
165     void
166     GetUserSpecifiedDirectoriesToSearch (std::vector<lldb_private::FileSpec> &directories);
167
168     void
169     GetCurrentDirectoryToSearch (std::vector<lldb_private::FileSpec> &directories);
170
171     // Directories where we may find kernels exclusively
172     void
173     GetKernelDirectoriesToSearch (std::vector<lldb_private::FileSpec> &directories);
174
175     // Search through a vector of SDK FileSpecs, add any directories that may contain kexts
176     // to the vector of kext dir FileSpecs
177     void
178     SearchSDKsForKextDirectories (std::vector<lldb_private::FileSpec> sdk_dirs, std::vector<lldb_private::FileSpec> &kext_dirs);
179
180     // Search through all of the directories passed in, find all .kext bundles in those directories,
181     // get the CFBundleIDs out of the Info.plists and add the bundle ID and kext path to m_name_to_kext_path_map.
182     void
183     IndexKextsInDirectories ();
184
185     // Search through all of the directories passed in, find all kernel binaries in those directories
186     // (look for "kernel*", "mach.*", assume those are kernels.  False positives aren't a huge problem.)
187     void
188     IndexKernelsInDirectories ();
189
190     // Callback which iterates over all the files in a given directory, looking for kernel binaries
191     static lldb_private::FileSpec::EnumerateDirectoryResult 
192     GetKernelsInDirectory (void *baton,
193                          lldb_private::FileSpec::FileType file_type,
194                          const lldb_private::FileSpec &file_spec);
195
196     lldb_private::Error
197     ExamineKextForMatchingUUID (const lldb_private::FileSpec &kext_bundle_path, const lldb_private::UUID &uuid, const lldb_private::ArchSpec &arch, lldb::ModuleSP &exe_module_sp);
198
199 private:
200
201     BundleIDToKextMap             m_name_to_kext_path_map; // multimap of CFBundleID to FileSpec on local filesystem
202     DirectoriesSearchedCollection m_search_directories;    // list of directories we search for kexts/kernels
203     KernelBinaryCollection        m_kernel_binaries;       // list of kernel binaries we found on local filesystem
204     lldb_private::LazyBool        m_ios_debug_session;
205
206     DISALLOW_COPY_AND_ASSIGN (PlatformDarwinKernel);
207
208 };
209
210 #else   // __APPLE__
211
212 // Since DynamicLoaderDarwinKernel is compiled in for all systems, and relies on
213 // PlatformDarwinKernel for the plug-in name, we compile just the plug-in name in
214 // here to avoid issues. We are tracking an internal bug to resolve this issue by
215 // either not compiling in DynamicLoaderDarwinKernel for non-apple builds, or to make
216 // PlatformDarwinKernel build on all systems. PlatformDarwinKernel is currently not
217 // compiled on other platforms due to the use of the Mac-specific
218 // source/Host/macosx/cfcpp utilities.
219
220 class PlatformDarwinKernel
221 {
222     static lldb_private::ConstString
223     GetPluginNameStatic ();
224 };
225
226 #endif  // __APPLE__
227
228 #endif  // liblldb_PlatformDarwinKernel_h_