From 1999b6d68c556b15e78fb4c20f62b75cff2fec98 Mon Sep 17 00:00:00 2001 From: Ashok Thirumurthi Date: Mon, 13 May 2013 19:56:46 +0000 Subject: [PATCH] Fixed expression evaluation with convenience registers. - Also improved test coverage for passing tests to include expr/x and a sanity check for $eax as the lower half of $rax. llvm-svn: 181727 --- lldb/include/lldb/Core/RegisterValue.h | 2 +- .../Process/POSIX/RegisterContext_x86_64.cpp | 15 +++++++++++++-- .../Process/POSIX/RegisterContext_x86_64.h | 8 +++++--- .../functionalities/register/TestRegisters.py | 6 ++++++ 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/lldb/include/lldb/Core/RegisterValue.h b/lldb/include/lldb/Core/RegisterValue.h index 67a43239473a..cf29cea46d36 100644 --- a/lldb/include/lldb/Core/RegisterValue.h +++ b/lldb/include/lldb/Core/RegisterValue.h @@ -382,7 +382,7 @@ namespace lldb_private { RegisterValue::Type m_type; union { - uint8_t uint8; + uint8_t uint8; uint16_t uint16; uint32_t uint32; uint64_t uint64; diff --git a/lldb/source/Plugins/Process/POSIX/RegisterContext_x86_64.cpp b/lldb/source/Plugins/Process/POSIX/RegisterContext_x86_64.cpp index b808140359be..62598cbb9f4f 100644 --- a/lldb/source/Plugins/Process/POSIX/RegisterContext_x86_64.cpp +++ b/lldb/source/Plugins/Process/POSIX/RegisterContext_x86_64.cpp @@ -547,6 +547,8 @@ RegisterContext_x86_64::GetRegisterCount() const RegisterInfo * RegisterContext_x86_64::GetRegisterInfo() { + // Commonly, this method is overridden and g_register_infos is copied and specialized. + // So, use GetRegisterInfo() rather than g_register_infos in this scope. return g_register_infos; } @@ -680,6 +682,9 @@ RegisterContext_x86_64::IsRegisterSetAvailable(size_t set_index) bool RegisterContext_x86_64::ReadRegister(const RegisterInfo *reg_info, RegisterValue &value) { + if (!reg_info) + return false; + const uint32_t reg = reg_info->kinds[eRegisterKindLLDB]; if (IsFPR(reg, m_fpr_type)) { @@ -688,8 +693,14 @@ RegisterContext_x86_64::ReadRegister(const RegisterInfo *reg_info, RegisterValue } else { ProcessMonitor &monitor = GetMonitor(); - return monitor.ReadRegisterValue(m_thread.GetID(), GetRegisterOffset(reg), - GetRegisterName(reg), GetRegisterSize(reg), value); + bool success = monitor.ReadRegisterValue(m_thread.GetID(), GetRegisterOffset(reg), + GetRegisterName(reg), GetRegisterSize(reg), value); + + // If an i386 register should be parsed from an x86_64 register... + if (success && reg >= k_first_i386 && reg <= k_last_i386) + if (value.GetByteSize() > reg_info->byte_size) + value.SetType(reg_info); // ...use the type specified by reg_info rather than the uint64_t default + return success; } if (reg_info->encoding == eEncodingVector) { diff --git a/lldb/source/Plugins/Process/POSIX/RegisterContext_x86_64.h b/lldb/source/Plugins/Process/POSIX/RegisterContext_x86_64.h index 8834a5169ca1..08ce682104b3 100644 --- a/lldb/source/Plugins/Process/POSIX/RegisterContext_x86_64.h +++ b/lldb/source/Plugins/Process/POSIX/RegisterContext_x86_64.h @@ -43,7 +43,8 @@ enum gpr_ss, gpr_ds, gpr_es, - gpr_eax, + k_first_i386, + gpr_eax = k_first_i386, gpr_ebx, gpr_ecx, gpr_edx, @@ -52,8 +53,9 @@ enum gpr_ebp, gpr_esp, gpr_eip, - gpr_eflags, - k_last_gpr = gpr_eflags, // eRegisterKindLLDB == 33 + gpr_eflags, // eRegisterKindLLDB == 33 + k_last_i386 = gpr_eflags, + k_last_gpr = gpr_eflags, k_first_fpr, fpu_fcw = k_first_fpr, diff --git a/lldb/test/functionalities/register/TestRegisters.py b/lldb/test/functionalities/register/TestRegisters.py index c2a538c7b87a..95ac450ae597 100644 --- a/lldb/test/functionalities/register/TestRegisters.py +++ b/lldb/test/functionalities/register/TestRegisters.py @@ -186,6 +186,12 @@ class RegisterCommandsTestCase(TestBase): """Test expression evaluation with commands related to registers.""" self.common_setup() + self.expect("expr/x $eax", + substrs = ['unsigned int', ' = 0x']) + + self.expect("expr -- ($rax & 0xffffffff) == $eax", + substrs = ['true']) + self.expect("expr $xmm0", substrs = ['vector_type'])