[Lldb-commits] [lldb] r226959 - Fixing TestRegisters on Linux with LLGS

Vince Harron vharron at google.com
Fri Jan 23 14:57:00 PST 2015


Author: vharron
Date: Fri Jan 23 16:57:00 2015
New Revision: 226959

URL: http://llvm.org/viewvc/llvm-project?rev=226959&view=rev
Log:
Fixing TestRegisters on Linux with LLGS

This patch fixes TestRegisters on Linux with LLGS

Introduce GetUserRegisterCount on RegisterInfoInterface to distinguish
lldb internal registers (e.g.: DR0-DR7) during register counting.

Update GDBRemoteCommunicationServer to skip lldb internal registers on
read/write register and on discover register.

Submitted for Tamas Berghammer


Modified:
    lldb/trunk/include/lldb/Target/NativeRegisterContext.h
    lldb/trunk/include/lldb/Target/NativeRegisterContextRegisterInfo.h
    lldb/trunk/source/Plugins/Process/Utility/RegisterContextLinux_i386.cpp
    lldb/trunk/source/Plugins/Process/Utility/RegisterContextLinux_i386.h
    lldb/trunk/source/Plugins/Process/Utility/RegisterContextLinux_x86_64.cpp
    lldb/trunk/source/Plugins/Process/Utility/RegisterContextLinux_x86_64.h
    lldb/trunk/source/Plugins/Process/Utility/RegisterInfoInterface.h
    lldb/trunk/source/Plugins/Process/Utility/lldb-x86-register-enums.h
    lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp
    lldb/trunk/source/Target/NativeRegisterContextRegisterInfo.cpp

Modified: lldb/trunk/include/lldb/Target/NativeRegisterContext.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/NativeRegisterContext.h?rev=226959&r1=226958&r2=226959&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/NativeRegisterContext.h (original)
+++ lldb/trunk/include/lldb/Target/NativeRegisterContext.h Fri Jan 23 16:57:00 2015
@@ -44,6 +44,9 @@ public:
     virtual uint32_t
     GetRegisterCount () const = 0;
 
+    virtual uint32_t
+    GetUserRegisterCount () const = 0;
+
     virtual const RegisterInfo *
     GetRegisterInfoAtIndex (uint32_t reg) const = 0;
 

Modified: lldb/trunk/include/lldb/Target/NativeRegisterContextRegisterInfo.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/NativeRegisterContextRegisterInfo.h?rev=226959&r1=226958&r2=226959&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/NativeRegisterContextRegisterInfo.h (original)
+++ lldb/trunk/include/lldb/Target/NativeRegisterContextRegisterInfo.h Fri Jan 23 16:57:00 2015
@@ -31,6 +31,9 @@ namespace lldb_private
         uint32_t
         GetRegisterCount () const override;
 
+        uint32_t
+        GetUserRegisterCount () const override;
+
         const RegisterInfo *
         GetRegisterInfoAtIndex (uint32_t reg_index) const override;
 

Modified: lldb/trunk/source/Plugins/Process/Utility/RegisterContextLinux_i386.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Utility/RegisterContextLinux_i386.cpp?rev=226959&r1=226958&r2=226959&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Utility/RegisterContextLinux_i386.cpp (original)
+++ lldb/trunk/source/Plugins/Process/Utility/RegisterContextLinux_i386.cpp Fri Jan 23 16:57:00 2015
@@ -125,3 +125,8 @@ RegisterContextLinux_i386::GetRegisterCo
     return static_cast<uint32_t> (sizeof (g_register_infos_i386) / sizeof (g_register_infos_i386 [0]));
 }
 
+uint32_t
+RegisterContextLinux_i386::GetUserRegisterCount () const
+{
+    return static_cast<uint32_t> (k_num_user_registers_i386);
+}

Modified: lldb/trunk/source/Plugins/Process/Utility/RegisterContextLinux_i386.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Utility/RegisterContextLinux_i386.h?rev=226959&r1=226958&r2=226959&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Utility/RegisterContextLinux_i386.h (original)
+++ lldb/trunk/source/Plugins/Process/Utility/RegisterContextLinux_i386.h Fri Jan 23 16:57:00 2015
@@ -26,6 +26,9 @@ public:
 
     uint32_t
     GetRegisterCount () const override;
+
+    uint32_t
+    GetUserRegisterCount () const override;
 };
 
 #endif

Modified: lldb/trunk/source/Plugins/Process/Utility/RegisterContextLinux_x86_64.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Utility/RegisterContextLinux_x86_64.cpp?rev=226959&r1=226958&r2=226959&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Utility/RegisterContextLinux_x86_64.cpp (original)
+++ lldb/trunk/source/Plugins/Process/Utility/RegisterContextLinux_x86_64.cpp Fri Jan 23 16:57:00 2015
@@ -145,10 +145,26 @@ GetRegisterInfoCount (const ArchSpec &ta
     }
 }
 
+static uint32_t
+GetUserRegisterInfoCount (const ArchSpec &target_arch)
+{
+    switch (target_arch.GetMachine())
+    {
+        case llvm::Triple::x86:
+            return static_cast<uint32_t> (k_num_user_registers_i386);
+        case llvm::Triple::x86_64:
+            return static_cast<uint32_t> (k_num_user_registers_x86_64);
+        default:
+            assert(false && "Unhandled target architecture.");
+            return 0;
+    }
+}
+
 RegisterContextLinux_x86_64::RegisterContextLinux_x86_64(const ArchSpec &target_arch) :
     lldb_private::RegisterInfoInterface(target_arch),
     m_register_info_p (GetRegisterInfoPtr (target_arch)),
-    m_register_info_count (GetRegisterInfoCount (target_arch))
+    m_register_info_count (GetRegisterInfoCount (target_arch)),
+    m_user_register_count (GetUserRegisterInfoCount (target_arch))
 {
 }
 
@@ -169,3 +185,9 @@ RegisterContextLinux_x86_64::GetRegister
 {
     return m_register_info_count;
 }
+
+uint32_t
+RegisterContextLinux_x86_64::GetUserRegisterCount () const
+{
+    return m_user_register_count;
+}

Modified: lldb/trunk/source/Plugins/Process/Utility/RegisterContextLinux_x86_64.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Utility/RegisterContextLinux_x86_64.h?rev=226959&r1=226958&r2=226959&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Utility/RegisterContextLinux_x86_64.h (original)
+++ lldb/trunk/source/Plugins/Process/Utility/RegisterContextLinux_x86_64.h Fri Jan 23 16:57:00 2015
@@ -27,9 +27,13 @@ public:
     uint32_t
     GetRegisterCount () const override;
 
+    uint32_t
+    GetUserRegisterCount () const override;
+
 private:
     const lldb_private::RegisterInfo *m_register_info_p;
     uint32_t m_register_info_count;
+    uint32_t m_user_register_count;
 };
 
 #endif

Modified: lldb/trunk/source/Plugins/Process/Utility/RegisterInfoInterface.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Utility/RegisterInfoInterface.h?rev=226959&r1=226958&r2=226959&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Utility/RegisterInfoInterface.h (original)
+++ lldb/trunk/source/Plugins/Process/Utility/RegisterInfoInterface.h Fri Jan 23 16:57:00 2015
@@ -32,9 +32,20 @@ namespace lldb_private
         virtual const lldb_private::RegisterInfo *
         GetRegisterInfo () const = 0;
 
+        // Returns the number of registers including the user registers and the
+        // lldb internal registers also
         virtual uint32_t
         GetRegisterCount () const = 0;
 
+        // Returns the number of the user registers (excluding the registers
+        // kept for lldb internal use only). Subclasses should override it if
+        // they belongs to an architecture with lldb internal registers.
+        virtual uint32_t
+        GetUserRegisterCount () const
+        {
+            return GetRegisterCount();
+        }
+
         const lldb_private::ArchSpec&
         GetTargetArchitecture() const
             { return m_target_arch; }

Modified: lldb/trunk/source/Plugins/Process/Utility/lldb-x86-register-enums.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Utility/lldb-x86-register-enums.h?rev=226959&r1=226958&r2=226959&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Utility/lldb-x86-register-enums.h (original)
+++ lldb/trunk/source/Plugins/Process/Utility/lldb-x86-register-enums.h Fri Jan 23 16:57:00 2015
@@ -118,7 +118,8 @@ namespace lldb_private
         k_num_registers_i386,
         k_num_gpr_registers_i386 = k_last_gpr_i386 - k_first_gpr_i386 + 1,
         k_num_fpr_registers_i386 = k_last_fpr_i386 - k_first_fpr_i386 + 1,
-        k_num_avx_registers_i386 = k_last_avx_i386 - k_first_avx_i386 + 1
+        k_num_avx_registers_i386 = k_last_avx_i386 - k_first_avx_i386 + 1,
+        k_num_user_registers_i386 = k_num_gpr_registers_i386 + k_num_fpr_registers_i386 + k_num_avx_registers_i386,
     };
 
     //---------------------------------------------------------------------------
@@ -285,7 +286,8 @@ namespace lldb_private
         k_num_registers_x86_64,
         k_num_gpr_registers_x86_64 = k_last_gpr_x86_64 - k_first_gpr_x86_64 + 1,
         k_num_fpr_registers_x86_64 = k_last_fpr_x86_64 - k_first_fpr_x86_64 + 1,
-        k_num_avx_registers_x86_64 = k_last_avx_x86_64 - k_first_avx_x86_64 + 1
+        k_num_avx_registers_x86_64 = k_last_avx_x86_64 - k_first_avx_x86_64 + 1,
+        k_num_user_registers_x86_64 = k_num_gpr_registers_x86_64 + k_num_fpr_registers_x86_64 + k_num_avx_registers_x86_64,
     };
 
 }

Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp?rev=226959&r1=226958&r2=226959&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp Fri Jan 23 16:57:00 2015
@@ -2995,7 +2995,7 @@ GDBRemoteCommunicationServer::Handle_qRe
         return SendErrorResponse (69);
 
     // Return the end of registers response if we've iterated one past the end of the register set.
-    if (reg_index >= reg_context_sp->GetRegisterCount ())
+    if (reg_index >= reg_context_sp->GetUserRegisterCount ())
         return SendErrorResponse (69);
 
     const RegisterInfo *reg_info = reg_context_sp->GetRegisterInfoAtIndex(reg_index);
@@ -3196,10 +3196,10 @@ GDBRemoteCommunicationServer::Handle_p (
     }
 
     // Return the end of registers response if we've iterated one past the end of the register set.
-    if (reg_index >= reg_context_sp->GetRegisterCount ())
+    if (reg_index >= reg_context_sp->GetUserRegisterCount ())
     {
         if (log)
-            log->Printf ("GDBRemoteCommunicationServer::%s failed, requested register %" PRIu32 " beyond register count %" PRIu32, __FUNCTION__, reg_index, reg_context_sp->GetRegisterCount ());
+            log->Printf ("GDBRemoteCommunicationServer::%s failed, requested register %" PRIu32 " beyond register count %" PRIu32, __FUNCTION__, reg_index, reg_context_sp->GetUserRegisterCount ());
         return SendErrorResponse (0x15);
     }
 
@@ -3305,10 +3305,10 @@ GDBRemoteCommunicationServer::Handle_P (
     }
 
     // Return the end of registers response if we've iterated one past the end of the register set.
-    if (reg_index >= reg_context_sp->GetRegisterCount ())
+    if (reg_index >= reg_context_sp->GetUserRegisterCount ())
     {
         if (log)
-            log->Printf ("GDBRemoteCommunicationServer::%s failed, requested register %" PRIu32 " beyond register count %" PRIu32, __FUNCTION__, reg_index, reg_context_sp->GetRegisterCount ());
+            log->Printf ("GDBRemoteCommunicationServer::%s failed, requested register %" PRIu32 " beyond register count %" PRIu32, __FUNCTION__, reg_index, reg_context_sp->GetUserRegisterCount ());
         return SendErrorResponse (0x47);
     }
 

Modified: lldb/trunk/source/Target/NativeRegisterContextRegisterInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/NativeRegisterContextRegisterInfo.cpp?rev=226959&r1=226958&r2=226959&view=diff
==============================================================================
--- lldb/trunk/source/Target/NativeRegisterContextRegisterInfo.cpp (original)
+++ lldb/trunk/source/Target/NativeRegisterContextRegisterInfo.cpp Fri Jan 23 16:57:00 2015
@@ -28,6 +28,12 @@ NativeRegisterContextRegisterInfo::GetRe
     return m_register_info_interface_up->GetRegisterCount ();
 }
 
+uint32_t
+NativeRegisterContextRegisterInfo::GetUserRegisterCount () const
+{
+    return m_register_info_interface_up->GetUserRegisterCount ();
+}
+
 const RegisterInfo *
 NativeRegisterContextRegisterInfo::GetRegisterInfoAtIndex (uint32_t reg_index) const
 {





More information about the lldb-commits mailing list