llvm / llvm/llvm-project

No way to get real x86 register "sp" from an SBValue representing a register set

Open
#212,778 4 comments 0 reactions 0 assignees View on GitHub
lldb
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

No intended way at least.

Set 0 is general purpose registers:
```
(lldb) script
Python Interactive Interpreter. To exit, type 'quit()', 'exit()' or Ctrl-D.
>>> lldb.frame.GetRegisters()[0]
General Purpose Registers = {
rax = 0x0000555555555129
rbx = 0x0000000000000000
rcx = 0x0000555555557df8
rdx = 0x00007fffffffdbd8
rdi = 0x0000000000000001
rsi = 0x00007fffffffdbc8
rbp = 0x00007fffffffdab0
rsp = 0x00007fffffffdab0
}
```
"rsp" is at index 7, but so is "sp". Where "sp" means the ABI register name, which due to code in `RegisterContext::GetRegisterInfoByName` is converted to "rsp" before lookup.
```
>>> lldb.frame.GetRegisters()[0].GetIndexOfChildWithName("rsp")
7
>>> lldb.frame.GetRegisters()[0].GetIndexOfChildWithName("sp")
7
```
The "real" "sp" is at a different index:
```
>>> lldb.frame.GetRegisters()[0].GetChildAtIndex(49)
(unsigned short) sp = 0xdab0
```

You can work around this by taking advantage of the fact that the name conversion is not case sensitive:
```
>>> lldb.frame.GetRegisters()[0].GetIndexOfChildWithName("sP")
49
```
`sp` is converted to `rsp`, but `sP` is not, is then lower cased, and `sp` is found.

But this in itself is a bug.

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue with the LLDB Python commands in the report, then inspect RegisterContext::GetRegisterInfoByName and the register-set child-name lookup it affects. Done means the ABI name "sp" and the real register named "sp" can be addressed distinctly without relying on case variation, with regression coverage for the reported lookups.

Written by the indexing model from the issue text.

Assessment

Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.