Copyright 1992, 1993, 1994, 1995, 1996, 1997, 1998, 2000, 2001, 2002,
2003, 2004, 2005, 2007 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License
as published by the Free Software Foundation; either version 2, or
(at your option) any later version.
In addition to the permissions in the GNU Library General Public
License, the Free Software Foundation gives you unlimited
permission to link the compiled version of this file into
combinations with other programs, and to distribute those
combinations without any restriction coming from the use of this
file. (The Library Public License restrictions do apply in other
respects; for example, they cover modification of the file, and
distribution when not linked into a combined executable.)
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
02110-1301, USA. */
#if !defined (DEMANGLE_H)
#define DEMANGLE_H
#include "libiberty.h"
#ifdef __cplusplus
extern "C" {
#endif
#define DMGL_NO_OPTS 0 /* For readability... */
#define DMGL_PARAMS (1 << 0) /* Include function args */
#define DMGL_ANSI (1 << 1) /* Include const, volatile, etc */
#define DMGL_JAVA (1 << 2) /* Demangle as Java rather than C++. */
#define DMGL_VERBOSE (1 << 3) /* Include implementation details. */
#define DMGL_TYPES (1 << 4) /* Also try to demangle type encodings. */
#define DMGL_RET_POSTFIX (1 << 5) /* Print function return types (when
present) after function signature */
#define DMGL_AUTO (1 << 8)
#define DMGL_GNU (1 << 9)
#define DMGL_LUCID (1 << 10)
#define DMGL_ARM (1 << 11)
#define DMGL_HP (1 << 12) /* For the HP aCC compiler;
same as ARM except for
template arguments, etc. */
#define DMGL_EDG (1 << 13)
#define DMGL_GNU_V3 (1 << 14)
#define DMGL_GNAT (1 << 15)
#define DMGL_STYLE_MASK (DMGL_AUTO|DMGL_GNU|DMGL_LUCID|DMGL_ARM|DMGL_HP|DMGL_EDG|DMGL_GNU_V3|DMGL_JAVA|DMGL_GNAT)
Lucid and ARM styles are still kept logically distinct, even though
they now both behave identically. The resulting style is actual the
union of both. I.E. either style recognizes both "__pt__" and "__rf__"
for operator "->", even though the first is lucid style and the second
is ARM style. (FIXME?) */
extern enum demangling_styles
{
no_demangling = -1,
unknown_demangling = 0,
auto_demangling = DMGL_AUTO,
gnu_demangling = DMGL_GNU,
lucid_demangling = DMGL_LUCID,
arm_demangling = DMGL_ARM,
hp_demangling = DMGL_HP,
edg_demangling = DMGL_EDG,
gnu_v3_demangling = DMGL_GNU_V3,
java_demangling = DMGL_JAVA,
gnat_demangling = DMGL_GNAT
} current_demangling_style;
#define NO_DEMANGLING_STYLE_STRING "none"
#define AUTO_DEMANGLING_STYLE_STRING "auto"
#define GNU_DEMANGLING_STYLE_STRING "gnu"
#define LUCID_DEMANGLING_STYLE_STRING "lucid"
#define ARM_DEMANGLING_STYLE_STRING "arm"
#define HP_DEMANGLING_STYLE_STRING "hp"
#define EDG_DEMANGLING_STYLE_STRING "edg"
#define GNU_V3_DEMANGLING_STYLE_STRING "gnu-v3"
#define JAVA_DEMANGLING_STYLE_STRING "java"
#define GNAT_DEMANGLING_STYLE_STRING "gnat"
#define CURRENT_DEMANGLING_STYLE current_demangling_style
#define AUTO_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_AUTO)
#define GNU_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_GNU)
#define LUCID_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_LUCID)
#define ARM_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_ARM)
#define HP_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_HP)
#define EDG_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_EDG)
#define GNU_V3_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_GNU_V3)
#define JAVA_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_JAVA)
#define GNAT_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_GNAT)
pulled from gdb into libiberty because it is useful to binutils also. */
extern const struct demangler_engine
{
const char *const demangling_style_name;
const enum demangling_styles demangling_style;
const char *const demangling_style_doc;
} libiberty_demanglers[];
extern char *
cplus_demangle (const char *mangled, int options);
extern int
cplus_demangle_opname (const char *opname, char *result, int options);
extern const char *
cplus_mangle_opname (const char *opname, int options);
extern void
set_cplus_marker_for_demangling (int ch);
extern enum demangling_styles
cplus_demangle_set_style (enum demangling_styles style);
extern enum demangling_styles
cplus_demangle_name_to_style (const char *name);
typedef void (*demangle_callbackref) (const char *, size_t, void *);
variants return non-zero on success, zero on error. char* variants
return a string allocated by malloc on success, NULL on error. */
extern int
cplus_demangle_v3_callback (const char *mangled, int options,
demangle_callbackref callback, void *opaque);
extern char*
cplus_demangle_v3 (const char *mangled, int options);
extern int
java_demangle_v3_callback (const char *mangled,
demangle_callbackref callback, void *opaque);
extern char*
java_demangle_v3 (const char *mangled);
enum gnu_v3_ctor_kinds {
gnu_v3_complete_object_ctor = 1,
gnu_v3_base_object_ctor,
gnu_v3_complete_object_allocating_ctor
};
in the G++ V3 ABI demangling style. Specifically, return an `enum
gnu_v3_ctor_kinds' value indicating what kind of constructor
it is. */
extern enum gnu_v3_ctor_kinds
is_gnu_v3_mangled_ctor (const char *name);
enum gnu_v3_dtor_kinds {
gnu_v3_deleting_dtor = 1,
gnu_v3_complete_object_dtor,
gnu_v3_base_object_dtor
};
in the G++ V3 ABI demangling style. Specifically, return an `enum
gnu_v3_dtor_kinds' value, indicating what kind of destructor
it is. */
extern enum gnu_v3_dtor_kinds
is_gnu_v3_mangled_dtor (const char *name);
representation of the mangled name, and the second pass turns the
tree representation into a demangled string. Here we define an
interface to permit a caller to build their own tree
representation, which they can pass to the demangler to get a
demangled string. This can be used to canonicalize user input into
something which the demangler might output. It could also be used
by other demanglers in the future. */
component types have one or two subtrees, referred to as left and
right (a component type with only one subtree puts it in the left
subtree). */
enum demangle_component_type
{
DEMANGLE_COMPONENT_NAME,
some such thing, and the right subtree is a name qualified by
that class. */
DEMANGLE_COMPONENT_QUAL_NAME,
right subtree is a name which is local to that function. */
DEMANGLE_COMPONENT_LOCAL_NAME,
describes that name as a function. */
DEMANGLE_COMPONENT_TYPED_NAME,
subtree is a template argument list. */
DEMANGLE_COMPONENT_TEMPLATE,
parameter index. */
DEMANGLE_COMPONENT_TEMPLATE_PARAM,
constructor. */
DEMANGLE_COMPONENT_CTOR,
DEMANGLE_COMPONENT_DTOR,
vtable. */
DEMANGLE_COMPONENT_VTABLE,
is a VTT. */
DEMANGLE_COMPONENT_VTT,
this is a vtable, and the right subtree is the derived type for
which this vtable is built. */
DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE,
this is the tpeinfo structure. */
DEMANGLE_COMPONENT_TYPEINFO,
is the typeinfo name. */
DEMANGLE_COMPONENT_TYPEINFO_NAME,
this is the tpyeinfo function. */
DEMANGLE_COMPONENT_TYPEINFO_FN,
thunk. */
DEMANGLE_COMPONENT_THUNK,
is a virtual thunk. */
DEMANGLE_COMPONENT_VIRTUAL_THUNK,
is a covariant thunk. */
DEMANGLE_COMPONENT_COVARIANT_THUNK,
DEMANGLE_COMPONENT_JAVA_CLASS,
is a guard variable. */
DEMANGLE_COMPONENT_GUARD,
this is a temporary. */
DEMANGLE_COMPONENT_REFTEMP,
is providing alternative linkage. */
DEMANGLE_COMPONENT_HIDDEN_ALIAS,
substitution. */
DEMANGLE_COMPONENT_SUB_STD,
being qualified. */
DEMANGLE_COMPONENT_RESTRICT,
being qualified. */
DEMANGLE_COMPONENT_VOLATILE,
qualified. */
DEMANGLE_COMPONENT_CONST,
subtree is the type which is being qualified. */
DEMANGLE_COMPONENT_RESTRICT_THIS,
subtree is the type which is being qualified. */
DEMANGLE_COMPONENT_VOLATILE_THIS,
is the type which is being qualified. */
DEMANGLE_COMPONENT_CONST_THIS,
qualified, and the right subtree is the name of the
qualifier. */
DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL,
to. */
DEMANGLE_COMPONENT_POINTER,
referenced. */
DEMANGLE_COMPONENT_REFERENCE,
being referenced. */
DEMANGLE_COMPONENT_RVALUE_REFERENCE,
DEMANGLE_COMPONENT_COMPLEX,
DEMANGLE_COMPONENT_IMAGINARY,
DEMANGLE_COMPONENT_BUILTIN_TYPE,
DEMANGLE_COMPONENT_VENDOR_TYPE,
subtree is a list of ARGLIST nodes. Either or both may be
NULL. */
DEMANGLE_COMPONENT_FUNCTION_TYPE,
NULL, or a string (represented as DEMANGLE_COMPONENT_NAME), or an
expression. The right subtree is the element type. */
DEMANGLE_COMPONENT_ARRAY_TYPE,
and the right subtree is the member type. CV-qualifiers appear
on the latter. */
DEMANGLE_COMPONENT_PTRMEM_TYPE,
the right subtree is either NULL or another ARGLIST node. */
DEMANGLE_COMPONENT_ARGLIST,
template argument, and the right subtree is either NULL or
another TEMPLATE_ARGLIST node. */
DEMANGLE_COMPONENT_TEMPLATE_ARGLIST,
operator. */
DEMANGLE_COMPONENT_OPERATOR,
the name of the extended operator. */
DEMANGLE_COMPONENT_EXTENDED_OPERATOR,
the type to which the argument should be cast. */
DEMANGLE_COMPONENT_CAST,
right subtree is the single argument. */
DEMANGLE_COMPONENT_UNARY,
right subtree is a BINARY_ARGS. */
DEMANGLE_COMPONENT_BINARY,
argument, and the right subtree is the second argument. */
DEMANGLE_COMPONENT_BINARY_ARGS,
right subtree is a TRINARY_ARG1. */
DEMANGLE_COMPONENT_TRINARY,
argument, and the right subtree is a TRINARY_ARG2. */
DEMANGLE_COMPONENT_TRINARY_ARG1,
second argument, and the right subtree is the third argument. */
DEMANGLE_COMPONENT_TRINARY_ARG2,
is the value, represented as a DEMANGLE_COMPONENT_NAME. */
DEMANGLE_COMPONENT_LITERAL,
This is a minor hack: the NAME used for LITERAL points directly
to the mangled string, but since negative numbers are mangled
using 'n' instead of '-', we want a way to indicate a negative
number which involves neither modifying the mangled string nor
allocating a new copy of the literal in memory. */
DEMANGLE_COMPONENT_LITERAL_NEG,
resource. */
DEMANGLE_COMPONENT_JAVA_RESOURCE,
subtree is the first part and the right subtree the second. */
DEMANGLE_COMPONENT_COMPOUND_NAME,
DEMANGLE_COMPONENT_CHARACTER
};
struct demangle_operator_info;
struct demangle_builtin_type_info;
demangle_component. Note that the field names of the struct are
not well protected against macros defined by the file including
this one. We can fix this if it ever becomes a problem. */
struct demangle_component
{
enum demangle_component_type type;
union
{
struct
{
its length. */
const char *s;
int len;
} s_name;
struct
{
const struct demangle_operator_info *op;
} s_operator;
struct
{
int args;
struct demangle_component *name;
} s_extended_operator;
struct
{
enum gnu_v3_ctor_kinds kind;
struct demangle_component *name;
} s_ctor;
struct
{
enum gnu_v3_dtor_kinds kind;
struct demangle_component *name;
} s_dtor;
struct
{
const struct demangle_builtin_type_info *type;
} s_builtin;
struct
{
const char* string;
int len;
} s_string;
struct
{
long number;
} s_number;
struct
{
int character;
} s_character;
struct
{
struct demangle_component *left;
struct demangle_component *right;
} s_binary;
} u;
};
struct demangle_component themselves. They can then call one of
the following functions to fill them in. */
subtree. Returns non-zero on success, zero on failure, such as an
unrecognized or inappropriate component type. */
extern int
cplus_demangle_fill_component (struct demangle_component *fill,
enum demangle_component_type,
struct demangle_component *left,
struct demangle_component *right);
zero for bad arguments. */
extern int
cplus_demangle_fill_name (struct demangle_component *fill,
const char *, int);
builtin type (e.g., "int", etc.). Returns non-zero on success,
zero if the type is not recognized. */
extern int
cplus_demangle_fill_builtin_type (struct demangle_component *fill,
const char *type_name);
operator and the number of arguments which it takes (the latter is
used to disambiguate operators which can be both binary and unary,
such as '-'). Returns non-zero on success, zero if the operator is
not recognized. */
extern int
cplus_demangle_fill_operator (struct demangle_component *fill,
const char *opname, int args);
number of arguments and the name. Returns non-zero on success,
zero for bad arguments. */
extern int
cplus_demangle_fill_extended_operator (struct demangle_component *fill,
int numargs,
struct demangle_component *nm);
zero for bad arguments. */
extern int
cplus_demangle_fill_ctor (struct demangle_component *fill,
enum gnu_v3_ctor_kinds kind,
struct demangle_component *name);
zero for bad arguments. */
extern int
cplus_demangle_fill_dtor (struct demangle_component *fill,
enum gnu_v3_dtor_kinds kind,
struct demangle_component *name);
demangle_component tree. The first argument is the mangled name.
The second argument is DMGL_* options. This returns a pointer to a
tree on success, or NULL on failure. On success, the third
argument is set to a block of memory allocated by malloc. This
block should be passed to free when the tree is no longer
needed. */
extern struct demangle_component *
cplus_demangle_v3_components (const char *mangled, int options, void **mem);
the corresponding demangled string. The first argument is DMGL_*
options. The second is the tree to demangle. The third is a guess
at the length of the demangled string, used to initially allocate
the return buffer. The fourth is a pointer to a size_t. On
success, this function returns a buffer allocated by malloc(), and
sets the size_t pointed to by the fourth argument to the size of
the allocated buffer (not the length of the returned string). On
failure, this function returns NULL, and sets the size_t pointed to
by the fourth argument to 0 for an invalid tree, or to 1 for a
memory allocation error. */
extern char *
cplus_demangle_print (int options,
const struct demangle_component *tree,
int estimated_length,
size_t *p_allocated_size);
a demangled string in one or more calls to a callback function.
The first argument is DMGL_* options. The second is the tree to
demangle. The third is a pointer to a callback function; on each call
this receives an element of the demangled string, its length, and an
opaque value. The fourth is the opaque value passed to the callback.
The callback is called once or more to return the full demangled
string. The demangled element string is always nul-terminated, though
its length is also provided for convenience. In contrast to
cplus_demangle_print(), this function does not allocate heap memory
to grow output strings (except perhaps where alloca() is implemented
by malloc()), and so is normally safe for use where the heap has been
corrupted. On success, this function returns 1; on failure, 0. */
extern int
cplus_demangle_print_callback (int options,
const struct demangle_component *tree,
demangle_callbackref callback, void *opaque);
#ifdef __cplusplus
}
#endif
#endif