[Lldb-commits] [PATCH] D23608: Fix parsing of complicated C++ names
Pavel Labath via lldb-commits
lldb-commits at lists.llvm.org
Wed Aug 17 06:43:45 PDT 2016
labath created this revision.
labath added a reviewer: clayborg.
labath added a subscriber: lldb-commits.
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.
https://reviews.llvm.org/D23608
Files:
source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
unittests/CMakeLists.txt
unittests/Language/CMakeLists.txt
unittests/Language/CPlusPlus/CMakeLists.txt
unittests/Language/CPlusPlus/CPlusPlusLanguageTest.cpp
Index: unittests/Language/CPlusPlus/CPlusPlusLanguageTest.cpp
===================================================================
--- /dev/null
+++ unittests/Language/CPlusPlus/CPlusPlusLanguageTest.cpp
@@ -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());
+ }
+}
Index: unittests/Language/CPlusPlus/CMakeLists.txt
===================================================================
--- /dev/null
+++ unittests/Language/CPlusPlus/CMakeLists.txt
@@ -0,0 +1,3 @@
+add_lldb_unittest(LanguageCPlusPlusTests
+ CPlusPlusLanguageTest.cpp
+ )
Index: unittests/Language/CMakeLists.txt
===================================================================
--- /dev/null
+++ unittests/Language/CMakeLists.txt
@@ -0,0 +1 @@
+add_subdirectory(CPlusPlus)
Index: unittests/CMakeLists.txt
===================================================================
--- unittests/CMakeLists.txt
+++ unittests/CMakeLists.txt
@@ -43,6 +43,7 @@
add_subdirectory(Expression)
add_subdirectory(Host)
add_subdirectory(Interpreter)
+add_subdirectory(Language)
add_subdirectory(Process)
add_subdirectory(ScriptInterpreter)
add_subdirectory(Symbol)
Index: source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
===================================================================
--- source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
+++ source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
@@ -220,6 +220,8 @@
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 @@
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);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D23608.68344.patch
Type: text/x-patch
Size: 4008 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20160817/83355333/attachment-0001.bin>
More information about the lldb-commits
mailing list