| Issue |
208888
|
| Summary |
[lldb] DW_OP_bit_piece is rejected for an empty location description
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
firmiana402
|
LLDB rejects `DW_OP_bit_piece` when it has no preceding location description. [DWARF v5 Section 2.6.1.2](https://dwarfstd.org/doc/DWARF5.pdf) explicitly defines this case:
> If the location description is empty, the offset doesn't matter and the `DW_OP_bit_piece` operation describes a piece consisting of the given number of bits whose values are undefined.
LLVM's [location-description stack extension](https://llvm.org/docs/AMDGPUDwarfExtensionAllowLocationDescriptionOnTheDwarfExpressionStack/AMDGPUDwarfExtensionAllowLocationDescriptionOnTheDwarfExpressionStack.html) preserves the same rule by defining `DW_OP_bit_piece` to have the same action as `DW_OP_piece`, with size and displacement expressed in bits.
An empty stack therefore denotes an empty preceding location description for this composition operation; it is not an operand-underflow error.
## Minimal Case
```text
DW_OP_bit_piece 8, 0
```
This describes an undefined 8-bit fragment. GDB accepts it and records an optimized-out piece. LLDB instead rejects it with:
```text
_expression_ stack needs at least 1 item for DW_OP_bit_piece
```
## Equivalent Byte-to-Bit Cases
The same issue appears in a larger composite location:
```text
DW_OP_piece 16
DW_OP_const4u 0xffffffff
DW_OP_stack_value
DW_OP_piece 4
DW_OP_piece 28
```
The trailing `DW_OP_piece 28` has no preceding location and therefore describes an unavailable 28-byte fragment. Replacing only that operation with `DW_OP_bit_piece 224, 0` preserves the composite size and every available bit:
```text
DW_OP_piece 16
DW_OP_const4u 0xffffffff
DW_OP_stack_value
DW_OP_piece 4
DW_OP_bit_piece 224, 0 # 224 bits = 28 bytes
```
GDB accepts both forms and describes the final fragment as either an empty 28-byte piece or an empty 224-bit piece. LLDB evaluates the original form, but the equivalent bit-granular form rejects the entire variable location with the error above.
## Source Evidence
In [`DWARFExpression.cpp`](https://github.com/llvm/llvm-project/blob/main/lldb/source/_expression_/DWARFExpression.cpp), the `DW_OP_bit_piece` handler identifies the location as `Empty`, but then returns an error instead of appending an unavailable fragment:
```cpp
case DW_OP_bit_piece:
if (stack.size() < 1) {
UpdateValueTypeFromLocationDescription(
eval_ctx, LocationDescriptionKind::Empty);
eval_ctx.loc_desc_kind = Memory;
return llvm::createStringError(
"_expression_ stack needs at least 1 item for DW_OP_bit_piece");
}
```
The byte-granular `Evaluate_DW_OP_piece` path already treats an empty stack as an unavailable piece and continues composite assembly. Its current zero-filled placeholder does not fully preserve undefined-bit availability, but that is a separate issue #202897; the relevant inconsistency here is that `DW_OP_bit_piece` aborts evaluation for the same empty-location state.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs