2020-01-18 09:38:21 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 09:38:21 +01:00
|
|
|
*/
|
|
|
|
|
2019-11-29 14:55:07 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AK/String.h>
|
2020-03-23 13:45:10 +01:00
|
|
|
#include <AK/StringView.h>
|
2020-02-03 06:26:32 +01:00
|
|
|
|
2020-05-20 14:23:32 +02:00
|
|
|
#ifndef BUILDING_SERENITY_TOOLCHAIN
|
2020-03-23 13:45:10 +01:00
|
|
|
# include <cxxabi.h>
|
2020-02-03 06:26:32 +01:00
|
|
|
#endif
|
2019-11-29 14:55:07 +01:00
|
|
|
|
|
|
|
namespace AK {
|
|
|
|
|
2020-01-16 22:04:44 +01:00
|
|
|
inline String demangle(const StringView& name)
|
2019-11-29 14:55:07 +01:00
|
|
|
{
|
2020-05-20 14:23:32 +02:00
|
|
|
#ifdef BUILDING_SERENITY_TOOLCHAIN
|
2020-02-03 06:26:32 +01:00
|
|
|
return name;
|
|
|
|
#else
|
2019-11-29 14:55:07 +01:00
|
|
|
int status = 0;
|
2020-05-06 18:18:24 +01:00
|
|
|
auto* demangled_name = abi::__cxa_demangle(name.to_string().characters(), nullptr, nullptr, &status);
|
2019-11-29 14:55:07 +01:00
|
|
|
auto string = String(status == 0 ? demangled_name : name);
|
|
|
|
if (status == 0)
|
|
|
|
kfree(demangled_name);
|
|
|
|
return string;
|
2020-02-03 06:26:32 +01:00
|
|
|
#endif
|
2019-11-29 14:55:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
using AK::demangle;
|