llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
27.61k stars 11.35k forks source link

LLDB typedefs are too lazy #91186

Open labath opened 3 months ago

labath commented 3 months ago
$ cat /tmp/a.cc
struct X {
  typedef int InX;
};

X a;
X::InX b;

int main() {
  return b;
}
$ g++ /tmp/a.cc -g -o /tmp/a.out
$ bin/lldb /tmp/a.out
(lldb) target create "/tmp/a.out"
Current executable set to '/tmp/a.out' (x86_64).
(lldb) expr -- X::InX a; a
error: <user expression 0>:1:4: no member named 'InX' in 'X'
    1 | X::InX a; a
      | ~~~^
(lldb) expr b
(X::InX) $0 = 0
(lldb) expr -- X::InX a; a
(X::InX) $1 = 0

This happens because lldb does not construct the clang ast type (only lldb_private::Type) when parsing the dwarf. The clang ast is contructed only when something references the lldb_private::Type -- which can sometimes be too late. Also see #90958 for another issue with lazy typedef parsing (however, unlike this issue, I know how to work around the other one).

llvmbot commented 3 months ago

@llvm/issue-subscribers-lldb

Author: Pavel Labath (labath)

``` $ cat /tmp/a.cc struct X { typedef int InX; }; X a; X::InX b; int main() { return b; } $ g++ /tmp/a.cc -g -o /tmp/a.out $ bin/lldb /tmp/a.out (lldb) target create "/tmp/a.out" Current executable set to '/tmp/a.out' (x86_64). (lldb) expr -- X::InX a; a error: <user expression 0>:1:4: no member named 'InX' in 'X' 1 | X::InX a; a | ~~~^ (lldb) expr b (X::InX) $0 = 0 (lldb) expr -- X::InX a; a (X::InX) $1 = 0 ``` This happens because lldb does not construct the clang ast type (only lldb_private::Type) when parsing the dwarf. The clang ast is contructed only when something references the lldb_private::Type -- which can sometimes be too late. Also see #90958 for another issue with lazy typedef parsing (however, unlike this issue, I know how to work around the other one).