[Lldb-commits] [PATCH] D147436: [lldb][ClangExpression] Filter out non-root namespaces in FindNamespace

Michael Buch via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Mon Apr 3 07:01:23 PDT 2023


Michael137 created this revision.
Michael137 added reviewers: aprantl, labath.
Herald added a project: All.
Michael137 updated this revision to Diff 510478.
Michael137 added a comment.
Michael137 updated this revision to Diff 510482.
Michael137 edited the summary of this revision.
Michael137 updated this revision to Diff 510489.
Michael137 published this revision for review.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

- Add docs


Michael137 added a comment.

- Merge into single API


Michael137 added a comment.

- Adjust test-case. Add FIXME


**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 flag to `SymbolFileDWARF::FindNamespace`
allows us to only consider top-level namespaces in our search, which is what
`FindExternalVisibleDecls` is attempting anyway; it just never
accounted for multiple namespaces of the same name.

**Testing**

- Added API test-case


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147436

Files:
  lldb/include/lldb/Symbol/SymbolFile.h
  lldb/include/lldb/Symbol/SymbolFileOnDemand.h
  lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
  lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.h
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h
  lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
  lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.h
  lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp
  lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.h
  lldb/source/Symbol/SymbolFileOnDemand.cpp
  lldb/test/API/commands/expression/inline-namespace/TestInlineNamespace.py
  lldb/test/API/lang/cpp/namespace/TestNamespace.py
  lldb/test/API/lang/cpp/namespace/TestNamespaceLookup.py
  lldb/test/API/lang/cpp/namespace/main.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D147436.510489.patch
Type: text/x-patch
Size: 17007 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20230403/c4a0202e/attachment-0001.bin>


More information about the lldb-commits mailing list