From 24e3626128a5bb62eb890cfbce7b8e3b381f6a39 Mon Sep 17 00:00:00 2001 From: Eugene Zemtsov Date: Wed, 7 Mar 2018 23:07:34 +0000 Subject: [PATCH] Use itaniumDemangle in llvm-symbolizer Currently on Windows (_MSC_VER) LLVMSymbolizer supports only Microsoft mangling. This fix just explicitly uses itaniumDemangle when mangled name starts with _Z. Differential Revision: https://reviews.llvm.org/D44192 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@326959 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/DebugInfo/Symbolize/Symbolize.cpp | 13 ++++--------- tools/llvm-symbolizer/CMakeLists.txt | 1 + 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/lib/DebugInfo/Symbolize/Symbolize.cpp b/lib/DebugInfo/Symbolize/Symbolize.cpp index 681334bc405..c4a8b8d31db 100644 --- a/lib/DebugInfo/Symbolize/Symbolize.cpp +++ b/lib/DebugInfo/Symbolize/Symbolize.cpp @@ -21,6 +21,7 @@ #include "llvm/DebugInfo/DWARF/DWARFContext.h" #include "llvm/DebugInfo/PDB/PDB.h" #include "llvm/DebugInfo/PDB/PDBContext.h" +#include "llvm/Demangle/Demangle.h" #include "llvm/Object/COFF.h" #include "llvm/Object/MachO.h" #include "llvm/Object/MachOUniversal.h" @@ -459,28 +460,22 @@ StringRef demanglePE32ExternCFunc(StringRef SymbolName) { } // end anonymous namespace -#if !defined(_MSC_VER) -// Assume that __cxa_demangle is provided by libcxxabi (except for Windows). -extern "C" char *__cxa_demangle(const char *mangled_name, char *output_buffer, - size_t *length, int *status); -#endif - std::string LLVMSymbolizer::DemangleName(const std::string &Name, const SymbolizableModule *DbiModuleDescriptor) { -#if !defined(_MSC_VER) // We can spoil names of symbols with C linkage, so use an heuristic // approach to check if the name should be demangled. if (Name.substr(0, 2) == "_Z") { int status = 0; - char *DemangledName = __cxa_demangle(Name.c_str(), nullptr, nullptr, &status); + char *DemangledName = itaniumDemangle(Name.c_str(), nullptr, nullptr, &status); if (status != 0) return Name; std::string Result = DemangledName; free(DemangledName); return Result; } -#else + +#if defined(_MSC_VER) if (!Name.empty() && Name.front() == '?') { // Only do MSVC C++ demangling on symbols starting with '?'. char DemangledName[1024] = {0}; diff --git a/tools/llvm-symbolizer/CMakeLists.txt b/tools/llvm-symbolizer/CMakeLists.txt index d9b05208afd..8185c296c50 100644 --- a/tools/llvm-symbolizer/CMakeLists.txt +++ b/tools/llvm-symbolizer/CMakeLists.txt @@ -6,6 +6,7 @@ set(LLVM_LINK_COMPONENTS DebugInfoDWARF DebugInfoPDB + Demangle Object Support Symbolize -- 2.11.0