[Lldb-commits] [PATCH] D50473: [Demangle] Add another test for ItaniumPartialDemangler
Stefan Gränitz via Phabricator via lldb-commits
lldb-commits at lists.llvm.org
Wed Aug 8 13:46:19 PDT 2018
sgraenitz created this revision.
sgraenitz added a reviewer: erik.pilkington.
Herald added a subscriber: llvm-commits.
Show the behavior of print operations in the ItaniumPartialDemangler. It's a summary of what the current integration in LLDB assumes. For new users this may be a useful example.
Repository:
rL LLVM
https://reviews.llvm.org/D50473
Files:
unittests/Demangle/PartialDemangleTest.cpp
Index: unittests/Demangle/PartialDemangleTest.cpp
===================================================================
--- unittests/Demangle/PartialDemangleTest.cpp
+++ unittests/Demangle/PartialDemangleTest.cpp
@@ -145,5 +145,50 @@
EXPECT_TRUE(D2.isFunction());
EXPECT_TRUE(D1.partialDemangle("Not a mangled name!"));
+}
+
+TEST(PartialDemanglerTest, TestPrintCases) {
+ llvm::ItaniumPartialDemangler D;
+
+ const size_t OriginalSize = 4;
+ char *Buf = static_cast<char *>(std::malloc(OriginalSize));
+ const char *OriginalBuf = Buf;
+
+ // Default success case: Result fits into the given buffer.
+ // Res points to Buf. N returns string size including null termination.
+ {
+ EXPECT_FALSE(D.partialDemangle("_ZN1a1bEv"));
+
+ size_t N = OriginalSize;
+ char *Res = D.getFunctionDeclContextName(Buf, &N);
+ EXPECT_STREQ("a", Res);
+ EXPECT_EQ(OriginalBuf, Res);
+ EXPECT_EQ(strlen(Res) + 1, N);
+ }
+ // Realloc success case: Result does not fit into the given buffer.
+ // Res points to the new or extended buffer. N returns string size
+ // including null termination. Buf was extended or freed.
+ {
+ EXPECT_FALSE(D.partialDemangle("_ZN1a1b1cIiiiEEvm"));
+
+ size_t N = OriginalSize;
+ char *Res = D.finishDemangle(Buf, &N);
+ EXPECT_STREQ("void a::b::c<int, int, int>(unsigned long)", Res);
+ EXPECT_EQ(strlen(Res) + 1, N);
+ Buf = Res;
+ }
+
+ // Failure case: a::c is not a function.
+ // Res is nullptr. N remains unchanged.
+ {
+ EXPECT_FALSE(D.partialDemangle("_ZN1a1cE"));
+
+ size_t N = OriginalSize;
+ char *Res = D.getFunctionName(Buf, &N);
+ EXPECT_EQ(nullptr, Res);
+ EXPECT_EQ(OriginalSize, N);
+ }
+
+ std::free(Buf);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D50473.159784.patch
Type: text/x-patch
Size: 1719 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20180808/dbc1b88f/attachment.bin>
More information about the lldb-commits
mailing list