Coverage Report

Created: 2022-01-15 10:30

/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.h
Line
Count
Source (jump to first uncovered line)
1
//===-- PlatformDarwinKernel.h ----------------------------------*- C++ -*-===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
9
#ifndef LLDB_SOURCE_PLUGINS_PLATFORM_MACOSX_PLATFORMDARWINKERNEL_H
10
#define LLDB_SOURCE_PLUGINS_PLATFORM_MACOSX_PLATFORMDARWINKERNEL_H
11
12
#include "lldb/Utility/ConstString.h"
13
14
#if defined(__APPLE__) // This Plugin uses the Mac-specific
15
                       // source/Host/macosx/cfcpp utilities
16
17
#include "lldb/Utility/FileSpec.h"
18
19
#include "llvm/Support/FileSystem.h"
20
21
#include "PlatformDarwin.h"
22
23
class PlatformDarwinKernel : public PlatformDarwin {
24
public:
25
  // Class Functions
26
  static lldb::PlatformSP CreateInstance(bool force,
27
                                         const lldb_private::ArchSpec *arch);
28
29
  static void DebuggerInitialize(lldb_private::Debugger &debugger);
30
31
  static void Initialize();
32
33
  static void Terminate();
34
35
3.44k
  static llvm::StringRef GetPluginNameStatic() { return "darwin-kernel"; }
36
37
  static llvm::StringRef GetDescriptionStatic();
38
39
  // Class Methods
40
  PlatformDarwinKernel(lldb_private::LazyBool is_ios_debug_session);
41
42
  virtual ~PlatformDarwinKernel();
43
44
  // lldb_private::PluginInterface functions
45
0
  llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
46
47
  // lldb_private::Platform functions
48
0
  llvm::StringRef GetDescription() override { return GetDescriptionStatic(); }
49
50
  void GetStatus(lldb_private::Stream &strm) override;
51
52
  lldb_private::Status
53
  GetSharedModule(const lldb_private::ModuleSpec &module_spec,
54
                  lldb_private::Process *process, lldb::ModuleSP &module_sp,
55
                  const lldb_private::FileSpecList *module_search_paths_ptr,
56
                  llvm::SmallVectorImpl<lldb::ModuleSP> *old_modules,
57
                  bool *did_create_ptr) override;
58
59
  std::vector<lldb_private::ArchSpec> GetSupportedArchitectures() override;
60
61
0
  bool SupportsModules() override { return false; }
62
63
  void CalculateTrapHandlerSymbolNames() override;
64
65
protected:
66
  // Map from kext bundle ID ("com.apple.filesystems.exfat") to FileSpec for the
67
  // kext bundle on
68
  // the host ("/System/Library/Extensions/exfat.kext/Contents/Info.plist").
69
  typedef std::multimap<lldb_private::ConstString, lldb_private::FileSpec>
70
      BundleIDToKextMap;
71
  typedef BundleIDToKextMap::iterator BundleIDToKextIterator;
72
73
  typedef std::vector<lldb_private::FileSpec> KernelBinaryCollection;
74
75
  // Array of directories that were searched for kext bundles (used only for
76
  // reporting to user)
77
  typedef std::vector<lldb_private::FileSpec> DirectoriesSearchedCollection;
78
  typedef DirectoriesSearchedCollection::iterator DirectoriesSearchedIterator;
79
80
  // Populate m_search_directories and m_search_directories_no_recursing vectors
81
  // of directories
82
  void CollectKextAndKernelDirectories();
83
84
  void GetUserSpecifiedDirectoriesToSearch();
85
86
  static void AddRootSubdirsToSearchPaths(PlatformDarwinKernel *thisp,
87
                                          const std::string &dir);
88
89
  void AddSDKSubdirsToSearchPaths(const std::string &dir);
90
91
  static lldb_private::FileSystem::EnumerateDirectoryResult
92
  FindKDKandSDKDirectoriesInDirectory(void *baton, llvm::sys::fs::file_type ft,
93
                                      llvm::StringRef path);
94
95
  void SearchForKextsAndKernelsRecursively();
96
97
  static lldb_private::FileSystem::EnumerateDirectoryResult
98
  GetKernelsAndKextsInDirectoryWithRecursion(void *baton,
99
                                             llvm::sys::fs::file_type ft,
100
                                             llvm::StringRef path);
101
102
  static lldb_private::FileSystem::EnumerateDirectoryResult
103
  GetKernelsAndKextsInDirectoryNoRecursion(void *baton,
104
                                           llvm::sys::fs::file_type ft,
105
                                           llvm::StringRef path);
106
107
  static lldb_private::FileSystem::EnumerateDirectoryResult
108
  GetKernelsAndKextsInDirectoryHelper(void *baton, llvm::sys::fs::file_type ft,
109
                                      llvm::StringRef path, bool recurse);
110
111
  static std::vector<lldb_private::FileSpec>
112
  SearchForExecutablesRecursively(const std::string &dir);
113
114
  static void AddKextToMap(PlatformDarwinKernel *thisp,
115
                           const lldb_private::FileSpec &file_spec);
116
117
  // Returns true if there is a .dSYM bundle next to the kext, or next to the
118
  // binary inside the kext.
119
  static bool
120
  KextHasdSYMSibling(const lldb_private::FileSpec &kext_bundle_filepath);
121
122
  // Returns true if there is a .dSYM bundle next to the kernel
123
  static bool
124
  KernelHasdSYMSibling(const lldb_private::FileSpec &kernel_filepath);
125
126
  // Returns true if there is a .dSYM bundle with NO kernel binary next to it
127
  static bool KerneldSYMHasNoSiblingBinary(
128
      const lldb_private::FileSpec &kernel_dsym_filepath);
129
130
  // Given a dsym_bundle argument ('.../foo.dSYM'), return a FileSpec
131
  // with the binary inside it ('.../foo.dSYM/Contents/Resources/DWARF/foo').
132
  // A dSYM bundle may have multiple DWARF binaries in them, so a vector
133
  // of matches is returned.
134
  static std::vector<lldb_private::FileSpec>
135
  GetDWARFBinaryInDSYMBundle(lldb_private::FileSpec dsym_bundle);
136
137
  lldb_private::Status
138
  GetSharedModuleKext(const lldb_private::ModuleSpec &module_spec,
139
                      lldb_private::Process *process, lldb::ModuleSP &module_sp,
140
                      const lldb_private::FileSpecList *module_search_paths_ptr,
141
                      llvm::SmallVectorImpl<lldb::ModuleSP> *old_modules,
142
                      bool *did_create_ptr);
143
144
  lldb_private::Status GetSharedModuleKernel(
145
      const lldb_private::ModuleSpec &module_spec,
146
      lldb_private::Process *process, lldb::ModuleSP &module_sp,
147
      const lldb_private::FileSpecList *module_search_paths_ptr,
148
      llvm::SmallVectorImpl<lldb::ModuleSP> *old_modules, bool *did_create_ptr);
149
150
  lldb_private::Status
151
  ExamineKextForMatchingUUID(const lldb_private::FileSpec &kext_bundle_path,
152
                             const lldb_private::UUID &uuid,
153
                             const lldb_private::ArchSpec &arch,
154
                             lldb::ModuleSP &exe_module_sp);
155
156
  // Most of the ivars are assembled under FileSystem::EnumerateDirectory calls
157
  // where the
158
  // function being called for each file/directory must be static.  We'll pass a
159
  // this pointer
160
  // as a baton and access the ivars directly.  Toss-up whether this should just
161
  // be a struct
162
  // at this point.
163
164
public:
165
  BundleIDToKextMap m_name_to_kext_path_map_with_dsyms;    // multimap of
166
                                                           // CFBundleID to
167
                                                           // FileSpec on local
168
                                                           // filesystem, kexts
169
                                                           // with dSYMs next to
170
                                                           // them
171
  BundleIDToKextMap m_name_to_kext_path_map_without_dsyms; // multimap of
172
                                                           // CFBundleID to
173
                                                           // FileSpec on local
174
                                                           // filesystem, kexts
175
                                                           // without dSYMs next
176
                                                           // to them
177
  DirectoriesSearchedCollection
178
      m_search_directories; // list of directories we search for kexts/kernels
179
  DirectoriesSearchedCollection
180
      m_search_directories_no_recursing; // list of directories we search for
181
                                         // kexts/kernels, no recursion
182
  KernelBinaryCollection m_kernel_binaries_with_dsyms; // list of kernel
183
                                                       // binaries we found on
184
                                                       // local filesystem,
185
                                                       // without dSYMs next to
186
                                                       // them
187
  KernelBinaryCollection m_kernel_binaries_without_dsyms; // list of kernel
188
                                                          // binaries we found
189
                                                          // on local
190
                                                          // filesystem, with
191
                                                          // dSYMs next to them
192
  KernelBinaryCollection m_kernel_dsyms_no_binaries;      // list of kernel
193
                                                          // dsyms with no
194
                                                          // binaries next to
195
                                                          // them
196
  KernelBinaryCollection m_kernel_dsyms_yaas;             // list of kernel
197
                                                          // .dSYM.yaa files
198
199
  lldb_private::LazyBool m_ios_debug_session;
200
201
  PlatformDarwinKernel(const PlatformDarwinKernel &) = delete;
202
  const PlatformDarwinKernel &operator=(const PlatformDarwinKernel &) = delete;
203
};
204
205
#else // __APPLE__
206
207
// Since DynamicLoaderDarwinKernel is compiled in for all systems, and relies on
208
// PlatformDarwinKernel for the plug-in name, we compile just the plug-in name
209
// in
210
// here to avoid issues. We are tracking an internal bug to resolve this issue
211
// by
212
// either not compiling in DynamicLoaderDarwinKernel for non-apple builds, or to
213
// make
214
// PlatformDarwinKernel build on all systems. PlatformDarwinKernel is currently
215
// not
216
// compiled on other platforms due to the use of the Mac-specific
217
// source/Host/macosx/cfcpp utilities.
218
219
class PlatformDarwinKernel {
220
public:
221
  static llvm::StringRef GetPluginNameStatic() { return "darwin-kernel"; }
222
};
223
224
#endif // __APPLE__
225
226
#endif // LLDB_SOURCE_PLUGINS_PLATFORM_MACOSX_PLATFORMDARWINKERNEL_H