aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/development/c++filt.md
blob: 38607ee2c2ef5a0886fc814be63b17f346603b97 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# c++filt(1)

## Demangle symbol
```markdown
  c++-filt [opts] <symbol_str>
    -t    Try to also demangle types.
```

## Demangle stream
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>
```