aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm/tools/llvm-cxxfilt/llvm-cxxfilt.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm/tools/llvm-cxxfilt/llvm-cxxfilt.cpp')
-rw-r--r--contrib/llvm/tools/llvm-cxxfilt/llvm-cxxfilt.cpp78
1 files changed, 69 insertions, 9 deletions
diff --git a/contrib/llvm/tools/llvm-cxxfilt/llvm-cxxfilt.cpp b/contrib/llvm/tools/llvm-cxxfilt/llvm-cxxfilt.cpp
index 1e2797ba3334..13024fbeaeaa 100644
--- a/contrib/llvm/tools/llvm-cxxfilt/llvm-cxxfilt.cpp
+++ b/contrib/llvm/tools/llvm-cxxfilt/llvm-cxxfilt.cpp
@@ -8,29 +8,89 @@
//===----------------------------------------------------------------------===//
#include "llvm/Demangle/Demangle.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/PrettyStackTrace.h"
+#include "llvm/Support/Signals.h"
#include "llvm/Support/raw_ostream.h"
#include <cstdlib>
#include <iostream>
using namespace llvm;
+enum Style {
+ Auto, ///< auto-detect mangling
+ GNU, ///< GNU
+ Lucid, ///< Lucid compiler (lcc)
+ ARM,
+ HP, ///< HP compiler (xCC)
+ EDG, ///< EDG compiler
+ GNUv3, ///< GNU C++ v3 ABI
+ Java, ///< Java (gcj)
+ GNAT ///< ADA copiler (gnat)
+};
+static cl::opt<Style>
+ Format("format", cl::desc("decoration style"),
+ cl::values(clEnumValN(Auto, "auto", "auto-detect style"),
+ clEnumValN(GNU, "gnu", "GNU (itanium) style")),
+ cl::init(Auto));
+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"),
+ 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")))
- 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);
+
+ if (!Undecorated &&
+ (DecoratedLength > 6 && strncmp(Decorated, "__imp_", 6) == 0)) {
+ OS << "import thunk for ";
+ Undecorated = itaniumDemangle(Decorated + 6, nullptr, nullptr, &Status);
+ }
+
+ OS << (Undecorated ? Undecorated : Mangled) << '\n';
+
+ free(Undecorated);
}
int main(int argc, char **argv) {
- if (argc == 1)
+ sys::PrintStackTraceOnErrorSignal(argv[0]);
+ PrettyStackTraceProgram X(argc, argv);
+
+ cl::ParseCommandLineOptions(argc, argv, "llvm symbol undecoration tool\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;
}