|
|
@ -1,6 +1,8 @@ |
|
|
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
|
|
|
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
#include <string_view>
|
|
|
#include <llvm/Demangle/Demangle.h>
|
|
|
#include <llvm/Demangle/Demangle.h>
|
|
|
|
|
|
|
|
|
#include "common/demangle.h"
|
|
|
#include "common/demangle.h"
|
|
|
@ -9,29 +11,22 @@ |
|
|
namespace Common { |
|
|
namespace Common { |
|
|
|
|
|
|
|
|
std::string DemangleSymbol(const std::string& mangled) { |
|
|
std::string DemangleSymbol(const std::string& mangled) { |
|
|
auto is_itanium = [](const std::string& name) -> bool { |
|
|
|
|
|
|
|
|
if (mangled.size() > 0) { |
|
|
|
|
|
auto const is_itanium = [](std::string_view name) -> bool { |
|
|
// A valid Itanium encoding requires 1-4 leading underscores, followed by 'Z'.
|
|
|
// A valid Itanium encoding requires 1-4 leading underscores, followed by 'Z'.
|
|
|
auto pos = name.find_first_not_of('_'); |
|
|
|
|
|
|
|
|
auto const pos = name.find_first_not_of('_'); |
|
|
return pos > 0 && pos <= 4 && pos < name.size() && name[pos] == 'Z'; |
|
|
return pos > 0 && pos <= 4 && pos < name.size() && name[pos] == 'Z'; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
if (mangled.empty()) { |
|
|
|
|
|
return mangled; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
char* demangled = nullptr; |
|
|
|
|
|
SCOPE_EXIT { |
|
|
|
|
|
std::free(demangled); |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::string ret = mangled; |
|
|
if (is_itanium(mangled)) { |
|
|
if (is_itanium(mangled)) { |
|
|
demangled = llvm::itaniumDemangle(mangled.c_str()); |
|
|
|
|
|
|
|
|
if (char* p = llvm::itaniumDemangle(mangled); p != nullptr) { |
|
|
|
|
|
ret = std::string{p}; |
|
|
|
|
|
std::free(p); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (!demangled) { |
|
|
|
|
|
return mangled; |
|
|
|
|
|
} |
|
|
} |
|
|
return demangled; |
|
|
|
|
|
|
|
|
return ret; |
|
|
|
|
|
} |
|
|
|
|
|
return std::string{}; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} // namespace Common
|
|
|
} // namespace Common
|