Skip to content

Commit

Permalink
[lldb] Cleanup MacOSX platform headers (NFC)
Browse files Browse the repository at this point in the history
While working on dde487e I noticed that the MacOSX platforms were
in need of some love. This patch cleans up the headers:

 - Move platforms into the lldb_private namespace.
 - Remove lldb_private:: prefixes to improve readability.
 - Fix header includes and use forward declarations (iwyu).
 - Fix formatting
  • Loading branch information
JDevlieghere committed Mar 15, 2022
1 parent cb22d71 commit 0aaf480
Show file tree
Hide file tree
Showing 10 changed files with 377 additions and 332 deletions.
98 changes: 57 additions & 41 deletions lldb/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.h
Expand Up @@ -9,14 +9,33 @@
#ifndef LLDB_SOURCE_PLUGINS_PLATFORM_MACOSX_PLATFORMAPPLESIMULATOR_H
#define LLDB_SOURCE_PLUGINS_PLATFORM_MACOSX_PLATFORMAPPLESIMULATOR_H

#include <mutex>

#include "Plugins/Platform/MacOSX/PlatformDarwin.h"
#include "Plugins/Platform/MacOSX/objcxx/PlatformiOSSimulatorCoreSimulatorSupport.h"
#include "lldb/Utility/ConstString.h"
#include "lldb/Utility/FileSpec.h"

#include "lldb/Utility/ProcessInfo.h"
#include "lldb/Utility/Status.h"
#include "lldb/Utility/XcodeSDK.h"
#include "lldb/lldb-forward.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Triple.h"

#include <mutex>
#include <vector>

namespace lldb_private {
class ArchSpec;
class Args;
class Debugger;
class FileSpecList;
class ModuleSpec;
class Process;
class ProcessLaunchInfo;
class Stream;
class Target;
class UUID;

class PlatformAppleSimulator : public PlatformDarwin {
public:
Expand All @@ -27,22 +46,22 @@ class PlatformAppleSimulator : public PlatformDarwin {

// Class Methods
PlatformAppleSimulator(
const char *class_name, const char *description,
lldb_private::ConstString plugin_name, llvm::Triple::OSType preferred_os,
const char *class_name, const char *description, ConstString plugin_name,
llvm::Triple::OSType preferred_os,
llvm::SmallVector<llvm::StringRef, 4> supported_triples,
llvm::StringRef sdk, lldb_private::XcodeSDK::Type sdk_type,
llvm::StringRef sdk, XcodeSDK::Type sdk_type,
CoreSimulatorSupport::DeviceType::ProductFamilyID kind);

static lldb::PlatformSP
CreateInstance(const char *class_name, const char *description,
lldb_private::ConstString plugin_name,
ConstString plugin_name,
llvm::SmallVector<llvm::Triple::ArchType, 4> supported_arch,
llvm::Triple::OSType preferred_os,
llvm::SmallVector<llvm::Triple::OSType, 4> supported_os,
llvm::SmallVector<llvm::StringRef, 4> supported_triples,
llvm::StringRef sdk, lldb_private::XcodeSDK::Type sdk_type,
llvm::StringRef sdk, XcodeSDK::Type sdk_type,
CoreSimulatorSupport::DeviceType::ProductFamilyID kind,
bool force, const lldb_private::ArchSpec *arch);
bool force, const ArchSpec *arch);

virtual ~PlatformAppleSimulator();

Expand All @@ -51,40 +70,36 @@ class PlatformAppleSimulator : public PlatformDarwin {
}
llvm::StringRef GetDescription() override { return m_description; }

lldb_private::Status
LaunchProcess(lldb_private::ProcessLaunchInfo &launch_info) override;
Status LaunchProcess(ProcessLaunchInfo &launch_info) override;

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

lldb_private::Status ConnectRemote(lldb_private::Args &args) override;
Status ConnectRemote(Args &args) override;

lldb_private::Status DisconnectRemote() override;
Status DisconnectRemote() override;

lldb::ProcessSP DebugProcess(lldb_private::ProcessLaunchInfo &launch_info,
lldb_private::Debugger &debugger,
lldb_private::Target &target,
lldb_private::Status &error) override;
lldb::ProcessSP DebugProcess(ProcessLaunchInfo &launch_info,
Debugger &debugger, Target &target,
Status &error) override;

std::vector<lldb_private::ArchSpec> GetSupportedArchitectures(
const lldb_private::ArchSpec &process_host_arch) override;
std::vector<ArchSpec>
GetSupportedArchitectures(const ArchSpec &process_host_arch) override;

lldb_private::Status ResolveExecutable(
const lldb_private::ModuleSpec &module_spec, lldb::ModuleSP &module_sp,
const lldb_private::FileSpecList *module_search_paths_ptr) override;
Status
ResolveExecutable(const ModuleSpec &module_spec, lldb::ModuleSP &module_sp,
const FileSpecList *module_search_paths_ptr) override;

lldb_private::Status
GetSharedModule(const lldb_private::ModuleSpec &module_spec,
lldb_private::Process *process, lldb::ModuleSP &module_sp,
const lldb_private::FileSpecList *module_search_paths_ptr,
llvm::SmallVectorImpl<lldb::ModuleSP> *old_modules,
bool *did_create_ptr) override;
Status GetSharedModule(const ModuleSpec &module_spec, Process *process,
lldb::ModuleSP &module_sp,
const FileSpecList *module_search_paths_ptr,
llvm::SmallVectorImpl<lldb::ModuleSP> *old_modules,
bool *did_create_ptr) override;

uint32_t
FindProcesses(const lldb_private::ProcessInstanceInfoMatch &match_info,
lldb_private::ProcessInstanceInfoList &process_infos) override;
uint32_t FindProcesses(const ProcessInstanceInfoMatch &match_info,
ProcessInstanceInfoList &process_infos) override;

void
AddClangModuleCompilationOptions(lldb_private::Target *target,
AddClangModuleCompilationOptions(Target *target,
std::vector<std::string> &options) override {
return PlatformDarwin::AddClangModuleCompilationOptionsForSDKType(
target, options, m_sdk_type);
Expand All @@ -93,18 +108,18 @@ class PlatformAppleSimulator : public PlatformDarwin {
protected:
const char *m_class_name;
const char *m_description;
lldb_private::ConstString m_plugin_name;
ConstString m_plugin_name;
std::mutex m_core_sim_path_mutex;
llvm::Optional<lldb_private::FileSpec> m_core_simulator_framework_path;
llvm::Optional<FileSpec> m_core_simulator_framework_path;
llvm::Optional<CoreSimulatorSupport::Device> m_device;
CoreSimulatorSupport::DeviceType::ProductFamilyID m_kind;

lldb_private::FileSpec GetCoreSimulatorPath();
FileSpec GetCoreSimulatorPath();

llvm::Triple::OSType m_os_type = llvm::Triple::UnknownOS;
llvm::SmallVector<llvm::StringRef, 4> m_supported_triples = {};
llvm::StringRef m_sdk;
lldb_private::XcodeSDK::Type m_sdk_type;
XcodeSDK::Type m_sdk_type;

void LoadCoreSimulator();

Expand All @@ -116,11 +131,12 @@ class PlatformAppleSimulator : public PlatformDarwin {
PlatformAppleSimulator(const PlatformAppleSimulator &) = delete;
const PlatformAppleSimulator &
operator=(const PlatformAppleSimulator &) = delete;
lldb_private::Status
Status

GetSymbolFile(const lldb_private::FileSpec &platform_file,
const lldb_private::UUID *uuid_ptr,
lldb_private::FileSpec &local_file);
GetSymbolFile(const FileSpec &platform_file, const UUID *uuid_ptr,
FileSpec &local_file);
};

} // namespace lldb_private

#endif // LLDB_SOURCE_PLUGINS_PLATFORM_MACOSX_PLATFORMAPPLESIMULATOR_H
144 changes: 75 additions & 69 deletions lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h
Expand Up @@ -10,101 +10,108 @@
#define LLDB_SOURCE_PLUGINS_PLATFORM_MACOSX_PLATFORMDARWIN_H

#include "Plugins/Platform/POSIX/PlatformPOSIX.h"
#include "lldb/Core/FileSpecList.h"
#include "lldb/Host/FileSystem.h"
#include "lldb/Host/ProcessLaunchInfo.h"
#include "lldb/Utility/ArchSpec.h"
#include "lldb/Utility/ConstString.h"
#include "lldb/Utility/FileSpec.h"
#include "lldb/Utility/Status.h"
#include "lldb/Utility/StructuredData.h"
#include "lldb/Utility/XcodeSDK.h"
#include "lldb/lldb-forward.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/ADT/Triple.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/VersionTuple.h"

#include <mutex>
#include <string>
#include <tuple>
#include <vector>

namespace lldb_private {
class BreakpointSite;
class Debugger;
class Module;
class ModuleSpec;
class Process;
class ProcessLaunchInfo;
class Stream;
class Target;

class PlatformDarwin : public PlatformPOSIX {
public:
using PlatformPOSIX::PlatformPOSIX;

~PlatformDarwin() override;

lldb_private::Status PutFile(const lldb_private::FileSpec &source,
const lldb_private::FileSpec &destination,
uint32_t uid = UINT32_MAX,
uint32_t gid = UINT32_MAX) override;
Status PutFile(const FileSpec &source, const FileSpec &destination,
uint32_t uid = UINT32_MAX, uint32_t gid = UINT32_MAX) override;

// lldb_private::Platform functions
lldb_private::Status
ResolveSymbolFile(lldb_private::Target &target,
const lldb_private::ModuleSpec &sym_spec,
lldb_private::FileSpec &sym_file) override;
// Platform functions
Status ResolveSymbolFile(Target &target, const ModuleSpec &sym_spec,
FileSpec &sym_file) override;

lldb_private::FileSpecList LocateExecutableScriptingResources(
lldb_private::Target *target, lldb_private::Module &module,
lldb_private::Stream *feedback_stream) override;
FileSpecList
LocateExecutableScriptingResources(Target *target, Module &module,
Stream *feedback_stream) override;

lldb_private::Status
GetSharedModule(const lldb_private::ModuleSpec &module_spec,
lldb_private::Process *process, lldb::ModuleSP &module_sp,
const lldb_private::FileSpecList *module_search_paths_ptr,
llvm::SmallVectorImpl<lldb::ModuleSP> *old_modules,
bool *did_create_ptr) override;
Status GetSharedModule(const ModuleSpec &module_spec, Process *process,
lldb::ModuleSP &module_sp,
const FileSpecList *module_search_paths_ptr,
llvm::SmallVectorImpl<lldb::ModuleSP> *old_modules,
bool *did_create_ptr) override;

size_t GetSoftwareBreakpointTrapOpcode(
lldb_private::Target &target,
lldb_private::BreakpointSite *bp_site) override;
size_t GetSoftwareBreakpointTrapOpcode(Target &target,
BreakpointSite *bp_site) override;

lldb::BreakpointSP
SetThreadCreationBreakpoint(lldb_private::Target &target) override;
lldb::BreakpointSP SetThreadCreationBreakpoint(Target &target) override;

bool ModuleIsExcludedForUnconstrainedSearches(
lldb_private::Target &target, const lldb::ModuleSP &module_sp) override;
Target &target, const lldb::ModuleSP &module_sp) override;

void
ARMGetSupportedArchitectures(std::vector<lldb_private::ArchSpec> &archs,
ARMGetSupportedArchitectures(std::vector<ArchSpec> &archs,
llvm::Optional<llvm::Triple::OSType> os = {});

void x86GetSupportedArchitectures(std::vector<lldb_private::ArchSpec> &archs);
void x86GetSupportedArchitectures(std::vector<ArchSpec> &archs);

uint32_t GetResumeCountForLaunchInfo(
lldb_private::ProcessLaunchInfo &launch_info) override;
uint32_t GetResumeCountForLaunchInfo(ProcessLaunchInfo &launch_info) override;

lldb::ProcessSP DebugProcess(lldb_private::ProcessLaunchInfo &launch_info,
lldb_private::Debugger &debugger,
lldb_private::Target &target,
lldb_private::Status &error) override;
lldb::ProcessSP DebugProcess(ProcessLaunchInfo &launch_info,
Debugger &debugger, Target &target,
Status &error) override;

void CalculateTrapHandlerSymbolNames() override;

llvm::VersionTuple
GetOSVersion(lldb_private::Process *process = nullptr) override;
llvm::VersionTuple GetOSVersion(Process *process = nullptr) override;

bool SupportsModules() override { return true; }

lldb_private::ConstString
GetFullNameForDylib(lldb_private::ConstString basename) override;
ConstString GetFullNameForDylib(ConstString basename) override;

lldb_private::FileSpec LocateExecutable(const char *basename) override;
FileSpec LocateExecutable(const char *basename) override;

lldb_private::Status
LaunchProcess(lldb_private::ProcessLaunchInfo &launch_info) override;
Status LaunchProcess(ProcessLaunchInfo &launch_info) override;

static std::tuple<llvm::VersionTuple, llvm::StringRef>
ParseVersionBuildDir(llvm::StringRef str);

llvm::Expected<lldb_private::StructuredData::DictionarySP>
FetchExtendedCrashInformation(lldb_private::Process &process) override;
llvm::Expected<StructuredData::DictionarySP>
FetchExtendedCrashInformation(Process &process) override;

/// Return the toolchain directory the current LLDB instance is located in.
static lldb_private::FileSpec GetCurrentToolchainDirectory();
static FileSpec GetCurrentToolchainDirectory();

/// Return the command line tools directory the current LLDB instance is
/// located in.
static lldb_private::FileSpec GetCurrentCommandLineToolsDirectory();
static FileSpec GetCurrentCommandLineToolsDirectory();

protected:
static const char *GetCompatibleArch(lldb_private::ArchSpec::Core core,
size_t idx);
static const char *GetCompatibleArch(ArchSpec::Core core, size_t idx);

struct CrashInfoAnnotations {
uint64_t version; // unsigned long
Expand All @@ -131,44 +138,41 @@ class PlatformDarwin : public PlatformPOSIX {
/// A structured data array containing at each entry in each entry, the
/// module spec, its UUID, the crash messages and the abort cause.
/// \b nullptr if process has no crash information annotations.
lldb_private::StructuredData::ArraySP
ExtractCrashInfoAnnotations(lldb_private::Process &process);
StructuredData::ArraySP ExtractCrashInfoAnnotations(Process &process);

void ReadLibdispatchOffsetsAddress(lldb_private::Process *process);
void ReadLibdispatchOffsetsAddress(Process *process);

void ReadLibdispatchOffsets(lldb_private::Process *process);
void ReadLibdispatchOffsets(Process *process);

virtual lldb_private::Status GetSharedModuleWithLocalCache(
const lldb_private::ModuleSpec &module_spec, lldb::ModuleSP &module_sp,
const lldb_private::FileSpecList *module_search_paths_ptr,
virtual Status GetSharedModuleWithLocalCache(
const ModuleSpec &module_spec, lldb::ModuleSP &module_sp,
const FileSpecList *module_search_paths_ptr,
llvm::SmallVectorImpl<lldb::ModuleSP> *old_modules, bool *did_create_ptr);

virtual bool CheckLocalSharedCache() const { return IsHost(); }

struct SDKEnumeratorInfo {
lldb_private::FileSpec found_path;
lldb_private::XcodeSDK::Type sdk_type;
FileSpec found_path;
XcodeSDK::Type sdk_type;
};

static lldb_private::FileSystem::EnumerateDirectoryResult
static FileSystem::EnumerateDirectoryResult
DirectoryEnumerator(void *baton, llvm::sys::fs::file_type file_type,
llvm::StringRef path);

static lldb_private::FileSpec
FindSDKInXcodeForModules(lldb_private::XcodeSDK::Type sdk_type,
const lldb_private::FileSpec &sdks_spec);
static FileSpec FindSDKInXcodeForModules(XcodeSDK::Type sdk_type,
const FileSpec &sdks_spec);

static lldb_private::FileSpec
GetSDKDirectoryForModules(lldb_private::XcodeSDK::Type sdk_type);
static FileSpec GetSDKDirectoryForModules(XcodeSDK::Type sdk_type);

void AddClangModuleCompilationOptionsForSDKType(
lldb_private::Target *target, std::vector<std::string> &options,
lldb_private::XcodeSDK::Type sdk_type);
void
AddClangModuleCompilationOptionsForSDKType(Target *target,
std::vector<std::string> &options,
XcodeSDK::Type sdk_type);

lldb_private::Status FindBundleBinaryInExecSearchPaths(
const lldb_private::ModuleSpec &module_spec,
lldb_private::Process *process, lldb::ModuleSP &module_sp,
const lldb_private::FileSpecList *module_search_paths_ptr,
Status FindBundleBinaryInExecSearchPaths(
const ModuleSpec &module_spec, Process *process,
lldb::ModuleSP &module_sp, const FileSpecList *module_search_paths_ptr,
llvm::SmallVectorImpl<lldb::ModuleSP> *old_modules, bool *did_create_ptr);

static std::string FindComponentInPath(llvm::StringRef path,
Expand All @@ -186,4 +190,6 @@ class PlatformDarwin : public PlatformPOSIX {
const PlatformDarwin &operator=(const PlatformDarwin &) = delete;
};

} // namespace lldb_private

#endif // LLDB_SOURCE_PLUGINS_PLATFORM_MACOSX_PLATFORMDARWIN_H

0 comments on commit 0aaf480

Please sign in to comment.