1 /* Demangler for GNU C++ - main program
2 Copyright 1989, 1991, 1994, 1995, 1996, 1997, 1998, 1999,
3 2000, 2001, 2002 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
31 static const char *program_name
;
32 static int flags
= DMGL_PARAMS
| DMGL_ANSI
| DMGL_VERBOSE
;
34 static void demangle_it
PARAMS ((char *));
35 static void usage
PARAMS ((FILE *, int)) ATTRIBUTE_NORETURN
;
36 static void fatal
PARAMS ((const char *)) ATTRIBUTE_NORETURN
;
37 static void print_demangler_list
PARAMS ((FILE *));
40 demangle_it (mangled_name
)
45 /* For command line args, also try to demangle type encodings. */
46 result
= cplus_demangle (mangled_name
, flags
| DMGL_TYPES
);
49 printf ("%s\n", mangled_name
);
53 printf ("%s\n", result
);
59 print_demangler_list (stream
)
62 const struct demangler_engine
*demangler
;
64 fprintf (stream
, "{%s", libiberty_demanglers
->demangling_style_name
);
66 for (demangler
= libiberty_demanglers
+ 1;
67 demangler
->demangling_style
!= unknown_demangling
;
69 fprintf (stream
, ",%s", demangler
->demangling_style_name
);
71 fprintf (stream
, "}");
75 usage (stream
, status
)
80 Usage: %s [-_] [-n] [--strip-underscores] [--no-strip-underscores] \n",
85 print_demangler_list (stream
);
86 fprintf (stream
, "]\n");
90 print_demangler_list (stream
);
91 fprintf (stream
, "]\n");
94 [--help] [--version] [arg...]\n");
98 #define MBUF_SIZE 32767
99 char mbuffer
[MBUF_SIZE
];
101 int strip_underscore
= 0;
103 static const struct option long_options
[] = {
104 {"strip-underscores", no_argument
, 0, '_'},
105 {"format", required_argument
, 0, 's'},
106 {"help", no_argument
, 0, 'h'},
107 {"no-strip-underscores", no_argument
, 0, 'n'},
108 {"version", no_argument
, 0, 'v'},
109 {0, no_argument
, 0, 0}
113 standard_symbol_characters
PARAMS ((void));
116 hp_symbol_characters
PARAMS ((void));
118 /* Return the string of non-alnum characters that may occur
119 as a valid symbol component, in the standard assembler symbol
123 standard_symbol_characters ()
129 /* Return the string of non-alnum characters that may occur
130 as a valid symbol name component in an HP object file.
132 Note that, since HP's compiler generates object code straight from
133 C++ source, without going through an assembler, its mangled
134 identifiers can use all sorts of characters that no assembler would
135 tolerate, so the alphabet this function creates is a little odd.
136 Here are some sample mangled identifiers offered by HP:
138 typeid*__XT24AddressIndExpClassMember_
139 [Vftptr]key:__dt__32OrdinaryCompareIndExpClassMemberFv
140 __ct__Q2_9Elf64_Dyn18{unnamed.union.#1}Fv
142 This still seems really weird to me, since nowhere else in this
143 file is there anything to recognize curly brackets, parens, etc.
144 I've talked with Srikanth <srikanth@cup.hp.com>, and he assures me
145 this is right, but I still strongly suspect that there's a
146 misunderstanding here.
148 If we decide it's better for c++filt to use HP's assembler syntax
149 to scrape identifiers out of its input, here's the definition of
150 the symbol name syntax from the HP assembler manual:
152 Symbols are composed of uppercase and lowercase letters, decimal
153 digits, dollar symbol, period (.), ampersand (&), pound sign(#) and
154 underscore (_). A symbol can begin with a letter, digit underscore or
155 dollar sign. If a symbol begins with a digit, it must contain a
160 hp_symbol_characters ()
162 return "_$.<>#,*&[]:(){}";
165 extern int main
PARAMS ((int, char **));
174 const char *valid_symbols
;
175 enum demangling_styles style
= auto_demangling
;
177 program_name
= argv
[0];
179 strip_underscore
= (USER_LABEL_PREFIX
[0] == '_');
181 while ((c
= getopt_long (argc
, argv
, "_ns:", long_options
, (int *) 0)) != EOF
)
191 strip_underscore
= 0;
194 printf ("GNU %s (C++ demangler), version %s\n",
195 program_name
, version_string
);
198 strip_underscore
= 1;
202 style
= cplus_demangle_name_to_style (optarg
);
203 if (style
== unknown_demangling
)
205 fprintf (stderr
, "%s: unknown demangling style `%s'\n",
206 program_name
, optarg
);
210 cplus_demangle_set_style (style
);
218 for ( ; optind
< argc
; optind
++)
220 demangle_it (argv
[optind
]);
225 switch (current_demangling_style
)
228 case lucid_demangling
:
230 case java_demangling
:
232 case gnat_demangling
:
233 case gnu_v3_demangling
:
234 case auto_demangling
:
235 valid_symbols
= standard_symbol_characters ();
238 valid_symbols
= hp_symbol_characters ();
241 /* Folks should explicitly indicate the appropriate alphabet for
242 each demangling. Providing a default would allow the
243 question to go unconsidered. */
244 fatal ("Internal error: no symbol alphabet for current style");
251 /* Try to read a label. */
252 while (c
!= EOF
&& (ISALNUM (c
) || strchr (valid_symbols
, c
)))
254 if (i
>= MBUF_SIZE
-1)
264 if (mbuffer
[0] == '.' || mbuffer
[0] == '$')
266 if (strip_underscore
&& mbuffer
[skip_first
] == '_')
272 flags
|= (int) style
;
273 result
= cplus_demangle (mbuffer
+ skip_first
, flags
);
276 if (mbuffer
[0] == '.')
278 fputs (result
, stdout
);
282 fputs (mbuffer
, stdout
);
300 fprintf (stderr
, "%s: %s\n", program_name
, str
);