[lldb] Cannot evaluate the value of a static local variable of an optimized-out inlined function.
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
After https://github.com/llvm/llvm-project/pull/159104, if a function is optimized-out, DIEs for static local variables referenced from the function's inlined instance go to the function's abstract DIE. gdb can discover such variables, but lldb cannot, apparently.
Example source file:
```
➜ cat ../test-static-local.cpp
__attribute__((always_inline))
static int foo() {
static int x = 35;
int y = 25;
return x;
}
int main() {
foo();
return foo();
}
➜ bin/clang ../test-static-local.cpp -g -o test-static-local -O0
```
LLDB and gdb behavior:
```
➜ bin/lldb test-static-local
(lldb) b foo
Breakpoint 1: 2 locations.
(lldb) r
Process 38232 launched: '/home/parallels/llvm/build/native/test-static-local' (aarch64)
Process 38232 stopped
* thread #1, name = 'test-static-loc', stop reason = breakpoint 1.1
frame #0: 0x0000aaaaaaaa06f4 test-static-local`foo() at test-static-local.cpp:4:9 [inlined]
-> 4 int y = 25;
(lldb) p y
(int) 4980991
(lldb) p x
˄
╰─ error: use of undeclared identifier 'x'
(lldb) q
➜ gdb test-static-local
GNU gdb (Ubuntu 16.2-8ubuntu1) 16.2
(gdb) b foo
Breakpoint 1 at 0x6f4: foo. (2 locations)
(gdb) r
Breakpoint 1.1, foo () at ../test-static-local.cpp:4
4 int y = 25;
(gdb) p x
$1 = 35
(gdb) p y
$2 = 5701887
```
Dwarfdump: https://gist.github.com/dzhidzhoev/b4ca1d74014b25642de6621fb677c35b
Contributor guide
Research direction
Reproduce the issue with test-static-local.cpp using clang -g -O0, then compare LLDB and gdb at the inlined foo breakpoint. Inspect the linked DWARF dump to understand where the static local variable DIE is attached. Done means LLDB can evaluate x and report 35, matching gdb.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100