Index: lldb/include/lldb/Host/common/NativeRegisterContext.h =================================================================== --- lldb/include/lldb/Host/common/NativeRegisterContext.h +++ lldb/include/lldb/Host/common/NativeRegisterContext.h @@ -35,6 +35,12 @@ virtual uint32_t GetUserRegisterCount() const = 0; + virtual uint32_t + RegInfosIndexToUserRegIndex(uint32_t user_reg_index) const = 0; + + virtual uint32_t + UserRegIndexToRegInfosIndex(uint32_t user_reg_index) const = 0; + virtual const RegisterInfo *GetRegisterInfoAtIndex(uint32_t reg) const = 0; const char *GetRegisterSetNameForRegisterAtIndex(uint32_t reg_index) const; Index: lldb/source/Plugins/Process/Utility/NativeRegisterContextRegisterInfo.h =================================================================== --- lldb/source/Plugins/Process/Utility/NativeRegisterContextRegisterInfo.h +++ lldb/source/Plugins/Process/Utility/NativeRegisterContextRegisterInfo.h @@ -29,6 +29,10 @@ uint32_t GetUserRegisterCount() const override; + uint32_t RegInfosIndexToUserRegIndex(uint32_t user_reg_index) const override; + + uint32_t UserRegIndexToRegInfosIndex(uint32_t user_reg_index) const override; + const RegisterInfo *GetRegisterInfoAtIndex(uint32_t reg_index) const override; const RegisterInfoInterface &GetRegisterInfoInterface() const; Index: lldb/source/Plugins/Process/Utility/NativeRegisterContextRegisterInfo.cpp =================================================================== --- lldb/source/Plugins/Process/Utility/NativeRegisterContextRegisterInfo.cpp +++ lldb/source/Plugins/Process/Utility/NativeRegisterContextRegisterInfo.cpp @@ -28,6 +28,16 @@ return m_register_info_interface_up->GetUserRegisterCount(); } +uint32_t NativeRegisterContextRegisterInfo::RegInfosIndexToUserRegIndex( + uint32_t reg_infos_index) const { + return reg_infos_index; +} + +uint32_t NativeRegisterContextRegisterInfo::UserRegIndexToRegInfosIndex( + uint32_t user_reg_index) const { + return user_reg_index; +} + const RegisterInfo *NativeRegisterContextRegisterInfo::GetRegisterInfoAtIndex( uint32_t reg_index) const { if (reg_index <= GetRegisterCount()) Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp =================================================================== --- lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp +++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp @@ -458,15 +458,18 @@ } } -static void CollectRegNums(const uint32_t *reg_num, StreamString &response, +static void CollectRegNums(NativeRegisterContext ®_context, + const uint32_t *reg_num, StreamString &response, bool usehex) { + uint32_t reg_index = 0; for (int i = 0; *reg_num != LLDB_INVALID_REGNUM; ++reg_num, ++i) { + reg_index = reg_context.RegInfosIndexToUserRegIndex(*reg_num); if (i > 0) response.PutChar(','); if (usehex) - response.Printf("%" PRIx32, *reg_num); + response.Printf("%" PRIx32, reg_index); else - response.Printf("%" PRIu32, *reg_num); + response.Printf("%" PRIu32, reg_index); } } @@ -1772,7 +1775,9 @@ if (reg_index >= reg_context.GetUserRegisterCount()) return SendErrorResponse(69); - const RegisterInfo *reg_info = reg_context.GetRegisterInfoAtIndex(reg_index); + uint32_t reg_infos_index = reg_context.UserRegIndexToRegInfosIndex(reg_index); + const RegisterInfo *reg_info = + reg_context.GetRegisterInfoAtIndex(reg_infos_index); if (!reg_info) return SendErrorResponse(69); @@ -1801,7 +1806,7 @@ response << "format:" << format << ';'; const char *const register_set_name = - reg_context.GetRegisterSetNameForRegisterAtIndex(reg_index); + reg_context.GetRegisterSetNameForRegisterAtIndex(reg_infos_index); if (register_set_name) response << "set:" << register_set_name << ';'; @@ -1820,13 +1825,13 @@ if (reg_info->value_regs && reg_info->value_regs[0] != LLDB_INVALID_REGNUM) { response.PutCString("container-regs:"); - CollectRegNums(reg_info->value_regs, response, true); + CollectRegNums(reg_context, reg_info->value_regs, response, true); response.PutChar(';'); } if (reg_info->invalidate_regs && reg_info->invalidate_regs[0]) { response.PutCString("invalidate-regs:"); - CollectRegNums(reg_info->invalidate_regs, response, true); + CollectRegNums(reg_context, reg_info->invalidate_regs, response, true); response.PutChar(';'); } @@ -1903,7 +1908,9 @@ std::vector regs_buffer; for (uint32_t reg_num = 0; reg_num < reg_ctx.GetUserRegisterCount(); ++reg_num) { - const RegisterInfo *reg_info = reg_ctx.GetRegisterInfoAtIndex(reg_num); + uint32_t reg_infos_index = reg_ctx.UserRegIndexToRegInfosIndex(reg_num); + const RegisterInfo *reg_info = + reg_ctx.GetRegisterInfoAtIndex(reg_infos_index); if (reg_info == nullptr) { LLDB_LOG(log, "failed to get register info for register index {0}", @@ -1974,7 +1981,9 @@ return SendErrorResponse(0x15); } - const RegisterInfo *reg_info = reg_context.GetRegisterInfoAtIndex(reg_index); + uint32_t reg_infos_index = reg_context.UserRegIndexToRegInfosIndex(reg_index); + const RegisterInfo *reg_info = + reg_context.GetRegisterInfoAtIndex(reg_infos_index); if (!reg_info) { LLDB_LOGF(log, "GDBRemoteCommunicationServerLLGS::%s failed, requested " @@ -2055,7 +2064,9 @@ // Get the thread's register context. NativeRegisterContext ®_context = thread->GetRegisterContext(); - const RegisterInfo *reg_info = reg_context.GetRegisterInfoAtIndex(reg_index); + uint32_t reg_infos_index = reg_context.UserRegIndexToRegInfosIndex(reg_index); + const RegisterInfo *reg_info = + reg_context.GetRegisterInfoAtIndex(reg_infos_index); if (!reg_info) { LLDB_LOGF(log, "GDBRemoteCommunicationServerLLGS::%s failed, requested " @@ -2763,8 +2774,10 @@ const int registers_count = reg_context.GetUserRegisterCount(); for (int reg_index = 0; reg_index < registers_count; reg_index++) { + uint32_t reg_infos_index = + reg_context.UserRegIndexToRegInfosIndex(reg_index); const RegisterInfo *reg_info = - reg_context.GetRegisterInfoAtIndex(reg_index); + reg_context.GetRegisterInfoAtIndex(reg_infos_index); if (!reg_info) { LLDB_LOGF(log, @@ -2790,7 +2803,7 @@ response << "format=\"" << format << "\" "; const char *const register_set_name = - reg_context.GetRegisterSetNameForRegisterAtIndex(reg_index); + reg_context.GetRegisterSetNameForRegisterAtIndex(reg_infos_index); if (register_set_name) response << "group=\"" << register_set_name << "\" "; @@ -2811,13 +2824,13 @@ if (reg_info->value_regs && reg_info->value_regs[0] != LLDB_INVALID_REGNUM) { response.PutCString("value_regnums=\""); - CollectRegNums(reg_info->value_regs, response, false); + CollectRegNums(reg_context, reg_info->value_regs, response, false); response.Printf("\" "); } if (reg_info->invalidate_regs && reg_info->invalidate_regs[0]) { response.PutCString("invalidate_regnums=\""); - CollectRegNums(reg_info->invalidate_regs, response, false); + CollectRegNums(reg_context, reg_info->invalidate_regs, response, false); response.Printf("\" "); } Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp =================================================================== --- lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp +++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp @@ -242,11 +242,15 @@ // Index of the primordial register. bool success = true; for (uint32_t idx = 0; success; ++idx) { - const uint32_t prim_reg = reg_info->value_regs[idx]; + uint32_t prim_reg = reg_info->value_regs[idx]; if (prim_reg == LLDB_INVALID_REGNUM) break; // We have a valid primordial register as our constituent. Grab the // corresponding register info. + uint32_t regnum = ConvertRegisterKindToRegisterNumber( + eRegisterKindProcessPlugin, prim_reg); + if (regnum != LLDB_INVALID_REGNUM) + prim_reg = regnum; const RegisterInfo *prim_reg_info = GetRegisterInfoAtIndex(prim_reg); if (prim_reg_info == nullptr) success = false; @@ -375,11 +379,15 @@ // Invalidate this composite register first. for (uint32_t idx = 0; success; ++idx) { - const uint32_t reg = reg_info->value_regs[idx]; + uint32_t reg = reg_info->value_regs[idx]; if (reg == LLDB_INVALID_REGNUM) break; // We have a valid primordial register as our constituent. Grab the // corresponding register info. + uint32_t lldb_regnum = ConvertRegisterKindToRegisterNumber( + eRegisterKindProcessPlugin, reg); + if (lldb_regnum != LLDB_INVALID_REGNUM) + reg = lldb_regnum; const RegisterInfo *value_reg_info = GetRegisterInfoAtIndex(reg); if (value_reg_info == nullptr) success = false; @@ -397,6 +405,10 @@ for (uint32_t idx = 0, reg = reg_info->invalidate_regs[0]; reg != LLDB_INVALID_REGNUM; reg = reg_info->invalidate_regs[++idx]) { + uint32_t lldb_regnum = ConvertRegisterKindToRegisterNumber( + eRegisterKindProcessPlugin, reg); + if (lldb_regnum != LLDB_INVALID_REGNUM) + reg = lldb_regnum; SetRegisterIsValid(reg, false); } }