Fix Demangle when used standalone (#2256)

This commit is contained in:
Peter Johnson
2020-01-10 23:41:40 -08:00
committed by GitHub
parent 56765cf49a
commit 795086b4cf
4 changed files with 32 additions and 22 deletions

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2008-2019 FIRST. All Rights Reserved. */
/* Copyright (c) 2008-2020 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
@@ -11,19 +11,22 @@
#include <dbghelp.h>
#include "wpi/SmallString.h"
#include "wpi/mutex.h"
#pragma comment(lib, "Dbghelp.lib")
namespace wpi {
std::string Demangle(char const* mangledSymbol) {
std::string Demangle(const Twine& mangledSymbol) {
static wpi::mutex m;
std::scoped_lock lock(m);
SmallString<128> buf;
char buffer[256];
DWORD sz = UnDecorateSymbolName(mangledSymbol, buffer, sizeof(buffer),
UNDNAME_COMPLETE);
if (sz == 0) return mangledSymbol;
DWORD sz =
UnDecorateSymbolName(mangledSymbol.toNullTerminatedStringRef(buf).data(),
buffer, sizeof(buffer), UNDNAME_COMPLETE);
if (sz == 0) return mangledSymbol.str();
return std::string(buffer, sz);
}