[lldb] lldb evaluates generic DW_OP_abs and DW_OP_shra with the wrong signedness
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
This is related to a previously reported LLDB `DW_OP_mod` issue: #207015
The common pattern is that LLDB appears to let the incidental signedness stored in its internal scalar value influence DWARF generic-operand evaluation. For some opcodes, this does not change the final bit pattern, but it does change the result for at least `DW_OP_abs` and `DW_OP_shra`.
[DWARF v5](https://dwarfstd.org/doc/DWARF5.pdf) Section 2.5.1.4 gives these operations explicit signed semantics:
- `DW_OP_abs` interprets the top stack entry as a signed value before taking the absolute value.
- `DW_OP_shra` performs an arithmetic right shift, keeping the sign of the shifted value.
GDB evaluates the examples below according to those rules. LLDB does not.
## Minimal Examples
### DW_OP_abs
```text
DW_OP_const8u 0xffffffffffffffff
DW_OP_abs
DW_OP_stack_value
```
On a 64-bit target, the correct `DW_OP_abs` interpretation is signed:
```text
DW_OP_const8u 0xffffffffffffffff -> generic all-ones value
DW_OP_abs -> abs(-1) = 1
```
- Expected result: `1`
- GDB result: `1`
- LLDB result: `-1`
LLDB instead keeps the value as unsigned all-ones:
```text
abs(UINT64_MAX) = UINT64_MAX
```
If that final all-ones value is later materialized and printed as a signed source-level integer, it is displayed as `-1` instead of `1`.
### DW_OP_shra
```text
DW_OP_const8u 0xffffffffffffffff
DW_OP_const1u 63
DW_OP_shra
DW_OP_stack_value
```
On a 64-bit target, the shifted value should be interpreted as signed `-1`:
```text
DW_OP_const8u 0xffffffffffffffff -> generic all-ones value
DW_OP_const1u 63
DW_OP_shra -> -1 >> 63 = -1
```
- Expected result: `-1`
- GDB result: `-1`
- LLDB result: `1`
LLDB instead behaves as if it shifted the value unsigned:
```text
UINT64_MAX >> 63 = 1
```
So LLDB returns `1` instead of `-1`.
Contributor guide
Research direction
Start by reproducing the two minimal DW_OP_abs and DW_OP_shra examples in LLDB and compare their results with the DWARF v5 rules and GDB. Trace LLDB's generic DWARF-operand evaluation and internal scalar signedness; the work is done when both examples produce 1 and -1 respectively.
Written by the indexing model from the issue text.
Assessment
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 50/100