1
/* Demangler for GNU C++ - main program
2
Copyright 1989, 1991, 1994, 1995, 1996, 1997, 1998, 1999,
3
2000, 2001, 2002, 2003 Free Software Foundation, Inc.
4
Written by James Clark (jjc@jclark.uucp)
5
Rewritten by Fred Fish (fnf@cygnus.com) for ARM and Lucid demangling
6
Modified by Satish Pai (pai@apollo.hp.com) for HP demangling
8
This file is part of GCC.
10
GCC is free software; you can redistribute it and/or modify it under
11
the terms of the GNU General Public License as published by the Free
12
Software Foundation; either version 2, or (at your option) any later
15
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
16
WARRANTY; without even the implied warranty of MERCHANTABILITY or
17
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20
You should have received a copy of the GNU General Public License
21
along with GCC; see the file COPYING. If not, write to the Free
22
Software Foundation, 59 Temple Place - Suite 330, Boston, MA
28
#include "libiberty.h"
31
#include "safe-ctype.h"
33
static void demangle_it (char *);
34
static void usage (FILE *, int) ATTRIBUTE_NORETURN;
37
demangle_it (char *mangled_name)
41
/* For command line args, also try to demangle type encodings. */
42
libiberty_demanglers [current_demangling_style].demangling_options
44
result = demangle_symbol (mangled_name);
47
printf ("%s\n", mangled_name);
51
printf ("%s\n", result);
57
usage (FILE *stream, int status)
60
Usage: %s [-_] [-n] [--strip-underscores] [--no-strip-underscores] \n",
64
[-s %s]\n", get_demangler_list ());
67
[--format %s]\n", get_demangler_list ());
70
[--help] [--version] [arg...]\n");
74
#define MBUF_SIZE 32767
75
char mbuffer[MBUF_SIZE];
77
int strip_underscore = 0;
79
static const struct option long_options[] = {
80
{"strip-underscores", no_argument, 0, '_'},
81
{"format", required_argument, 0, 's'},
82
{"demangler", required_argument, 0, 'd'},
83
{"help", no_argument, 0, 'h'},
84
{"no-strip-underscores", no_argument, 0, 'n'},
85
{"version", no_argument, 0, 'v'},
86
{0, no_argument, 0, 0}
89
static const char *standard_symbol_characters (void);
91
static const char *hp_symbol_characters (void);
93
/* Return the string of non-alnum characters that may occur
94
as a valid symbol component, in the standard assembler symbol
98
standard_symbol_characters (void)
104
/* Return the string of non-alnum characters that may occur
105
as a valid symbol name component in an HP object file.
107
Note that, since HP's compiler generates object code straight from
108
C++ source, without going through an assembler, its mangled
109
identifiers can use all sorts of characters that no assembler would
110
tolerate, so the alphabet this function creates is a little odd.
111
Here are some sample mangled identifiers offered by HP:
113
typeid*__XT24AddressIndExpClassMember_
114
[Vftptr]key:__dt__32OrdinaryCompareIndExpClassMemberFv
115
__ct__Q2_9Elf64_Dyn18{unnamed.union.#1}Fv
117
This still seems really weird to me, since nowhere else in this
118
file is there anything to recognize curly brackets, parens, etc.
119
I've talked with Srikanth <srikanth@cup.hp.com>, and he assures me
120
this is right, but I still strongly suspect that there's a
121
misunderstanding here.
123
If we decide it's better for c++filt to use HP's assembler syntax
124
to scrape identifiers out of its input, here's the definition of
125
the symbol name syntax from the HP assembler manual:
127
Symbols are composed of uppercase and lowercase letters, decimal
128
digits, dollar symbol, period (.), ampersand (&), pound sign(#) and
129
underscore (_). A symbol can begin with a letter, digit underscore or
130
dollar sign. If a symbol begins with a digit, it must contain a
135
hp_symbol_characters (void)
137
return "_$.<>#,*&[]:(){}";
140
extern int main (int, char **);
143
main (int argc, char **argv)
147
const char *valid_symbols;
148
const char *demangler = NULL;
149
const char *options = NULL;
151
program_name = argv[0];
152
xmalloc_set_program_name (program_name);
154
strip_underscore = TARGET_PREPENDS_UNDERSCORE;
156
while ((c = getopt_long (argc, argv, "_ns:d:", long_options, (int *) 0)) != EOF)
166
strip_underscore = 0;
169
print_version ("c++filt");
172
strip_underscore = 1;
178
current_demangling_style
179
= cplus_demangle_name_to_style (optarg);
180
if (current_demangling_style == unknown_demangling)
182
fprintf (stderr, "%s: unknown demangling style `%s'\n",
183
program_name, optarg);
190
init_demangler (NULL, options, demangler);
194
for ( ; optind < argc; optind++)
196
demangle_it (argv[optind]);
201
switch (current_demangling_style)
204
case lucid_demangling:
206
case java_demangling:
208
case gnat_demangling:
209
case gnu_v3_demangling:
210
case auto_demangling:
211
case compaq_demangling:
212
valid_symbols = standard_symbol_characters ();
215
valid_symbols = hp_symbol_characters ();
218
/* Folks should explicitly indicate the appropriate alphabet for
219
each demangling. Providing a default would allow the
220
question to go unconsidered. */
221
fatal ("Internal error: no symbol alphabet for current style");
228
/* Try to read a label. */
229
while (c != EOF && (ISALNUM (c) || strchr (valid_symbols, c)))
231
if (i >= MBUF_SIZE-1)
241
if (mbuffer[0] == '.' || mbuffer[0] == '$')
243
if (strip_underscore && mbuffer[skip_first] == '_')
249
result = demangle_symbol (mbuffer + skip_first);
252
if (mbuffer[0] == '.')
254
fputs (result, stdout);
258
fputs (mbuffer, stdout);