llvm / llvm/llvm-project

[LLDB] Shadowed variable printing behavior differs with PDB vs DWARF debug info

Open
#221,696 6 comments 0 reactions 0 assignees View on GitHub
lldb platform:windows
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

LLDB 23.1.0-rc3

Sample program (from Rust test suite):

```rust
fn main() {
let x = false;

zzz(); // #break
sentinel();

{
zzz(); // #break
sentinel();

let x = 10;

zzz(); // #break
sentinel();

{
zzz(); // #break
sentinel();

let x = 10.5f64;

zzz(); // #break
sentinel();
}

zzz(); // #break
sentinel();
}

zzz(); // #break
sentinel();
}

fn zzz() {()}
fn sentinel() {()}

```

When compiled for `windows-gnu` (i.e. DWARF debug info) printing `x` at each of the labelled breakpoints yields the following:

```
v x
(bool) x = false
c
...
v x
(bool) x = false
c
...
v x
(int) x = 10
c
...
v x
(int) x = 10
c
...
v x
(double) x = 10.5
c
...
v x
(int) x = 10
c
...
v x
(bool) x = false
```

When compiled for `windows-msvc`, each print yields `(bool) x = false`

LLDB-DAP is able to recognize the shadowed variable and the appropriate scopes for all 3 versions

Image

but `v` always seems to choose to print the one in the oldest scope rather than the newest.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the Rust sample under windows-gnu and windows-msvc, stopping at each labelled breakpoint and running `v x`. Compare LLDB's output with LLDB-DAP's recognized shadowed-variable scopes; done means `v x` selects the variable in the innermost active scope consistently across the nested scopes.

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
Active
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.