Skip to content

Commit 1ca074b

Browse files
committedOct 4, 2019
[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: 373698
1 parent 30cb220 commit 1ca074b

File tree

3 files changed

+4
-45
lines changed

3 files changed

+4
-45
lines changed
 

‎llvm/lib/DebugInfo/Symbolize/Symbolize.cpp

+4-37
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,6 @@
3535
#include <cassert>
3636
#include <cstring>
3737

38-
#if defined(_MSC_VER)
39-
#include <Windows.h>
40-
41-
// This must be included after windows.h.
42-
#include <DbgHelp.h>
43-
#pragma comment(lib, "dbghelp.lib")
44-
45-
// Windows.h conflicts with our COFF header definitions.
46-
#ifdef IMAGE_FILE_MACHINE_I386
47-
#undef IMAGE_FILE_MACHINE_I386
48-
#endif
49-
#endif
50-
5138
namespace llvm {
5239
namespace symbolize {
5340

@@ -524,31 +511,11 @@ LLVMSymbolizer::DemangleName(const std::string &Name,
524511
const SymbolizableModule *DbiModuleDescriptor) {
525512
// We can spoil names of symbols with C linkage, so use an heuristic
526513
// approach to check if the name should be demangled.
527-
if (Name.substr(0, 2) == "_Z") {
528-
int status = 0;
529-
char *DemangledName = itaniumDemangle(Name.c_str(), nullptr, nullptr, &status);
530-
if (status != 0)
531-
return Name;
532-
std::string Result = DemangledName;
533-
free(DemangledName);
534-
return Result;
535-
}
514+
// MSVC C++ mangled symbols start with '?', while itanium mangled ones
515+
// start with _Z.
516+
if (Name.substr(0, 2) == "_Z" || (!Name.empty() && Name.front() == '?'))
517+
return demangle(Name);
536518

537-
#if defined(_MSC_VER)
538-
if (!Name.empty() && Name.front() == '?') {
539-
// Only do MSVC C++ demangling on symbols starting with '?'.
540-
char DemangledName[1024] = {0};
541-
DWORD result = ::UnDecorateSymbolName(
542-
Name.c_str(), DemangledName, 1023,
543-
UNDNAME_NO_ACCESS_SPECIFIERS | // Strip public, private, protected
544-
UNDNAME_NO_ALLOCATION_LANGUAGE | // Strip __thiscall, __stdcall, etc
545-
UNDNAME_NO_THROW_SIGNATURES | // Strip throw() specifications
546-
UNDNAME_NO_MEMBER_TYPE | // Strip virtual, static, etc specifiers
547-
UNDNAME_NO_MS_KEYWORDS | // Strip all MS extension keywords
548-
UNDNAME_NO_FUNCTION_RETURNS); // Strip function return types
549-
return (result == 0) ? Name : std::string(DemangledName);
550-
}
551-
#endif
552519
if (DbiModuleDescriptor && DbiModuleDescriptor->isWin32Module())
553520
return std::string(demanglePE32ExternCFunc(Name));
554521
return Name;

‎llvm/test/tools/llvm-symbolizer/coff-dwarf.test

-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ RUN: | FileCheck %s
55
RUN: llvm-symbolizer 0x5009 0x5038 -i --relative-address -obj="%p/Inputs/coff-dwarf.exe" \
66
RUN: | FileCheck %s
77

8-
This test relies on UnDecorateSymbolName, which is Windows-only.
9-
REQUIRES: target-windows, system-windows
10-
118
CHECK: foo(void)
129
CHECK: coff-dwarf.cpp:7
1310
CHECK: bar(void)

‎llvm/test/tools/llvm-symbolizer/coff-exports.test

-5
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@ RUN: | FileCheck %s
55
RUN: llvm-symbolizer 0x500A 0x5038 0x504B -i --relative-address -obj="%p/Inputs/coff-exports.exe" \
66
RUN: | FileCheck %s
77

8-
This test relies on UnDecorateSymbolName, which is Win32-only.
9-
REQUIRES: system-windows
10-
REQUIRES: target-windows
11-
FIXME: This test depends on host, not target.
12-
138
We get the expected stack trace, except 'foo' appears for the 'bar' frame
149
because 'bar' isn't in the export table.
1510

0 commit comments

Comments
 (0)
Please sign in to comment.