Skip to content

Commit b43c39a

Browse files
committed
[Demangle] Add a new function 'demangleGetFunctionName'
1 parent f7c0b21 commit b43c39a

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

llvm/include/llvm/Demangle/Demangle.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ char *dlangDemangle(std::string_view MangledName);
6767
/// demangling occurred.
6868
std::string demangle(std::string_view MangledName);
6969

70+
/// demangle a string to get the function name.
71+
std::string demangleGetFunctionName(std::string_view MangledName);
72+
7073
bool nonMicrosoftDemangle(std::string_view MangledName, std::string &Result);
7174

7275
/// "Partial" demangler. This supports demangling a string into an AST

llvm/lib/Demangle/Demangle.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,20 @@
1717

1818
using llvm::itanium_demangle::starts_with;
1919

20+
/// demangle a string to get the function name.
21+
std::string llvm::demangleGetFunctionName(std::string_view MangledName) {
22+
std::string DemangledStr = llvm::demangle(MangledName);
23+
size_t StartIndex = DemangledStr.find("(");
24+
if (StartIndex != std::string::npos) {
25+
size_t EndIndex = DemangledStr.rfind(" ", StartIndex);
26+
if (EndIndex != std::string::npos) {
27+
DemangledStr =
28+
DemangledStr.substr(EndIndex + 1, StartIndex - EndIndex - 1);
29+
}
30+
}
31+
return DemangledStr;
32+
}
33+
2034
std::string llvm::demangle(std::string_view MangledName) {
2135
std::string Result;
2236

0 commit comments

Comments
 (0)