xref: /illumos-gate/usr/src/man/man1/demangle.1 (revision c3937c08b16d32677a7dc955a81325f2e7a61b5d)
1.\" The contents of this file are subject to the terms of the
2.\" Common Development and Distribution License (the "License").
3.\" You may not use this file except in compliance with the License.
4.\"
5.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
6.\" or http://www.opensolaris.org/os/licensing.
7.\" See the License for the specific language governing permissions
8.\" and limitations under the License.
9.\"
10.\" When distributing Covered Code, include this CDDL HEADER in each
11.\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
12.\" If applicable, add the following below this CDDL HEADER, with the
13.\" fields enclosed by brackets "[]" replaced with your own identifying
14.\" information: Portions Copyright [yyyy] [name of copyright owner]
15.\"
16.\" Copyright 2020 Joyent, Inc.
17.\"
18.Dd March  3, 2020
19.Dt DEMANGLE 1
20.Os
21.Sh NAME
22.Nm demangle
23.Nd demangle symbols
24.Sh SYNOPSIS
25.Nm
26.Oo
27.Fl l
28.Ar lang
29.Oc
30.Op Ar symbol Ns ...
31.Sh DESCRIPTION
32The
33.Nm
34utility attempts to detect mangled symbols and transform them back into a
35more human friendly version of the symbol.
36.Pp
37Some languages allow the same identifier to refer to multiple things
38(functions, variables, etc\&.) where some additional context such as
39parameter types, return types, etc\&. are used to disambiguate between the
40symbols sharing the same name.
41When compiling such languages into an executable form, most binary formats
42do not allow for duplicate symbol names or provide a way to disambiguate
43between duplicate names.
44.Pp
45To solve this problem, many languages will use the additional context from
46the source code to transform the symbol name into a unique name.
47This process is called name mangling.
48While the resulting name is predictable, the mangled names are often difficult
49for humans to interpret.
50.Pp
51The
52.Nm
53utility can be invoked in one of two ways.
54In the first method,
55.Ar symbol
56is demangled and the result is written to standard out, one line per input
57.Ar symbol .
58If any input
59.Ar symbol
60cannot be demangled, the original value of
61.Ar symbol
62is output unchanged.
63In the second method,
64.Nm
65reads standard in, and whenever it encounters a potential symbol, it will
66attempt to replace the symbol in stdandard out with the demangled version.
67If the symbol cannot be demangled, it is output unchanged.
68.Pp
69For either method, if an error other than attempting to demangle an non-mangled
70symbol (e.g. out of memory), that error will be written to standard error.
71.Sh OPTIONS
72.Bl -tag -width Fl
73.It Fl l Ar lang
74Treat all potential symbols as symbols from
75.Ar lang .
76By default,
77.Nm
78will attempt to detect the language and demangle symbols for all supported
79languages.
80Current supported values of
81.Ar lang
82are:
83.Bl -tag -width rust -offset indent
84.It c++
85The C++ mangling format defined by the Itanium ABI.
86While the mangling format was originally defined for the Itanium processor, g++
87and clang use this format for all their supported platforms (including x86 and
88SPARC).
89.It rust
90The legacy rust mangling format.
91.It auto
92Attempt to detect the language automatically (default).
93.El
94.El
95.Sh EXIT STATUS
96.Ex -std
97.Sh EXAMPLES
98.Sy Example 1
99Demangle symbols given as command line arguments.
100.Bd -literal
101% demangle '_ZGVN9__gnu_cxx16bitmap_allocatorIwE13_S_mem_blocksE'
102guard variable for __gnu_cxx::bitmap_allocator<wchar_t>::_S_mem_blocks
103%
104.Ed
105.Pp
106.Sy Example 2
107Demangle symbols from the output of another command.
108.Bd -literal
109% grep slice rust.c | head -1
110    T("__ZN4core5slice89_$LT$impl$u20$core..iter..traits..IntoIterator$u20$for$u20$$RF$$u27$a$u20$$u5b$T$u5d$$GT$9into_iter17h450e234d27262170E",
111% grep slice rust.c | head -1 | demangle
112    T("core::slice::<impl core::iter::traits::IntoIterator for &'a [T]>::into_iter::h450e234d27262170",
113%
114.Ed
115.Sh INTERFACE STABILITY
116The command line options are
117.Sy Uncommitted .
118The output format is
119.Sy Not-an-Interface .
120