RichManglingContextTest.cpp
4.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
//===-- RichManglingContextTest.cpp -----------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "lldb/Core/RichManglingContext.h"
#include "lldb/Utility/ConstString.h"
#include "gtest/gtest.h"
using namespace lldb;
using namespace lldb_private;
TEST(RichManglingContextTest, Basic) {
RichManglingContext RMC;
ConstString mangled("_ZN3foo3barEv");
EXPECT_TRUE(RMC.FromItaniumName(mangled));
EXPECT_TRUE(RMC.IsFunction());
EXPECT_FALSE(RMC.IsCtorOrDtor());
RMC.ParseFunctionDeclContextName();
EXPECT_EQ("foo", RMC.GetBufferRef());
RMC.ParseFunctionBaseName();
EXPECT_EQ("bar", RMC.GetBufferRef());
RMC.ParseFullName();
EXPECT_EQ("foo::bar()", RMC.GetBufferRef());
}
TEST(RichManglingContextTest, FromCxxMethodName) {
RichManglingContext ItaniumRMC;
ConstString mangled("_ZN3foo3barEv");
EXPECT_TRUE(ItaniumRMC.FromItaniumName(mangled));
RichManglingContext CxxMethodRMC;
ConstString demangled("foo::bar()");
EXPECT_TRUE(CxxMethodRMC.FromCxxMethodName(demangled));
EXPECT_TRUE(ItaniumRMC.IsFunction() == CxxMethodRMC.IsFunction());
EXPECT_TRUE(ItaniumRMC.IsCtorOrDtor() == CxxMethodRMC.IsCtorOrDtor());
ItaniumRMC.ParseFunctionDeclContextName();
CxxMethodRMC.ParseFunctionDeclContextName();
EXPECT_TRUE(ItaniumRMC.GetBufferRef() == CxxMethodRMC.GetBufferRef());
ItaniumRMC.ParseFunctionBaseName();
CxxMethodRMC.ParseFunctionBaseName();
EXPECT_TRUE(ItaniumRMC.GetBufferRef() == CxxMethodRMC.GetBufferRef());
ItaniumRMC.ParseFullName();
CxxMethodRMC.ParseFullName();
EXPECT_TRUE(ItaniumRMC.GetBufferRef() == CxxMethodRMC.GetBufferRef());
// Construct with a random name.
{
RichManglingContext CxxMethodRMC;
EXPECT_TRUE(CxxMethodRMC.FromCxxMethodName(ConstString("X")));
// We expect it is not a function.
EXPECT_FALSE(CxxMethodRMC.IsFunction());
}
// Construct with a function without a context.
{
RichManglingContext CxxMethodRMC;
EXPECT_TRUE(CxxMethodRMC.FromCxxMethodName(
ConstString("void * operator new(unsigned __int64)")));
// We expect it is a function.
EXPECT_TRUE(CxxMethodRMC.IsFunction());
// We expect its context is empty.
CxxMethodRMC.ParseFunctionDeclContextName();
EXPECT_TRUE(CxxMethodRMC.GetBufferRef().empty());
}
}
TEST(RichManglingContextTest, SwitchProvider) {
RichManglingContext RMC;
llvm::StringRef mangled = "_ZN3foo3barEv";
llvm::StringRef demangled = "foo::bar()";
EXPECT_TRUE(RMC.FromItaniumName(ConstString(mangled)));
RMC.ParseFullName();
EXPECT_EQ("foo::bar()", RMC.GetBufferRef());
EXPECT_TRUE(RMC.FromCxxMethodName(ConstString(demangled)));
RMC.ParseFullName();
EXPECT_EQ("foo::bar()", RMC.GetBufferRef());
EXPECT_TRUE(RMC.FromItaniumName(ConstString(mangled)));
RMC.ParseFullName();
EXPECT_EQ("foo::bar()", RMC.GetBufferRef());
}
TEST(RichManglingContextTest, IPDRealloc) {
// The demangled name should fit into the Itanium default buffer.
const char *ShortMangled = "_ZN3foo3barEv";
// The demangled name for this will certainly not fit into the default buffer.
const char *LongMangled =
"_ZNK3shk6detail17CallbackPublisherIZNS_5ThrowERKNSt15__exception_"
"ptr13exception_ptrEEUlOT_E_E9SubscribeINS0_9ConcatMapINS0_"
"18CallbackSubscriberIZNS_6GetAllIiNS1_IZZNS_9ConcatMapIZNS_6ConcatIJNS1_"
"IZZNS_3MapIZZNS_7IfEmptyIS9_EEDaS7_ENKUlS6_E_clINS1_IZZNS_4TakeIiEESI_"
"S7_ENKUlS6_E_clINS1_IZZNS_6FilterIZNS_9ElementAtEmEUlS7_E_EESI_S7_"
"ENKUlS6_E_clINS1_IZZNSL_ImEESI_S7_ENKUlS6_E_clINS1_IZNS_4FromINS0_"
"22InfiniteRangeContainerIiEEEESI_S7_EUlS7_E_EEEESI_S6_EUlS7_E_EEEESI_S6_"
"EUlS7_E_EEEESI_S6_EUlS7_E_EEEESI_S6_EUlS7_E_EESI_S7_ENKUlS6_E_clIS14_"
"EESI_S6_EUlS7_E_EERNS1_IZZNSH_IS9_EESI_S7_ENKSK_IS14_EESI_S6_EUlS7_E0_"
"EEEEESI_DpOT_EUlS7_E_EESI_S7_ENKUlS6_E_clINS1_IZNS_5StartIJZNS_"
"4JustIJS19_S1C_EEESI_S1F_EUlvE_ZNS1K_IJS19_S1C_EEESI_S1F_EUlvE0_EEESI_"
"S1F_EUlS7_E_EEEESI_S6_EUlS7_E_EEEESt6vectorIS6_SaIS6_EERKT0_NS_"
"12ElementCountEbEUlS7_E_ZNSD_IiS1Q_EES1T_S1W_S1X_bEUlOS3_E_ZNSD_IiS1Q_"
"EES1T_S1W_S1X_bEUlvE_EES1G_S1O_E25ConcatMapValuesSubscriberEEEDaS7_";
RichManglingContext RMC;
// Demangle the short one.
EXPECT_TRUE(RMC.FromItaniumName(ConstString(ShortMangled)));
RMC.ParseFullName();
const char *ShortDemangled = RMC.GetBufferRef().data();
// Demangle the long one.
EXPECT_TRUE(RMC.FromItaniumName(ConstString(LongMangled)));
RMC.ParseFullName();
const char *LongDemangled = RMC.GetBufferRef().data();
// Make sure a new buffer was allocated or the default buffer was extended.
bool AllocatedNewBuffer = (ShortDemangled != LongDemangled);
bool ExtendedExistingBuffer = (strlen(LongDemangled) > 2048);
EXPECT_TRUE(AllocatedNewBuffer || ExtendedExistingBuffer);
}