[llvm] r292576 - llvm-cxxfilt: support `-t` to demangle types
Saleem Abdulrasool via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 19 20:25:26 PST 2017
Author: compnerd
Date: Thu Jan 19 22:25:26 2017
New Revision: 292576
URL: http://llvm.org/viewvc/llvm-project?rev=292576&view=rev
Log:
llvm-cxxfilt: support `-t` to demangle types
By default c++filt demangles functions, though you can optionally pass
`-t` to have it decode types as well, behaving nearly identical to
`__cxa_demangle`. Add support for this mode.
Added:
llvm/trunk/test/tools/llvm-cxxfilt/types.test
Modified:
llvm/trunk/tools/llvm-cxxfilt/llvm-cxxfilt.cpp
Added: llvm/trunk/test/tools/llvm-cxxfilt/types.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-cxxfilt/types.test?rev=292576&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-cxxfilt/types.test (added)
+++ llvm/trunk/test/tools/llvm-cxxfilt/types.test Thu Jan 19 22:25:26 2017
@@ -0,0 +1,5 @@
+RUN: llvm-cxxfilt -t f i | FileCheck %s
+
+CHECK: float
+CHECK-NEXT: int
+
Modified: llvm/trunk/tools/llvm-cxxfilt/llvm-cxxfilt.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-cxxfilt/llvm-cxxfilt.cpp?rev=292576&r1=292575&r2=292576&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-cxxfilt/llvm-cxxfilt.cpp (original)
+++ llvm/trunk/tools/llvm-cxxfilt/llvm-cxxfilt.cpp Thu Jan 19 22:25:26 2017
@@ -8,29 +8,42 @@
//===----------------------------------------------------------------------===//
#include "llvm/Demangle/Demangle.h"
+#include "llvm/Support/CommandLine.h"
#include "llvm/Support/raw_ostream.h"
#include <cstdlib>
#include <iostream>
using namespace llvm;
+static cl::opt<bool>
+ Types("types",
+ cl::desc("attempt to demangle types as well as function names"),
+ cl::init(false));
+static cl::alias TypesShort("t", cl::desc("alias for --types"),
+ cl::aliasopt(Types));
+
+static cl::list<std::string>
+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 ((Mangled.size() >= 2 && Mangled.compare(0, 2, "_Z")) ||
- (Mangled.size() >= 4 && Mangled.compare(0, 4, "___Z")))
+ 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);
}
int main(int argc, char **argv) {
- if (argc == 1)
+ cl::ParseCommandLineOptions(argc, argv, "llvm symbol table dumper\n");
+
+ if (Decorated.empty())
for (std::string Mangled; std::getline(std::cin, Mangled);)
demangle(llvm::outs(), Mangled);
else
- for (int I = 1; I < argc; ++I)
- demangle(llvm::outs(), argv[I]);
+ for (const auto &Symbol : Decorated)
+ demangle(llvm::outs(), Symbol);
return EXIT_SUCCESS;
}
More information about the llvm-commits
mailing list