mirror of
https://github.com/tbsdtv/linux_media.git
synced 2025-07-23 20:51:03 +02:00
Refactor C++ demangling out of symbol-elf into its own files similar to other languages. Add abi::__cxa_demangle support. As the other demanglers are not shippable with distributions, this brings back C++ demangling in a common case. It isn't perfect as the support for optionally demangling arguments and modifiers isn't present. Signed-off-by: Ian Rogers <irogers@google.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Andres Freund <andres@anarazel.de> Cc: Ingo Molnar <mingo@redhat.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Leo Yan <leo.yan@linaro.org> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Martin Liška <mliska@suse.cz> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Nathan Chancellor <nathan@kernel.org> Cc: Nick Desaulniers <ndesaulniers@google.com> Cc: Pavithra Gurushankar <gpavithrasha@gmail.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Quentin Monnet <quentin@isovalent.com> Cc: Roberto Sassu <roberto.sassu@huawei.com> Cc: Stephane Eranian <eranian@google.com> Cc: Tiezhu Yang <yangtiezhu@loongson.cn> Cc: Tom Rix <trix@redhat.com> Cc: Yang Jihong <yangjihong1@huawei.com> Cc: llvm@lists.linux.dev Link: https://lore.kernel.org/r/20230311065753.3012826-2-irogers@google.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
51 lines
1.3 KiB
C++
51 lines
1.3 KiB
C++
// SPDX-License-Identifier: GPL-2.0
|
|
#include "demangle-cxx.h"
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <linux/compiler.h>
|
|
|
|
#ifdef HAVE_LIBBFD_SUPPORT
|
|
#define PACKAGE 'perf'
|
|
#include <bfd.h>
|
|
#endif
|
|
|
|
#ifdef HAVE_CXA_DEMANGLE_SUPPORT
|
|
#include <cxxabi.h>
|
|
#endif
|
|
|
|
#if defined(HAVE_LIBBFD_SUPPORT) || defined(HAVE_CPLUS_DEMANGLE_SUPPORT)
|
|
#ifndef DMGL_PARAMS
|
|
#define DMGL_PARAMS (1 << 0) /* Include function args */
|
|
#define DMGL_ANSI (1 << 1) /* Include const, volatile, etc */
|
|
#endif
|
|
#endif
|
|
|
|
/*
|
|
* Demangle C++ function signature
|
|
*
|
|
* Note: caller is responsible for freeing demangled string
|
|
*/
|
|
extern "C"
|
|
char *cxx_demangle_sym(const char *str, bool params __maybe_unused,
|
|
bool modifiers __maybe_unused)
|
|
{
|
|
#ifdef HAVE_LIBBFD_SUPPORT
|
|
int flags = (params ? DMGL_PARAMS : 0) | (modifiers ? DMGL_ANSI : 0);
|
|
|
|
return bfd_demangle(NULL, str, flags);
|
|
#elif defined(HAVE_CPLUS_DEMANGLE_SUPPORT)
|
|
int flags = (params ? DMGL_PARAMS : 0) | (modifiers ? DMGL_ANSI : 0);
|
|
|
|
return cplus_demangle(str, flags);
|
|
#elif defined(HAVE_CXA_DEMANGLE_SUPPORT)
|
|
size_t len = strlen(str);
|
|
char *output = (char*)malloc(len);
|
|
int status;
|
|
|
|
output = abi::__cxa_demangle(str, output, &len, &status);
|
|
return output;
|
|
#else
|
|
return NULL;
|
|
#endif
|
|
}
|