From ffdd9bb38eded278f4e0ed1f54f8d7ec187ec52c Mon Sep 17 00:00:00 2001 From: Johannes Stoelp Date: Wed, 27 Mar 2024 19:37:05 +0100 Subject: c++filt: note to demangle type --- src/development/c++filt.md | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'src/development') diff --git a/src/development/c++filt.md b/src/development/c++filt.md index 2592ba9..38607ee 100644 --- a/src/development/c++filt.md +++ b/src/development/c++filt.md @@ -2,7 +2,8 @@ ## Demangle symbol ```markdown - c++-filt + c++-filt [opts] + -t Try to also demangle types. ``` ## Demangle stream @@ -10,3 +11,36 @@ For example dynamic symbol table: ```markdown readelf -W --dyn-syms | c++filt ``` + +## Demangle types +```c++ +// file: type.cc +#include +#include + +#define P(ty) printf(#ty " -> %s\n", typeid(ty).name()) + +template +struct Foo {}; + +int main() { + P(int); + P(unsigned char); + P(Foo<>); + P(Foo); +} +``` +Build and run: +```sh +$ clang++ type.cc && ./a.out | c++filt +int -> i +unsigned char -> h +Foo<> -> 3FooIvE +Foo -> 3FooIiE + +$ clang++ type.cc && ./a.out | c++filt -t +int -> int +unsigned char -> unsigned char +Foo<> -> Foo +Foo -> Foo +``` -- cgit v1.2.3