1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
//===-- 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"
#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;
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 (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) {
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 (const auto &Symbol : Decorated)
demangle(llvm::outs(), Symbol);
return EXIT_SUCCESS;
}
|