2023-01-14 06:12:41 +01:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
2023-01-23 01:51:12 +01:00
|
|
|
#include <llvm/Demangle/Demangle.h>
|
|
|
|
|
2023-01-14 06:12:41 +01:00
|
|
|
#include "common/demangle.h"
|
2023-01-14 20:53:55 +01:00
|
|
|
#include "common/scope_exit.h"
|
2023-01-14 06:12:41 +01:00
|
|
|
|
|
|
|
namespace Common {
|
|
|
|
|
|
|
|
std::string DemangleSymbol(const std::string& mangled) {
|
|
|
|
auto is_itanium = [](const std::string& name) -> bool {
|
|
|
|
// A valid Itanium encoding requires 1-4 leading underscores, followed by 'Z'.
|
|
|
|
auto pos = name.find_first_not_of('_');
|
2023-01-14 20:53:55 +01:00
|
|
|
return pos > 0 && pos <= 4 && pos < name.size() && name[pos] == 'Z';
|
2023-01-14 06:12:41 +01:00
|
|
|
};
|
|
|
|
|
2023-01-14 20:53:55 +01:00
|
|
|
if (mangled.empty()) {
|
|
|
|
return mangled;
|
|
|
|
}
|
|
|
|
|
2023-01-14 06:12:41 +01:00
|
|
|
char* demangled = nullptr;
|
2023-01-14 20:53:55 +01:00
|
|
|
SCOPE_EXIT({ std::free(demangled); });
|
|
|
|
|
2023-01-14 06:12:41 +01:00
|
|
|
if (is_itanium(mangled)) {
|
2023-07-19 01:31:35 +02:00
|
|
|
demangled = llvm::itaniumDemangle(mangled.c_str());
|
2023-01-14 06:12:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!demangled) {
|
|
|
|
return mangled;
|
|
|
|
}
|
2023-01-14 20:53:55 +01:00
|
|
|
return demangled;
|
2023-01-14 06:12:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Common
|