[Lldb-commits] [lldb] 6fbed33 - [lldb] [gdb-remote] Use local regnos for value_regs/invalidate_regs
Michał Górny via lldb-commits
lldb-commits at lists.llvm.org
Thu Sep 23 08:22:04 PDT 2021
Author: Michał Górny
Date: 2021-09-23T17:21:56+02:00
New Revision: 6fbed33d4a7de2229c40e6318f223092d3a23848
URL: https://github.com/llvm/llvm-project/commit/6fbed33d4a7de2229c40e6318f223092d3a23848
DIFF: https://github.com/llvm/llvm-project/commit/6fbed33d4a7de2229c40e6318f223092d3a23848.diff
LOG: [lldb] [gdb-remote] Use local regnos for value_regs/invalidate_regs
Switch the gdb-remote client logic to use local (LLDB) register numbers
in value_regs/invalidate_regs rather than remote regnos. This involves
translating regnos received from lldb-server.
Differential Revision: https://reviews.llvm.org/D110027
Added:
Modified:
lldb/source/Plugins/Process/Utility/DynamicRegisterInfo.cpp
lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
Removed:
################################################################################
diff --git a/lldb/source/Plugins/Process/Utility/DynamicRegisterInfo.cpp b/lldb/source/Plugins/Process/Utility/DynamicRegisterInfo.cpp
index 2755e5f93d5ad..721a03745c3ef 100644
--- a/lldb/source/Plugins/Process/Utility/DynamicRegisterInfo.cpp
+++ b/lldb/source/Plugins/Process/Utility/DynamicRegisterInfo.cpp
@@ -665,9 +665,7 @@ void DynamicRegisterInfo::ConfigureOffsets() {
if (reg.byte_offset == LLDB_INVALID_INDEX32) {
uint32_t value_regnum = reg.value_regs[0];
if (value_regnum != LLDB_INVALID_INDEX32)
- reg.byte_offset =
- GetRegisterInfoAtIndex(remote_to_local_regnum_map[value_regnum])
- ->byte_offset;
+ reg.byte_offset = GetRegisterInfoAtIndex(value_regnum)->byte_offset;
}
}
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
index df5d052d2e33b..92a5227a9a3a8 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
@@ -253,7 +253,7 @@ bool GDBRemoteRegisterContext::ReadRegisterBytes(const RegisterInfo *reg_info) {
// We have a valid primordial register as our constituent. Grab the
// corresponding register info.
const RegisterInfo *prim_reg_info =
- GetRegisterInfo(eRegisterKindProcessPlugin, prim_reg);
+ GetRegisterInfo(eRegisterKindLLDB, prim_reg);
if (prim_reg_info == nullptr)
success = false;
else {
@@ -384,7 +384,7 @@ bool GDBRemoteRegisterContext::WriteRegisterBytes(const RegisterInfo *reg_info,
// We have a valid primordial register as our constituent. Grab the
// corresponding register info.
const RegisterInfo *value_reg_info =
- GetRegisterInfo(eRegisterKindProcessPlugin, reg);
+ GetRegisterInfo(eRegisterKindLLDB, reg);
if (value_reg_info == nullptr)
success = false;
else
@@ -405,7 +405,7 @@ bool GDBRemoteRegisterContext::WriteRegisterBytes(const RegisterInfo *reg_info,
reg != LLDB_INVALID_REGNUM;
reg = reg_info->invalidate_regs[++idx])
SetRegisterIsValid(ConvertRegisterKindToRegisterNumber(
- eRegisterKindProcessPlugin, reg),
+ eRegisterKindLLDB, reg),
false);
}
diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
index 5b49c0c2c652a..eec0c55e75bed 100644
--- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
@@ -4591,13 +4591,35 @@ void ProcessGDBRemote::AddRemoteRegisters(
// ABI is also potentially incorrect.
ABISP abi_sp = ABI::FindPlugin(shared_from_this(), arch_to_use);
+ std::map<uint32_t, uint32_t> remote_to_local_map;
uint32_t remote_regnum = 0;
+ for (auto it : llvm::enumerate(registers)) {
+ RemoteRegisterInfo &remote_reg_info = it.value();
+
+ // Assign successive remote regnums if missing.
+ if (remote_reg_info.regnum_remote == LLDB_INVALID_REGNUM)
+ remote_reg_info.regnum_remote = remote_regnum;
+
+ // Create a mapping from remote to local regnos.
+ remote_to_local_map[remote_reg_info.regnum_remote] = it.index();
+
+ remote_regnum = remote_reg_info.regnum_remote + 1;
+ }
+
for (auto it : llvm::enumerate(registers)) {
uint32_t local_regnum = it.index();
RemoteRegisterInfo &remote_reg_info = it.value();
- // Use remote regnum if available, previous remote regnum + 1 when not.
- if (remote_reg_info.regnum_remote != LLDB_INVALID_REGNUM)
- remote_regnum = remote_reg_info.regnum_remote;
+
+ auto proc_to_lldb = [&remote_to_local_map](uint32_t process_regnum) {
+ auto lldb_regit = remote_to_local_map.find(process_regnum);
+ return lldb_regit != remote_to_local_map.end() ? lldb_regit->second
+ : LLDB_INVALID_REGNUM;
+ };
+
+ llvm::transform(remote_reg_info.value_regs,
+ remote_reg_info.value_regs.begin(), proc_to_lldb);
+ llvm::transform(remote_reg_info.invalidate_regs,
+ remote_reg_info.invalidate_regs.begin(), proc_to_lldb);
auto regs_with_sentinel = [](std::vector<uint32_t> &vec) -> uint32_t * {
if (!vec.empty()) {
@@ -4612,7 +4634,8 @@ void ProcessGDBRemote::AddRemoteRegisters(
remote_reg_info.byte_size, remote_reg_info.byte_offset,
remote_reg_info.encoding, remote_reg_info.format,
{remote_reg_info.regnum_ehframe, remote_reg_info.regnum_dwarf,
- remote_reg_info.regnum_generic, remote_regnum++, local_regnum},
+ remote_reg_info.regnum_generic, remote_reg_info.regnum_remote,
+ local_regnum},
regs_with_sentinel(remote_reg_info.value_regs),
regs_with_sentinel(remote_reg_info.invalidate_regs),
!remote_reg_info.dwarf_opcode_bytes.empty()
More information about the lldb-commits
mailing list