Coverage Report

Created: 2022-01-25 06:29

/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h
Line
Count
Source
1
//===-- PlatformDarwin.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_PLATFORMDARWIN_H
10
#define LLDB_SOURCE_PLUGINS_PLATFORM_MACOSX_PLATFORMDARWIN_H
11
12
#include "Plugins/Platform/POSIX/PlatformPOSIX.h"
13
#include "lldb/Host/FileSystem.h"
14
#include "lldb/Host/ProcessLaunchInfo.h"
15
#include "lldb/Utility/ConstString.h"
16
#include "lldb/Utility/FileSpec.h"
17
#include "lldb/Utility/StructuredData.h"
18
#include "lldb/Utility/XcodeSDK.h"
19
#include "llvm/ADT/StringRef.h"
20
#include "llvm/Support/FileSystem.h"
21
22
#include <string>
23
#include <tuple>
24
25
class PlatformDarwin : public PlatformPOSIX {
26
public:
27
  PlatformDarwin(bool is_host);
28
29
  ~PlatformDarwin() override;
30
31
  lldb_private::Status PutFile(const lldb_private::FileSpec &source,
32
                               const lldb_private::FileSpec &destination,
33
                               uint32_t uid = UINT32_MAX,
34
                               uint32_t gid = UINT32_MAX) override;
35
36
  // lldb_private::Platform functions
37
  lldb_private::Status
38
  ResolveSymbolFile(lldb_private::Target &target,
39
                    const lldb_private::ModuleSpec &sym_spec,
40
                    lldb_private::FileSpec &sym_file) override;
41
42
  lldb_private::FileSpecList LocateExecutableScriptingResources(
43
      lldb_private::Target *target, lldb_private::Module &module,
44
      lldb_private::Stream *feedback_stream) override;
45
46
  lldb_private::Status
47
  GetSharedModule(const lldb_private::ModuleSpec &module_spec,
48
                  lldb_private::Process *process, lldb::ModuleSP &module_sp,
49
                  const lldb_private::FileSpecList *module_search_paths_ptr,
50
                  llvm::SmallVectorImpl<lldb::ModuleSP> *old_modules,
51
                  bool *did_create_ptr) override;
52
53
  size_t GetSoftwareBreakpointTrapOpcode(
54
      lldb_private::Target &target,
55
      lldb_private::BreakpointSite *bp_site) override;
56
57
  lldb::BreakpointSP
58
  SetThreadCreationBreakpoint(lldb_private::Target &target) override;
59
60
  bool ModuleIsExcludedForUnconstrainedSearches(
61
      lldb_private::Target &target, const lldb::ModuleSP &module_sp) override;
62
63
  void
64
  ARMGetSupportedArchitectures(std::vector<lldb_private::ArchSpec> &archs,
65
                               llvm::Optional<llvm::Triple::OSType> os = {});
66
67
  void x86GetSupportedArchitectures(std::vector<lldb_private::ArchSpec> &archs);
68
69
  uint32_t GetResumeCountForLaunchInfo(
70
      lldb_private::ProcessLaunchInfo &launch_info) override;
71
72
  lldb::ProcessSP DebugProcess(lldb_private::ProcessLaunchInfo &launch_info,
73
                               lldb_private::Debugger &debugger,
74
                               lldb_private::Target &target,
75
                               lldb_private::Status &error) override;
76
77
  void CalculateTrapHandlerSymbolNames() override;
78
79
  llvm::VersionTuple
80
  GetOSVersion(lldb_private::Process *process = nullptr) override;
81
82
1.42k
  bool SupportsModules() override { return true; }
83
84
  lldb_private::ConstString
85
  GetFullNameForDylib(lldb_private::ConstString basename) override;
86
87
  lldb_private::FileSpec LocateExecutable(const char *basename) override;
88
89
  lldb_private::Status
90
  LaunchProcess(lldb_private::ProcessLaunchInfo &launch_info) override;
91
92
  static std::tuple<llvm::VersionTuple, llvm::StringRef>
93
  ParseVersionBuildDir(llvm::StringRef str);
94
95
  llvm::Expected<lldb_private::StructuredData::DictionarySP>
96
  FetchExtendedCrashInformation(lldb_private::Process &process) override;
97
98
  /// Return the toolchain directory the current LLDB instance is located in.
99
  static lldb_private::FileSpec GetCurrentToolchainDirectory();
100
101
  /// Return the command line tools directory the current LLDB instance is
102
  /// located in.
103
  static lldb_private::FileSpec GetCurrentCommandLineToolsDirectory();
104
105
protected:
106
  static const char *GetCompatibleArch(lldb_private::ArchSpec::Core core,
107
                                       size_t idx);
108
109
  struct CrashInfoAnnotations {
110
    uint64_t version;          // unsigned long
111
    uint64_t message;          // char *
112
    uint64_t signature_string; // char *
113
    uint64_t backtrace;        // char *
114
    uint64_t message2;         // char *
115
    uint64_t thread;           // uint64_t
116
    uint64_t dialog_mode;      // unsigned int
117
    uint64_t abort_cause;      // unsigned int
118
  };
119
120
  /// Extract the `__crash_info` annotations from each of of the target's
121
  /// modules.
122
  ///
123
  /// If the platform have a crashed processes with a `__crash_info` section,
124
  /// extract the section to gather the messages annotations and the abort
125
  /// cause.
126
  ///
127
  /// \param[in] process
128
  ///     The crashed process.
129
  ///
130
  /// \return
131
  ///     A  structured data array containing at each entry in each entry, the
132
  ///     module spec, its UUID, the crash messages and the abort cause.
133
  ///     \b nullptr if process has no crash information annotations.
134
  lldb_private::StructuredData::ArraySP
135
  ExtractCrashInfoAnnotations(lldb_private::Process &process);
136
137
  void ReadLibdispatchOffsetsAddress(lldb_private::Process *process);
138
139
  void ReadLibdispatchOffsets(lldb_private::Process *process);
140
141
  virtual lldb_private::Status GetSharedModuleWithLocalCache(
142
      const lldb_private::ModuleSpec &module_spec, lldb::ModuleSP &module_sp,
143
      const lldb_private::FileSpecList *module_search_paths_ptr,
144
      llvm::SmallVectorImpl<lldb::ModuleSP> *old_modules, bool *did_create_ptr);
145
146
136k
  virtual bool CheckLocalSharedCache() const { return IsHost(); }
147
148
  struct SDKEnumeratorInfo {
149
    lldb_private::FileSpec found_path;
150
    lldb_private::XcodeSDK::Type sdk_type;
151
  };
152
153
  static lldb_private::FileSystem::EnumerateDirectoryResult
154
  DirectoryEnumerator(void *baton, llvm::sys::fs::file_type file_type,
155
                      llvm::StringRef path);
156
157
  static lldb_private::FileSpec
158
  FindSDKInXcodeForModules(lldb_private::XcodeSDK::Type sdk_type,
159
                           const lldb_private::FileSpec &sdks_spec);
160
161
  static lldb_private::FileSpec
162
  GetSDKDirectoryForModules(lldb_private::XcodeSDK::Type sdk_type);
163
164
  void AddClangModuleCompilationOptionsForSDKType(
165
      lldb_private::Target *target, std::vector<std::string> &options,
166
      lldb_private::XcodeSDK::Type sdk_type);
167
168
  lldb_private::Status FindBundleBinaryInExecSearchPaths(
169
      const lldb_private::ModuleSpec &module_spec,
170
      lldb_private::Process *process, lldb::ModuleSP &module_sp,
171
      const lldb_private::FileSpecList *module_search_paths_ptr,
172
      llvm::SmallVectorImpl<lldb::ModuleSP> *old_modules, bool *did_create_ptr);
173
174
  static std::string FindComponentInPath(llvm::StringRef path,
175
                                         llvm::StringRef component);
176
177
  std::string m_developer_directory;
178
  llvm::StringMap<std::string> m_sdk_path;
179
  std::mutex m_sdk_path_mutex;
180
181
private:
182
  PlatformDarwin(const PlatformDarwin &) = delete;
183
  const PlatformDarwin &operator=(const PlatformDarwin &) = delete;
184
};
185
186
#endif // LLDB_SOURCE_PLUGINS_PLATFORM_MACOSX_PLATFORMDARWIN_H