Index: lldb/include/lldb/Target/ABI.h =================================================================== --- lldb/include/lldb/Target/ABI.h +++ lldb/include/lldb/Target/ABI.h @@ -11,6 +11,7 @@ #include "lldb/Core/PluginInterface.h" #include "lldb/Symbol/UnwindPlan.h" +#include "lldb/Target/DynamicRegisterInfo.h" #include "lldb/Utility/Status.h" #include "lldb/lldb-private.h" @@ -127,7 +128,7 @@ llvm::MCRegisterInfo &GetMCRegisterInfo() { return *m_mc_register_info_up; } - virtual void AugmentRegisterInfo(RegisterInfo &info) = 0; + virtual void AugmentRegisterInfo(DynamicRegisterInfo &dyn_info) = 0; virtual bool GetPointerReturnRegister(const char *&name) { return false; } @@ -159,7 +160,7 @@ class RegInfoBasedABI : public ABI { public: - void AugmentRegisterInfo(RegisterInfo &info) override; + void AugmentRegisterInfo(DynamicRegisterInfo &dyn_info) override; protected: using ABI::ABI; @@ -171,7 +172,7 @@ class MCBasedABI : public ABI { public: - void AugmentRegisterInfo(RegisterInfo &info) override; + void AugmentRegisterInfo(DynamicRegisterInfo &dyn_info) override; /// If the register name is of the form "[]" then change /// the name to "[]". Otherwise, leave the name unchanged. Index: lldb/include/lldb/Target/DynamicRegisterInfo.h =================================================================== --- lldb/include/lldb/Target/DynamicRegisterInfo.h +++ lldb/include/lldb/Target/DynamicRegisterInfo.h @@ -77,6 +77,9 @@ const lldb_private::RegisterInfo * GetRegisterInfo(llvm::StringRef reg_name) const; + lldb_private::RegisterInfo * + GetRegisterInfo(llvm::StringRef reg_name); + typedef std::vector reg_collection; llvm::iterator_range Registers() { return llvm::iterator_range(m_regs); Index: lldb/source/Plugins/ABI/AArch64/ABIAArch64.h =================================================================== --- lldb/source/Plugins/ABI/AArch64/ABIAArch64.h +++ lldb/source/Plugins/ABI/AArch64/ABIAArch64.h @@ -31,7 +31,8 @@ uint32_t GetGenericNum(llvm::StringRef name) override; - void AugmentRegisterInfo(lldb_private::RegisterInfo &info) override; + void + AugmentRegisterInfo(lldb_private::DynamicRegisterInfo &dyn_info) override; using lldb_private::MCBasedABI::MCBasedABI; }; Index: lldb/source/Plugins/ABI/AArch64/ABIAArch64.cpp =================================================================== --- lldb/source/Plugins/ABI/AArch64/ABIAArch64.cpp +++ lldb/source/Plugins/ABI/AArch64/ABIAArch64.cpp @@ -71,10 +71,13 @@ .Default(LLDB_INVALID_REGNUM); } -void ABIAArch64::AugmentRegisterInfo(lldb_private::RegisterInfo &info) { - lldb_private::MCBasedABI::AugmentRegisterInfo(info); +void ABIAArch64::AugmentRegisterInfo( + lldb_private::DynamicRegisterInfo &dyn_info) { + lldb_private::MCBasedABI::AugmentRegisterInfo(dyn_info); - // GDB sends x31 as "sp". Add the "x31" alt_name for convenience. - if (!strcmp(info.name, "sp") && !info.alt_name) - info.alt_name = "x31"; + if (lldb_private::RegisterInfo *sp = dyn_info.GetRegisterInfo("sp")) { + // GDB sends x31 as "sp". Add the "x31" alt_name for convenience. + if (!strcmp(sp->name, "sp") && !sp->alt_name) + sp->alt_name = "x31"; + } } Index: lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp =================================================================== --- lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp +++ lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp @@ -557,6 +557,8 @@ } // At this point, we can finalize our register info. + if (ABISP abi_sp = ABI::FindPlugin(shared_from_this(), arch_to_use)) + abi_sp->AugmentRegisterInfo(*m_register_info_sp); m_register_info_sp->Finalize(GetTarget().GetArchitecture()); } @@ -4482,11 +4484,6 @@ void ProcessGDBRemote::AddRemoteRegisters( std::vector ®isters, const ArchSpec &arch_to_use) { - // Don't use Process::GetABI, this code gets called from DidAttach, and - // in that context we haven't set the Target's architecture yet, so the - // ABI is also potentially incorrect. - ABISP abi_sp = ABI::FindPlugin(shared_from_this(), arch_to_use); - std::map remote_to_local_map; uint32_t remote_regnum = 0; for (auto it : llvm::enumerate(registers)) { @@ -4539,12 +4536,14 @@ : nullptr, remote_reg_info.dwarf_opcode_bytes.size(), }; - - if (abi_sp) - abi_sp->AugmentRegisterInfo(reg_info); m_register_info_sp->AddRegister(reg_info, remote_reg_info.set_name); }; + // Don't use Process::GetABI, this code gets called from DidAttach, and + // in that context we haven't set the Target's architecture yet, so the + // ABI is also potentially incorrect. + if (ABISP abi_sp = ABI::FindPlugin(shared_from_this(), arch_to_use)) + abi_sp->AugmentRegisterInfo(*m_register_info_sp); m_register_info_sp->Finalize(arch_to_use); } Index: lldb/source/Target/ABI.cpp =================================================================== --- lldb/source/Target/ABI.cpp +++ lldb/source/Target/ABI.cpp @@ -214,33 +214,37 @@ return info_up; } -void RegInfoBasedABI::AugmentRegisterInfo(RegisterInfo &info) { - if (info.kinds[eRegisterKindEHFrame] != LLDB_INVALID_REGNUM && - info.kinds[eRegisterKindDWARF] != LLDB_INVALID_REGNUM) - return; - - RegisterInfo abi_info; - if (!GetRegisterInfoByName(info.name, abi_info)) - return; - - if (info.kinds[eRegisterKindEHFrame] == LLDB_INVALID_REGNUM) - info.kinds[eRegisterKindEHFrame] = abi_info.kinds[eRegisterKindEHFrame]; - if (info.kinds[eRegisterKindDWARF] == LLDB_INVALID_REGNUM) - info.kinds[eRegisterKindDWARF] = abi_info.kinds[eRegisterKindDWARF]; - if (info.kinds[eRegisterKindGeneric] == LLDB_INVALID_REGNUM) - info.kinds[eRegisterKindGeneric] = abi_info.kinds[eRegisterKindGeneric]; +void RegInfoBasedABI::AugmentRegisterInfo(DynamicRegisterInfo &dyn_info) { + for (RegisterInfo &info : dyn_info.Registers()) { + if (info.kinds[eRegisterKindEHFrame] != LLDB_INVALID_REGNUM && + info.kinds[eRegisterKindDWARF] != LLDB_INVALID_REGNUM) + continue; + + RegisterInfo abi_info; + if (!GetRegisterInfoByName(info.name, abi_info)) + continue; + + if (info.kinds[eRegisterKindEHFrame] == LLDB_INVALID_REGNUM) + info.kinds[eRegisterKindEHFrame] = abi_info.kinds[eRegisterKindEHFrame]; + if (info.kinds[eRegisterKindDWARF] == LLDB_INVALID_REGNUM) + info.kinds[eRegisterKindDWARF] = abi_info.kinds[eRegisterKindDWARF]; + if (info.kinds[eRegisterKindGeneric] == LLDB_INVALID_REGNUM) + info.kinds[eRegisterKindGeneric] = abi_info.kinds[eRegisterKindGeneric]; + } } -void MCBasedABI::AugmentRegisterInfo(RegisterInfo &info) { +void MCBasedABI::AugmentRegisterInfo(DynamicRegisterInfo &dyn_info) { uint32_t eh, dwarf; - std::tie(eh, dwarf) = GetEHAndDWARFNums(info.name); - - if (info.kinds[eRegisterKindEHFrame] == LLDB_INVALID_REGNUM) - info.kinds[eRegisterKindEHFrame] = eh; - if (info.kinds[eRegisterKindDWARF] == LLDB_INVALID_REGNUM) - info.kinds[eRegisterKindDWARF] = dwarf; - if (info.kinds[eRegisterKindGeneric] == LLDB_INVALID_REGNUM) - info.kinds[eRegisterKindGeneric] = GetGenericNum(info.name); + for (RegisterInfo &info : dyn_info.Registers()) { + std::tie(eh, dwarf) = GetEHAndDWARFNums(info.name); + + if (info.kinds[eRegisterKindEHFrame] == LLDB_INVALID_REGNUM) + info.kinds[eRegisterKindEHFrame] = eh; + if (info.kinds[eRegisterKindDWARF] == LLDB_INVALID_REGNUM) + info.kinds[eRegisterKindDWARF] = dwarf; + if (info.kinds[eRegisterKindGeneric] == LLDB_INVALID_REGNUM) + info.kinds[eRegisterKindGeneric] = GetGenericNum(info.name); + } } std::pair Index: lldb/source/Target/DynamicRegisterInfo.cpp =================================================================== --- lldb/source/Target/DynamicRegisterInfo.cpp +++ lldb/source/Target/DynamicRegisterInfo.cpp @@ -837,3 +837,11 @@ return ®_info; return nullptr; } + +lldb_private::RegisterInfo * +DynamicRegisterInfo::GetRegisterInfo(llvm::StringRef reg_name) { + for (auto ®_info : m_regs) + if (reg_info.name == reg_name) + return ®_info; + return nullptr; +}