2016-09-06 21:16:48 +02:00
|
|
|
//===-- llvm-c++filt.cpp --------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/Demangle/Demangle.h"
|
2017-01-20 05:25:26 +01:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
2018-04-13 20:26:06 +02:00
|
|
|
#include "llvm/Support/InitLLVM.h"
|
2016-09-27 20:50:30 +02:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2016-11-13 21:43:38 +01:00
|
|
|
#include <cstdlib>
|
|
|
|
#include <iostream>
|
2016-09-06 21:16:48 +02:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2017-01-21 03:36:26 +01:00
|
|
|
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));
|
|
|
|
|
2017-01-22 18:41:10 +01:00
|
|
|
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));
|
|
|
|
|
2017-01-20 05:25:26 +01:00
|
|
|
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);
|
|
|
|
|
2017-01-19 03:58:46 +01:00
|
|
|
static void demangle(llvm::raw_ostream &OS, const std::string &Mangled) {
|
2016-11-13 21:43:38 +01:00
|
|
|
int Status;
|
2017-01-22 18:41:10 +01:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2017-03-22 22:15:19 +01:00
|
|
|
if (!Undecorated &&
|
|
|
|
(DecoratedLength > 6 && strncmp(Decorated, "__imp_", 6) == 0)) {
|
|
|
|
OS << "import thunk for ";
|
|
|
|
Undecorated = itaniumDemangle(Decorated + 6, nullptr, nullptr, &Status);
|
|
|
|
}
|
|
|
|
|
2017-01-22 18:41:10 +01:00
|
|
|
OS << (Undecorated ? Undecorated : Mangled) << '\n';
|
2017-11-29 18:07:41 +01:00
|
|
|
OS.flush();
|
2017-01-22 18:41:10 +01:00
|
|
|
|
|
|
|
free(Undecorated);
|
2016-11-13 21:43:38 +01:00
|
|
|
}
|
|
|
|
|
2016-09-06 21:16:48 +02:00
|
|
|
int main(int argc, char **argv) {
|
2018-04-13 20:26:06 +02:00
|
|
|
InitLLVM X(argc, argv);
|
2017-01-20 06:27:09 +01:00
|
|
|
|
|
|
|
cl::ParseCommandLineOptions(argc, argv, "llvm symbol undecoration tool\n");
|
2017-01-20 05:25:26 +01:00
|
|
|
|
|
|
|
if (Decorated.empty())
|
2016-11-13 21:43:38 +01:00
|
|
|
for (std::string Mangled; std::getline(std::cin, Mangled);)
|
2017-01-19 03:58:46 +01:00
|
|
|
demangle(llvm::outs(), Mangled);
|
2016-11-13 21:43:38 +01:00
|
|
|
else
|
2017-01-20 05:25:26 +01:00
|
|
|
for (const auto &Symbol : Decorated)
|
|
|
|
demangle(llvm::outs(), Symbol);
|
2016-11-13 21:43:38 +01:00
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
2016-09-06 21:16:48 +02:00
|
|
|
}
|