2019-01-17 16:18:44 +01:00
|
|
|
//===-- Demangle.cpp - Common demangling functions ------------------------===//
|
|
|
|
//
|
2019-01-19 09:50:56 +01:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2019-01-17 16:18:44 +01:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
///
|
|
|
|
/// \file This file contains definitions of common demangling functions.
|
|
|
|
///
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/Demangle/Demangle.h"
|
2019-01-22 20:18:18 +01:00
|
|
|
#include <cstdlib>
|
2019-01-17 16:18:44 +01:00
|
|
|
|
2019-01-18 14:58:41 +01:00
|
|
|
static bool isItaniumEncoding(const std::string &MangledName) {
|
|
|
|
size_t Pos = MangledName.find_first_not_of('_');
|
|
|
|
// A valid Itanium encoding requires 1-4 leading underscores, followed by 'Z'.
|
|
|
|
return Pos > 0 && Pos <= 4 && MangledName[Pos] == 'Z';
|
|
|
|
}
|
|
|
|
|
2019-01-17 16:18:44 +01:00
|
|
|
std::string llvm::demangle(const std::string &MangledName) {
|
|
|
|
char *Demangled;
|
2019-01-18 14:58:41 +01:00
|
|
|
if (isItaniumEncoding(MangledName))
|
2019-01-17 16:18:44 +01:00
|
|
|
Demangled = itaniumDemangle(MangledName.c_str(), nullptr, nullptr, nullptr);
|
|
|
|
else
|
2020-05-19 01:57:30 +02:00
|
|
|
Demangled = microsoftDemangle(MangledName.c_str(), nullptr, nullptr,
|
|
|
|
nullptr, nullptr);
|
2019-01-17 16:18:44 +01:00
|
|
|
|
|
|
|
if (!Demangled)
|
|
|
|
return MangledName;
|
|
|
|
|
|
|
|
std::string Ret = Demangled;
|
2020-07-20 22:15:49 +02:00
|
|
|
std::free(Demangled);
|
2019-01-17 16:18:44 +01:00
|
|
|
return Ret;
|
|
|
|
}
|