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 May 12, 2024 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 standard 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 rust v0 91.Pq Rust RFC 2603 92and legacy mangling formats. 93The specific rust mangling format will be automatically detected. 94.It auto 95Attempt to detect the language automatically (default). 96.El 97.El 98.Sh EXIT STATUS 99.Ex -std 100.Sh EXAMPLES 101.Sy Example 1 102Demangle symbols given as command line arguments. 103.Bd -literal 104% demangle '_ZGVN9__gnu_cxx16bitmap_allocatorIwE13_S_mem_blocksE' 105guard variable for __gnu_cxx::bitmap_allocator<wchar_t>::_S_mem_blocks 106% 107.Ed 108.Pp 109.Sy Example 2 110Demangle symbols from the output of another command. 111.Bd -literal 112% grep slice rust.c | head -1 113 T("__ZN4core5slice89_$LT$impl$u20$core..iter..traits..IntoIterator$u20$for$u20$$RF$$u27$a$u20$$u5b$T$u5d$$GT$9into_iter17h450e234d27262170E", 114% grep slice rust.c | head -1 | demangle 115 T("core::slice::<impl core::iter::traits::IntoIterator for &'a [T]>::into_iter::h450e234d27262170", 116% 117.Ed 118.Sh INTERFACE STABILITY 119The command line options are 120.Sy Uncommitted . 121The output format is 122.Sy Not-an-Interface . 123