aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJohannes Stoelp <johannes.stoelp@gmail.com>2024-03-27 19:37:05 +0100
committerJohannes Stoelp <johannes.stoelp@gmail.com>2024-03-27 19:37:05 +0100
commitffdd9bb38eded278f4e0ed1f54f8d7ec187ec52c (patch)
treeffee1981c50c537f3b2b6014e347c0889471c21d
parent0ccba0943d477b71cdccd2505eb81b95f091263a (diff)
downloadnotes-ffdd9bb38eded278f4e0ed1f54f8d7ec187ec52c.tar.gz
notes-ffdd9bb38eded278f4e0ed1f54f8d7ec187ec52c.zip
c++filt: note to demangle type
-rw-r--r--src/development/c++filt.md36
1 files changed, 35 insertions, 1 deletions
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 <symbol_str>
+ c++-filt [opts] <symbol_str>
+ -t Try to also demangle types.
```
## Demangle stream
@@ -10,3 +11,36 @@ For example dynamic symbol table:
```markdown
readelf -W --dyn-syms <elf> | c++filt
```
+
+## Demangle types
+```c++
+// file: type.cc
+#include <cstdio>
+#include <typeinfo>
+
+#define P(ty) printf(#ty " -> %s\n", typeid(ty).name())
+
+template <typename T = void>
+struct Foo {};
+
+int main() {
+ P(int);
+ P(unsigned char);
+ P(Foo<>);
+ P(Foo<int>);
+}
+```
+Build and run:
+```sh
+$ clang++ type.cc && ./a.out | c++filt
+int -> i
+unsigned char -> h
+Foo<> -> 3FooIvE
+Foo<int> -> 3FooIiE
+
+$ clang++ type.cc && ./a.out | c++filt -t
+int -> int
+unsigned char -> unsigned char
+Foo<> -> Foo<void>
+Foo<int> -> Foo<int>
+```