Skip to content

Commit cc3c6d1

Browse files
refactor demangler range tracking
1 parent 7cf2860 commit cc3c6d1

File tree

7 files changed

+33
-10
lines changed

7 files changed

+33
-10
lines changed

lldb/include/lldb/Core/DemangledNameInfo.h

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ struct DemangledNameInfo {
3939
/// \endcode
4040
std::pair<size_t, size_t> ScopeRange;
4141

42-
/// Indicates the [start, end) of the function argument lits.
42+
/// Indicates the [start, end) of the function argument list.
4343
/// E.g.,
4444
/// \code{.cpp}
4545
/// int (*getFunc<float>(float, double))(int, int)
@@ -59,11 +59,27 @@ struct DemangledNameInfo {
5959
/// \endcode
6060
std::pair<size_t, size_t> QualifiersRange;
6161

62+
/// Indicates the [start, end) of the function's prefix. This is a
63+
/// catch-all range for anything that is not tracked by the rest of
64+
/// the pairs.
65+
std::pair<size_t, size_t> PrefixRange;
66+
67+
/// Indicates the [start, end) of the function's suffix. This is a
68+
/// catch-all range for anything that is not tracked by the rest of
69+
/// the pairs.
70+
std::pair<size_t, size_t> SuffixRange;
71+
6272
/// Returns \c true if this object holds a valid basename range.
6373
bool hasBasename() const {
6474
return BasenameRange.second > BasenameRange.first &&
6575
BasenameRange.second > 0;
6676
}
77+
78+
/// Returns \c true if this object holds a valid arguments range.
79+
bool hasArguments() const {
80+
return ArgumentsRange.second > ArgumentsRange.first &&
81+
ArgumentsRange.second > 0;
82+
}
6783
};
6884

6985
/// An OutputBuffer which keeps a record of where certain parts of a

lldb/include/lldb/Core/FormatEntity.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ struct Entry {
8888
FunctionNameWithArgs,
8989
FunctionNameNoArgs,
9090
FunctionMangledName,
91+
FunctionPrefix,
9192
FunctionScope,
9293
FunctionBasename,
9394
FunctionTemplateArguments,

lldb/source/Core/FormatEntity.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ constexpr Definition g_function_child_entries[] = {
124124
Definition("initial-function", EntryType::FunctionInitial),
125125
Definition("changed", EntryType::FunctionChanged),
126126
Definition("is-optimized", EntryType::FunctionIsOptimized),
127+
Definition("prefix", EntryType::FunctionPrefix),
127128
Definition("scope", EntryType::FunctionScope),
128129
Definition("basename", EntryType::FunctionBasename),
129130
Definition("template-arguments", EntryType::FunctionTemplateArguments),
@@ -385,6 +386,7 @@ const char *FormatEntity::Entry::TypeToCString(Type t) {
385386
ENUM_TO_CSTR(FunctionNameWithArgs);
386387
ENUM_TO_CSTR(FunctionNameNoArgs);
387388
ENUM_TO_CSTR(FunctionMangledName);
389+
ENUM_TO_CSTR(FunctionPrefix);
388390
ENUM_TO_CSTR(FunctionScope);
389391
ENUM_TO_CSTR(FunctionBasename);
390392
ENUM_TO_CSTR(FunctionTemplateArguments);
@@ -1835,6 +1837,7 @@ bool FormatEntity::Format(const Entry &entry, Stream &s,
18351837
return true;
18361838
}
18371839

1840+
case Entry::Type::FunctionPrefix:
18381841
case Entry::Type::FunctionScope:
18391842
case Entry::Type::FunctionBasename:
18401843
case Entry::Type::FunctionTemplateArguments:

lldb/source/Core/Mangled.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ GetItaniumDemangledStr(const char *M) {
172172

173173
TrackingOutputBuffer OB(demangled_cstr, demangled_size);
174174
demangled_cstr = ipd.finishDemangle(&OB);
175+
OB.NameInfo.SuffixRange.first = OB.NameInfo.QualifiersRange.second;
176+
OB.NameInfo.SuffixRange.second = std::string(demangled_cstr).length();
175177
info = std::move(OB.NameInfo);
176178

177179
assert(demangled_cstr &&

lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,8 +401,8 @@ GetDemangledFunctionSuffix(const SymbolContext &sc) {
401401
if (!info->hasBasename())
402402
return std::nullopt;
403403

404-
return demangled_name.slice(info->QualifiersRange.second,
405-
llvm::StringRef::npos);
404+
return demangled_name.slice(info->SuffixRange.first,
405+
info->SuffixRange.second);
406406
}
407407

408408
static bool PrintDemangledArgumentList(Stream &s, const SymbolContext &sc) {

lldb/unittests/Core/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ add_lldb_unittest(LLDBCoreTests
66
DumpDataExtractorTest.cpp
77
DumpRegisterInfoTest.cpp
88
FormatEntityTest.cpp
9-
MangledTest.cpp
9+
ItaniumMangledTest.cpp
1010
ModuleSpecTest.cpp
1111
PluginManagerTest.cpp
1212
ProgressReportTest.cpp

lldb/unittests/Core/MangledTest.cpp renamed to lldb/unittests/Core/ItaniumMangledTest.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===-- MangledTest.cpp ---------------------------------------------------===//
1+
//===-- ItaniumMangledTest.cpp --------------------------------------------===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
@@ -401,7 +401,7 @@ TEST(MangledTest, DemangledNameInfo_SetValue) {
401401
EXPECT_FALSE(mangled.GetDemangledInfo()->hasBasename());
402402
}
403403

404-
struct DemanglingPartsTestCase {
404+
struct ItaniumDemanglingPartsTestCase {
405405
const char *mangled;
406406
DemangledNameInfo expected_info;
407407
std::string_view basename;
@@ -410,7 +410,7 @@ struct DemanglingPartsTestCase {
410410
bool valid_basename = true;
411411
};
412412

413-
DemanglingPartsTestCase g_demangling_parts_test_cases[] = {
413+
ItaniumDemanglingPartsTestCase g_demangling_itanium_parts_test_cases[] = {
414414
// clang-format off
415415
{ "_ZNVKO3BarIN2ns3QuxIiEEE1CIPFi3FooIS_IiES6_EEE6methodIS6_EENS5_IT_SC_E5InnerIiEESD_SD_",
416416
{ /*.BasenameRange=*/{92, 98}, /*.ScopeRange=*/{36, 92}, /*.ArgumentsRange=*/{ 108, 158 },
@@ -555,7 +555,7 @@ DemanglingPartsTestCase g_demangling_parts_test_cases[] = {
555555
};
556556

557557
struct DemanglingPartsTestFixture
558-
: public ::testing::TestWithParam<DemanglingPartsTestCase> {};
558+
: public ::testing::TestWithParam<ItaniumDemanglingPartsTestCase> {};
559559

560560
namespace {
561561
class TestAllocator {
@@ -608,5 +608,6 @@ TEST_P(DemanglingPartsTestFixture, DemanglingParts) {
608608
std::free(OB.getBuffer());
609609
}
610610

611-
INSTANTIATE_TEST_SUITE_P(DemanglingPartsTests, DemanglingPartsTestFixture,
612-
::testing::ValuesIn(g_demangling_parts_test_cases));
611+
INSTANTIATE_TEST_SUITE_P(
612+
DemanglingPartsTests, DemanglingPartsTestFixture,
613+
::testing::ValuesIn(g_demangling_itanium_parts_test_cases));

0 commit comments

Comments
 (0)