From db8b81d2d33c1ab6457176ee43157e0aaf925be6 Mon Sep 17 00:00:00 2001 From: Martin Storsjo Date: Fri, 4 Oct 2019 07:22:37 +0000 Subject: [PATCH] Revert "[Symbolize] Use the local MSVC C++ demangler instead of relying on dbghelp. NFC." This reverts SVN r373698, as it broke sanitizer tests, e.g. in http://lab.llvm.org:8011/builders/sanitizer-windows/builds/52441. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@373701 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/DebugInfo/Symbolize/Symbolize.cpp | 41 +++++++++++++++++++++++++--- test/tools/llvm-symbolizer/coff-dwarf.test | 3 ++ test/tools/llvm-symbolizer/coff-exports.test | 5 ++++ 3 files changed, 45 insertions(+), 4 deletions(-) diff --git a/lib/DebugInfo/Symbolize/Symbolize.cpp b/lib/DebugInfo/Symbolize/Symbolize.cpp index 389a8f743e9..8e1852bcf8e 100644 --- a/lib/DebugInfo/Symbolize/Symbolize.cpp +++ b/lib/DebugInfo/Symbolize/Symbolize.cpp @@ -35,6 +35,19 @@ #include #include +#if defined(_MSC_VER) +#include + +// This must be included after windows.h. +#include +#pragma comment(lib, "dbghelp.lib") + +// Windows.h conflicts with our COFF header definitions. +#ifdef IMAGE_FILE_MACHINE_I386 +#undef IMAGE_FILE_MACHINE_I386 +#endif +#endif + namespace llvm { namespace symbolize { @@ -511,11 +524,31 @@ LLVMSymbolizer::DemangleName(const std::string &Name, const SymbolizableModule *DbiModuleDescriptor) { // We can spoil names of symbols with C linkage, so use an heuristic // approach to check if the name should be demangled. - // MSVC C++ mangled symbols start with '?', while itanium mangled ones - // start with _Z. - if (Name.substr(0, 2) == "_Z" || (!Name.empty() && Name.front() == '?')) - return demangle(Name); + if (Name.substr(0, 2) == "_Z") { + int status = 0; + char *DemangledName = itaniumDemangle(Name.c_str(), nullptr, nullptr, &status); + if (status != 0) + return Name; + std::string Result = DemangledName; + free(DemangledName); + return Result; + } +#if defined(_MSC_VER) + if (!Name.empty() && Name.front() == '?') { + // Only do MSVC C++ demangling on symbols starting with '?'. + char DemangledName[1024] = {0}; + DWORD result = ::UnDecorateSymbolName( + Name.c_str(), DemangledName, 1023, + UNDNAME_NO_ACCESS_SPECIFIERS | // Strip public, private, protected + UNDNAME_NO_ALLOCATION_LANGUAGE | // Strip __thiscall, __stdcall, etc + UNDNAME_NO_THROW_SIGNATURES | // Strip throw() specifications + UNDNAME_NO_MEMBER_TYPE | // Strip virtual, static, etc specifiers + UNDNAME_NO_MS_KEYWORDS | // Strip all MS extension keywords + UNDNAME_NO_FUNCTION_RETURNS); // Strip function return types + return (result == 0) ? Name : std::string(DemangledName); + } +#endif if (DbiModuleDescriptor && DbiModuleDescriptor->isWin32Module()) return std::string(demanglePE32ExternCFunc(Name)); return Name; diff --git a/test/tools/llvm-symbolizer/coff-dwarf.test b/test/tools/llvm-symbolizer/coff-dwarf.test index 21d06b197ee..790763a2ddf 100644 --- a/test/tools/llvm-symbolizer/coff-dwarf.test +++ b/test/tools/llvm-symbolizer/coff-dwarf.test @@ -5,6 +5,9 @@ RUN: | FileCheck %s RUN: llvm-symbolizer 0x5009 0x5038 -i --relative-address -obj="%p/Inputs/coff-dwarf.exe" \ RUN: | FileCheck %s +This test relies on UnDecorateSymbolName, which is Windows-only. +REQUIRES: target-windows, system-windows + CHECK: foo(void) CHECK: coff-dwarf.cpp:7 CHECK: bar(void) diff --git a/test/tools/llvm-symbolizer/coff-exports.test b/test/tools/llvm-symbolizer/coff-exports.test index a5d972f6e49..8678aae2960 100644 --- a/test/tools/llvm-symbolizer/coff-exports.test +++ b/test/tools/llvm-symbolizer/coff-exports.test @@ -5,6 +5,11 @@ RUN: | FileCheck %s RUN: llvm-symbolizer 0x500A 0x5038 0x504B -i --relative-address -obj="%p/Inputs/coff-exports.exe" \ RUN: | FileCheck %s +This test relies on UnDecorateSymbolName, which is Win32-only. +REQUIRES: system-windows +REQUIRES: target-windows +FIXME: This test depends on host, not target. + We get the expected stack trace, except 'foo' appears for the 'bar' frame because 'bar' isn't in the export table. -- 2.11.4.GIT