brintos

brintos / llvm-project-archived public Read only

0
0
Text · 6.9 KiB · 82e69e3 Raw
209 lines · c
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-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef LLDB_SOURCE_PLUGINS_PLATFORM_MACOSX_PLATFORMDARWIN_H10#define LLDB_SOURCE_PLUGINS_PLATFORM_MACOSX_PLATFORMDARWIN_H11 12#include "Plugins/Platform/POSIX/PlatformPOSIX.h"13#include "lldb/Host/FileSystem.h"14#include "lldb/Host/ProcessLaunchInfo.h"15#include "lldb/Utility/ArchSpec.h"16#include "lldb/Utility/ConstString.h"17#include "lldb/Utility/FileSpec.h"18#include "lldb/Utility/FileSpecList.h"19#include "lldb/Utility/Status.h"20#include "lldb/Utility/StructuredData.h"21#include "lldb/Utility/XcodeSDK.h"22#include "lldb/lldb-forward.h"23#include "llvm/ADT/SmallVector.h"24#include "llvm/ADT/StringMap.h"25#include "llvm/ADT/StringRef.h"26#include "llvm/Support/Error.h"27#include "llvm/Support/VersionTuple.h"28#include "llvm/TargetParser/Triple.h"29 30#include <mutex>31#include <optional>32#include <string>33#include <vector>34 35namespace lldb_private {36class BreakpointSite;37class Debugger;38class Module;39class ModuleSpec;40class Process;41class ProcessLaunchInfo;42class Stream;43class Target;44 45class PlatformDarwin : public PlatformPOSIX {46public:47  using PlatformPOSIX::PlatformPOSIX;48 49  ~PlatformDarwin() override;50 51  static lldb::PlatformSP CreateInstance(bool force, const ArchSpec *arch);52 53  static void DebuggerInitialize(lldb_private::Debugger &debugger);54 55  static void Initialize();56 57  static void Terminate();58 59  static llvm::StringRef GetPluginNameStatic() { return "darwin"; }60 61  static llvm::StringRef GetDescriptionStatic();62 63  Status PutFile(const FileSpec &source, const FileSpec &destination,64                 uint32_t uid = UINT32_MAX, uint32_t gid = UINT32_MAX) override;65 66  // Platform functions67  Status ResolveSymbolFile(Target &target, const ModuleSpec &sym_spec,68                           FileSpec &sym_file) override;69 70  FileSpecList71  LocateExecutableScriptingResources(Target *target, Module &module,72                                     Stream &feedback_stream) override;73 74  Status GetSharedModule(const ModuleSpec &module_spec, Process *process,75                         lldb::ModuleSP &module_sp,76                         llvm::SmallVectorImpl<lldb::ModuleSP> *old_modules,77                         bool *did_create_ptr) override;78 79  size_t GetSoftwareBreakpointTrapOpcode(Target &target,80                                         BreakpointSite *bp_site) override;81 82  lldb::BreakpointSP SetThreadCreationBreakpoint(Target &target) override;83 84  bool ModuleIsExcludedForUnconstrainedSearches(85      Target &target, const lldb::ModuleSP &module_sp) override;86 87  void88  ARMGetSupportedArchitectures(std::vector<ArchSpec> &archs,89                               std::optional<llvm::Triple::OSType> os = {});90 91  void x86GetSupportedArchitectures(std::vector<ArchSpec> &archs);92 93  uint32_t GetResumeCountForLaunchInfo(ProcessLaunchInfo &launch_info) override;94 95  lldb::ProcessSP DebugProcess(ProcessLaunchInfo &launch_info,96                               Debugger &debugger, Target &target,97                               Status &error) override;98 99  void CalculateTrapHandlerSymbolNames() override;100 101  llvm::VersionTuple GetOSVersion(Process *process = nullptr) override;102 103  bool SupportsModules() override { return true; }104 105  ConstString GetFullNameForDylib(ConstString basename) override;106 107  FileSpec LocateExecutable(const char *basename) override;108 109  Status LaunchProcess(ProcessLaunchInfo &launch_info) override;110 111  Args GetExtraStartupCommands() override;112 113  static std::tuple<llvm::VersionTuple, llvm::StringRef>114  ParseVersionBuildDir(llvm::StringRef str);115 116  llvm::Expected<StructuredData::DictionarySP>117  FetchExtendedCrashInformation(Process &process) override;118 119  llvm::Expected<std::pair<XcodeSDK, bool>>120  GetSDKPathFromDebugInfo(Module &module) override;121 122  llvm::Expected<std::string>123  ResolveSDKPathFromDebugInfo(Module &module) override;124 125  llvm::Expected<XcodeSDK> GetSDKPathFromDebugInfo(CompileUnit &unit) override;126 127  llvm::Expected<std::string>128  ResolveSDKPathFromDebugInfo(CompileUnit &unit) override;129 130protected:131  static const char *GetCompatibleArch(ArchSpec::Core core, size_t idx);132 133  struct CrashInfoAnnotations {134    uint64_t version;          // unsigned long135    uint64_t message;          // char *136    uint64_t signature_string; // char *137    uint64_t backtrace;        // char *138    uint64_t message2;         // char *139    uint64_t thread;           // uint64_t140    uint64_t dialog_mode;      // unsigned int141    uint64_t abort_cause;      // unsigned int142  };143 144  /// Extract the `__crash_info` annotations from each of the target's145  /// modules.146  ///147  /// If the platform have a crashed processes with a `__crash_info` section,148  /// extract the section to gather the messages annotations and the abort149  /// cause.150  ///151  /// \param[in] process152  ///     The crashed process.153  ///154  /// \return155  ///     A  structured data array containing at each entry in each entry, the156  ///     module spec, its UUID, the crash messages and the abort cause.157  ///     \b nullptr if process has no crash information annotations.158  StructuredData::ArraySP ExtractCrashInfoAnnotations(Process &process);159 160  /// Extract the `Application Specific Information` messages from a crash161  /// report.162  StructuredData::DictionarySP ExtractAppSpecificInfo(Process &process);163 164  void ReadLibdispatchOffsetsAddress(Process *process);165 166  void ReadLibdispatchOffsets(Process *process);167 168  virtual bool CheckLocalSharedCache() const { return IsHost(); }169 170  struct SDKEnumeratorInfo {171    FileSpec found_path;172    XcodeSDK::Type sdk_type;173  };174 175  static FileSystem::EnumerateDirectoryResult176  DirectoryEnumerator(void *baton, llvm::sys::fs::file_type file_type,177                      llvm::StringRef path);178 179  static FileSpec FindSDKInXcodeForModules(XcodeSDK::Type sdk_type,180                                           const FileSpec &sdks_spec);181 182  static FileSpec GetSDKDirectoryForModules(XcodeSDK::Type sdk_type);183 184  void185  AddClangModuleCompilationOptionsForSDKType(Target *target,186                                             std::vector<std::string> &options,187                                             XcodeSDK::Type sdk_type);188 189  Status FindBundleBinaryInExecSearchPaths(190      const ModuleSpec &module_spec, Process *process,191      lldb::ModuleSP &module_sp,192      llvm::SmallVectorImpl<lldb::ModuleSP> *old_modules, bool *did_create_ptr);193 194  // The OSType where lldb is running.195  static llvm::Triple::OSType GetHostOSType();196 197  std::string m_developer_directory;198  llvm::StringMap<std::string> m_sdk_path;199  std::mutex m_sdk_path_mutex;200 201private:202  PlatformDarwin(const PlatformDarwin &) = delete;203  const PlatformDarwin &operator=(const PlatformDarwin &) = delete;204};205 206} // namespace lldb_private207 208#endif // LLDB_SOURCE_PLUGINS_PLATFORM_MACOSX_PLATFORMDARWIN_H209