diff --git a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp index 4b66ff814935a..a3624accf9b5a 100644 --- a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp +++ b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp @@ -208,6 +208,20 @@ static bool IsTrivialBasename(const llvm::StringRef &basename) { return idx == basename.size(); } +/// A context is trivial if an only if it matches this pattern. +/// "^\s*([A-Za-z_:]*)\s*$". for example function `foo::bar::func()` +/// has a trivial context but. but `foo::bar::func()` doesn't. +static bool IsTrivialContext(llvm::StringRef context) { + // remove trailing or leading whitespace. + context = context.trim(); + + const auto iter = context.find_if_not([](char current) { + return std::isalnum(static_cast(current)) || + current == '_' || current == ':'; + }); + return iter == llvm::StringRef::npos; +} + /// Writes out the function name in 'full_name' to 'out_stream' /// but replaces each argument type with the variable name /// and the corresponding pretty-printed value @@ -481,18 +495,17 @@ bool CPlusPlusLanguage::CxxMethodName::TrySimplifiedParse() { m_basename = full.substr(basename_begin, basename_end - basename_begin); } - if (IsTrivialBasename(m_basename)) { + if (IsTrivialBasename(m_basename) && IsTrivialContext(m_context)) { return true; - } else { - // The C++ basename doesn't match our regular expressions so this can't - // be a valid C++ method, clear everything out and indicate an error - m_context = llvm::StringRef(); - m_basename = llvm::StringRef(); - m_arguments = llvm::StringRef(); - m_qualifiers = llvm::StringRef(); - m_return_type = llvm::StringRef(); - return false; } + // The C++ basename doesn't match our regular expressions so this can't + // be a valid C++ method, clear everything out and indicate an error + m_context = llvm::StringRef(); + m_basename = llvm::StringRef(); + m_arguments = llvm::StringRef(); + m_qualifiers = llvm::StringRef(); + m_return_type = llvm::StringRef(); + return false; } return false; } diff --git a/lldb/unittests/Language/CPlusPlus/CPlusPlusLanguageTest.cpp b/lldb/unittests/Language/CPlusPlus/CPlusPlusLanguageTest.cpp index 23f2f4218601a..c05418168e62e 100644 --- a/lldb/unittests/Language/CPlusPlus/CPlusPlusLanguageTest.cpp +++ b/lldb/unittests/Language/CPlusPlus/CPlusPlusLanguageTest.cpp @@ -30,6 +30,10 @@ TEST(CPlusPlusLanguage, MethodNameParsing) { {"foo::~bar(baz)", "", "foo", "~bar", "(baz)", "", "foo::~bar"}, {"a::b::c::d(e,f)", "", "a::b::c", "d", "(e,f)", "", "a::b::c::d"}, {"void f(int)", "void", "", "f", "(int)", "", "f"}, + {"std::vectorfoo::bar()", "std::vector", "foo", "bar", "()", "", + "foo::bar"}, + {"int foo::bar::func01(int a, double b)", "int", "foo::bar", "func01", + "(int a, double b)", "", "foo::bar::func01"}, // Operators {"std::basic_ostream >& " @@ -101,6 +105,8 @@ TEST(CPlusPlusLanguage, MethodNameParsing) { "std::forward"}, // Templates + {"vector foo::bar::func(int)", "vector", "foo::bar", "func", + "(int)", "", "foo::bar::func"}, {"void llvm::PM>::" "addPass(llvm::VP)", "void", "llvm::PM>",