简体   繁体   English

我可以解读GCC的RTTI名称吗?

[英]Can I ungarble GCC's RTTI names?

Using gcc, when I ask for an object/variable's type using typeid, I get a different result from the type_info::name method from what I'd expect to get on Windows. 使用gcc,当我使用typeid请求对象/变量的类型时,我得到了与我期望在Windows上获得的type_info :: name方法不同的结果。 I Googled around a bit, and found out that RTTI names are implementation-specific. 我用Google搜索了一下,发现RTTI名称是特定于实现的。

Problem is, I want to get a type's name as it would be returned on Windows. 问题是,我想获得一个类型的名称,因为它将在Windows上返回。 Is there an easy way to do this? 是否有捷径可寻?

If it's what you're asking, there is no compiler switch that would make gcc behave like msvc regarding the name returned by type_info::name() . 如果你问的是,没有编译器开关可以使gcc表现得像msvc那样关于type_info::name()返回的type_info::name()

However, in your code you can rely on the gcc specific __cxa_demangle function. 但是,在您的代码中,您可以依赖于特定于gcc的__cxa_demangle函数。

There is in fact an answer on SO that addresses your problem . 事实上,有一个答案可以解决您的问题

Reference: libstdc++ manual, Chapter 40. Demangling . 参考: libstdc ++手册,第40章.Demangling

c++ function names really include all the return and argument type information as well as the class and method name. c ++函数名称实际上包含所有返回和参数类型信息以及类和方法名称。 When compiled, they are 'mangled' into a standard form (standard for each compiler) that can act as an assembler symbol and includes all the type information. 在编译时,它们被“修改”为标准形式(每个编译器的标准),它可以充当汇编符号并包含所有类型信息。

You need to run a function or program to reverse this mangling, called a demangler . 您需要运行一个函数或程序来反转这个称为demangler的修改

try running 试试跑步

c++filt myoutput.txt

on the output of the function. 在函数的输出上。 This demangles the real symbol name back into a human readable form. 这将真实的符号名称解压缩回人类可读的形式。

Based on this other question Is there an online name demangler for C++? 基于这个问题, 有一个在线名称demangler for C ++? I've written a online tool for this: c++filtjs 我为此编写了一个在线工具: c ++ filtjs

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM