Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
Demangle.cpp
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#include "Stroika/Foundation/StroikaPreComp.h"
5
6#include <cstdlib> // to force __GLIBCXX__ define reference
7
8#if defined(__GNUC__) && defined(__GLIBCXX__)
9#include <cxxabi.h>
10#elif qStroika_Foundation_Common_Platform_Windows
11#include <Windows.h>
12
13#include <Dbghelp.h>
14#endif
15
17
18#include "Demangle.h"
19
20using namespace Stroika::Foundation;
21
22#if qStroika_Foundation_Common_Platform_Windows
23// otherwise modules linking with this code will tend to get link errors without explicitly linking
24// to this module...
25#pragma comment(lib, "Dbghelp.lib")
26#endif
27
28/*
29 ********************************************************************************
30 ************************ Debug::DropIntoDebuggerIfPresent **********************
31 ********************************************************************************
32 */
33Characters::String Debug::Demangle (const Characters::String& originalName)
34{
35#if defined(__GNUC__) && defined(__GLIBCXX__)
36 int status{};
37 char* realname = abi::__cxa_demangle (originalName.AsNarrowSDKString (Characters::eIgnoreErrors).c_str (), 0, 0, &status);
38 [[maybe_unused]] auto&& cleanup = Execution::Finally ([&realname] () noexcept {
39 if (realname != nullptr) {
40 ::free (realname);
41 }
42 });
43 if (status == 0) {
45 }
46#elif qStroika_Foundation_Common_Platform_Windows
47 char resultBuf[10 * 1024];
48 if (::UnDecorateSymbolName (originalName.AsNarrowSDKString (Characters::eIgnoreErrors).c_str (), resultBuf, sizeof (resultBuf), UNDNAME_COMPLETE) != 0) {
50 }
51#endif
52 return originalName;
53}
String is like std::u32string, except it is much easier to use, often much more space efficient,...
Definition String.h:201
nonvirtual string AsNarrowSDKString() const
Definition String.inl:830
static String FromNarrowSDKString(const char *from)
Definition String.inl:470
auto Finally(FUNCTION &&f) -> Private_::FinallySentry< FUNCTION >
Definition Finally.inl:31