4,431 changes: 4,431 additions & 0 deletions llvm/lib/Demangle/ItaniumDemangle.cpp

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions llvm/lib/Demangle/LLVMBuild.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
;===- ./lib/Support/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 = Library
name = Demangle
parent = Libraries
1 change: 1 addition & 0 deletions llvm/lib/LLVMBuild.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ subdirectories =
Bitcode
CodeGen
DebugInfo
Demangle
ExecutionEngine
LibDriver
LineEditor
Expand Down
1 change: 1 addition & 0 deletions llvm/lib/Support/LLVMBuild.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@
type = Library
name = Support
parent = Libraries
required_libraries = Demangle
10 changes: 2 additions & 8 deletions llvm/lib/Support/Unix/Signals.inc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include "Unix.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/Demangle/Demangle.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/FileUtilities.h"
Expand All @@ -33,9 +34,6 @@
#if HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif
#if HAVE_CXXABI_H
#include <cxxabi.h>
#endif
#if HAVE_DLFCN_H
#include <dlfcn.h>
#endif
Expand Down Expand Up @@ -443,12 +441,8 @@ void llvm::sys::PrintStackTrace(raw_ostream &OS) {

if (dlinfo.dli_sname != nullptr) {
OS << ' ';
# if HAVE_CXXABI_H
int res;
char* d = abi::__cxa_demangle(dlinfo.dli_sname, nullptr, nullptr, &res);
# else
char* d = NULL;
# endif
char* d = itaniumDemangle(dlinfo.dli_sname, nullptr, nullptr, &res);
if (!d) OS << dlinfo.dli_sname;
else OS << d;
free(d);
Expand Down
1 change: 1 addition & 0 deletions llvm/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ set(LLVM_TEST_DEPENDS
llvm-as
llvm-bcanalyzer
llvm-c-test
llvm-cxxfilt
llvm-config
llvm-cov
llvm-cxxdump
Expand Down
1 change: 1 addition & 0 deletions llvm/test/Demangle/lit.local.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
config.suffixes = ['.test']
4 changes: 4 additions & 0 deletions llvm/test/Demangle/simple.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
RUN: llvm-cxxfilt _Z1fi abc | FileCheck %s

CHECK: f(int)
CHECK-NEXT: abc
1 change: 1 addition & 0 deletions llvm/test/lit.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ for pattern in [r"\bbugpoint\b(?!-)",
r"\bllvm-split\b",
r"\bllvm-tblgen\b",
r"\bllvm-c-test\b",
r"\bllvm-cxxfilt\b",
NOJUNK + r"\bllvm-symbolizer\b",
NOJUNK + r"\bopt\b",
r"\bFileCheck\b",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ ObjC-EXE: 0000000100000f1b movq 0x10e(%rip), %rsi ## Objc selector ref: da
ObjC-EXE: 0000000100000f25 callq 0x100000f4a ## Objc message: +[NSDate date]
ObjC-EXE: 0000000100000f33 callq 0x100000f44 ## symbol stub for: _NSLog

CXX-EXE: 00000001000014cb callq __ZNSt3__116__pad_and_outputIcNS_11char_traitsIcEEEENS_19ostreambuf_iteratorIT_T0_EES6_PKS4_S8_S8_RNS_8ios_baseES4_

// FIXME: Demangler depends on host's <cxxabi.h>.
// std::__1::ostreambuf_iterator<char, std::__1::char_traits<char> > std::__1::__pad_and_output<char, std::__1::char_traits<char> >(std::__1::ostreambuf_iterator<char, std::__1::char_traits<char> >, char const*, char const*, char const*, std::__1::ios_base&, char)
CXX-EXE: 00000001000014cb callq __ZNSt3__116__pad_and_outputIcNS_11char_traitsIcEEEENS_19ostreambuf_iteratorIT_T0_EES6_PKS4_S8_S8_RNS_8ios_baseES4_ ## std::__1::ostreambuf_iterator<char, std::__1::char_traits<char> > std::__1::__pad_and_output<char, std::__1::char_traits<char> >(std::__1::ostreambuf_iterator<char, std::__1::char_traits<char> >, char const*, char const*, char const*, std::__1::ios_base&, char)

i386-OBJ: 0000002f calll _printf

Expand Down
7 changes: 7 additions & 0 deletions llvm/tools/llvm-cxxfilt/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
set(LLVM_LINK_COMPONENTS
Demangle
)

add_llvm_tool(llvm-cxxfilt
llvm-cxxfilt.cpp
)
29 changes: 29 additions & 0 deletions llvm/tools/llvm-cxxfilt/llvm-cxxfilt.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//===-- 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 <stdio.h>
#include <stdlib.h>

using namespace llvm;

int main(int argc, char **argv) {
for (int I = 1; I < argc; ++I) {
const char *Mangled = argv[I];
int Status;
char *Demangled = itaniumDemangle(Mangled, nullptr, nullptr, &Status);
if (Demangled)
printf("%s\n", Demangled);
else
printf("%s\n", Mangled);
free(Demangled);
}
return 0;
}
1 change: 1 addition & 0 deletions llvm/tools/llvm-objdump/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ set(LLVM_LINK_COMPONENTS
CodeGen
DebugInfoDWARF
DebugInfoPDB
Demangle
MC
MCDisassembler
Object
Expand Down
2 changes: 1 addition & 1 deletion llvm/tools/llvm-objdump/LLVMBuild.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@
type = Tool
name = llvm-objdump
parent = Tools
required_libraries = DebugInfoDWARF MC MCDisassembler MCParser Object all-targets
required_libraries = DebugInfoDWARF MC MCDisassembler MCParser Object all-targets Demangle
21 changes: 5 additions & 16 deletions llvm/tools/llvm-objdump/MachODump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "llvm/Config/config.h"
#include "llvm/DebugInfo/DIContext.h"
#include "llvm/DebugInfo/DWARF/DWARFContext.h"
#include "llvm/Demangle/Demangle.h"
#include "llvm/MC/MCAsmInfo.h"
#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCDisassembler/MCDisassembler.h"
Expand Down Expand Up @@ -48,10 +49,6 @@
#include <cstring>
#include <system_error>

#if HAVE_CXXABI_H
#include <cxxabi.h>
#endif

#ifdef HAVE_LIBXAR
extern "C" {
#include <xar/xar.h>
Expand Down Expand Up @@ -6235,11 +6232,9 @@ static const char *GuessLiteralPointer(uint64_t ReferenceValue,
// Out type and the ReferenceName will also be set which is added as a comment
// to the disassembled instruction.
//
#if HAVE_CXXABI_H
// If the symbol name is a C++ mangled name then the demangled name is
// returned through ReferenceName and ReferenceType is set to
// LLVMDisassembler_ReferenceType_DeMangled_Name .
#endif
//
// When this is called to get a symbol name for a branch target then the
// ReferenceType will be LLVMDisassembler_ReferenceType_In_Branch and then
Expand Down Expand Up @@ -6274,21 +6269,18 @@ static const char *SymbolizerSymbolLookUp(void *DisInfo,
method_reference(info, ReferenceType, ReferenceName);
if (*ReferenceType != LLVMDisassembler_ReferenceType_Out_Objc_Message)
*ReferenceType = LLVMDisassembler_ReferenceType_Out_SymbolStub;
} else
#if HAVE_CXXABI_H
if (SymbolName != nullptr && strncmp(SymbolName, "__Z", 3) == 0) {
} else if (SymbolName != nullptr && strncmp(SymbolName, "__Z", 3) == 0) {
if (info->demangled_name != nullptr)
free(info->demangled_name);
int status;
info->demangled_name =
abi::__cxa_demangle(SymbolName + 1, nullptr, nullptr, &status);
itaniumDemangle(SymbolName + 1, nullptr, nullptr, &status);
if (info->demangled_name != nullptr) {
*ReferenceName = info->demangled_name;
*ReferenceType = LLVMDisassembler_ReferenceType_DeMangled_Name;
} else
*ReferenceType = LLVMDisassembler_ReferenceType_InOut_None;
} else
#endif
*ReferenceType = LLVMDisassembler_ReferenceType_InOut_None;
} else if (*ReferenceType == LLVMDisassembler_ReferenceType_In_PCrel_Load) {
*ReferenceName =
Expand Down Expand Up @@ -6377,20 +6369,17 @@ static const char *SymbolizerSymbolLookUp(void *DisInfo,
GuessLiteralPointer(ReferenceValue, ReferencePC, ReferenceType, info);
if (*ReferenceName == nullptr)
*ReferenceType = LLVMDisassembler_ReferenceType_InOut_None;
}
#if HAVE_CXXABI_H
else if (SymbolName != nullptr && strncmp(SymbolName, "__Z", 3) == 0) {
} else if (SymbolName != nullptr && strncmp(SymbolName, "__Z", 3) == 0) {
if (info->demangled_name != nullptr)
free(info->demangled_name);
int status;
info->demangled_name =
abi::__cxa_demangle(SymbolName + 1, nullptr, nullptr, &status);
itaniumDemangle(SymbolName + 1, nullptr, nullptr, &status);
if (info->demangled_name != nullptr) {
*ReferenceName = info->demangled_name;
*ReferenceType = LLVMDisassembler_ReferenceType_DeMangled_Name;
}
}
#endif
else {
*ReferenceName = nullptr;
*ReferenceType = LLVMDisassembler_ReferenceType_InOut_None;
Expand Down