blob: 34d1cabc612c757b3cdfcb442a4bf8ecfa49843a [file] [log] [blame]
Brian Silverman8fce7482020-01-05 13:18:21 -08001/*----------------------------------------------------------------------------*/
2/* Copyright (c) 2008-2019 FIRST. All Rights Reserved. */
3/* Open Source Software - may be modified and shared by FRC teams. The code */
4/* must be accompanied by the FIRST BSD license file in the root directory of */
5/* the project. */
6/*----------------------------------------------------------------------------*/
7
8#include "wpi/Demangle.h"
9
10#include <windows.h> // NOLINT(build/include_order)
11
12#include <dbghelp.h>
13
14#include "wpi/mutex.h"
15
16#pragma comment(lib, "Dbghelp.lib")
17
18namespace wpi {
19
20std::string Demangle(char const* mangledSymbol) {
21 static wpi::mutex m;
22 std::scoped_lock lock(m);
23 char buffer[256];
24 DWORD sz = UnDecorateSymbolName(mangledSymbol, buffer, sizeof(buffer),
25 UNDNAME_COMPLETE);
26 if (sz == 0) return mangledSymbol;
27 return std::string(buffer, sz);
28}
29
30} // namespace wpi