]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lld/COFF/Strings.cpp
MFC r343601:
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lld / COFF / Strings.cpp
1 //===- Strings.cpp -------------------------------------------------------===//
2 //
3 //                             The LLVM Linker
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #include "Strings.h"
11 #include <mutex>
12
13 #if defined(_MSC_VER)
14 #include <Windows.h>
15 #include <DbgHelp.h>
16 #pragma comment(lib, "dbghelp.lib")
17 #endif
18
19 using namespace lld;
20 using namespace lld::coff;
21 using namespace llvm;
22
23 Optional<std::string> coff::demangleMSVC(StringRef S) {
24 #if defined(_MSC_VER)
25   // UnDecorateSymbolName is not thread-safe, so we need a mutex.
26   static std::mutex Mu;
27   std::lock_guard<std::mutex> Lock(Mu);
28
29   char Buf[4096];
30   if (S.startswith("?"))
31     if (size_t Len = UnDecorateSymbolName(S.str().c_str(), Buf, sizeof(Buf), 0))
32       return std::string(Buf, Len);
33 #endif
34   return None;
35 }