llvm / llvm/llvm-project

[LLDB] silently allows a malformed DWARF expression, uses DW_OP_reg for DWARF expressions

Open
#221,613 2 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

Per the manual (https://dwarfstd.org/doc/DWARF5.pdf):

Image

DW_OP_reg can only be used in a simple location description, not in a dwarf expression. However, LLDB allows it in a dwarf expression:

https://github.com/llvm/llvm-project/blob/067b6d90b64e8f43c9a2388530b7f98911d77421/lldb/source/Expression/DWARFExpression.cpp#L1959-L1967

It should show an appropriate error when it encounters such malformed dwarf.

### Example

```cpp
#include
#include

void thrower() {
throw 1lu;
}

void middle() {
__asm__(".cfi_escape 0x16, 0x03, 0x03, 0x53, 0x32, 0x24");
thrower();
}

int main() {
try {
middle();
} catch (uint64_t i) {
uint64_t rbx;
__asm__("mov %%rbx, %0" : "=r"(rbx));
std::cout << "RBX: " << rbx << std::endl;
}
}
```
Compile with:
```bash
clang++ -g -o main main.cpp
```

Run:
```
$ lldb main --batch -o "b thrower" -o "run" -o "up" -o "up" -o 'expr $rbx'
(lldb) expr $rbx
(unsigned long) $0 = 0
```

Comparatively, GDB shows the error:
```
$ gdb main --batch -nx -ex "b thrower" -ex "run" -ex "up" -ex "up" -ex 'p $rbx'
DWARF-2 expression error: `DW_OP_reg' operations must be used either alone or in conjunction with DW_OP_piece or DW_OP_bit_piece.
```

Contributor guide

Open the contributing guide

Research direction

Start with the linked handling in lldb/source/Expression/DWARFExpression.cpp at lines 1959-1967, then reproduce the behavior using the supplied C++ example and LLDB batch commands. Done means malformed DWARF using DW_OP_reg in an expression is rejected with an appropriate error instead of evaluating as zero.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.