Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame^] | 1 | /*----------------------------------------------------------------------------*/ |
| 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 | |
| 18 | namespace wpi { |
| 19 | |
| 20 | std::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 |