2020-01-18 08:38:21 +00:00
|
|
|
/*
|
2024-10-04 11:19:50 +00:00
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <andreas@ladybird.org>
|
2020-01-18 08:38:21 +00:00
|
|
|
*
|
2021-04-22 08:24:48 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 08:38:21 +00:00
|
|
|
*/
|
|
|
|
|
2019-11-29 13:55:07 +00:00
|
|
|
#pragma once
|
|
|
|
|
2024-06-17 22:12:53 +00:00
|
|
|
#include <AK/ByteString.h>
|
|
|
|
#include <AK/StringView.h>
|
|
|
|
#include <cxxabi.h>
|
2019-11-29 13:55:07 +00:00
|
|
|
|
|
|
|
namespace AK {
|
|
|
|
|
2023-12-16 14:19:34 +00:00
|
|
|
inline ByteString demangle(StringView name)
|
2019-11-29 13:55:07 +00:00
|
|
|
{
|
|
|
|
int status = 0;
|
2023-12-16 14:19:34 +00:00
|
|
|
auto* demangled_name = abi::__cxa_demangle(name.to_byte_string().characters(), nullptr, nullptr, &status);
|
|
|
|
auto string = ByteString(status == 0 ? StringView { demangled_name, strlen(demangled_name) } : name);
|
2019-11-29 13:55:07 +00:00
|
|
|
if (status == 0)
|
2022-01-12 03:27:21 +00:00
|
|
|
free(demangled_name);
|
2019-11-29 13:55:07 +00:00
|
|
|
return string;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2024-06-17 22:12:53 +00:00
|
|
|
#if USING_AK_GLOBALLY
|
2019-11-29 13:55:07 +00:00
|
|
|
using AK::demangle;
|
2021-12-26 17:07:14 +00:00
|
|
|
#endif
|