[Symbolize] Use the local MSVC C++ demangler instead of relying on dbghelp. NFC.

This allows making a couple llvm-symbolizer tests run in all
environments.

Differential Revision: https://reviews.llvm.org/D68133

llvm-svn: 375041
This commit is contained in:
Martin Storsjo 2019-10-16 20:38:44 +00:00
parent ac77947315
commit a4f6b59846
3 changed files with 11 additions and 31 deletions

View File

@ -35,19 +35,6 @@
#include <cassert> #include <cassert>
#include <cstring> #include <cstring>
#if defined(_MSC_VER)
#include <Windows.h>
// This must be included after windows.h.
#include <DbgHelp.h>
#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 llvm {
namespace symbolize { namespace symbolize {
@ -534,21 +521,20 @@ LLVMSymbolizer::DemangleName(const std::string &Name,
return Result; return Result;
} }
#if defined(_MSC_VER)
if (!Name.empty() && Name.front() == '?') { if (!Name.empty() && Name.front() == '?') {
// Only do MSVC C++ demangling on symbols starting with '?'. // Only do MSVC C++ demangling on symbols starting with '?'.
char DemangledName[1024] = {0}; int status = 0;
DWORD result = ::UnDecorateSymbolName( char *DemangledName = microsoftDemangle(
Name.c_str(), DemangledName, 1023, Name.c_str(), nullptr, nullptr, &status,
UNDNAME_NO_ACCESS_SPECIFIERS | // Strip public, private, protected MSDemangleFlags(MSDF_NoAccessSpecifier | MSDF_NoCallingConvention |
UNDNAME_NO_ALLOCATION_LANGUAGE | // Strip __thiscall, __stdcall, etc MSDF_NoMemberType | MSDF_NoReturnType));
UNDNAME_NO_THROW_SIGNATURES | // Strip throw() specifications if (status != 0)
UNDNAME_NO_MEMBER_TYPE | // Strip virtual, static, etc specifiers return Name;
UNDNAME_NO_MS_KEYWORDS | // Strip all MS extension keywords std::string Result = DemangledName;
UNDNAME_NO_FUNCTION_RETURNS); // Strip function return types free(DemangledName);
return (result == 0) ? Name : std::string(DemangledName); return Result;
} }
#endif
if (DbiModuleDescriptor && DbiModuleDescriptor->isWin32Module()) if (DbiModuleDescriptor && DbiModuleDescriptor->isWin32Module())
return std::string(demanglePE32ExternCFunc(Name)); return std::string(demanglePE32ExternCFunc(Name));
return Name; return Name;

View File

@ -5,9 +5,6 @@ RUN: | FileCheck %s
RUN: llvm-symbolizer 0x5009 0x5038 -i --relative-address -obj="%p/Inputs/coff-dwarf.exe" \ RUN: llvm-symbolizer 0x5009 0x5038 -i --relative-address -obj="%p/Inputs/coff-dwarf.exe" \
RUN: | FileCheck %s RUN: | FileCheck %s
This test relies on UnDecorateSymbolName, which is Windows-only.
REQUIRES: system-windows
CHECK: foo(void) CHECK: foo(void)
CHECK: coff-dwarf.cpp:7 CHECK: coff-dwarf.cpp:7
CHECK: bar(void) CHECK: bar(void)

View File

@ -5,9 +5,6 @@ RUN: | FileCheck %s
RUN: llvm-symbolizer 0x500A 0x5038 0x504B -i --relative-address -obj="%p/Inputs/coff-exports.exe" \ RUN: llvm-symbolizer 0x500A 0x5038 0x504B -i --relative-address -obj="%p/Inputs/coff-exports.exe" \
RUN: | FileCheck %s RUN: | FileCheck %s
This test relies on UnDecorateSymbolName, which is Win32-only.
REQUIRES: system-windows
We get the expected stack trace, except 'foo' appears for the 'bar' frame We get the expected stack trace, except 'foo' appears for the 'bar' frame
because 'bar' isn't in the export table. because 'bar' isn't in the export table.