[Lldb-commits] [lldb] r279038 - Fix parsing of complicated C++ names
Pavel Labath via lldb-commits
lldb-commits at lists.llvm.org
Thu Aug 18 01:21:39 PDT 2016
Author: labath
Date: Thu Aug 18 03:21:38 2016
New Revision: 279038
URL: http://llvm.org/viewvc/llvm-project?rev=279038&view=rev
Log:
Fix parsing of complicated C++ names
Summary:
CPlusPlusLanguage::MethodName was not correctly parsing templated functions whose demangled name
included the return type -- the space before the function name was included in the "context" and
the context itself was not terminated correctly due to a misuse of the substr function (second
argument is length, not the end position). Fix that and add a regression test.
Reviewers: clayborg
Subscribers: lldb-commits
Differential Revision: https://reviews.llvm.org/D23608
Added:
lldb/trunk/unittests/Language/
lldb/trunk/unittests/Language/CMakeLists.txt
lldb/trunk/unittests/Language/CPlusPlus/
lldb/trunk/unittests/Language/CPlusPlus/CMakeLists.txt
lldb/trunk/unittests/Language/CPlusPlus/CPlusPlusLanguageTest.cpp
Modified:
lldb/trunk/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
lldb/trunk/unittests/CMakeLists.txt
Modified: lldb/trunk/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp?rev=279038&r1=279037&r2=279038&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp (original)
+++ lldb/trunk/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp Thu Aug 18 03:21:38 2016
@@ -220,6 +220,8 @@ CPlusPlusLanguage::MethodName::Parse()
context_start = full.rfind(' ', template_start);
if (context_start == llvm::StringRef::npos)
context_start = 0;
+ else
+ ++context_start;
context_end = full.rfind(':', template_start);
if (context_end == llvm::StringRef::npos || context_end < context_start)
@@ -240,7 +242,7 @@ CPlusPlusLanguage::MethodName::Parse()
else
{
if (context_start < context_end)
- m_context = full.substr(context_start, context_end - 1);
+ m_context = full.substr(context_start, context_end - 1 - context_start);
const size_t basename_begin = context_end + 1;
m_basename = full.substr(basename_begin, basename_end - basename_begin);
}
Modified: lldb/trunk/unittests/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/CMakeLists.txt?rev=279038&r1=279037&r2=279038&view=diff
==============================================================================
--- lldb/trunk/unittests/CMakeLists.txt (original)
+++ lldb/trunk/unittests/CMakeLists.txt Thu Aug 18 03:21:38 2016
@@ -43,6 +43,7 @@ add_subdirectory(Editline)
add_subdirectory(Expression)
add_subdirectory(Host)
add_subdirectory(Interpreter)
+add_subdirectory(Language)
add_subdirectory(Process)
add_subdirectory(ScriptInterpreter)
add_subdirectory(Symbol)
Added: lldb/trunk/unittests/Language/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Language/CMakeLists.txt?rev=279038&view=auto
==============================================================================
--- lldb/trunk/unittests/Language/CMakeLists.txt (added)
+++ lldb/trunk/unittests/Language/CMakeLists.txt Thu Aug 18 03:21:38 2016
@@ -0,0 +1 @@
+add_subdirectory(CPlusPlus)
Added: lldb/trunk/unittests/Language/CPlusPlus/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Language/CPlusPlus/CMakeLists.txt?rev=279038&view=auto
==============================================================================
--- lldb/trunk/unittests/Language/CPlusPlus/CMakeLists.txt (added)
+++ lldb/trunk/unittests/Language/CPlusPlus/CMakeLists.txt Thu Aug 18 03:21:38 2016
@@ -0,0 +1,3 @@
+add_lldb_unittest(LanguageCPlusPlusTests
+ CPlusPlusLanguageTest.cpp
+ )
Added: lldb/trunk/unittests/Language/CPlusPlus/CPlusPlusLanguageTest.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Language/CPlusPlus/CPlusPlusLanguageTest.cpp?rev=279038&view=auto
==============================================================================
--- lldb/trunk/unittests/Language/CPlusPlus/CPlusPlusLanguageTest.cpp (added)
+++ lldb/trunk/unittests/Language/CPlusPlus/CPlusPlusLanguageTest.cpp Thu Aug 18 03:21:38 2016
@@ -0,0 +1,41 @@
+//===-- CPlusPlusLanguageTest.cpp -------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "gtest/gtest.h"
+
+#include "Plugins/Language/CPlusPlus/CPlusPlusLanguage.h"
+
+using namespace lldb_private;
+
+TEST(CPlusPlusLanguage, MethodName)
+{
+ struct TestCase {
+ std::string input;
+ std::string context, basename, arguments, qualifiers, scope_qualified_name;
+ };
+
+ TestCase test_cases[] = {{"foo::bar(baz)", "foo", "bar", "(baz)", "", "foo::bar"},
+ {"std::basic_ostream<char, std::char_traits<char> >& "
+ "std::operator<<<std::char_traits<char> >"
+ "(std::basic_ostream<char, std::char_traits<char> >&, char const*)",
+ "std", "operator<<<std::char_traits<char> >",
+ "(std::basic_ostream<char, std::char_traits<char> >&, char const*)", "",
+ "std::operator<<<std::char_traits<char> >"}};
+
+ for (const auto &test: test_cases)
+ {
+ CPlusPlusLanguage::MethodName method(ConstString(test.input));
+ EXPECT_TRUE(method.IsValid());
+ EXPECT_EQ(test.context, method.GetContext());
+ EXPECT_EQ(test.basename, method.GetBasename());
+ EXPECT_EQ(test.arguments, method.GetArguments());
+ EXPECT_EQ(test.qualifiers, method.GetQualifiers());
+ EXPECT_EQ(test.scope_qualified_name, method.GetScopeQualifiedName());
+ }
+}
More information about the lldb-commits
mailing list