From d0b44dbefd140949fed7916dc33e19f7c86b2cfd Mon Sep 17 00:00:00 2001 From: Pavel Labath Date: Wed, 25 Sep 2019 13:03:04 +0000 Subject: [PATCH] Have ABI plugins vend llvm MCRegisterInfo data Summary: I was recently surprised to learn that there is a total of 2 (two) users of the register info definitions contained in the ABI plugins. Yet, the defitions themselves span nearly 10kLOC. The two users are: - dwarf expression pretty printer - the mechanism for augmenting the register info definitions obtained over gdb-remote protocol (AugmentRegisterInfoViaABI) Both of these uses need the DWARF an EH register numbers, which is information that is already available in LLVM. This patch makes it possible to do so. It adds a GetMCRegisterInfo method to the ABI class, which every class is expected to implement. Normally, it should be sufficient to obtain the definitions from the appropriate llvm::Target object (for which I provide a utility function), but the subclasses are free to construct it in any way they deem fit. We should be able to always get the MCRegisterInfo object from llvm, with one important exception: if the relevant llvm target was disabled at compile time. To handle this, I add a mechanism to disable the compilation of ABI plugins based on the value of LLVM_TARGETS_TO_BUILD cmake setting. This ensures all our existing are able to create their MCRegisterInfo objects. The new MCRegisterInfo api is not used yet, but the intention is to make use of it in follow-up patches. Reviewers: jasonmolenda, aprantl, JDevlieghere, tatyana-krasnukha Subscribers: wuzish, nemanjai, mgorny, kbarton, atanasyan, lldb-commits Differential Revision: https://reviews.llvm.org/D67965 llvm-svn: 372862 --- lldb/include/lldb/Target/ABI.h | 18 +++++-- lldb/source/API/CMakeLists.txt | 5 ++ lldb/source/API/SystemInitializerFull.cpp | 57 +++++++++++++++----- lldb/source/Plugins/ABI/CMakeLists.txt | 42 ++++++++++----- .../Plugins/ABI/MacOSX-arm/ABIMacOSX_arm.cpp | 3 +- lldb/source/Plugins/ABI/MacOSX-arm/ABIMacOSX_arm.h | 4 +- .../Plugins/ABI/MacOSX-arm64/ABIMacOSX_arm64.cpp | 3 +- .../Plugins/ABI/MacOSX-arm64/ABIMacOSX_arm64.h | 4 +- .../Plugins/ABI/MacOSX-i386/ABIMacOSX_i386.cpp | 3 +- .../Plugins/ABI/MacOSX-i386/ABIMacOSX_i386.h | 4 +- lldb/source/Plugins/ABI/SysV-arm/ABISysV_arm.cpp | 3 +- lldb/source/Plugins/ABI/SysV-arm/ABISysV_arm.h | 4 +- .../Plugins/ABI/SysV-arm64/ABISysV_arm64.cpp | 3 +- lldb/source/Plugins/ABI/SysV-arm64/ABISysV_arm64.h | 4 +- .../Plugins/ABI/SysV-hexagon/ABISysV_hexagon.cpp | 3 +- .../Plugins/ABI/SysV-hexagon/ABISysV_hexagon.h | 4 +- lldb/source/Plugins/ABI/SysV-i386/ABISysV_i386.cpp | 3 +- lldb/source/Plugins/ABI/SysV-i386/ABISysV_i386.h | 4 +- lldb/source/Plugins/ABI/SysV-mips/ABISysV_mips.cpp | 3 +- lldb/source/Plugins/ABI/SysV-mips/ABISysV_mips.h | 4 +- .../Plugins/ABI/SysV-mips64/ABISysV_mips64.cpp | 3 +- .../Plugins/ABI/SysV-mips64/ABISysV_mips64.h | 4 +- lldb/source/Plugins/ABI/SysV-ppc/ABISysV_ppc.cpp | 3 +- lldb/source/Plugins/ABI/SysV-ppc/ABISysV_ppc.h | 4 +- .../Plugins/ABI/SysV-ppc64/ABISysV_ppc64.cpp | 3 +- lldb/source/Plugins/ABI/SysV-ppc64/ABISysV_ppc64.h | 4 +- .../Plugins/ABI/SysV-s390x/ABISysV_s390x.cpp | 2 +- lldb/source/Plugins/ABI/SysV-s390x/ABISysV_s390x.h | 4 +- .../Plugins/ABI/SysV-x86_64/ABISysV_x86_64.cpp | 6 ++- .../Plugins/ABI/SysV-x86_64/ABISysV_x86_64.h | 4 +- .../ABI/Windows-x86_64/ABIWindows_x86_64.cpp | 3 +- .../Plugins/ABI/Windows-x86_64/ABIWindows_x86_64.h | 4 +- lldb/source/Target/ABI.cpp | 19 +++++++ lldb/tools/lldb-test/CMakeLists.txt | 5 ++ lldb/tools/lldb-test/SystemInitializerTest.cpp | 60 +++++++++++++++++----- 35 files changed, 230 insertions(+), 76 deletions(-) diff --git a/lldb/include/lldb/Target/ABI.h b/lldb/include/lldb/Target/ABI.h index f254839..93378ab 100644 --- a/lldb/include/lldb/Target/ABI.h +++ b/lldb/include/lldb/Target/ABI.h @@ -15,8 +15,8 @@ #include "lldb/lldb-private.h" #include "llvm/ADT/ArrayRef.h" +#include "llvm/MC/MCRegisterInfo.h" -// forward define the llvm::Type class namespace llvm { class Type; } @@ -124,6 +124,8 @@ public: return pc; } + llvm::MCRegisterInfo &GetMCRegisterInfo() { return *m_mc_register_info_up; } + virtual const RegisterInfo *GetRegisterInfoArray(uint32_t &count) = 0; bool GetRegisterInfoByName(ConstString name, RegisterInfo &info); @@ -136,13 +138,19 @@ public: static lldb::ABISP FindPlugin(lldb::ProcessSP process_sp, const ArchSpec &arch); protected: - // Classes that inherit from ABI can see and modify these - ABI(lldb::ProcessSP process_sp) { - if (process_sp.get()) - m_process_wp = process_sp; + ABI(lldb::ProcessSP process_sp, std::unique_ptr info_up) + : m_process_wp(process_sp), m_mc_register_info_up(std::move(info_up)) { + assert(m_mc_register_info_up && "ABI must have MCRegisterInfo"); } + /// Utility function to construct a MCRegisterInfo using the ArchSpec triple. + /// Plugins wishing to customize the construction can construct the + /// MCRegisterInfo themselves. + static std::unique_ptr + MakeMCRegisterInfo(const ArchSpec &arch); + lldb::ProcessWP m_process_wp; + std::unique_ptr m_mc_register_info_up; private: DISALLOW_COPY_AND_ASSIGN(ABI); diff --git a/lldb/source/API/CMakeLists.txt b/lldb/source/API/CMakeLists.txt index d93b8b5..ff42cb3 100644 --- a/lldb/source/API/CMakeLists.txt +++ b/lldb/source/API/CMakeLists.txt @@ -103,6 +103,11 @@ add_lldb_library(liblldb SHARED ${option_install_prefix} ) +foreach (t ${LLVM_TARGETS_TO_BUILD}) + set_property(SOURCE SystemInitializerFull.cpp APPEND PROPERTY + COMPILE_DEFINITIONS "LLVM_TARGET_${t}_BUILT") +endforeach() + if (MSVC) set_source_files_properties(SBReproducer.cpp PROPERTIES COMPILE_FLAGS /bigobj) endif() diff --git a/lldb/source/API/SystemInitializerFull.cpp b/lldb/source/API/SystemInitializerFull.cpp index e7f2206..f71dd51 100644 --- a/lldb/source/API/SystemInitializerFull.cpp +++ b/lldb/source/API/SystemInitializerFull.cpp @@ -174,20 +174,34 @@ llvm::Error SystemInitializerFull::Initialize() { ClangASTContext::Initialize(); - ABIMacOSX_i386::Initialize(); - ABIMacOSX_arm::Initialize(); +#ifdef LLVM_TARGET_AArch64_BUILT ABIMacOSX_arm64::Initialize(); - ABISysV_arm::Initialize(); ABISysV_arm64::Initialize(); +#endif +#ifdef LLVM_TARGET_ARM_BUILT + ABIMacOSX_arm::Initialize(); + ABISysV_arm::Initialize(); +#endif +#ifdef LLVM_TARGET_Hexagon_BUILT ABISysV_hexagon::Initialize(); - ABISysV_i386::Initialize(); - ABISysV_x86_64::Initialize(); - ABISysV_ppc::Initialize(); - ABISysV_ppc64::Initialize(); +#endif +#ifdef LLVM_TARGET_Mips_BUILT ABISysV_mips::Initialize(); ABISysV_mips64::Initialize(); +#endif +#ifdef LLVM_TARGET_PowerPC_BUILT + ABISysV_ppc::Initialize(); + ABISysV_ppc64::Initialize(); +#endif +#ifdef LLVM_TARGET_SystemZ_BUILT ABISysV_s390x::Initialize(); +#endif +#ifdef LLVM_TARGET_X86_BUILT + ABIMacOSX_i386::Initialize(); + ABISysV_i386::Initialize(); + ABISysV_x86_64::Initialize(); ABIWindows_x86_64::Initialize(); +#endif ArchitectureArm::Initialize(); ArchitectureMips::Initialize(); @@ -288,20 +302,35 @@ void SystemInitializerFull::Terminate() { ArchitectureMips::Terminate(); ArchitecturePPC64::Terminate(); - ABIMacOSX_i386::Terminate(); - ABIMacOSX_arm::Terminate(); +#ifdef LLVM_TARGET_AArch64_BUILT ABIMacOSX_arm64::Terminate(); - ABISysV_arm::Terminate(); ABISysV_arm64::Terminate(); +#endif +#ifdef LLVM_TARGET_ARM_BUILT + ABIMacOSX_arm::Terminate(); + ABISysV_arm::Terminate(); +#endif +#ifdef LLVM_TARGET_Hexagon_BUILT ABISysV_hexagon::Terminate(); - ABISysV_i386::Terminate(); - ABISysV_x86_64::Terminate(); - ABISysV_ppc::Terminate(); - ABISysV_ppc64::Terminate(); +#endif +#ifdef LLVM_TARGET_Mips_BUILT ABISysV_mips::Terminate(); ABISysV_mips64::Terminate(); +#endif +#ifdef LLVM_TARGET_PowerPC_BUILT + ABISysV_ppc::Terminate(); + ABISysV_ppc64::Terminate(); +#endif +#ifdef LLVM_TARGET_SystemZ_BUILT ABISysV_s390x::Terminate(); +#endif +#ifdef LLVM_TARGET_X86_BUILT + ABIMacOSX_i386::Terminate(); + ABISysV_i386::Terminate(); + ABISysV_x86_64::Terminate(); ABIWindows_x86_64::Terminate(); +#endif + DisassemblerLLVMC::Terminate(); JITLoaderGDB::Terminate(); diff --git a/lldb/source/Plugins/ABI/CMakeLists.txt b/lldb/source/Plugins/ABI/CMakeLists.txt index c88affd..3d10f96 100644 --- a/lldb/source/Plugins/ABI/CMakeLists.txt +++ b/lldb/source/Plugins/ABI/CMakeLists.txt @@ -1,14 +1,28 @@ -add_subdirectory(SysV-arm) -add_subdirectory(SysV-arm64) -add_subdirectory(SysV-hexagon) -add_subdirectory(SysV-ppc) -add_subdirectory(SysV-ppc64) -add_subdirectory(SysV-mips) -add_subdirectory(SysV-mips64) -add_subdirectory(SysV-s390x) -add_subdirectory(SysV-i386) -add_subdirectory(SysV-x86_64) -add_subdirectory(MacOSX-i386) -add_subdirectory(MacOSX-arm) -add_subdirectory(MacOSX-arm64) -add_subdirectory(Windows-x86_64) +if ("AArch64" IN_LIST LLVM_TARGETS_TO_BUILD) + add_subdirectory(MacOSX-arm64) + add_subdirectory(SysV-arm64) +endif() +if ("ARM" IN_LIST LLVM_TARGETS_TO_BUILD) + add_subdirectory(MacOSX-arm) + add_subdirectory(SysV-arm) +endif() +if ("Hexagon" IN_LIST LLVM_TARGETS_TO_BUILD) + add_subdirectory(SysV-hexagon) +endif() +if ("Mips" IN_LIST LLVM_TARGETS_TO_BUILD) + add_subdirectory(SysV-mips) + add_subdirectory(SysV-mips64) +endif() +if ("PowerPC" IN_LIST LLVM_TARGETS_TO_BUILD) + add_subdirectory(SysV-ppc) + add_subdirectory(SysV-ppc64) +endif() +if ("SystemZ" IN_LIST LLVM_TARGETS_TO_BUILD) + add_subdirectory(SysV-s390x) +endif() +if ("X86" IN_LIST LLVM_TARGETS_TO_BUILD) + add_subdirectory(SysV-i386) + add_subdirectory(SysV-x86_64) + add_subdirectory(MacOSX-i386) + add_subdirectory(Windows-x86_64) +endif() diff --git a/lldb/source/Plugins/ABI/MacOSX-arm/ABIMacOSX_arm.cpp b/lldb/source/Plugins/ABI/MacOSX-arm/ABIMacOSX_arm.cpp index f2d01db..9dff12b 100644 --- a/lldb/source/Plugins/ABI/MacOSX-arm/ABIMacOSX_arm.cpp +++ b/lldb/source/Plugins/ABI/MacOSX-arm/ABIMacOSX_arm.cpp @@ -1326,7 +1326,8 @@ ABIMacOSX_arm::CreateInstance(ProcessSP process_sp, const ArchSpec &arch) { if (vendor_type == llvm::Triple::Apple) { if ((arch_type == llvm::Triple::arm) || (arch_type == llvm::Triple::thumb)) { - return ABISP(new ABIMacOSX_arm(process_sp)); + return ABISP( + new ABIMacOSX_arm(std::move(process_sp), MakeMCRegisterInfo(arch))); } } diff --git a/lldb/source/Plugins/ABI/MacOSX-arm/ABIMacOSX_arm.h b/lldb/source/Plugins/ABI/MacOSX-arm/ABIMacOSX_arm.h index ac9ba00..e512651 100644 --- a/lldb/source/Plugins/ABI/MacOSX-arm/ABIMacOSX_arm.h +++ b/lldb/source/Plugins/ABI/MacOSX-arm/ABIMacOSX_arm.h @@ -85,7 +85,9 @@ protected: lldb_private::CompilerType &ast_type) const override; private: - ABIMacOSX_arm(lldb::ProcessSP process_sp) : lldb_private::ABI(process_sp) { + ABIMacOSX_arm(lldb::ProcessSP process_sp, + std::unique_ptr info_up) + : lldb_private::ABI(std::move(process_sp), std::move(info_up)) { // Call CreateInstance instead. } }; diff --git a/lldb/source/Plugins/ABI/MacOSX-arm64/ABIMacOSX_arm64.cpp b/lldb/source/Plugins/ABI/MacOSX-arm64/ABIMacOSX_arm64.cpp index e5c72bd..a9c57df 100644 --- a/lldb/source/Plugins/ABI/MacOSX-arm64/ABIMacOSX_arm64.cpp +++ b/lldb/source/Plugins/ABI/MacOSX-arm64/ABIMacOSX_arm64.cpp @@ -1666,7 +1666,8 @@ ABIMacOSX_arm64::CreateInstance(ProcessSP process_sp, const ArchSpec &arch) { if (vendor_type == llvm::Triple::Apple) { if (arch_type == llvm::Triple::aarch64) { - return ABISP(new ABIMacOSX_arm64(process_sp)); + return ABISP( + new ABIMacOSX_arm64(std::move(process_sp), MakeMCRegisterInfo(arch))); } } diff --git a/lldb/source/Plugins/ABI/MacOSX-arm64/ABIMacOSX_arm64.h b/lldb/source/Plugins/ABI/MacOSX-arm64/ABIMacOSX_arm64.h index bfacbcd..c7a91ba 100644 --- a/lldb/source/Plugins/ABI/MacOSX-arm64/ABIMacOSX_arm64.h +++ b/lldb/source/Plugins/ABI/MacOSX-arm64/ABIMacOSX_arm64.h @@ -93,7 +93,9 @@ protected: lldb_private::CompilerType &ast_type) const override; private: - ABIMacOSX_arm64(lldb::ProcessSP process_sp) : lldb_private::ABI(process_sp) { + ABIMacOSX_arm64(lldb::ProcessSP process_sp, + std::unique_ptr info_up) + : lldb_private::ABI(std::move(process_sp), std::move(info_up)) { // Call CreateInstance instead. } }; diff --git a/lldb/source/Plugins/ABI/MacOSX-i386/ABIMacOSX_i386.cpp b/lldb/source/Plugins/ABI/MacOSX-i386/ABIMacOSX_i386.cpp index adb40cf..76ebd64 100644 --- a/lldb/source/Plugins/ABI/MacOSX-i386/ABIMacOSX_i386.cpp +++ b/lldb/source/Plugins/ABI/MacOSX-i386/ABIMacOSX_i386.cpp @@ -710,7 +710,8 @@ ABIMacOSX_i386::CreateInstance(lldb::ProcessSP process_sp, const ArchSpec &arch) if ((arch.GetTriple().getArch() == llvm::Triple::x86) && (arch.GetTriple().isMacOSX() || arch.GetTriple().isiOS() || arch.GetTriple().isWatchOS())) { - return ABISP(new ABIMacOSX_i386(process_sp)); + return ABISP( + new ABIMacOSX_i386(std::move(process_sp), MakeMCRegisterInfo(arch))); } return ABISP(); } diff --git a/lldb/source/Plugins/ABI/MacOSX-i386/ABIMacOSX_i386.h b/lldb/source/Plugins/ABI/MacOSX-i386/ABIMacOSX_i386.h index 57def68..50062b8 100644 --- a/lldb/source/Plugins/ABI/MacOSX-i386/ABIMacOSX_i386.h +++ b/lldb/source/Plugins/ABI/MacOSX-i386/ABIMacOSX_i386.h @@ -92,7 +92,9 @@ protected: bool RegisterIsCalleeSaved(const lldb_private::RegisterInfo *reg_info); private: - ABIMacOSX_i386(lldb::ProcessSP process_sp) : lldb_private::ABI(process_sp) { + ABIMacOSX_i386(lldb::ProcessSP process_sp, + std::unique_ptr info_up) + : lldb_private::ABI(std::move(process_sp), std::move(info_up)) { // Call CreateInstance instead. } }; diff --git a/lldb/source/Plugins/ABI/SysV-arm/ABISysV_arm.cpp b/lldb/source/Plugins/ABI/SysV-arm/ABISysV_arm.cpp index b074714..b6e8f88 100644 --- a/lldb/source/Plugins/ABI/SysV-arm/ABISysV_arm.cpp +++ b/lldb/source/Plugins/ABI/SysV-arm/ABISysV_arm.cpp @@ -1327,7 +1327,8 @@ ABISysV_arm::CreateInstance(lldb::ProcessSP process_sp, const ArchSpec &arch) { if (vendor_type != llvm::Triple::Apple) { if ((arch_type == llvm::Triple::arm) || (arch_type == llvm::Triple::thumb)) { - return ABISP(new ABISysV_arm(process_sp)); + return ABISP( + new ABISysV_arm(std::move(process_sp), MakeMCRegisterInfo(arch))); } } diff --git a/lldb/source/Plugins/ABI/SysV-arm/ABISysV_arm.h b/lldb/source/Plugins/ABI/SysV-arm/ABISysV_arm.h index a0f00c8..60fb14b 100644 --- a/lldb/source/Plugins/ABI/SysV-arm/ABISysV_arm.h +++ b/lldb/source/Plugins/ABI/SysV-arm/ABISysV_arm.h @@ -85,7 +85,9 @@ protected: lldb_private::CompilerType &ast_type) const override; private: - ABISysV_arm(lldb::ProcessSP process_sp) : lldb_private::ABI(process_sp) { + ABISysV_arm(lldb::ProcessSP process_sp, + std::unique_ptr info_up) + : lldb_private::ABI(std::move(process_sp), std::move(info_up)) { // Call CreateInstance instead. } }; diff --git a/lldb/source/Plugins/ABI/SysV-arm64/ABISysV_arm64.cpp b/lldb/source/Plugins/ABI/SysV-arm64/ABISysV_arm64.cpp index beb5403..781d71c 100644 --- a/lldb/source/Plugins/ABI/SysV-arm64/ABISysV_arm64.cpp +++ b/lldb/source/Plugins/ABI/SysV-arm64/ABISysV_arm64.cpp @@ -1669,7 +1669,8 @@ ABISysV_arm64::CreateInstance(lldb::ProcessSP process_sp, const ArchSpec &arch) if (vendor_type != llvm::Triple::Apple) { if (arch_type == llvm::Triple::aarch64) { - return ABISP(new ABISysV_arm64(process_sp)); + return ABISP( + new ABISysV_arm64(std::move(process_sp), MakeMCRegisterInfo(arch))); } } diff --git a/lldb/source/Plugins/ABI/SysV-arm64/ABISysV_arm64.h b/lldb/source/Plugins/ABI/SysV-arm64/ABISysV_arm64.h index 1fbdc79..1bf5773 100644 --- a/lldb/source/Plugins/ABI/SysV-arm64/ABISysV_arm64.h +++ b/lldb/source/Plugins/ABI/SysV-arm64/ABISysV_arm64.h @@ -92,7 +92,9 @@ protected: lldb_private::CompilerType &ast_type) const override; private: - ABISysV_arm64(lldb::ProcessSP process_sp) : lldb_private::ABI(process_sp) { + ABISysV_arm64(lldb::ProcessSP process_sp, + std::unique_ptr info_up) + : lldb_private::ABI(std::move(process_sp), std::move(info_up)) { // Call CreateInstance instead. } }; diff --git a/lldb/source/Plugins/ABI/SysV-hexagon/ABISysV_hexagon.cpp b/lldb/source/Plugins/ABI/SysV-hexagon/ABISysV_hexagon.cpp index ae83685..34d9258 100644 --- a/lldb/source/Plugins/ABI/SysV-hexagon/ABISysV_hexagon.cpp +++ b/lldb/source/Plugins/ABI/SysV-hexagon/ABISysV_hexagon.cpp @@ -1014,7 +1014,8 @@ size_t ABISysV_hexagon::GetRedZoneSize() const { return 0; } ABISP ABISysV_hexagon::CreateInstance(lldb::ProcessSP process_sp, const ArchSpec &arch) { if (arch.GetTriple().getArch() == llvm::Triple::hexagon) { - return ABISP(new ABISysV_hexagon(process_sp)); + return ABISP( + new ABISysV_hexagon(std::move(process_sp), MakeMCRegisterInfo(arch))); } return ABISP(); } diff --git a/lldb/source/Plugins/ABI/SysV-hexagon/ABISysV_hexagon.h b/lldb/source/Plugins/ABI/SysV-hexagon/ABISysV_hexagon.h index 459b631..bef64a2 100644 --- a/lldb/source/Plugins/ABI/SysV-hexagon/ABISysV_hexagon.h +++ b/lldb/source/Plugins/ABI/SysV-hexagon/ABISysV_hexagon.h @@ -97,7 +97,9 @@ protected: bool RegisterIsCalleeSaved(const lldb_private::RegisterInfo *reg_info); private: - ABISysV_hexagon(lldb::ProcessSP process_sp) : lldb_private::ABI(process_sp) { + ABISysV_hexagon(lldb::ProcessSP process_sp, + std::unique_ptr info_up) + : lldb_private::ABI(std::move(process_sp), std::move(info_up)) { // Call CreateInstance instead. } }; diff --git a/lldb/source/Plugins/ABI/SysV-i386/ABISysV_i386.cpp b/lldb/source/Plugins/ABI/SysV-i386/ABISysV_i386.cpp index 41148b7..69e4cff 100644 --- a/lldb/source/Plugins/ABI/SysV-i386/ABISysV_i386.cpp +++ b/lldb/source/Plugins/ABI/SysV-i386/ABISysV_i386.cpp @@ -198,7 +198,8 @@ ABISP ABISysV_i386::CreateInstance(lldb::ProcessSP process_sp, const ArchSpec &arch) { if (arch.GetTriple().getVendor() != llvm::Triple::Apple) { if (arch.GetTriple().getArch() == llvm::Triple::x86) { - return ABISP(new ABISysV_i386(process_sp)); + return ABISP( + new ABISysV_i386(std::move(process_sp), MakeMCRegisterInfo(arch))); } } return ABISP(); diff --git a/lldb/source/Plugins/ABI/SysV-i386/ABISysV_i386.h b/lldb/source/Plugins/ABI/SysV-i386/ABISysV_i386.h index 982bdd6..2362e9a 100644 --- a/lldb/source/Plugins/ABI/SysV-i386/ABISysV_i386.h +++ b/lldb/source/Plugins/ABI/SysV-i386/ABISysV_i386.h @@ -100,7 +100,9 @@ protected: bool RegisterIsCalleeSaved(const lldb_private::RegisterInfo *reg_info); private: - ABISysV_i386(lldb::ProcessSP process_sp) : lldb_private::ABI(process_sp) { + ABISysV_i386(lldb::ProcessSP process_sp, + std::unique_ptr info_up) + : lldb_private::ABI(std::move(process_sp), std::move(info_up)) { // Call CreateInstance instead. } }; diff --git a/lldb/source/Plugins/ABI/SysV-mips/ABISysV_mips.cpp b/lldb/source/Plugins/ABI/SysV-mips/ABISysV_mips.cpp index df63a31..416db9f 100644 --- a/lldb/source/Plugins/ABI/SysV-mips/ABISysV_mips.cpp +++ b/lldb/source/Plugins/ABI/SysV-mips/ABISysV_mips.cpp @@ -556,7 +556,8 @@ ABISysV_mips::CreateInstance(lldb::ProcessSP process_sp, const ArchSpec &arch) { const llvm::Triple::ArchType arch_type = arch.GetTriple().getArch(); if ((arch_type == llvm::Triple::mips) || (arch_type == llvm::Triple::mipsel)) { - return ABISP(new ABISysV_mips(process_sp)); + return ABISP( + new ABISysV_mips(std::move(process_sp), MakeMCRegisterInfo(arch))); } return ABISP(); } diff --git a/lldb/source/Plugins/ABI/SysV-mips/ABISysV_mips.h b/lldb/source/Plugins/ABI/SysV-mips/ABISysV_mips.h index 6cd9c19..8143f55 100644 --- a/lldb/source/Plugins/ABI/SysV-mips/ABISysV_mips.h +++ b/lldb/source/Plugins/ABI/SysV-mips/ABISysV_mips.h @@ -87,7 +87,9 @@ protected: bool RegisterIsCalleeSaved(const lldb_private::RegisterInfo *reg_info); private: - ABISysV_mips(lldb::ProcessSP process_sp) : lldb_private::ABI(process_sp) { + ABISysV_mips(lldb::ProcessSP process_sp, + std::unique_ptr info_up) + : lldb_private::ABI(std::move(process_sp), std::move(info_up)) { // Call CreateInstance instead. } }; diff --git a/lldb/source/Plugins/ABI/SysV-mips64/ABISysV_mips64.cpp b/lldb/source/Plugins/ABI/SysV-mips64/ABISysV_mips64.cpp index 7fb1ea2..72ec071 100644 --- a/lldb/source/Plugins/ABI/SysV-mips64/ABISysV_mips64.cpp +++ b/lldb/source/Plugins/ABI/SysV-mips64/ABISysV_mips64.cpp @@ -554,7 +554,8 @@ size_t ABISysV_mips64::GetRedZoneSize() const { return 0; } ABISP ABISysV_mips64::CreateInstance(lldb::ProcessSP process_sp, const ArchSpec &arch) { if (arch.GetTriple().isMIPS64()) - return ABISP(new ABISysV_mips64(process_sp)); + return ABISP( + new ABISysV_mips64(std::move(process_sp), MakeMCRegisterInfo(arch))); return ABISP(); } diff --git a/lldb/source/Plugins/ABI/SysV-mips64/ABISysV_mips64.h b/lldb/source/Plugins/ABI/SysV-mips64/ABISysV_mips64.h index 7da71b3..76c3c54 100644 --- a/lldb/source/Plugins/ABI/SysV-mips64/ABISysV_mips64.h +++ b/lldb/source/Plugins/ABI/SysV-mips64/ABISysV_mips64.h @@ -100,7 +100,9 @@ protected: bool RegisterIsCalleeSaved(const lldb_private::RegisterInfo *reg_info); private: - ABISysV_mips64(lldb::ProcessSP process_sp) : lldb_private::ABI(process_sp) { + ABISysV_mips64(lldb::ProcessSP process_sp, + std::unique_ptr info_up) + : lldb_private::ABI(std::move(process_sp), std::move(info_up)) { // Call CreateInstance instead. } }; diff --git a/lldb/source/Plugins/ABI/SysV-ppc/ABISysV_ppc.cpp b/lldb/source/Plugins/ABI/SysV-ppc/ABISysV_ppc.cpp index e37a6ae..857b7fe 100644 --- a/lldb/source/Plugins/ABI/SysV-ppc/ABISysV_ppc.cpp +++ b/lldb/source/Plugins/ABI/SysV-ppc/ABISysV_ppc.cpp @@ -218,7 +218,8 @@ size_t ABISysV_ppc::GetRedZoneSize() const { return 224; } ABISP ABISysV_ppc::CreateInstance(lldb::ProcessSP process_sp, const ArchSpec &arch) { if (arch.GetTriple().getArch() == llvm::Triple::ppc) { - return ABISP(new ABISysV_ppc(process_sp)); + return ABISP( + new ABISysV_ppc(std::move(process_sp), MakeMCRegisterInfo(arch))); } return ABISP(); } diff --git a/lldb/source/Plugins/ABI/SysV-ppc/ABISysV_ppc.h b/lldb/source/Plugins/ABI/SysV-ppc/ABISysV_ppc.h index 3b19985..59907c4 100644 --- a/lldb/source/Plugins/ABI/SysV-ppc/ABISysV_ppc.h +++ b/lldb/source/Plugins/ABI/SysV-ppc/ABISysV_ppc.h @@ -96,7 +96,9 @@ protected: bool RegisterIsCalleeSaved(const lldb_private::RegisterInfo *reg_info); private: - ABISysV_ppc(lldb::ProcessSP process_sp) : lldb_private::ABI(process_sp) { + ABISysV_ppc(lldb::ProcessSP process_sp, + std::unique_ptr info_up) + : lldb_private::ABI(std::move(process_sp), std::move(info_up)) { // Call CreateInstance instead. } }; diff --git a/lldb/source/Plugins/ABI/SysV-ppc64/ABISysV_ppc64.cpp b/lldb/source/Plugins/ABI/SysV-ppc64/ABISysV_ppc64.cpp index 92d5f9c..935353c 100644 --- a/lldb/source/Plugins/ABI/SysV-ppc64/ABISysV_ppc64.cpp +++ b/lldb/source/Plugins/ABI/SysV-ppc64/ABISysV_ppc64.cpp @@ -70,7 +70,8 @@ ABISP ABISysV_ppc64::CreateInstance(lldb::ProcessSP process_sp, const ArchSpec &arch) { if (arch.GetTriple().isPPC64()) - return ABISP(new ABISysV_ppc64(process_sp)); + return ABISP( + new ABISysV_ppc64(std::move(process_sp), MakeMCRegisterInfo(arch))); return ABISP(); } diff --git a/lldb/source/Plugins/ABI/SysV-ppc64/ABISysV_ppc64.h b/lldb/source/Plugins/ABI/SysV-ppc64/ABISysV_ppc64.h index d5fb09e..1b58975 100644 --- a/lldb/source/Plugins/ABI/SysV-ppc64/ABISysV_ppc64.h +++ b/lldb/source/Plugins/ABI/SysV-ppc64/ABISysV_ppc64.h @@ -96,7 +96,9 @@ protected: bool RegisterIsCalleeSaved(const lldb_private::RegisterInfo *reg_info); private: - ABISysV_ppc64(lldb::ProcessSP process_sp) : lldb_private::ABI(process_sp) { + ABISysV_ppc64(lldb::ProcessSP process_sp, + std::unique_ptr info_up) + : lldb_private::ABI(std::move(process_sp), std::move(info_up)) { // Call CreateInstance instead. } diff --git a/lldb/source/Plugins/ABI/SysV-s390x/ABISysV_s390x.cpp b/lldb/source/Plugins/ABI/SysV-s390x/ABISysV_s390x.cpp index 227925f..f4f803a 100644 --- a/lldb/source/Plugins/ABI/SysV-s390x/ABISysV_s390x.cpp +++ b/lldb/source/Plugins/ABI/SysV-s390x/ABISysV_s390x.cpp @@ -200,7 +200,7 @@ size_t ABISysV_s390x::GetRedZoneSize() const { return 0; } ABISP ABISysV_s390x::CreateInstance(lldb::ProcessSP process_sp, const ArchSpec &arch) { if (arch.GetTriple().getArch() == llvm::Triple::systemz) { - return ABISP(new ABISysV_s390x(process_sp)); + return ABISP(new ABISysV_s390x(std::move(process_sp), MakeMCRegisterInfo(arch))); } return ABISP(); } diff --git a/lldb/source/Plugins/ABI/SysV-s390x/ABISysV_s390x.h b/lldb/source/Plugins/ABI/SysV-s390x/ABISysV_s390x.h index 13df477..671d6a1 100644 --- a/lldb/source/Plugins/ABI/SysV-s390x/ABISysV_s390x.h +++ b/lldb/source/Plugins/ABI/SysV-s390x/ABISysV_s390x.h @@ -88,7 +88,9 @@ protected: bool RegisterIsCalleeSaved(const lldb_private::RegisterInfo *reg_info); private: - ABISysV_s390x(lldb::ProcessSP process_sp) : lldb_private::ABI(process_sp) { + ABISysV_s390x(lldb::ProcessSP process_sp, + std::unique_ptr info_up) + : lldb_private::ABI(std::move(process_sp), std::move(info_up)) { // Call CreateInstance instead. } }; diff --git a/lldb/source/Plugins/ABI/SysV-x86_64/ABISysV_x86_64.cpp b/lldb/source/Plugins/ABI/SysV-x86_64/ABISysV_x86_64.cpp index 7370e11..bf1c48f 100644 --- a/lldb/source/Plugins/ABI/SysV-x86_64/ABISysV_x86_64.cpp +++ b/lldb/source/Plugins/ABI/SysV-x86_64/ABISysV_x86_64.cpp @@ -235,7 +235,8 @@ ABISysV_x86_64::CreateInstance(lldb::ProcessSP process_sp, const ArchSpec &arch) case llvm::Triple::EnvironmentType::UnknownEnvironment: // UnknownEnvironment is needed for older compilers that don't // support the simulator environment. - return ABISP(new ABISysV_x86_64(process_sp)); + return ABISP(new ABISysV_x86_64(std::move(process_sp), + MakeMCRegisterInfo(arch))); default: return ABISP(); } @@ -246,7 +247,8 @@ ABISysV_x86_64::CreateInstance(lldb::ProcessSP process_sp, const ArchSpec &arch) case llvm::Triple::OSType::NetBSD: case llvm::Triple::OSType::Solaris: case llvm::Triple::OSType::UnknownOS: - return ABISP(new ABISysV_x86_64(process_sp)); + return ABISP( + new ABISysV_x86_64(std::move(process_sp), MakeMCRegisterInfo(arch))); default: return ABISP(); } diff --git a/lldb/source/Plugins/ABI/SysV-x86_64/ABISysV_x86_64.h b/lldb/source/Plugins/ABI/SysV-x86_64/ABISysV_x86_64.h index f6704af..d445d8f 100644 --- a/lldb/source/Plugins/ABI/SysV-x86_64/ABISysV_x86_64.h +++ b/lldb/source/Plugins/ABI/SysV-x86_64/ABISysV_x86_64.h @@ -98,7 +98,9 @@ protected: bool RegisterIsCalleeSaved(const lldb_private::RegisterInfo *reg_info); private: - ABISysV_x86_64(lldb::ProcessSP process_sp) : lldb_private::ABI(process_sp) { + ABISysV_x86_64(lldb::ProcessSP process_sp, + std::unique_ptr info_up) + : lldb_private::ABI(std::move(process_sp), std::move(info_up)) { // Call CreateInstance instead. } }; diff --git a/lldb/source/Plugins/ABI/Windows-x86_64/ABIWindows_x86_64.cpp b/lldb/source/Plugins/ABI/Windows-x86_64/ABIWindows_x86_64.cpp index fdd10a6..ac24426 100644 --- a/lldb/source/Plugins/ABI/Windows-x86_64/ABIWindows_x86_64.cpp +++ b/lldb/source/Plugins/ABI/Windows-x86_64/ABIWindows_x86_64.cpp @@ -1092,7 +1092,8 @@ ABISP ABIWindows_x86_64::CreateInstance(lldb::ProcessSP process_sp, const ArchSpec &arch) { if (arch.GetTriple().getArch() == llvm::Triple::x86_64 && arch.GetTriple().isOSWindows()) { - return ABISP(new ABIWindows_x86_64(process_sp)); + return ABISP( + new ABIWindows_x86_64(std::move(process_sp), MakeMCRegisterInfo(arch))); } return ABISP(); } diff --git a/lldb/source/Plugins/ABI/Windows-x86_64/ABIWindows_x86_64.h b/lldb/source/Plugins/ABI/Windows-x86_64/ABIWindows_x86_64.h index 9f6b2ce..2366566 100644 --- a/lldb/source/Plugins/ABI/Windows-x86_64/ABIWindows_x86_64.h +++ b/lldb/source/Plugins/ABI/Windows-x86_64/ABIWindows_x86_64.h @@ -91,7 +91,9 @@ protected: bool RegisterIsCalleeSaved(const lldb_private::RegisterInfo *reg_info); private: - ABIWindows_x86_64(lldb::ProcessSP process_sp) : lldb_private::ABI(process_sp) { + ABIWindows_x86_64(lldb::ProcessSP process_sp, + std::unique_ptr info_up) + : lldb_private::ABI(std::move(process_sp), std::move(info_up)) { // Call CreateInstance instead. } }; diff --git a/lldb/source/Target/ABI.cpp b/lldb/source/Target/ABI.cpp index 28cd9ae..005261e 100644 --- a/lldb/source/Target/ABI.cpp +++ b/lldb/source/Target/ABI.cpp @@ -15,6 +15,8 @@ #include "lldb/Symbol/TypeSystem.h" #include "lldb/Target/Target.h" #include "lldb/Target/Thread.h" +#include "lldb/Utility/Log.h" +#include "llvm/Support/TargetRegistry.h" using namespace lldb; using namespace lldb_private; @@ -210,3 +212,20 @@ bool ABI::GetFallbackRegisterLocation( return false; } + +std::unique_ptr ABI::MakeMCRegisterInfo(const ArchSpec &arch) { + std::string triple = arch.GetTriple().getTriple(); + std::string lookup_error; + const llvm::Target *target = + llvm::TargetRegistry::lookupTarget(triple, lookup_error); + if (!target) { + LLDB_LOG(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS), + "Failed to create an llvm target for {0}: {1}", triple, + lookup_error); + return nullptr; + } + std::unique_ptr info_up( + target->createMCRegInfo(triple)); + assert(info_up); + return info_up; +} diff --git a/lldb/tools/lldb-test/CMakeLists.txt b/lldb/tools/lldb-test/CMakeLists.txt index 2ab1cea..df9d043 100644 --- a/lldb/tools/lldb-test/CMakeLists.txt +++ b/lldb/tools/lldb-test/CMakeLists.txt @@ -24,4 +24,9 @@ add_lldb_tool(lldb-test Support ) +foreach (t ${LLVM_TARGETS_TO_BUILD}) + set_property(SOURCE SystemInitializerTest.cpp APPEND PROPERTY + COMPILE_DEFINITIONS "LLVM_TARGET_${t}_BUILT") +endforeach() + include_directories(${LLDB_SOURCE_DIR}/source) diff --git a/lldb/tools/lldb-test/SystemInitializerTest.cpp b/lldb/tools/lldb-test/SystemInitializerTest.cpp index 44b960c..51ffb6b 100644 --- a/lldb/tools/lldb-test/SystemInitializerTest.cpp +++ b/lldb/tools/lldb-test/SystemInitializerTest.cpp @@ -28,6 +28,7 @@ #include "Plugins/ABI/SysV-ppc64/ABISysV_ppc64.h" #include "Plugins/ABI/SysV-s390x/ABISysV_s390x.h" #include "Plugins/ABI/SysV-x86_64/ABISysV_x86_64.h" +#include "Plugins/ABI/Windows-x86_64/ABIWindows_x86_64.h" #include "Plugins/Architecture/Arm/ArchitectureArm.h" #include "Plugins/Architecture/PPC64/ArchitecturePPC64.h" #include "Plugins/Disassembler/llvm/DisassemblerLLVMC.h" @@ -144,19 +145,34 @@ llvm::Error SystemInitializerTest::Initialize() { ClangASTContext::Initialize(); - ABIMacOSX_i386::Initialize(); - ABIMacOSX_arm::Initialize(); +#ifdef LLVM_TARGET_AArch64_BUILT ABIMacOSX_arm64::Initialize(); - ABISysV_arm::Initialize(); ABISysV_arm64::Initialize(); +#endif +#ifdef LLVM_TARGET_ARM_BUILT + ABIMacOSX_arm::Initialize(); + ABISysV_arm::Initialize(); +#endif +#ifdef LLVM_TARGET_Hexagon_BUILT ABISysV_hexagon::Initialize(); - ABISysV_i386::Initialize(); - ABISysV_x86_64::Initialize(); - ABISysV_ppc::Initialize(); - ABISysV_ppc64::Initialize(); +#endif +#ifdef LLVM_TARGET_Mips_BUILT ABISysV_mips::Initialize(); ABISysV_mips64::Initialize(); +#endif +#ifdef LLVM_TARGET_PowerPC_BUILT + ABISysV_ppc::Initialize(); + ABISysV_ppc64::Initialize(); +#endif +#ifdef LLVM_TARGET_SystemZ_BUILT ABISysV_s390x::Initialize(); +#endif +#ifdef LLVM_TARGET_X86_BUILT + ABIMacOSX_i386::Initialize(); + ABISysV_i386::Initialize(); + ABISysV_x86_64::Initialize(); + ABIWindows_x86_64::Initialize(); +#endif ArchitectureArm::Initialize(); ArchitecturePPC64::Initialize(); @@ -246,19 +262,35 @@ void SystemInitializerTest::Terminate() { ClangASTContext::Terminate(); - ABIMacOSX_i386::Terminate(); - ABIMacOSX_arm::Terminate(); +#ifdef LLVM_TARGET_AArch64_BUILT ABIMacOSX_arm64::Terminate(); - ABISysV_arm::Terminate(); ABISysV_arm64::Terminate(); +#endif +#ifdef LLVM_TARGET_ARM_BUILT + ABIMacOSX_arm::Terminate(); + ABISysV_arm::Terminate(); +#endif +#ifdef LLVM_TARGET_Hexagon_BUILT ABISysV_hexagon::Terminate(); - ABISysV_i386::Terminate(); - ABISysV_x86_64::Terminate(); - ABISysV_ppc::Terminate(); - ABISysV_ppc64::Terminate(); +#endif +#ifdef LLVM_TARGET_Mips_BUILT ABISysV_mips::Terminate(); ABISysV_mips64::Terminate(); +#endif +#ifdef LLVM_TARGET_PowerPC_BUILT + ABISysV_ppc::Terminate(); + ABISysV_ppc64::Terminate(); +#endif +#ifdef LLVM_TARGET_SystemZ_BUILT ABISysV_s390x::Terminate(); +#endif +#ifdef LLVM_TARGET_X86_BUILT + ABIMacOSX_i386::Terminate(); + ABISysV_i386::Terminate(); + ABISysV_x86_64::Terminate(); + ABIWindows_x86_64::Terminate(); +#endif + DisassemblerLLVMC::Terminate(); JITLoaderGDB::Terminate(); -- 2.7.4