[*] Demangle

This commit is contained in:
Reece Wilson 2022-03-31 21:34:37 +01:00
parent 2eb5c97800
commit 556c6c37bb
3 changed files with 99 additions and 0 deletions

View File

@ -75,6 +75,10 @@ namespace Aurora::Debug
*/ */
AUKN_SYM AU_NORETURN void Panic(); AUKN_SYM AU_NORETURN void Panic();
/**
Localize platform dependent abi mangled name
*/
AUKN_SYM AuResult<AuString> DemangleName(const AuString &pName);
AUKN_SYM void DebugBreak(); AUKN_SYM void DebugBreak();
} }

82
Source/Debug/Demangle.cpp Normal file
View File

@ -0,0 +1,82 @@
/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: Demangle.cpp
Date: 2022-3-31
Author: Reece
***/
#pragma once
#include <Source/RuntimeInternal.hpp>
#include "Debug.hpp"
#include <DbgHelp.h>
namespace Aurora::Debug
{
AUKN_SYM AuResult<AuString> DemangleName(const AuString &pName)
{
// Wine impl: https://github.com/wine-mirror/wine/blob/master/dlls/msvcrt/undname.c
// Google impl: idr where i saw it last
AuResult<AuString> ret;
#if defined(AURORA_IS_MODERNNT_DERIVED)
struct win32poll
{
const char *ptr;
char name[4096] = {0};
} poll;
poll.ptr = {};
if (pName.size() >= AuArraySize(poll.name))
{
return ret;
}
AuMemcpy(poll.name, pName.data(), pName.size());
auto pInfo = (__std_type_info_data *)&poll;
#ifdef _M_CEE_PURE
ret.type = __std_type_info_name((__std_type_info_data *)&poll, static_cast<__type_info_node *>(__type_info_root_node.ToPointer()));
#else
ret.type = __std_type_info_name(pInfo, &__type_info_root_node);
#endif
// On failure, the undecorated name is assigned the dname docorated name, which is offset by +1 (the '?' or '_' hint)
if (strcmp(pInfo->_UndecoratedName, pInfo->_DecoratedName + 1) == 0)
{
auto characters = UnDecorateSymbolName(pName.c_str(), poll.name, AuArraySize(poll.name), UNDNAME_32_BIT_DECODE);
if (!characters)
{
return ret;
}
ret.type = AuString(poll.name, characters);
}
#else
int status;
char *res = abi::__cxa_demangle(pName.c_str(),
nullptr,
nullptr,
&status);
if (!res)
{
return ret;
}
if (status != 0)
{
free(res);
return ret;
}
ret.type = res;
free(res);
#endif
ret.Complete();
return ret;
}
}

13
Source/Debug/Demangle.hpp Normal file
View File

@ -0,0 +1,13 @@
/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: Demangle.hpp
Date: 2022-3-31
Author: Reece
***/
#pragma once
namespace Aurora::Debug
{
}