1 //===-- llvm-undname.cpp - Microsoft ABI name undecorator
2 //------------------===//
4 // The LLVM Compiler Infrastructure
6 // This file is distributed under the University of Illinois Open Source
7 // License. See LICENSE.TXT for details.
9 //===----------------------------------------------------------------------===//
11 // This utility works like the windows undname utility. It converts mangled
12 // Microsoft symbol names into pretty C/C++ human-readable names.
14 //===----------------------------------------------------------------------===//
16 #include "llvm/ADT/StringRef.h"
17 #include "llvm/Demangle/Demangle.h"
18 #include "llvm/Support/CommandLine.h"
19 #include "llvm/Support/InitLLVM.h"
20 #include "llvm/Support/Process.h"
21 #include "llvm/Support/WithColor.h"
22 #include "llvm/Support/raw_ostream.h"
30 cl::opt
<bool> DumpBackReferences("backrefs", cl::Optional
,
31 cl::desc("dump backreferences"), cl::Hidden
,
33 cl::list
<std::string
> Symbols(cl::Positional
, cl::desc("<input symbols>"),
36 static void demangle(const std::string
&S
) {
38 MSDemangleFlags Flags
= MSDF_None
;
39 if (DumpBackReferences
)
40 Flags
= MSDemangleFlags(Flags
| MSDF_DumpBackrefs
);
43 microsoftDemangle(S
.c_str(), nullptr, nullptr, &Status
, Flags
);
44 if (Status
== llvm::demangle_success
) {
45 outs() << ResultBuf
<< "\n";
48 WithColor::error() << "Invalid mangled name\n";
53 int main(int argc
, char **argv
) {
54 InitLLVM
X(argc
, argv
);
56 cl::ParseCommandLineOptions(argc
, argv
, "llvm-undname\n");
58 if (Symbols
.empty()) {
61 std::getline(std::cin
, LineStr
);
65 StringRef
Line(LineStr
);
67 if (Line
.empty() || Line
.startswith("#") || Line
.startswith(";"))
70 // If the user is manually typing in these decorated names, don't echo
71 // them to the terminal a second time. If they're coming from redirected
72 // input, however, then we should display the input line so that the
73 // mangled and demangled name can be easily correlated in the output.
74 if (!sys::Process::StandardInIsUserInput()) {
75 outs() << Line
<< "\n";
82 for (StringRef S
: Symbols
) {