xref: /freebsd/contrib/elftoolchain/libelftc/elftc_demangle.3 (revision 2e3f49888ec8851bafb22011533217487764fdb0)
1.\" Copyright (c) 2009,2011 Joseph Koshy.  All rights reserved.
2.\"
3.\" Redistribution and use in source and binary forms, with or without
4.\" modification, are permitted provided that the following conditions
5.\" are met:
6.\" 1. Redistributions of source code must retain the above copyright
7.\"    notice, this list of conditions and the following disclaimer.
8.\" 2. Redistributions in binary form must reproduce the above copyright
9.\"    notice, this list of conditions and the following disclaimer in the
10.\"    documentation and/or other materials provided with the distribution.
11.\"
12.\" This software is provided by Joseph Koshy ``as is'' and
13.\" any express or implied warranties, including, but not limited to, the
14.\" implied warranties of merchantability and fitness for a particular purpose
15.\" are disclaimed.  in no event shall Joseph Koshy be liable
16.\" for any direct, indirect, incidental, special, exemplary, or consequential
17.\" damages (including, but not limited to, procurement of substitute goods
18.\" or services; loss of use, data, or profits; or business interruption)
19.\" however caused and on any theory of liability, whether in contract, strict
20.\" liability, or tort (including negligence or otherwise) arising in any way
21.\" out of the use of this software, even if advised of the possibility of
22.\" such damage.
23.\"
24.\" $Id: elftc_demangle.3 3645 2018-10-15 20:17:14Z jkoshy $
25.\"
26.Dd August 24, 2011
27.Dt ELFTC_DEMANGLE 3
28.Os
29.Sh NAME
30.Nm elftc_demangle
31.Nd demangle a C++ name
32.Sh LIBRARY
33.Lb libelftc
34.Sh SYNOPSIS
35.In libelftc.h
36.Ft int
37.Fo elftc_demangle
38.Fa "const char *encodedname"
39.Fa "char *buffer"
40.Fa "size_t bufsize"
41.Fa "unsigned int flags"
42.Fc
43.Sh DESCRIPTION
44Function
45.Fn elftc_demangle
46decodes a symbol name encoded according to the type encoding rules
47for the C++ language and returns a string denoting an equivalent
48C++ prototype.
49.Pp
50Argument
51.Ar encodedname
52specifies the encoded symbol name.
53Argument
54.Ar buffer
55denotes a programmer-specified area to place the prototype string in.
56Argument
57.Ar bufsize
58specifies the size of the programmer-specified area.
59Argument
60.Ar flags
61specifies the encoding style in use for argument
62.Ar encodedname .
63Supported encoding styles are:
64.Bl -tag -width ".Dv ELFTC_DEM_GNU3"
65.It Dv ELFTC_DEM_ARM
66The encoding style used by compilers adhering to the conventions of the
67C++ Annotated Reference Manual.
68.It Dv ELFTC_DEM_GNU2
69The encoding style by GNU C++ version 2.
70.It Dv ELFTC_DEM_GNU3
71The encoding style by GNU C++ version 3 and later.
72.El
73.Pp
74Argument
75.Ar flags
76may be zero, in which case the function will attempt to guess the
77encoding scheme from the contents of
78.Ar encodedname .
79.Sh RETURN VALUES
80Function
81.Fn elftc_demangle
82returns 0 on success.
83In case of an error it returns -1 and sets the
84.Va errno
85variable.
86.Sh EXAMPLES
87To decode a name that uses an unknown encoding style use:
88.Bd -literal -offset indent
89char buffer[1024];
90const char *funcname;
91
92funcname = ...; /* points to string to be demangled */
93if (elftc_demangle(funcname, buffer, sizeof(buffer), 0) == 0)
94	printf("Demangled name: %\\n", buffer);
95else
96	perror("Cannot demangle %s", funcname);
97.Ed
98.Sh ERRORS
99Function
100.Fn elftc_demangle
101may fail with the following errors:
102.Bl -tag -width ".Bq Er ENAMETOOLONG"
103.It Bq Er EINVAL
104Argument
105.Ar encodedname
106was not a valid encoded name.
107.It Bq Er ENAMETOOLONG
108The output buffer specified by arguments
109.Ar buffer
110and
111.Ar bufsize
112was too small to hold the decoded function prototype.
113.El
114.Sh SEE ALSO
115.Xr elf 3 ,
116.Xr elf_strptr 3
117