Index: lldb/include/lldb/Core/ValueObjectRegister.h =================================================================== --- lldb/include/lldb/Core/ValueObjectRegister.h +++ lldb/include/lldb/Core/ValueObjectRegister.h @@ -84,7 +84,7 @@ static lldb::ValueObjectSP Create(ExecutionContextScope *exe_scope, lldb::RegisterContextSP ®_ctx_sp, - uint32_t reg_num); + const RegisterInfo *reg_info); llvm::Optional GetByteSize() override; @@ -119,15 +119,16 @@ CompilerType m_compiler_type; private: - void ConstructObject(uint32_t reg_num); + void ConstructObject(const RegisterInfo *reg_info); friend class ValueObjectRegisterSet; ValueObjectRegister(ValueObject &parent, lldb::RegisterContextSP ®_ctx_sp, - uint32_t reg_num); + const RegisterInfo *reg_info); ValueObjectRegister(ExecutionContextScope *exe_scope, ValueObjectManager &manager, - lldb::RegisterContextSP ®_ctx_sp, uint32_t reg_num); + lldb::RegisterContextSP ®_ctx_sp, + const RegisterInfo *reg_info); // For ValueObject only ValueObjectRegister(const ValueObjectRegister &) = delete; Index: lldb/source/API/SBFrame.cpp =================================================================== --- lldb/source/API/SBFrame.cpp +++ lldb/source/API/SBFrame.cpp @@ -633,18 +633,10 @@ { RegisterContextSP reg_ctx(frame->GetRegisterContext()); if (reg_ctx) { - const uint32_t num_regs = reg_ctx->GetRegisterCount(); - for (uint32_t reg_idx = 0; reg_idx < num_regs; ++reg_idx) { - const RegisterInfo *reg_info = - reg_ctx->GetRegisterInfoAtIndex(reg_idx); - if (reg_info && - ((reg_info->name && strcasecmp(reg_info->name, name) == 0) || - (reg_info->alt_name && - strcasecmp(reg_info->alt_name, name) == 0))) { - value_sp = ValueObjectRegister::Create(frame, reg_ctx, reg_idx); - sb_value.SetSP(value_sp); - break; - } + if (const RegisterInfo *reg_info = + reg_ctx->GetRegisterInfoByName(name)) { + value_sp = ValueObjectRegister::Create(frame, reg_ctx, reg_info); + sb_value.SetSP(value_sp); } } } break; @@ -953,18 +945,10 @@ if (frame) { RegisterContextSP reg_ctx(frame->GetRegisterContext()); if (reg_ctx) { - const uint32_t num_regs = reg_ctx->GetRegisterCount(); - for (uint32_t reg_idx = 0; reg_idx < num_regs; ++reg_idx) { - const RegisterInfo *reg_info = - reg_ctx->GetRegisterInfoAtIndex(reg_idx); - if (reg_info && - ((reg_info->name && strcasecmp(reg_info->name, name) == 0) || - (reg_info->alt_name && - strcasecmp(reg_info->alt_name, name) == 0))) { - value_sp = ValueObjectRegister::Create(frame, reg_ctx, reg_idx); - result.SetSP(value_sp); - break; - } + if (const RegisterInfo *reg_info = + reg_ctx->GetRegisterInfoByName(name)) { + value_sp = ValueObjectRegister::Create(frame, reg_ctx, reg_info); + result.SetSP(value_sp); } } } Index: lldb/source/Core/ValueObjectRegister.cpp =================================================================== --- lldb/source/Core/ValueObjectRegister.cpp +++ lldb/source/Core/ValueObjectRegister.cpp @@ -118,8 +118,9 @@ if (m_reg_ctx_sp && m_reg_set) { const size_t num_children = GetNumChildren(); if (idx < num_children) - valobj = new ValueObjectRegister(*this, m_reg_ctx_sp, - m_reg_set->registers[idx]); + valobj = new ValueObjectRegister( + *this, m_reg_ctx_sp, + m_reg_ctx_sp->GetRegisterInfoAtIndex(m_reg_set->registers[idx])); } return valobj; } @@ -132,8 +133,7 @@ const RegisterInfo *reg_info = m_reg_ctx_sp->GetRegisterInfoByName(name.GetStringRef()); if (reg_info != nullptr) - valobj = new ValueObjectRegister(*this, m_reg_ctx_sp, - reg_info->kinds[eRegisterKindLLDB]); + valobj = new ValueObjectRegister(*this, m_reg_ctx_sp, reg_info); } if (valobj) return valobj->GetSP(); @@ -155,8 +155,7 @@ #pragma mark - #pragma mark ValueObjectRegister -void ValueObjectRegister::ConstructObject(uint32_t reg_num) { - const RegisterInfo *reg_info = m_reg_ctx_sp->GetRegisterInfoAtIndex(reg_num); +void ValueObjectRegister::ConstructObject(const RegisterInfo *reg_info) { if (reg_info) { m_reg_info = *reg_info; if (reg_info->name) @@ -168,29 +167,29 @@ ValueObjectRegister::ValueObjectRegister(ValueObject &parent, lldb::RegisterContextSP ®_ctx_sp, - uint32_t reg_num) + const RegisterInfo *reg_info) : ValueObject(parent), m_reg_ctx_sp(reg_ctx_sp), m_reg_info(), m_reg_value(), m_type_name(), m_compiler_type() { assert(reg_ctx_sp.get()); - ConstructObject(reg_num); + ConstructObject(reg_info); } ValueObjectSP ValueObjectRegister::Create(ExecutionContextScope *exe_scope, lldb::RegisterContextSP ®_ctx_sp, - uint32_t reg_num) { + const RegisterInfo *reg_info) { auto manager_sp = ValueObjectManager::Create(); - return (new ValueObjectRegister(exe_scope, *manager_sp, reg_ctx_sp, reg_num)) + return (new ValueObjectRegister(exe_scope, *manager_sp, reg_ctx_sp, reg_info)) ->GetSP(); } ValueObjectRegister::ValueObjectRegister(ExecutionContextScope *exe_scope, ValueObjectManager &manager, lldb::RegisterContextSP ®_ctx, - uint32_t reg_num) + const RegisterInfo *reg_info) : ValueObject(exe_scope, manager), m_reg_ctx_sp(reg_ctx), m_reg_info(), m_reg_value(), m_type_name(), m_compiler_type() { assert(reg_ctx); - ConstructObject(reg_num); + ConstructObject(reg_info); } ValueObjectRegister::~ValueObjectRegister() = default; Index: lldb/source/Target/RegisterContext.cpp =================================================================== --- lldb/source/Target/RegisterContext.cpp +++ lldb/source/Target/RegisterContext.cpp @@ -54,6 +54,17 @@ if (reg_name.empty()) return nullptr; + // Try matching generic register names first. This is consistent with + // how aliases work, esp. wrt "sp" generic alias taking precedence over + // "sp" pseudo-register on x86_64. + uint32_t generic_reg = Args::StringToGenericRegister(reg_name); + if (generic_reg != LLDB_INVALID_REGNUM) { + const RegisterInfo *reg_info = + GetRegisterInfo(eRegisterKindGeneric, generic_reg); + if (reg_info) + return reg_info; + } + const uint32_t num_registers = GetRegisterCount(); for (uint32_t reg = start_idx; reg < num_registers; ++reg) { const RegisterInfo *reg_info = GetRegisterInfoAtIndex(reg); @@ -62,6 +73,7 @@ reg_name.equals_insensitive(reg_info->alt_name)) return reg_info; } + return nullptr; } Index: lldb/test/API/functionalities/gdb_remote_client/TestGDBServerTargetXML.py =================================================================== --- lldb/test/API/functionalities/gdb_remote_client/TestGDBServerTargetXML.py +++ lldb/test/API/functionalities/gdb_remote_client/TestGDBServerTargetXML.py @@ -9,6 +9,7 @@ @skipIfXmlSupportMissing @skipIfRemote + @skipIfLLVMTargetMissing("X86") def test_x86_64_vec_regs(self): """Test rendering of x86_64 vector registers from gdbserver.""" class MyResponder(MockGDBServerResponder): @@ -20,8 +21,16 @@ i386:x86-64 GNU/Linux + + + + + + + + @@ -59,8 +68,16 @@ def readRegisters(self): return ( - "0102030405060708" # rsp - "1112131415161718" # rip + "0102030405060708" # rcx + "1112131415161718" # rdx + "2122232425262728" # rsi + "3132333435363738" # rdi + "4142434445464748" # rbp + "5152535455565758" # rsp + "6162636465666768" # r8 + "7172737475767778" # r9 + "8182838485868788" # rip + "91929394" # eflags "0102030405060708090a" # st0 "1112131415161718191a" + # st1 "2122232425262728292a" * 6 + # st2..st7 @@ -82,9 +99,31 @@ # rsp and rip should be displayed as uints self.match("register read rsp", - ["rsp = 0x0807060504030201"]) + ["rsp = 0x5857565554535251"]) self.match("register read rip", - ["rip = 0x1817161514131211"]) + ["rip = 0x8887868584838281"]) + + # test generic aliases + self.match("register read arg4", + ["rcx = 0x0807060504030201"]) + self.match("register read arg3", + ["rdx = 0x1817161514131211"]) + self.match("register read arg2", + ["rsi = 0x2827262524232221"]) + self.match("register read arg1", + ["rdi = 0x3837363534333231"]) + self.match("register read fp", + ["rbp = 0x4847464544434241"]) + self.match("register read sp", + ["rsp = 0x5857565554535251"]) + self.match("register read arg5", + ["r8 = 0x6867666564636261"]) + self.match("register read arg6", + ["r9 = 0x7877767574737271"]) + self.match("register read pc", + ["rip = 0x8887868584838281"]) + self.match("register read flags", + ["eflags = 0x94939291"]) # both stX and xmmX should be displayed as vectors self.match("register read st0",