Skip to content

Commit 47d5754

Browse files
committed
[lldb] [Process/gdb-remote] Alias sp to x31 on AArch64 for gdbserver
Alias the "sp" register to "x31" on AArch64 if one is present and does not have the alt_name. This is the case when connecting to gdbserver. Differential Revision: https://reviews.llvm.org/D109695
1 parent 1ef62cb commit 47d5754

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

lldb/source/Plugins/ABI/AArch64/ABIAArch64.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ std::string ABIAArch64::GetMCName(std::string reg) {
5252
MapRegisterName(reg, "x30", "lr");
5353
return reg;
5454
}
55+
5556
uint32_t ABIAArch64::GetGenericNum(llvm::StringRef name) {
5657
return llvm::StringSwitch<uint32_t>(name)
5758
.Case("pc", LLDB_REGNUM_GENERIC_PC)
@@ -69,3 +70,11 @@ uint32_t ABIAArch64::GetGenericNum(llvm::StringRef name) {
6970
.Case("x7", LLDB_REGNUM_GENERIC_ARG8)
7071
.Default(LLDB_INVALID_REGNUM);
7172
}
73+
74+
void ABIAArch64::AugmentRegisterInfo(lldb_private::RegisterInfo &info) {
75+
lldb_private::MCBasedABI::AugmentRegisterInfo(info);
76+
77+
// GDB sends x31 as "sp". Add the "x31" alt_name for convenience.
78+
if (!strcmp(info.name, "sp") && !info.alt_name)
79+
info.alt_name = "x31";
80+
}

lldb/source/Plugins/ABI/AArch64/ABIAArch64.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ class ABIAArch64: public lldb_private::MCBasedABI {
3131

3232
uint32_t GetGenericNum(llvm::StringRef name) override;
3333

34+
void AugmentRegisterInfo(lldb_private::RegisterInfo &info) override;
35+
3436
using lldb_private::MCBasedABI::MCBasedABI;
3537
};
3638
#endif

lldb/test/API/functionalities/gdb_remote_client/TestGDBServerTargetXML.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,12 @@ def haltReason(self):
397397
["x0 = 0x0807060504030201"])
398398
self.match("register read x1",
399399
["x1 = 0x1817161514131211"])
400+
self.match("register read x29",
401+
["x29 = 0x3837363534333231"])
402+
self.match("register read x30",
403+
["x30 = 0x4847464544434241"])
404+
self.match("register read x31",
405+
["sp = 0x5857565554535251"])
400406
self.match("register read sp",
401407
["sp = 0x5857565554535251"])
402408
self.match("register read pc",

0 commit comments

Comments
 (0)