diff options
| author | Zachary Turner <zturner@google.com> | 2018-07-20 17:27:48 +0000 | 
|---|---|---|
| committer | Zachary Turner <zturner@google.com> | 2018-07-20 17:27:48 +0000 | 
| commit | f435a7eada02567e315371f73e64eab26829a67b (patch) | |
| tree | 1761ca957da6f2600a2c2de7d107f64d914e9399 /llvm/tools | |
| parent | 2628620b62d57ca68a2df7220b28c05852a9dd98 (diff) | |
| download | bcm5719-llvm-f435a7eada02567e315371f73e64eab26829a67b.tar.gz bcm5719-llvm-f435a7eada02567e315371f73e64eab26829a67b.zip | |
Add a Microsoft Demangler.
This adds initial support for a demangling library (LLVMDemangle)
and tool (llvm-undname) for demangling Microsoft names.  This
doesn't cover 100% of cases and there are some known limitations
which I intend to address in followup patches, at least until such
time that we have (near) 100% test coverage matching up with all
of the test cases in clang/test/CodeGenCXX/mangle-ms-*.
Differential Revision: https://reviews.llvm.org/D49552
llvm-svn: 337584
Diffstat (limited to 'llvm/tools')
| -rw-r--r-- | llvm/tools/LLVMBuild.txt | 1 | ||||
| -rw-r--r-- | llvm/tools/llvm-undname/CMakeLists.txt | 8 | ||||
| -rw-r--r-- | llvm/tools/llvm-undname/LLVMBuild.txt | 23 | ||||
| -rw-r--r-- | llvm/tools/llvm-undname/llvm-undname.cpp | 79 | 
4 files changed, 111 insertions, 0 deletions
| diff --git a/llvm/tools/LLVMBuild.txt b/llvm/tools/LLVMBuild.txt index 5dea5b44048..1732ea0cb8a 100644 --- a/llvm/tools/LLVMBuild.txt +++ b/llvm/tools/LLVMBuild.txt @@ -50,6 +50,7 @@ subdirectories =   llvm-rtdyld   llvm-size   llvm-split + llvm-undname   opt   verify-uselistorder diff --git a/llvm/tools/llvm-undname/CMakeLists.txt b/llvm/tools/llvm-undname/CMakeLists.txt new file mode 100644 index 00000000000..062f0052597 --- /dev/null +++ b/llvm/tools/llvm-undname/CMakeLists.txt @@ -0,0 +1,8 @@ +set(LLVM_LINK_COMPONENTS +  Demangle +  Support +  ) + +add_llvm_tool(llvm-undname +  llvm-undname.cpp +  ) diff --git a/llvm/tools/llvm-undname/LLVMBuild.txt b/llvm/tools/llvm-undname/LLVMBuild.txt new file mode 100644 index 00000000000..6e598f888ff --- /dev/null +++ b/llvm/tools/llvm-undname/LLVMBuild.txt @@ -0,0 +1,23 @@ +;===- ./tools/llvm-undname/LLVMBuild.txt -----------------------*- Conf -*--===; +; +;                     The LLVM Compiler Infrastructure +; +; This file is distributed under the University of Illinois Open Source +; License. See LICENSE.TXT for details. +; +;===------------------------------------------------------------------------===; +; +; This is an LLVMBuild description file for the components in this subdirectory. +; +; For more information on the LLVMBuild system, please see: +; +;   http://llvm.org/docs/LLVMBuild.html +; +;===------------------------------------------------------------------------===; + +[component_0] +type = Tool +name = llvm-undname +parent = Tools +required_libraries = Demangle Support + diff --git a/llvm/tools/llvm-undname/llvm-undname.cpp b/llvm/tools/llvm-undname/llvm-undname.cpp new file mode 100644 index 00000000000..f4c09f57505 --- /dev/null +++ b/llvm/tools/llvm-undname/llvm-undname.cpp @@ -0,0 +1,79 @@ +//===-- llvm-undname.cpp - Microsoft ABI name undecorator +//------------------===// +// +//                     The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This utility works like the windows undname utility. It converts mangled +// Microsoft symbol names into pretty C/C++ human-readable names. +// +//===----------------------------------------------------------------------===// + +#include "llvm/ADT/StringRef.h" +#include "llvm/Demangle/Demangle.h" +#include "llvm/Support/CommandLine.h" +#include "llvm/Support/InitLLVM.h" +#include "llvm/Support/Process.h" +#include "llvm/Support/raw_ostream.h" +#include <cstdio> +#include <cstring> +#include <iostream> +#include <string> + +using namespace llvm; + +cl::list<std::string> Symbols(cl::Positional, cl::desc("<input symbols>"), +                              cl::ZeroOrMore); + +static void demangle(const std::string &S) { +  int Status; +  char *ResultBuf = microsoftDemangle(S.c_str(), nullptr, nullptr, &Status); +  if (Status == llvm::demangle_success) { +    outs() << ResultBuf << "\n"; +    outs().flush(); +  } else { +    errs() << "Error: Invalid mangled name\n"; +  } +  std::free(ResultBuf); +}; + +int main(int argc, char **argv) { +  InitLLVM X(argc, argv); + +  cl::ParseCommandLineOptions(argc, argv, "llvm-undname\n"); + +  if (Symbols.empty()) { +    while (true) { +      std::string LineStr; +      std::getline(std::cin, LineStr); +      if (std::cin.eof()) +        break; + +      StringRef Line(LineStr); +      Line = Line.trim(); +      if (Line.empty() || Line.startswith("#") || Line.startswith(";")) +        continue; + +      // If the user is manually typing in these decorated names, don't echo +      // them to the terminal a second time.  If they're coming from redirected +      // input, however, then we should display the input line so that the +      // mangled and demangled name can be easily correlated in the output. +      if (!sys::Process::StandardInIsUserInput()) +        outs() << Line << "\n"; +      demangle(Line); +      outs() << "\n"; +    } +  } else { +    for (StringRef S : Symbols) { +      outs() << S << "\n"; +      demangle(S); +      outs() << "\n"; +    } +  } + +  return 0; +}
\ No newline at end of file | 

