1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-18 18:42:46 +02:00

llvm-cxxfilt: support -_

Add the `--strip-underscore` option to llvm-cxxfilt to strip the leading
underscore.  This is useful for when dealing with targets which add a
leading underscore.

llvm-svn: 292759
This commit is contained in:
Saleem Abdulrasool 2017-01-22 17:41:10 +00:00
parent 0cd7759843
commit d73327ebbc
2 changed files with 34 additions and 6 deletions

View File

@ -0,0 +1,11 @@
RUN: llvm-cxxfilt -_ __ZN2ns1fE _ZSt1f _f | FileCheck %s -check-prefix CHECK-STRIPPED
RUN: llvm-cxxfilt __ZN2ns1fE _ZSt1f _f | FileCheck %s -check-prefix CHECK-UNSTRIPPED
CHECK-STRIPPED: ns::f
CHECK-STRIPPED: _ZSt1f
CHECK-STRIPPED: _f
CHECK-UNSTRIPPED: __ZN2ns1fE
CHECK-UNSTRIPPED: std::f
CHECK-UNSTRIPPED: _f

View File

@ -36,6 +36,13 @@ static cl::opt<Style>
static cl::alias FormatShort("s", cl::desc("alias for --format"),
cl::aliasopt(Format));
static cl::opt<bool> StripUnderscore("strip-underscore",
cl::desc("strip the leading underscore"),
cl::init(false));
static cl::alias StripUnderscoreShort("_",
cl::desc("alias for --strip-underscore"),
cl::aliasopt(StripUnderscore));
static cl::opt<bool>
Types("types",
cl::desc("attempt to demangle types as well as function names"),
@ -48,12 +55,22 @@ Decorated(cl::Positional, cl::desc("<mangled>"), cl::ZeroOrMore);
static void demangle(llvm::raw_ostream &OS, const std::string &Mangled) {
int Status;
char *Demangled = nullptr;
if (Types || ((Mangled.size() >= 2 && Mangled.compare(0, 2, "_Z")) ||
(Mangled.size() >= 4 && Mangled.compare(0, 4, "___Z"))))
Demangled = itaniumDemangle(Mangled.c_str(), nullptr, nullptr, &Status);
OS << (Demangled ? Demangled : Mangled) << '\n';
free(Demangled);
const char *Decorated = Mangled.c_str();
if (StripUnderscore)
if (Decorated[0] == '_')
++Decorated;
size_t DecoratedLength = strlen(Decorated);
char *Undecorated = nullptr;
if (Types || ((DecoratedLength >= 2 && strncmp(Decorated, "_Z", 2) == 0) ||
(DecoratedLength >= 4 && strncmp(Decorated, "___Z", 4) == 0)))
Undecorated = itaniumDemangle(Decorated, nullptr, nullptr, &Status);
OS << (Undecorated ? Undecorated : Mangled) << '\n';
free(Undecorated);
}
int main(int argc, char **argv) {