mgorny created this revision. mgorny added reviewers: labath, emaste, krytarowski. Herald added subscribers: omjavaid, kristof.beyls. mgorny requested review of this revision.
Create an x31 register that is aliased to sp if the latter is present and the former is not. This is needed to bring gdbserver support in line with lldb-server support, since the former reports x31 as sp. https://reviews.llvm.org/D109695 Files: lldb/source/Plugins/Process/gdb-remote/CMakeLists.txt lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.h lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext_aarch64.cpp lldb/test/API/functionalities/gdb_remote_client/TestGDBServerTargetXML.py
Index: lldb/test/API/functionalities/gdb_remote_client/TestGDBServerTargetXML.py =================================================================== --- lldb/test/API/functionalities/gdb_remote_client/TestGDBServerTargetXML.py +++ lldb/test/API/functionalities/gdb_remote_client/TestGDBServerTargetXML.py @@ -623,6 +623,12 @@ ["x0 = 0x0807060504030201"]) self.match("register read x1", ["x1 = 0x1817161514131211"]) + self.match("register read x29", + ["x29 = 0x3837363534333231"]) + self.match("register read x30", + ["x30 = 0x4847464544434241"]) + self.match("register read x31", + ["x31 = 0x5857565554535251"]) self.match("register read sp", ["sp = 0x5857565554535251"]) self.match("register read pc", Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext_aarch64.cpp =================================================================== --- /dev/null +++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext_aarch64.cpp @@ -0,0 +1,49 @@ +//===-- GDBRemoteRegisterContext_aarch64.cpp ------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "GDBRemoteRegisterContext.h" + +using namespace lldb; +using namespace lldb_private; +using namespace lldb_private::process_gdb_remote; + +static uint32_t x31_value_regs[2]; + +void GDBRemoteDynamicRegisterInfo::PreFinalize_aarch64() { + uint32_t max_regnum = 0; + uint32_t next_regindex = m_regs.size(); + for (const RegisterInfo ® : m_regs) + max_regnum = std::max(max_regnum, reg.kinds[eRegisterKindProcessPlugin]); + + ConstString group; + group.SetCString("aliases"); + + // Alias "sp" into "x31" if necessary. + const RegisterInfo *sp_reg = GetRegisterInfo("sp"); + const RegisterInfo *x31_reg = GetRegisterInfo("x31"); + + if (sp_reg && !x31_reg) { + x31_value_regs[0] = sp_reg->kinds[eRegisterKindProcessPlugin]; + x31_value_regs[1] = LLDB_INVALID_REGNUM; + + struct RegisterInfo new_reg { + "x31", nullptr, sp_reg->byte_size, LLDB_INVALID_INDEX32, sp_reg->encoding, + sp_reg->format, + { + LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, + ++max_regnum, next_regindex++, + }, + x31_value_regs, nullptr, nullptr, 0 + }; + + ConstString name; + ConstString alt_name; + name.SetCString(new_reg.name); + AddRegister(new_reg, name, alt_name, group); + } +} Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.h =================================================================== --- lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.h +++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.h @@ -42,6 +42,7 @@ bool UpdateARM64SVERegistersInfos(uint64_t vg); void Finalize(const lldb_private::ArchSpec &arch); + void PreFinalize_aarch64(); void PreFinalize_x86(const lldb_private::ArchSpec &arch); void PostFinalize_x86(); }; 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 @@ -1107,6 +1107,9 @@ return; switch (arch.GetMachine()) { + case llvm::Triple::aarch64: + PreFinalize_aarch64(); + break; case llvm::Triple::x86: case llvm::Triple::x86_64: PreFinalize_x86(arch); Index: lldb/source/Plugins/Process/gdb-remote/CMakeLists.txt =================================================================== --- lldb/source/Plugins/Process/gdb-remote/CMakeLists.txt +++ lldb/source/Plugins/Process/gdb-remote/CMakeLists.txt @@ -26,6 +26,7 @@ GDBRemoteCommunicationServerLLGS.cpp GDBRemoteCommunicationServerPlatform.cpp GDBRemoteRegisterContext.cpp + GDBRemoteRegisterContext_aarch64.cpp GDBRemoteRegisterContext_x86.cpp ProcessGDBRemote.cpp ProcessGDBRemoteLog.cpp
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits