Author: jdevlieghere Date: Wed Jul 31 10:58:00 2019 New Revision: 367455 URL: http://llvm.org/viewvc/llvm-project?rev=367455&view=rev Log: Fix completion for functions in anonymous namespaces
I was going through some of the old bugs and came across PR21069 which I was able to reproduce. The issue is that we match the regex `^foo` against the `DW_AT_name` in the DWARF, which for our anonymous function is indeed `foo`. However, when we get the function name from the symbol context, the result is `(anonymous namespace)::foo()`. This throws off completions, which assumes that it's appending to whatever is already present on the input, resulting in a bogus `b fooonymous\ namespace)::foo()`. Bug report: https://llvm.org/PR21069 Differential revision: https://reviews.llvm.org/D65498 Modified: lldb/trunk/packages/Python/lldbsuite/test/functionalities/completion/TestCompletion.py lldb/trunk/packages/Python/lldbsuite/test/functionalities/completion/main.cpp lldb/trunk/source/Commands/CommandCompletions.cpp Modified: lldb/trunk/packages/Python/lldbsuite/test/functionalities/completion/TestCompletion.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/functionalities/completion/TestCompletion.py?rev=367455&r1=367454&r2=367455&view=diff ============================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/completion/TestCompletion.py (original) +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/completion/TestCompletion.py Wed Jul 31 10:58:00 2019 @@ -297,3 +297,6 @@ class CommandLineCompletionTestCase(Test self.complete_from_to('breakpoint set -n Fo', 'breakpoint set -n Foo::Bar(int,\\ int)', turn_off_re_match=True) + # No completion for Qu because the candidate is + # (anonymous namespace)::Quux(). + self.complete_from_to('breakpoint set -n Qu', '') Modified: lldb/trunk/packages/Python/lldbsuite/test/functionalities/completion/main.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/functionalities/completion/main.cpp?rev=367455&r1=367454&r2=367455&view=diff ============================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/completion/main.cpp (original) +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/completion/main.cpp Wed Jul 31 10:58:00 2019 @@ -7,6 +7,8 @@ public: } }; +namespace { int Quux (void) { return 0; } } + struct Container { int MemberVar; }; int main() @@ -17,5 +19,6 @@ int main() Container container; Container *ptr_container = &container; + int q = Quux(); return container.MemberVar = 3; // Break here } Modified: lldb/trunk/source/Commands/CommandCompletions.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandCompletions.cpp?rev=367455&r1=367454&r2=367455&view=diff ============================================================================== --- lldb/trunk/source/Commands/CommandCompletions.cpp (original) +++ lldb/trunk/source/Commands/CommandCompletions.cpp Wed Jul 31 10:58:00 2019 @@ -471,7 +471,11 @@ Searcher::CallbackReturn CommandCompleti for (uint32_t i = 0; i < sc_list.GetSize(); i++) { if (sc_list.GetContextAtIndex(i, sc)) { ConstString func_name = sc.GetFunctionName(Mangled::ePreferDemangled); - if (!func_name.IsEmpty()) + // Ensure that the function name matches the regex. This is more than a + // sanity check. It is possible that the demangled function name does + // not start with the prefix, for example when it's in an anonymous + // namespace. + if (!func_name.IsEmpty() && m_regex.Execute(func_name.GetStringRef())) m_match_set.insert(func_name); } } _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits