Debian Codegraph @

src/demangle/demangle_with_winapi.cpp

raw
1 #ifdef CPPTRACE_DEMANGLE_WITH_WINAPI
2
3 #include "demangle/demangle.hpp"
4 #include "platform/dbghelp_utils.hpp"
5
6 #include <string>
7
8 #ifndef WIN32_LEAN_AND_MEAN
9 #define WIN32_LEAN_AND_MEAN
10 #endif
11 #include <windows.h>
12 #include <dbghelp.h>
13
14 CPPTRACE_BEGIN_NAMESPACE
15 namespace detail {
16 std::string demangle(const std::string& name, bool) {
17 // Dbghelp is is single-threaded, so acquire a lock.
18 auto lock = get_dbghelp_lock();
19 char buffer[500];
20 auto ret = UnDecorateSymbolName(name.c_str(), buffer, sizeof(buffer) - 1, 0);
21 if(ret == 0) {
22 return name;
23 } else {
24 buffer[ret] = 0; // just in case, ms' docs unclear if null terminator inserted
25 return buffer;
26 }
27 }
28 }
29 CPPTRACE_END_NAMESPACE
30
31 #endif