【问题标题】:C equivalent for __cxa_demangle for gcc?用于 gcc 的 __cxa_demangle 的 C 等效项?
【发布时间】:2019-09-18 09:17:08
【问题描述】:

我过去曾使用以下函数来解开 c++ 符号,它已被证明非常有用:

char* __cxa_demangle(const char* __mangled_name, char* __output_buffer, size_t* __length, int* __status);

现在我在一个使用 gcc 的 C 应用程序上工作,但不能使用 __cxa_demangle 因为它是一个 C 程序(它仅适用于 C++ 编译器的 g++),在 C++ 中我通常会调用如下:

abi::__cxa_demangle(mangled.c_str(), NULL, 0, 0);

有人知道如何在 C 中实现相同的功能吗?

【问题讨论】:

  • C 中的 demangle 功能的目的是什么?
  • 这本身可能是另一个stackoverflow问题:)它破坏了函数签名,生成的回溯带有错误的名称。这是一篇关于它的 wiki 文章 :) en.wikipedia.org/wiki/Name_mangling
  • 好的,我明白了:这是微软的事情,在为 Windows 编译时,后面跟着 GCC。
  • 这适用于所有平台。我从未在 Windows 上使用过它,尽管我确信它在那里也很重要。

标签: c gcc demangler


【解决方案1】:

在源代码的注释中回答我自己的问题:

   *  @note The same demangling functionality is available via
   *  libiberty (@c <libiberty/demangle.h> and @c libiberty.a) in GCC
   *  3.1 and later, but that requires explicit installation (@c
   *  --enable-install-libiberty) and uses a different API, although
   *  the ABI is unchanged.
   */
  char*
  __cxa_demangle(const char* __mangled_name, char* __output_buffer,
         size_t* __length, int* __status);

【讨论】:

  • 道歉我写完问题后很快就看到了这条评论
猜你喜欢
  • 1970-01-01
  • 2015-09-16
  • 1970-01-01
  • 2011-02-07
  • 1970-01-01
  • 2012-01-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多