Index: include/lldb/Target/NativeRegisterContext.h =================================================================== --- include/lldb/Target/NativeRegisterContext.h +++ include/lldb/Target/NativeRegisterContext.h @@ -44,6 +44,9 @@ virtual uint32_t GetRegisterCount () const = 0; + virtual uint32_t + GetUserRegisterCount () const = 0; + virtual const RegisterInfo * GetRegisterInfoAtIndex (uint32_t reg) const = 0; Index: include/lldb/Target/NativeRegisterContextRegisterInfo.h =================================================================== --- include/lldb/Target/NativeRegisterContextRegisterInfo.h +++ include/lldb/Target/NativeRegisterContextRegisterInfo.h @@ -31,6 +31,9 @@ uint32_t GetRegisterCount () const override; + uint32_t + GetUserRegisterCount () const override; + const RegisterInfo * GetRegisterInfoAtIndex (uint32_t reg_index) const override; Index: source/Plugins/Process/Utility/RegisterContextLinux_i386.h =================================================================== --- source/Plugins/Process/Utility/RegisterContextLinux_i386.h +++ source/Plugins/Process/Utility/RegisterContextLinux_i386.h @@ -26,6 +26,9 @@ uint32_t GetRegisterCount () const override; + + uint32_t + GetUserRegisterCount () const override; }; #endif Index: source/Plugins/Process/Utility/RegisterContextLinux_i386.cpp =================================================================== --- source/Plugins/Process/Utility/RegisterContextLinux_i386.cpp +++ source/Plugins/Process/Utility/RegisterContextLinux_i386.cpp @@ -125,3 +125,8 @@ return static_cast (sizeof (g_register_infos_i386) / sizeof (g_register_infos_i386 [0])); } +uint32_t +RegisterContextLinux_i386::GetUserRegisterCount () const +{ + return static_cast (k_num_user_registers_i386); +} Index: source/Plugins/Process/Utility/RegisterContextLinux_x86_64.h =================================================================== --- source/Plugins/Process/Utility/RegisterContextLinux_x86_64.h +++ source/Plugins/Process/Utility/RegisterContextLinux_x86_64.h @@ -27,9 +27,13 @@ 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 Index: source/Plugins/Process/Utility/RegisterContextLinux_x86_64.cpp =================================================================== --- source/Plugins/Process/Utility/RegisterContextLinux_x86_64.cpp +++ source/Plugins/Process/Utility/RegisterContextLinux_x86_64.cpp @@ -145,10 +145,26 @@ } } +static uint32_t +GetUserRegisterInfoCount (const ArchSpec &target_arch) +{ + switch (target_arch.GetMachine()) + { + case llvm::Triple::x86: + return static_cast (k_num_user_registers_i386); + case llvm::Triple::x86_64: + return static_cast (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 @@ { return m_register_info_count; } + +uint32_t +RegisterContextLinux_x86_64::GetUserRegisterCount () const +{ + return m_user_register_count; +} Index: source/Plugins/Process/Utility/RegisterInfoInterface.h =================================================================== --- source/Plugins/Process/Utility/RegisterInfoInterface.h +++ source/Plugins/Process/Utility/RegisterInfoInterface.h @@ -32,9 +32,20 @@ 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; } Index: source/Plugins/Process/Utility/lldb-x86-register-enums.h =================================================================== --- source/Plugins/Process/Utility/lldb-x86-register-enums.h +++ source/Plugins/Process/Utility/lldb-x86-register-enums.h @@ -118,7 +118,8 @@ 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 @@ 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, }; } Index: source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp =================================================================== --- source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp +++ source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp @@ -2990,7 +2990,7 @@ 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); @@ -3191,10 +3191,10 @@ } // 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); } @@ -3301,10 +3301,10 @@ } // 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); } Index: source/Target/NativeRegisterContextRegisterInfo.cpp =================================================================== --- source/Target/NativeRegisterContextRegisterInfo.cpp +++ source/Target/NativeRegisterContextRegisterInfo.cpp @@ -28,6 +28,12 @@ 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 {