[all-commits] [llvm/llvm-project] 6cdfa2: [lldb][ClangExpression] Filter out non-root namesp...

Michael Buch via All-commits all-commits at lists.llvm.org
Fri Apr 14 09:12:30 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 6cdfa295743729178ff6f15a8dcd36f8f7d27c2c
      https://github.com/llvm/llvm-project/commit/6cdfa295743729178ff6f15a8dcd36f8f7d27c2c
  Author: Michael Buch <michaelbuch12 at gmail.com>
  Date:   2023-04-14 (Fri, 14 Apr 2023)

  Changed paths:
    M lldb/include/lldb/Symbol/SymbolFile.h
    M lldb/include/lldb/Symbol/SymbolFileOnDemand.h
    M lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
    M lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.h
    M lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
    M lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
    M lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
    M lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h
    M lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
    M lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.h
    M lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp
    M lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.h
    M lldb/source/Symbol/SymbolFileOnDemand.cpp
    M lldb/test/API/lang/cpp/namespace/TestNamespace.py
    M lldb/test/API/lang/cpp/namespace/main.cpp

  Log Message:
  -----------
  [lldb][ClangExpression] Filter out non-root namespaces in FindNamespace

**Summary**

In a program such as:
```
namespace A {
namespace B {
struct Bar {};
}
}

namespace B {
struct Foo {};
}
```
...LLDB would run into issues such as:
```
(lldb) expr ::B::Foo f
error: expression failed to parse:
error: <user expression 0>:1:6: no type named 'Foo' in namespace 'A::B'
::B::Foo f
~~~~~^
```

This is because the `SymbolFileDWARF::FindNamespace` implementation
will return *any* namespace it finds if the `parent_decl_ctx` provided
is empty. In `FindExternalVisibleDecls` we use this API to find the
namespace that symbol `B` refers to. If `A::B` happened to be the one
that `SymbolFileDWARF::FindNamespace` looked at first, we would try
to find `struct Foo` in `A::B`. Hence the error.

This patch proposes a new `SymbolFileDWARF::FindNamespace` API that
will only find a match for top-level namespaces, which is what
`FindExternalVisibleDecls` is attempting anyway; it just never
accounted for multiple namespaces of the same name.

**Testing**

* Added API test-case

Differential Revision: https://reviews.llvm.org/D147436




More information about the All-commits mailing list