C++ 我可以使用枚举数的标识符请求枚举数吗?
假设我写了以下内容:C++ 我可以使用枚举数的标识符请求枚举数吗?,c++,gcc,symbols,abi,C++,Gcc,Symbols,Abi,假设我写了以下内容: enum class Color { Red, Green, Blue, }; template <Color c> Color foo() { return c; } template Color foo<Color::Green>(); enum类颜色{红、绿、蓝,}; 模板颜色foo(){return c;} 模板颜色foo(); 并编译了它。当我查看编译代码的objdump时,我得到: [einpoklum@myhost /tmp]$ o
enum class Color { Red, Green, Blue, };
template <Color c> Color foo() { return c; }
template Color foo<Color::Green>();
enum类颜色{红、绿、蓝,};
模板颜色foo(){return c;}
模板颜色foo();
并编译了它。当我查看编译代码的objdump时,我得到:
[einpoklum@myhost /tmp]$ objdump -t f.o | grep "\.text\." | sed 's/^.*\.text\.//;' | c++filt
Color foo<(Color)1>()
Color foo<(Color)1>() 000000000000000b Color foo<(Color)1>()
[einpoklum@myhost/tmp]$objdump-t f.o|grep“\.text\。”sed's/^.*\.text\。/;'c++过滤器
彩色foo()
颜色foo()000000000000000 B颜色foo()
如果我对
(GCC;可能它与您的编译器不同)使用abi::\uuucxa\u demangle()
,它也类似-(Color)0
或Color)1
是模板参数,而不是红色
或绿色
或颜色::红色
或绿色
显然,我不能让名字被我喜欢的方式弄乱。但是-我真的希望能够获得(或编写?)Demanling调用的一个变体,它不是
“Color foo()”
返回“Color foo()”
(或“Color foo()”)
。这可行吗?对于包含调试信息-部分的对象文件可能是可行的。调试信息包含有关枚举类颜色的信息
,它需要一些工具来读取ELF调试信息,从语义上解析数据,并将信息应用/传递到c++过滤器。我不知道这些工具是否存在(可能,在GDB中,它们是粘在一起的)
一般来说,使用优化编译的对象文件或剥离的调试信息几乎是不可能的-关于enum class Color
的信息根本不存在
从优化构建
objdump -s aaa.o
aaa.o: file format pe-x86-64
Contents of section .text$_Z3fooIL5Color1EES0_v:
0000 554889e5 b8010000 005dc390 90909090 UH.......]......
Contents of section .xdata$_Z3fooIL5Color1EES0_v:
0000 01040205 04030150 .......P
Contents of section .pdata$_Z3fooIL5Color1EES0_v:
0000 00000000 0b000000 00000000 ............
Contents of section .rdata$zzz:
0000 4743433a 20287838 365f3634 2d706f73 GCC: (x86_64-pos
0010 69782d73 65682d72 6576302c 20427569 ix-seh-rev0, Bui
0020 6c742062 79204d69 6e47572d 57363420 lt by MinGW-W64
0030 70726f6a 65637429 20352e33 2e300000 project) 5.3.0..
调试生成包含节的部分内容。调试\u信息:
0070 00000000 00000000 00000002 436f6c6f ............Colo
0080 720004a3 00000001 01a30000 00035265 r.............Re
0090 64000003 47726565 6e000103 426c7565 d...Green...Blue
00a0 00020004 0405696e 74000566 6f6f3c28 ......int..foo<(
00b0 436f6c6f 7229313e 0001065f 5a33666f Color)1>..._Z3fo
00c0 6f494c35 436f6c6f 72314545 53305f76 oIL5Color1EES0_v
00d0 007b0000 00000000 00000000 000b0000 .{..............
00e0 00000000 00019c06 63007b00 00000100 ........c.{.....
00f0 00
0070000000000000000000002436F6C6F
0080 720004a3 0000000 1 01a30000 00035265 r……….关于
0090 64000003 47726565 6e000103 426c7565 d…绿色…蓝色
00a0 000200004 0405696e 74000566 6f6f3c28……国际……食品
00c0 6f494c35 436f6c6f 72314545 53305f76油5COLOR1EES0_v
00D0007B0000000000000000000000000B0000.{。。。。。。。。。。。。。。
00e0 00000000 00019c06 63007000 00000100…….c.{。。。。。
00F000
@severinpapadeux:查看我的编辑。请检查答案