mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-25 01:41:43 +00:00
Move GetStackTrace and Demangle to wpiutil, add Windows support (#1819)
For Windows, import the StackWalker source (https://github.com/JochenKalmbach/StackWalker) plus PR 35 in that repo, with a few simplifications to StackWalker.h.
This commit is contained in:
30
wpiutil/src/main/native/windows/Demangle.cpp
Normal file
30
wpiutil/src/main/native/windows/Demangle.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2008-2019 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. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#include "wpi/Demangle.h"
|
||||
|
||||
#include <windows.h> // NOLINT(build/include_order)
|
||||
|
||||
#include <dbghelp.h>
|
||||
|
||||
#include "wpi/mutex.h"
|
||||
|
||||
#pragma comment(lib, "Dbghelp.lib")
|
||||
|
||||
namespace wpi {
|
||||
|
||||
std::string Demangle(char const* mangledSymbol) {
|
||||
static wpi::mutex m;
|
||||
std::scoped_lock lock(m);
|
||||
char buffer[256];
|
||||
DWORD sz = UnDecorateSymbolName(mangledSymbol, buffer, sizeof(buffer),
|
||||
UNDNAME_COMPLETE);
|
||||
if (sz == 0) return mangledSymbol;
|
||||
return std::string(buffer, sz);
|
||||
}
|
||||
|
||||
} // namespace wpi
|
||||
Reference in New Issue
Block a user