1 |
/* Demangler for GNU C++ |
/* Demangler for GNU C++ |
2 |
Copyright 1989, 1991, 1994, 1995, 1996, 1997, 1998, 1999, |
Copyright 1989, 1991, 1994, 1995, 1996, 1997, 1998, 1999, |
3 |
2000, 2001 Free Software Foundation, Inc. |
2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc. |
4 |
Written by James Clark (jjc@jclark.uucp) |
Written by James Clark (jjc@jclark.uucp) |
5 |
Rewritten by Fred Fish (fnf@cygnus.com) for ARM and Lucid demangling |
Rewritten by Fred Fish (fnf@cygnus.com) for ARM and Lucid demangling |
6 |
Modified by Satish Pai (pai@apollo.hp.com) for HP demangling |
Modified by Satish Pai (pai@apollo.hp.com) for HP demangling |
11 |
License as published by the Free Software Foundation; either |
License as published by the Free Software Foundation; either |
12 |
version 2 of the License, or (at your option) any later version. |
version 2 of the License, or (at your option) any later version. |
13 |
|
|
14 |
|
In addition to the permissions in the GNU Library General Public |
15 |
|
License, the Free Software Foundation gives you unlimited permission |
16 |
|
to link the compiled version of this file into combinations with other |
17 |
|
programs, and to distribute those combinations without any restriction |
18 |
|
coming from the use of this file. (The Library Public License |
19 |
|
restrictions do apply in other respects; for example, they cover |
20 |
|
modification of the file, and distribution when not linked into a |
21 |
|
combined executable.) |
22 |
|
|
23 |
Libiberty is distributed in the hope that it will be useful, |
Libiberty is distributed in the hope that it will be useful, |
24 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
25 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
49 |
#include <string.h> |
#include <string.h> |
50 |
#include <stdio.h> |
#include <stdio.h> |
51 |
|
|
|
#if defined(HAVE_DLOPEN) && defined(HAVE_WEAK_SYMBOL) && defined(HAVE_DLFCN_H) |
|
|
#include <dlfcn.h> |
|
|
|
|
|
#pragma weak dlopen |
|
|
#pragma weak dlsym |
|
|
#pragma weak dlerror |
|
|
#endif |
|
|
|
|
52 |
#ifdef HAVE_STDLIB_H |
#ifdef HAVE_STDLIB_H |
53 |
#include <stdlib.h> |
#include <stdlib.h> |
54 |
#else |
#else |
62 |
|
|
63 |
#include "libiberty.h" |
#include "libiberty.h" |
64 |
|
|
65 |
static char *ada_demangle PARAMS ((const char *, int)); |
static char *ada_demangle PARAMS ((const char *, int)); |
|
static int cplus_demangle_name_to_mnemonic |
|
|
PARAMS ((const char *mnemonic)); |
|
66 |
|
|
67 |
#define min(X,Y) (((X) < (Y)) ? (X) : (Y)) |
#define min(X,Y) (((X) < (Y)) ? (X) : (Y)) |
68 |
|
|
246 |
tk_real |
tk_real |
247 |
} type_kind_t; |
} type_kind_t; |
248 |
|
|
249 |
struct demangler_engine libiberty_demanglers[] = |
const struct demangler_engine libiberty_demanglers[] = |
250 |
{ |
{ |
251 |
{ |
{ |
252 |
NO_DEMANGLING_STYLE_STRING, |
NO_DEMANGLING_STYLE_STRING, |
253 |
DMGL_NO_OPTS, |
no_demangling, |
254 |
DMGL_NO_OPTS, |
"Demangling disabled" |
|
"Demangling disabled", |
|
|
cplus_demangle_with_style |
|
255 |
} |
} |
256 |
, |
, |
257 |
{ |
{ |
258 |
AUTO_DEMANGLING_STYLE_STRING, |
AUTO_DEMANGLING_STYLE_STRING, |
259 |
DMGL_AUTO, |
auto_demangling, |
260 |
DMGL_PARAMS | DMGL_ANSI | DMGL_VERBOSE, |
"Automatic selection based on executable" |
|
"Automatic selection based on executable", |
|
|
cplus_demangle_with_style |
|
261 |
} |
} |
262 |
, |
, |
263 |
{ |
{ |
264 |
GNU_DEMANGLING_STYLE_STRING, |
GNU_DEMANGLING_STYLE_STRING, |
265 |
DMGL_GNU, |
gnu_demangling, |
266 |
DMGL_PARAMS | DMGL_ANSI | DMGL_VERBOSE, |
"GNU (g++) style demangling" |
|
"GNU (g++) style demangling", |
|
|
cplus_demangle_with_style |
|
267 |
} |
} |
268 |
, |
, |
269 |
{ |
{ |
270 |
LUCID_DEMANGLING_STYLE_STRING, |
LUCID_DEMANGLING_STYLE_STRING, |
271 |
DMGL_LUCID, |
lucid_demangling, |
272 |
DMGL_PARAMS | DMGL_ANSI | DMGL_VERBOSE, |
"Lucid (lcc) style demangling" |
|
"Lucid (lcc) style demangling", |
|
|
cplus_demangle_with_style |
|
273 |
} |
} |
274 |
, |
, |
275 |
{ |
{ |
276 |
ARM_DEMANGLING_STYLE_STRING, |
ARM_DEMANGLING_STYLE_STRING, |
277 |
DMGL_ARM, |
arm_demangling, |
278 |
DMGL_PARAMS | DMGL_ANSI | DMGL_VERBOSE, |
"ARM style demangling" |
|
"ANSI style demangling", |
|
|
cplus_demangle_with_style |
|
279 |
} |
} |
280 |
, |
, |
281 |
{ |
{ |
282 |
HP_DEMANGLING_STYLE_STRING, |
HP_DEMANGLING_STYLE_STRING, |
283 |
DMGL_HP, |
hp_demangling, |
284 |
DMGL_PARAMS | DMGL_ANSI | DMGL_VERBOSE, |
"HP (aCC) style demangling" |
|
"HP (aCC) style demangling", |
|
|
cplus_demangle_with_style |
|
285 |
} |
} |
286 |
, |
, |
287 |
{ |
{ |
288 |
EDG_DEMANGLING_STYLE_STRING, |
EDG_DEMANGLING_STYLE_STRING, |
289 |
DMGL_EDG, |
edg_demangling, |
290 |
DMGL_PARAMS | DMGL_ANSI | DMGL_VERBOSE, |
"EDG style demangling" |
|
"EDG style demangling", |
|
|
cplus_demangle_with_style |
|
291 |
} |
} |
292 |
, |
, |
293 |
{ |
{ |
294 |
GNU_V3_DEMANGLING_STYLE_STRING, |
GNU_V3_DEMANGLING_STYLE_STRING, |
295 |
DMGL_GNU_V3, |
gnu_v3_demangling, |
296 |
DMGL_PARAMS | DMGL_ANSI | DMGL_VERBOSE, |
"GNU (g++) V3 ABI-style demangling" |
|
"GNU (g++) V3 ABI-style demangling", |
|
|
cplus_demangle_with_style |
|
297 |
} |
} |
298 |
, |
, |
299 |
{ |
{ |
300 |
JAVA_DEMANGLING_STYLE_STRING, |
JAVA_DEMANGLING_STYLE_STRING, |
301 |
DMGL_JAVA, |
java_demangling, |
302 |
DMGL_PARAMS | DMGL_ANSI | DMGL_VERBOSE, |
"Java style demangling" |
|
"Java style demangling", |
|
|
cplus_demangle_with_style |
|
303 |
} |
} |
304 |
, |
, |
305 |
{ |
{ |
306 |
GNAT_DEMANGLING_STYLE_STRING, |
GNAT_DEMANGLING_STYLE_STRING, |
307 |
DMGL_GNAT, |
gnat_demangling, |
308 |
DMGL_PARAMS | DMGL_ANSI | DMGL_VERBOSE, |
"GNAT style demangling" |
|
"GNAT (ada) style demangling", |
|
|
cplus_demangle_with_style, |
|
309 |
} |
} |
310 |
, |
, |
311 |
{ |
{ |
312 |
COMPAQ_DEMANGLING_STYLE_STRING, |
NULL, unknown_demangling, NULL |
|
DMGL_COMPAQ, |
|
|
DMGL_PARAMS | DMGL_ANSI | DMGL_VERBOSE, |
|
|
"Compaq (cxx) style demangling", |
|
|
NULL |
|
313 |
} |
} |
314 |
}; |
}; |
315 |
|
|
316 |
#define STRING_EMPTY(str) ((str) -> b == (str) -> p) |
#define STRING_EMPTY(str) ((str) -> b == (str) -> p) |
|
#define PREPEND_BLANK(str) {if (!STRING_EMPTY(str)) \ |
|
|
string_prepend(str, " ");} |
|
317 |
#define APPEND_BLANK(str) {if (!STRING_EMPTY(str)) \ |
#define APPEND_BLANK(str) {if (!STRING_EMPTY(str)) \ |
318 |
string_append(str, " ");} |
string_append(str, " ");} |
319 |
#define LEN_STRING(str) ( (STRING_EMPTY(str))?0:((str)->p - (str)->b)) |
#define LEN_STRING(str) ( (STRING_EMPTY(str))?0:((str)->p - (str)->b)) |
523 |
int)); |
int)); |
524 |
|
|
525 |
static void |
static void |
526 |
grow_vect PARAMS ((void **, size_t *, size_t, int)); |
grow_vect PARAMS ((char **, size_t *, size_t, int)); |
527 |
|
|
528 |
/* Translate count to integer, consuming tokens in the process. |
/* Translate count to integer, consuming tokens in the process. |
529 |
Conversion terminates on the first non-digit character. |
Conversion terminates on the first non-digit character. |
844 |
cplus_demangle_set_style (style) |
cplus_demangle_set_style (style) |
845 |
enum demangling_styles style; |
enum demangling_styles style; |
846 |
{ |
{ |
847 |
if (first_demangling <= style && style < unknown_demangling) |
const struct demangler_engine *demangler = libiberty_demanglers; |
848 |
{ |
|
849 |
current_demangling_style = style; |
for (; demangler->demangling_style != unknown_demangling; ++demangler) |
850 |
return current_demangling_style; |
if (style == demangler->demangling_style) |
851 |
} |
{ |
852 |
|
current_demangling_style = style; |
853 |
|
return current_demangling_style; |
854 |
|
} |
855 |
|
|
856 |
return unknown_demangling; |
return unknown_demangling; |
857 |
} |
} |
862 |
cplus_demangle_name_to_style (name) |
cplus_demangle_name_to_style (name) |
863 |
const char *name; |
const char *name; |
864 |
{ |
{ |
865 |
enum demangling_styles i; |
const struct demangler_engine *demangler = libiberty_demanglers; |
866 |
|
|
867 |
for (i = 0; i < unknown_demangling; i++) |
for (; demangler->demangling_style != unknown_demangling; ++demangler) |
868 |
if (strcasecmp (libiberty_demanglers [i].demangling_style_name, |
if (strcmp (name, demangler->demangling_style_name) == 0) |
869 |
name) == 0) |
return demangler->demangling_style; |
|
break; |
|
870 |
|
|
871 |
return i; |
return unknown_demangling; |
872 |
} |
} |
873 |
|
|
874 |
/* char *cplus_demangle (const char *mangled, int options) |
/* char *cplus_demangle (const char *mangled, int options) |
900 |
MANGLED. */ |
MANGLED. */ |
901 |
|
|
902 |
char * |
char * |
903 |
cplus_demangle_with_style (mangled, style, options) |
cplus_demangle (mangled, options) |
904 |
const char *mangled; |
const char *mangled; |
|
enum demangling_styles style; |
|
905 |
int options; |
int options; |
906 |
{ |
{ |
907 |
char *ret; |
char *ret; |
908 |
struct work_stuff work[1]; |
struct work_stuff work[1]; |
909 |
|
|
910 |
if (style == no_demangling) |
if (current_demangling_style == no_demangling) |
911 |
return xstrdup (mangled); |
return xstrdup (mangled); |
912 |
|
|
913 |
memset ((char *) work, 0, sizeof (work)); |
memset ((char *) work, 0, sizeof (work)); |
914 |
work->options = options; |
work->options = options; |
915 |
if ((work->options & DMGL_STYLE_MASK) == 0) |
if ((work->options & DMGL_STYLE_MASK) == 0) |
916 |
work->options |= libiberty_demanglers [style].demangling_style |
work->options |= (int) current_demangling_style & DMGL_STYLE_MASK; |
|
& DMGL_STYLE_MASK; |
|
917 |
|
|
918 |
/* The V3 ABI demangling is implemented elsewhere. */ |
/* The V3 ABI demangling is implemented elsewhere. */ |
919 |
if (libiberty_demanglers [style].demangling_style |
if (GNU_V3_DEMANGLING || AUTO_DEMANGLING) |
|
& (DMGL_GNU_V3 | DMGL_AUTO)) |
|
920 |
{ |
{ |
921 |
ret = cplus_demangle_v3 (mangled, work->options); |
ret = cplus_demangle_v3 (mangled, work->options); |
922 |
if (ret || (libiberty_demanglers [style].demangling_style |
if (ret || GNU_V3_DEMANGLING) |
|
& DMGL_GNU_V3)) |
|
923 |
return ret; |
return ret; |
924 |
} |
} |
925 |
|
|
926 |
if (libiberty_demanglers [style].demangling_style & DMGL_JAVA) |
if (JAVA_DEMANGLING) |
927 |
{ |
{ |
928 |
ret = java_demangle_v3 (mangled); |
ret = java_demangle_v3 (mangled); |
929 |
if (ret) |
if (ret) |
930 |
return ret; |
return ret; |
931 |
} |
} |
932 |
|
|
933 |
if (libiberty_demanglers [style].demangling_style & DMGL_GNAT) |
if (GNAT_DEMANGLING) |
934 |
return ada_demangle (mangled, options); |
return ada_demangle(mangled,options); |
935 |
|
|
936 |
ret = internal_cplus_demangle (work, mangled); |
ret = internal_cplus_demangle (work, mangled); |
937 |
squangle_mop_up (work); |
squangle_mop_up (work); |
938 |
return (ret); |
return (ret); |
939 |
} |
} |
940 |
|
|
941 |
|
|
942 |
/* Assuming *OLD_VECT points to an array of *SIZE objects of size |
/* Assuming *OLD_VECT points to an array of *SIZE objects of size |
943 |
ELEMENT_SIZE, grow it to contain at least MIN_SIZE objects, |
ELEMENT_SIZE, grow it to contain at least MIN_SIZE objects, |
944 |
updating *OLD_VECT and *SIZE as necessary. */ |
updating *OLD_VECT and *SIZE as necessary. */ |
945 |
|
|
946 |
static void |
static void |
947 |
grow_vect (old_vect, size, min_size, element_size) |
grow_vect (old_vect, size, min_size, element_size) |
948 |
void **old_vect; |
char **old_vect; |
949 |
size_t *size; |
size_t *size; |
950 |
size_t min_size; |
size_t min_size; |
951 |
int element_size; |
int element_size; |
955 |
*size *= 2; |
*size *= 2; |
956 |
if (*size < min_size) |
if (*size < min_size) |
957 |
*size = min_size; |
*size = min_size; |
958 |
*old_vect = xrealloc (*old_vect, *size * element_size); |
*old_vect = (void *) xrealloc (*old_vect, *size * element_size); |
959 |
} |
} |
960 |
} |
} |
961 |
|
|
976 |
int len0; |
int len0; |
977 |
const char* p; |
const char* p; |
978 |
char *demangled = NULL; |
char *demangled = NULL; |
|
int at_start_name; |
|
979 |
int changed; |
int changed; |
980 |
char *demangling_buffer = NULL; |
size_t demangled_size = 0; |
|
size_t demangling_buffer_size = 0; |
|
981 |
|
|
982 |
changed = 0; |
changed = 0; |
983 |
|
|
1005 |
} |
} |
1006 |
|
|
1007 |
/* Make demangled big enough for possible expansion by operator name. */ |
/* Make demangled big enough for possible expansion by operator name. */ |
1008 |
grow_vect ((void **) &(demangling_buffer), |
grow_vect (&demangled, |
1009 |
&demangling_buffer_size, 2 * len0 + 1, |
&demangled_size, 2 * len0 + 1, |
1010 |
sizeof (char)); |
sizeof (char)); |
|
demangled = demangling_buffer; |
|
1011 |
|
|
1012 |
if (ISDIGIT ((unsigned char) mangled[len0 - 1])) { |
if (ISDIGIT ((unsigned char) mangled[len0 - 1])) { |
1013 |
for (i = len0 - 2; i >= 0 && ISDIGIT ((unsigned char) mangled[i]); i -= 1) |
for (i = len0 - 2; i >= 0 && ISDIGIT ((unsigned char) mangled[i]); i -= 1) |
1028 |
i += 1, j += 1) |
i += 1, j += 1) |
1029 |
demangled[j] = mangled[i]; |
demangled[j] = mangled[i]; |
1030 |
|
|
|
at_start_name = 1; |
|
1031 |
while (i < len0) |
while (i < len0) |
1032 |
{ |
{ |
|
at_start_name = 0; |
|
|
|
|
1033 |
if (i < len0 - 2 && mangled[i] == '_' && mangled[i + 1] == '_') |
if (i < len0 - 2 && mangled[i] == '_' && mangled[i + 1] == '_') |
1034 |
{ |
{ |
1035 |
demangled[j] = '.'; |
demangled[j] = '.'; |
1036 |
changed = at_start_name = 1; |
changed = 1; |
1037 |
i += 2; j += 1; |
i += 2; j += 1; |
1038 |
} |
} |
1039 |
else |
else |
1054 |
return demangled; |
return demangled; |
1055 |
|
|
1056 |
Suppress: |
Suppress: |
1057 |
grow_vect ((void **) &(demangling_buffer), |
grow_vect (&demangled, |
1058 |
&demangling_buffer_size, strlen (mangled) + 3, |
&demangled_size, strlen (mangled) + 3, |
1059 |
sizeof (char)); |
sizeof (char)); |
1060 |
demangled = demangling_buffer; |
|
1061 |
if (mangled[0] == '<') |
if (mangled[0] == '<') |
1062 |
strcpy (demangled, mangled); |
strcpy (demangled, mangled); |
1063 |
else |
else |
1066 |
return demangled; |
return demangled; |
1067 |
} |
} |
1068 |
|
|
|
char * |
|
|
cplus_demangle (mangled, options) |
|
|
const char *mangled; |
|
|
int options; |
|
|
{ |
|
|
return cplus_demangle_with_style (mangled, current_demangling_style, |
|
|
options); |
|
|
} |
|
|
|
|
|
static int |
|
|
cplus_demangle_name_to_mnemonic (mnemonic) |
|
|
const char *mnemonic; |
|
|
{ |
|
|
enum demangling_styles i; |
|
|
|
|
|
for (i = 0; i < unknown_demangling; i++) |
|
|
if (strcasecmp (libiberty_demanglers [i].demangling_style_name, |
|
|
mnemonic) == 0) |
|
|
break; |
|
|
|
|
|
if (i != unknown_demangling) |
|
|
return libiberty_demanglers [i].demangling_style; |
|
|
else |
|
|
{ |
|
|
if (strncasecmp (mnemonic, "PARAMS", sizeof ("PARAMS") - 1) == 0) |
|
|
return DMGL_PARAMS; |
|
|
else |
|
|
return DMGL_NO_OPTS; |
|
|
} |
|
|
} |
|
|
|
|
|
int |
|
|
init_demangler (style, options, demangler) |
|
|
const char *style; |
|
|
const char *options; |
|
|
const char *demangler; |
|
|
{ |
|
|
#if defined(HAVE_DLOPEN) && defined(HAVE_WEAK_SYMBOL) && defined(HAVE_DLFCN_H) |
|
|
char *dso = NULL; |
|
|
char *function = NULL; |
|
|
demangle_function df; |
|
|
#endif |
|
|
|
|
|
/* Initialize demangler_list_buffer. */ |
|
|
(void) get_demangler_list (); |
|
|
|
|
|
if (style != NULL) |
|
|
{ |
|
|
current_demangling_style = cplus_demangle_name_to_style (style); |
|
|
if (current_demangling_style == unknown_demangling) |
|
|
{ |
|
|
fprintf (stderr, "init_demangler: unknown demangling style `%s'\n", |
|
|
style); |
|
|
exit (1); |
|
|
} |
|
|
} |
|
|
|
|
|
if (options != NULL) |
|
|
{ |
|
|
const char *cp; |
|
|
int demangler_options = 0; |
|
|
|
|
|
for (cp = options; *cp; ) |
|
|
{ |
|
|
if (*cp == ';') |
|
|
cp++; |
|
|
demangler_options |= cplus_demangle_name_to_mnemonic (cp); |
|
|
while (*cp && *cp != ':') |
|
|
cp++; |
|
|
} |
|
|
|
|
|
libiberty_demanglers [current_demangling_style].demangling_options |
|
|
= demangler_options; |
|
|
} |
|
|
|
|
|
#if defined(HAVE_DLOPEN) && defined(HAVE_WEAK_SYMBOL) && defined(HAVE_DLFCN_H) |
|
|
if (demangler) |
|
|
{ |
|
|
dso = alloca (strlen (demangler) + 1); |
|
|
strcpy (dso, demangler); |
|
|
function = strchr (dso, ':'); |
|
|
if (!function) |
|
|
{ |
|
|
fprintf (stderr, "init_demangler: invalid `dso:function': `%s'\n", |
|
|
demangler); |
|
|
exit (1); |
|
|
} |
|
|
*function = '\0'; |
|
|
function++; |
|
|
} |
|
|
|
|
|
if (current_demangling_style == compaq_demangling) |
|
|
{ |
|
|
if (dso == NULL || *dso == '\0') |
|
|
dso = "libcompaq_demangle.so"; |
|
|
if (function == NULL) |
|
|
function = "libiberty_demangle_string"; |
|
|
} |
|
|
|
|
|
if (dso && function) |
|
|
{ |
|
|
void *handle; |
|
|
|
|
|
#ifndef __linux__ |
|
|
if (&dlopen == NULL || &dlsym == NULL || &dlerror == NULL) |
|
|
{ |
|
|
fprintf (stderr, "init_demangler: dynamic linking is unsupported\n"); |
|
|
exit (1); |
|
|
} |
|
|
#endif |
|
|
|
|
|
handle = dlopen (dso, RTLD_LAZY); |
|
|
if (handle == NULL) |
|
|
{ |
|
|
fprintf(stderr, "init_demangler: %s\n", dlerror ()); |
|
|
exit (1); |
|
|
} |
|
|
|
|
|
df = (demangle_function) dlsym (handle, function); |
|
|
if (df == NULL) |
|
|
{ |
|
|
fprintf(stderr, "init_demangler: %s\n", dlerror ()); |
|
|
exit (1); |
|
|
} |
|
|
|
|
|
libiberty_demanglers [current_demangling_style].df = df; |
|
|
} |
|
|
#endif |
|
|
|
|
|
return 0; |
|
|
} |
|
|
|
|
|
char * |
|
|
demangle_symbol (mangled) |
|
|
const char *mangled; |
|
|
{ |
|
|
return demangle_symbol_with_style (mangled, |
|
|
current_demangling_style); |
|
|
} |
|
|
|
|
|
char * |
|
|
demangle_symbol_with_style (mangled, style) |
|
|
const char *mangled; |
|
|
enum demangling_styles style; |
|
|
{ |
|
|
return demangle_symbol_with_style_options |
|
|
(mangled, style, |
|
|
libiberty_demanglers [style].demangling_options); |
|
|
} |
|
|
|
|
|
char * |
|
|
demangle_symbol_with_options (mangled, options) |
|
|
const char *mangled; |
|
|
int options; |
|
|
{ |
|
|
return demangle_symbol_with_style_options |
|
|
(mangled, current_demangling_style, options); |
|
|
} |
|
|
|
|
|
char * |
|
|
demangle_symbol_with_style_options (mangled, style, options) |
|
|
const char *mangled; |
|
|
enum demangling_styles style; |
|
|
int options; |
|
|
{ |
|
|
switch (style) |
|
|
{ |
|
|
case compaq_demangling: |
|
|
if (libiberty_demanglers [style].df == NULL) |
|
|
{ |
|
|
#if defined(HAVE_DLOPEN) && defined(HAVE_WEAK_SYMBOL) && defined(HAVE_DLFCN_H) |
|
|
init_demangler ("compaq", NULL, NULL); |
|
|
#else |
|
|
fprintf (stderr, "demangle_symbol_with_style_options: compaq_demangling is unsupported\n"); |
|
|
exit (1); |
|
|
#endif |
|
|
} |
|
|
break; |
|
|
default: |
|
|
break; |
|
|
} |
|
|
|
|
|
return (*libiberty_demanglers [style].df) (mangled, style, options); |
|
|
} |
|
|
|
|
1069 |
/* This function performs most of what cplus_demangle use to do, but |
/* This function performs most of what cplus_demangle use to do, but |
1070 |
to be able to demangle a name with a B, K or n code, we need to |
to be able to demangle a name with a B, K or n code, we need to |
1071 |
have a longer term memory of what types have been seen. The original |
have a longer term memory of what types have been seen. The original |
1072 |
now intializes and cleans up the squangle code info, while internal |
now initializes and cleans up the squangle code info, while internal |
1073 |
calls go directly to this routine to avoid resetting that info. */ |
calls go directly to this routine to avoid resetting that info. */ |
1074 |
|
|
1075 |
static char * |
static char * |
1209 |
|
|
1210 |
if (from->ntmpl_args) |
if (from->ntmpl_args) |
1211 |
to->tmpl_argvec |
to->tmpl_argvec |
1212 |
= xmalloc (from->ntmpl_args * sizeof (to->tmpl_argvec[0])); |
= (char **) xmalloc (from->ntmpl_args * sizeof (to->tmpl_argvec[0])); |
1213 |
|
|
1214 |
for (i = 0; i < from->ntmpl_args; i++) |
for (i = 0; i < from->ntmpl_args; i++) |
1215 |
{ |
{ |
1434 |
{ |
{ |
1435 |
string_append (&s, SCOPE_STRING (work)); |
string_append (&s, SCOPE_STRING (work)); |
1436 |
string_prepends (declp, &s); |
string_prepends (declp, &s); |
1437 |
|
string_delete (&s); |
1438 |
} |
} |
1439 |
oldmangled = NULL; |
oldmangled = NULL; |
1440 |
expect_func = 1; |
expect_func = 1; |
1514 |
{ |
{ |
1515 |
/* Read the return type. */ |
/* Read the return type. */ |
1516 |
string return_type; |
string return_type; |
|
string_init (&return_type); |
|
1517 |
|
|
1518 |
(*mangled)++; |
(*mangled)++; |
1519 |
success = do_type (work, mangled, &return_type); |
success = do_type (work, mangled, &return_type); |
1793 |
|
|
1794 |
success = 0; |
success = 0; |
1795 |
|
|
1796 |
/* Negative numbers are indicated with a leading `m'. */ |
if (**mangled == '_') |
1797 |
if (**mangled == 'm') |
{ |
1798 |
{ |
if (mangled[0][1] == 'm') |
1799 |
string_appendn (s, "-", 1); |
{ |
1800 |
(*mangled)++; |
/* Since consume_count_with_underscores does not handle the |
1801 |
} |
`m'-prefix we must do it here, using consume_count and |
1802 |
else if (mangled[0][0] == '_' && mangled[0][1] == 'm') |
adjusting underscores: we have to consume the underscore |
1803 |
{ |
matching the prepended one. */ |
1804 |
/* Since consume_count_with_underscores does not handle the |
multidigit_without_leading_underscore = 1; |
1805 |
`m'-prefix we must do it here, using consume_count and |
string_appendn (s, "-", 1); |
1806 |
adjusting underscores: we have to consume the underscore |
(*mangled) += 2; |
1807 |
matching the prepended one. */ |
} |
1808 |
multidigit_without_leading_underscore = 1; |
else |
1809 |
string_appendn (s, "-", 1); |
{ |
1810 |
(*mangled) += 2; |
/* Do not consume a following underscore; |
1811 |
} |
consume_count_with_underscores will consume what |
1812 |
else if (**mangled == '_') |
should be consumed. */ |
1813 |
{ |
leave_following_underscore = 1; |
1814 |
/* Do not consume a following underscore; |
} |
|
multidigit_without_leading_underscore will consume what should be |
|
|
consumed. */ |
|
|
leave_following_underscore = 1; |
|
1815 |
} |
} |
1816 |
else |
else |
1817 |
{ |
{ |
1818 |
|
/* Negative numbers are indicated with a leading `m'. */ |
1819 |
|
if (**mangled == 'm') |
1820 |
|
{ |
1821 |
|
string_appendn (s, "-", 1); |
1822 |
|
(*mangled)++; |
1823 |
|
} |
1824 |
/* Since consume_count_with_underscores does not handle |
/* Since consume_count_with_underscores does not handle |
1825 |
multi-digit numbers that do not start with an underscore, |
multi-digit numbers that do not start with an underscore, |
1826 |
and this number can be an integer template parameter, |
and this number can be an integer template parameter, |
1861 |
/* All is well. */ |
/* All is well. */ |
1862 |
success = 1; |
success = 1; |
1863 |
} |
} |
1864 |
} |
} |
1865 |
|
|
1866 |
return success; |
return success; |
1867 |
} |
} |
2036 |
int r; |
int r; |
2037 |
int need_comma = 0; |
int need_comma = 0; |
2038 |
int success = 0; |
int success = 0; |
|
const char *start; |
|
2039 |
int is_java_array = 0; |
int is_java_array = 0; |
2040 |
string temp; |
string temp; |
|
int bindex = 0; |
|
2041 |
|
|
2042 |
(*mangled)++; |
(*mangled)++; |
2043 |
if (is_type) |
if (is_type) |
2044 |
{ |
{ |
|
if (remember) |
|
|
bindex = register_Btype (work); |
|
|
start = *mangled; |
|
2045 |
/* get template name */ |
/* get template name */ |
2046 |
if (**mangled == 'z') |
if (**mangled == 'z') |
2047 |
{ |
{ |
2217 |
} |
} |
2218 |
|
|
2219 |
if (is_type && remember) |
if (is_type && remember) |
2220 |
remember_Btype (work, tname->b, LEN_STRING (tname), bindex); |
{ |
2221 |
|
const int bindex = register_Btype (work); |
2222 |
|
remember_Btype (work, tname->b, LEN_STRING (tname), bindex); |
2223 |
|
} |
2224 |
|
|
2225 |
/* |
/* |
2226 |
if (work -> static_type) |
if (work -> static_type) |
2312 |
if (HP_DEMANGLING && ((*mangled)[n] == 'X')) |
if (HP_DEMANGLING && ((*mangled)[n] == 'X')) |
2313 |
{ |
{ |
2314 |
char *start_spec_args = NULL; |
char *start_spec_args = NULL; |
2315 |
|
int hold_options; |
2316 |
|
|
2317 |
/* First check for and omit template specialization pseudo-arguments, |
/* First check for and omit template specialization pseudo-arguments, |
2318 |
such as in "Spec<#1,#1.*>" */ |
such as in "Spec<#1,#1.*>" */ |
2325 |
string_init (&arg); |
string_init (&arg); |
2326 |
if (work->temp_start == -1) /* non-recursive call */ |
if (work->temp_start == -1) /* non-recursive call */ |
2327 |
work->temp_start = declp->p - declp->b; |
work->temp_start = declp->p - declp->b; |
2328 |
|
|
2329 |
|
/* We want to unconditionally demangle parameter types in |
2330 |
|
template parameters. */ |
2331 |
|
hold_options = work->options; |
2332 |
|
work->options |= DMGL_PARAMS; |
2333 |
|
|
2334 |
string_append (declp, "<"); |
string_append (declp, "<"); |
2335 |
while (1) |
while (1) |
2336 |
{ |
{ |
2337 |
string_clear (&arg); |
string_delete (&arg); |
2338 |
switch (**mangled) |
switch (**mangled) |
2339 |
{ |
{ |
2340 |
case 'T': |
case 'T': |
2377 |
string_delete (&arg); |
string_delete (&arg); |
2378 |
if (**mangled == '_') |
if (**mangled == '_') |
2379 |
(*mangled)++; |
(*mangled)++; |
2380 |
|
work->options = hold_options; |
2381 |
return; |
return; |
2382 |
} |
} |
2383 |
/* ARM template? (Also handles HP cfront extensions) */ |
/* ARM template? (Also handles HP cfront extensions) */ |
2384 |
else if (arm_pt (work, *mangled, n, &p, &args)) |
else if (arm_pt (work, *mangled, n, &p, &args)) |
2385 |
{ |
{ |
2386 |
|
int hold_options; |
2387 |
string type_str; |
string type_str; |
2388 |
|
|
2389 |
string_init (&arg); |
string_init (&arg); |
2390 |
string_appendn (declp, *mangled, p - *mangled); |
string_appendn (declp, *mangled, p - *mangled); |
2391 |
if (work->temp_start == -1) /* non-recursive call */ |
if (work->temp_start == -1) /* non-recursive call */ |
2392 |
work->temp_start = declp->p - declp->b; |
work->temp_start = declp->p - declp->b; |
2393 |
|
|
2394 |
|
/* We want to unconditionally demangle parameter types in |
2395 |
|
template parameters. */ |
2396 |
|
hold_options = work->options; |
2397 |
|
work->options |= DMGL_PARAMS; |
2398 |
|
|
2399 |
string_append (declp, "<"); |
string_append (declp, "<"); |
2400 |
/* should do error checking here */ |
/* should do error checking here */ |
2401 |
while (args < e) { |
while (args < e) { |
2402 |
string_clear (&arg); |
string_delete (&arg); |
2403 |
|
|
2404 |
/* Check for type or literal here */ |
/* Check for type or literal here */ |
2405 |
switch (*args) |
switch (*args) |
2414 |
goto cfront_template_args_done; |
goto cfront_template_args_done; |
2415 |
string_append (&arg, "("); |
string_append (&arg, "("); |
2416 |
string_appends (&arg, &type_str); |
string_appends (&arg, &type_str); |
2417 |
|
string_delete (&type_str); |
2418 |
string_append (&arg, ")"); |
string_append (&arg, ")"); |
2419 |
if (*args != 'L') |
if (*args != 'L') |
2420 |
goto cfront_template_args_done; |
goto cfront_template_args_done; |
2439 |
|
|
2440 |
/* Fail if we didn't make any progress: prevent infinite loop. */ |
/* Fail if we didn't make any progress: prevent infinite loop. */ |
2441 |
if (args == old_args) |
if (args == old_args) |
2442 |
return; |
{ |
2443 |
|
work->options = hold_options; |
2444 |
|
return; |
2445 |
|
} |
2446 |
} |
} |
2447 |
} |
} |
2448 |
string_appends (declp, &arg); |
string_appends (declp, &arg); |
2453 |
if (args >= e) |
if (args >= e) |
2454 |
--declp->p; /* remove extra comma */ |
--declp->p; /* remove extra comma */ |
2455 |
string_append (declp, ">"); |
string_append (declp, ">"); |
2456 |
|
work->options = hold_options; |
2457 |
} |
} |
2458 |
else if (n>10 && strncmp (*mangled, "_GLOBAL_", 8) == 0 |
else if (n>10 && strncmp (*mangled, "_GLOBAL_", 8) == 0 |
2459 |
&& (*mangled)[9] == 'N' |
&& (*mangled)[9] == 'N' |
3376 |
} |
} |
3377 |
else |
else |
3378 |
{ |
{ |
3379 |
|
string_delete (&last_name); |
3380 |
success = do_type (work, mangled, &last_name); |
success = do_type (work, mangled, &last_name); |
3381 |
if (!success) |
if (!success) |
3382 |
break; |
break; |
3519 |
string decl; |
string decl; |
3520 |
const char *remembered_type; |
const char *remembered_type; |
3521 |
int type_quals; |
int type_quals; |
|
string btype; |
|
3522 |
type_kind_t tk = tk_none; |
type_kind_t tk = tk_none; |
3523 |
|
|
|
string_init (&btype); |
|
3524 |
string_init (&decl); |
string_init (&decl); |
3525 |
string_init (result); |
string_init (result); |
3526 |
|
|
3638 |
string temp; |
string temp; |
3639 |
do_type (work, mangled, &temp); |
do_type (work, mangled, &temp); |
3640 |
string_prepends (&decl, &temp); |
string_prepends (&decl, &temp); |
3641 |
|
string_delete (&temp); |
3642 |
} |
} |
3643 |
else if (**mangled == 't') |
else if (**mangled == 't') |
3644 |
{ |
{ |
3649 |
if (success) |
if (success) |
3650 |
{ |
{ |
3651 |
string_prependn (&decl, temp.b, temp.p - temp.b); |
string_prependn (&decl, temp.b, temp.p - temp.b); |
3652 |
string_clear (&temp); |
string_delete (&temp); |
3653 |
} |
} |
3654 |
else |
else |
3655 |
break; |
break; |
3829 |
int success = 1; |
int success = 1; |
3830 |
char buf[10]; |
char buf[10]; |
3831 |
unsigned int dec = 0; |
unsigned int dec = 0; |
|
string btype; |
|
3832 |
type_kind_t tk = tk_integral; |
type_kind_t tk = tk_integral; |
3833 |
|
|
|
string_init (&btype); |
|
|
|
|
3834 |
/* First pick off any type qualifiers. There can be more than one. */ |
/* First pick off any type qualifiers. There can be more than one. */ |
3835 |
|
|
3836 |
while (!done) |
while (!done) |
4002 |
} |
} |
4003 |
case 't': |
case 't': |
4004 |
{ |
{ |
4005 |
|
string btype; |
4006 |
|
string_init (&btype); |
4007 |
success = demangle_template (work, mangled, &btype, 0, 1, 1); |
success = demangle_template (work, mangled, &btype, 0, 1, 1); |
4008 |
string_appends (result, &btype); |
string_appends (result, &btype); |
4009 |
|
string_delete (&btype); |
4010 |
break; |
break; |
4011 |
} |
} |
4012 |
default: |
default: |
4208 |
do not want to add additional types to the back-referenceable |
do not want to add additional types to the back-referenceable |
4209 |
type vector when processing a repeated type. */ |
type vector when processing a repeated type. */ |
4210 |
if (work->previous_argument) |
if (work->previous_argument) |
4211 |
string_clear (work->previous_argument); |
string_delete (work->previous_argument); |
4212 |
else |
else |
4213 |
{ |
work->previous_argument = (string*) xmalloc (sizeof (string)); |
|
work->previous_argument = (string*) xmalloc (sizeof (string)); |
|
|
string_init (work->previous_argument); |
|
|
} |
|
4214 |
|
|
4215 |
if (!do_type (work, mangled, work->previous_argument)) |
if (!do_type (work, mangled, work->previous_argument)) |
4216 |
return 0; |
return 0; |
4574 |
|
|
4575 |
/* Restore the previous_argument field. */ |
/* Restore the previous_argument field. */ |
4576 |
if (work->previous_argument) |
if (work->previous_argument) |
4577 |
string_delete (work->previous_argument); |
{ |
4578 |
|
string_delete (work->previous_argument); |
4579 |
|
free ((char *) work->previous_argument); |
4580 |
|
} |
4581 |
work->previous_argument = saved_previous_argument; |
work->previous_argument = saved_previous_argument; |
4582 |
--work->forgetting_types; |
--work->forgetting_types; |
4583 |
work->nrepeats = saved_nrepeats; |
work->nrepeats = saved_nrepeats; |
4902 |
sprintf(buf, "T%d", idx); |
sprintf(buf, "T%d", idx); |
4903 |
string_append (s, buf); |
string_append (s, buf); |
4904 |
} |
} |
|
|
|
|
static const char * demangler_list = NULL; |
|
|
|
|
|
/* The buffer should be big enough to hold the list. */ |
|
|
static char demangler_list_buffer [128]; |
|
|
|
|
|
const char * |
|
|
get_demangler_list () |
|
|
{ |
|
|
enum demangling_styles i; |
|
|
int start, len, left; |
|
|
|
|
|
if (!demangler_list) |
|
|
{ |
|
|
demangler_list = demangler_list_buffer; |
|
|
demangler_list_buffer [0] = '{'; |
|
|
|
|
|
start = 1; |
|
|
left = sizeof (demangler_list_buffer) - start; |
|
|
|
|
|
for (i = 0; i < unknown_demangling && left > 0; i++) |
|
|
{ |
|
|
strncpy (&demangler_list_buffer [start], |
|
|
libiberty_demanglers [i].demangling_style_name, left); |
|
|
len = strlen (libiberty_demanglers [i].demangling_style_name); |
|
|
start += len; |
|
|
if (left > 0) |
|
|
{ |
|
|
demangler_list_buffer [start] = ','; |
|
|
start++; |
|
|
left -= len + 1; |
|
|
} |
|
|
} |
|
|
|
|
|
if (left >= 0) |
|
|
{ |
|
|
demangler_list_buffer [--start] = '}'; |
|
|
} |
|
|
} |
|
|
|
|
|
return demangler_list; |
|
|
} |
|
|
|
|
|
/* To generate a standalone demangler program for testing purposes, |
|
|
just compile and link this file with -DMAIN and libiberty.a. When |
|
|
run, it demangles each command line arg, or each stdin string, and |
|
|
prints the result on stdout. */ |
|
|
|
|
|
#ifdef MAIN |
|
|
|
|
|
#include "getopt.h" |
|
|
|
|
|
static const char *program_name; |
|
|
static const char *program_version = VERSION; |
|
|
|
|
|
static void demangle_it PARAMS ((char *)); |
|
|
static void usage PARAMS ((FILE *, int)) ATTRIBUTE_NORETURN; |
|
|
static void fatal PARAMS ((const char *)) ATTRIBUTE_NORETURN; |
|
|
|
|
|
static void |
|
|
demangle_it (mangled_name) |
|
|
char *mangled_name; |
|
|
{ |
|
|
char *result; |
|
|
|
|
|
/* For command line args, also try to demangle type encodings. */ |
|
|
libiberty_demanglers [current_demangling_style].demangling_options |
|
|
|= DMGL_TYPES; |
|
|
result = demangle_symbol (mangled_name); |
|
|
if (result == NULL) |
|
|
{ |
|
|
printf ("%s\n", mangled_name); |
|
|
} |
|
|
else |
|
|
{ |
|
|
printf ("%s\n", result); |
|
|
free (result); |
|
|
} |
|
|
} |
|
|
|
|
|
static void |
|
|
usage (stream, status) |
|
|
FILE *stream; |
|
|
int status; |
|
|
{ |
|
|
fprintf (stream, "\ |
|
|
Usage: %s [-_] [-n] [--strip-underscores] [--no-strip-underscores] \n", |
|
|
program_name); |
|
|
|
|
|
fprintf (stream, "\ |
|
|
[-s %s]\n", get_demangler_list ()); |
|
|
|
|
|
fprintf (stream, "\ |
|
|
[--format %s]\n", get_demangler_list ()); |
|
|
|
|
|
fprintf (stream, "\ |
|
|
[--help] [--version] [arg...]\n"); |
|
|
exit (status); |
|
|
} |
|
|
|
|
|
#define MBUF_SIZE 32767 |
|
|
char mbuffer[MBUF_SIZE]; |
|
|
|
|
|
/* Defined in the automatically-generated underscore.c. */ |
|
|
extern int prepends_underscore; |
|
|
|
|
|
int strip_underscore = 0; |
|
|
|
|
|
static const struct option long_options[] = { |
|
|
{"strip-underscores", no_argument, 0, '_'}, |
|
|
{"format", required_argument, 0, 's'}, |
|
|
{"demangler", required_argument, 0, 'd'}, |
|
|
{"help", no_argument, 0, 'h'}, |
|
|
{"no-strip-underscores", no_argument, 0, 'n'}, |
|
|
{"version", no_argument, 0, 'v'}, |
|
|
{0, no_argument, 0, 0} |
|
|
}; |
|
|
|
|
|
/* More 'friendly' abort that prints the line and file. |
|
|
config.h can #define abort fancy_abort if you like that sort of thing. */ |
|
|
|
|
|
void |
|
|
fancy_abort () |
|
|
{ |
|
|
fatal ("Internal gcc abort."); |
|
|
} |
|
|
|
|
|
|
|
|
static const char * |
|
|
standard_symbol_characters PARAMS ((void)); |
|
|
|
|
|
static const char * |
|
|
hp_symbol_characters PARAMS ((void)); |
|
|
|
|
|
static const char * |
|
|
gnu_v3_symbol_characters PARAMS ((void)); |
|
|
|
|
|
/* Return the string of non-alnum characters that may occur |
|
|
as a valid symbol component, in the standard assembler symbol |
|
|
syntax. */ |
|
|
|
|
|
static const char * |
|
|
standard_symbol_characters () |
|
|
{ |
|
|
return "_$."; |
|
|
} |
|
|
|
|
|
|
|
|
/* Return the string of non-alnum characters that may occur |
|
|
as a valid symbol name component in an HP object file. |
|
|
|
|
|
Note that, since HP's compiler generates object code straight from |
|
|
C++ source, without going through an assembler, its mangled |
|
|
identifiers can use all sorts of characters that no assembler would |
|
|
tolerate, so the alphabet this function creates is a little odd. |
|
|
Here are some sample mangled identifiers offered by HP: |
|
|
|
|
|
typeid*__XT24AddressIndExpClassMember_ |
|
|
[Vftptr]key:__dt__32OrdinaryCompareIndExpClassMemberFv |
|
|
__ct__Q2_9Elf64_Dyn18{unnamed.union.#1}Fv |
|
|
|
|
|
This still seems really weird to me, since nowhere else in this |
|
|
file is there anything to recognize curly brackets, parens, etc. |
|
|
I've talked with Srikanth <srikanth@cup.hp.com>, and he assures me |
|
|
this is right, but I still strongly suspect that there's a |
|
|
misunderstanding here. |
|
|
|
|
|
If we decide it's better for c++filt to use HP's assembler syntax |
|
|
to scrape identifiers out of its input, here's the definition of |
|
|
the symbol name syntax from the HP assembler manual: |
|
|
|
|
|
Symbols are composed of uppercase and lowercase letters, decimal |
|
|
digits, dollar symbol, period (.), ampersand (&), pound sign(#) and |
|
|
underscore (_). A symbol can begin with a letter, digit underscore or |
|
|
dollar sign. If a symbol begins with a digit, it must contain a |
|
|
non-digit character. |
|
|
|
|
|
So have fun. */ |
|
|
static const char * |
|
|
hp_symbol_characters () |
|
|
{ |
|
|
return "_$.<>#,*&[]:(){}"; |
|
|
} |
|
|
|
|
|
|
|
|
/* Return the string of non-alnum characters that may occur |
|
|
as a valid symbol component in the GNU C++ V3 ABI mangling |
|
|
scheme. */ |
|
|
|
|
|
static const char * |
|
|
gnu_v3_symbol_characters () |
|
|
{ |
|
|
return "_$."; |
|
|
} |
|
|
|
|
|
|
|
|
extern int main PARAMS ((int, char **)); |
|
|
|
|
|
int |
|
|
main (argc, argv) |
|
|
int argc; |
|
|
char **argv; |
|
|
{ |
|
|
char *result; |
|
|
int c; |
|
|
const char *valid_symbols; |
|
|
const char *demangler = NULL; |
|
|
const char *options = NULL; |
|
|
|
|
|
program_name = argv[0]; |
|
|
|
|
|
strip_underscore = prepends_underscore; |
|
|
|
|
|
while ((c = getopt_long (argc, argv, "_ns:d:", long_options, (int *) 0)) != EOF) |
|
|
{ |
|
|
switch (c) |
|
|
{ |
|
|
case '?': |
|
|
usage (stderr, 1); |
|
|
break; |
|
|
case 'h': |
|
|
usage (stdout, 0); |
|
|
case 'n': |
|
|
strip_underscore = 0; |
|
|
break; |
|
|
case 'v': |
|
|
printf ("GNU %s (C++ demangler), version %s\n", program_name, program_version); |
|
|
return (0); |
|
|
case '_': |
|
|
strip_underscore = 1; |
|
|
break; |
|
|
case 'd': |
|
|
demangler = optarg; |
|
|
break; |
|
|
case 's': |
|
|
current_demangling_style |
|
|
= cplus_demangle_name_to_style (optarg); |
|
|
if (current_demangling_style == unknown_demangling) |
|
|
{ |
|
|
fprintf (stderr, "%s: unknown demangling style `%s'\n", |
|
|
program_name, optarg); |
|
|
return (1); |
|
|
} |
|
|
break; |
|
|
} |
|
|
} |
|
|
|
|
|
init_demangler (NULL, options, demangler); |
|
|
|
|
|
if (optind < argc) |
|
|
{ |
|
|
for ( ; optind < argc; optind++) |
|
|
{ |
|
|
demangle_it (argv[optind]); |
|
|
} |
|
|
} |
|
|
else |
|
|
{ |
|
|
switch (current_demangling_style) |
|
|
{ |
|
|
case gnu_demangling: |
|
|
case lucid_demangling: |
|
|
case arm_demangling: |
|
|
case java_demangling: |
|
|
case edg_demangling: |
|
|
case gnat_demangling: |
|
|
case auto_demangling: |
|
|
case compaq_demangling: |
|
|
valid_symbols = standard_symbol_characters (); |
|
|
break; |
|
|
case hp_demangling: |
|
|
valid_symbols = hp_symbol_characters (); |
|
|
break; |
|
|
case gnu_v3_demangling: |
|
|
valid_symbols = gnu_v3_symbol_characters (); |
|
|
break; |
|
|
default: |
|
|
/* Folks should explicitly indicate the appropriate alphabet for |
|
|
each demangling. Providing a default would allow the |
|
|
question to go unconsidered. */ |
|
|
abort (); |
|
|
} |
|
|
|
|
|
for (;;) |
|
|
{ |
|
|
int i = 0; |
|
|
c = getchar (); |
|
|
/* Try to read a label. */ |
|
|
while (c != EOF && (ISALNUM (c) || strchr (valid_symbols, c))) |
|
|
{ |
|
|
if (i >= MBUF_SIZE-1) |
|
|
break; |
|
|
mbuffer[i++] = c; |
|
|
c = getchar (); |
|
|
} |
|
|
if (i > 0) |
|
|
{ |
|
|
int skip_first = 0; |
|
|
|
|
|
if (mbuffer[0] == '.' || mbuffer[0] == '$') |
|
|
++skip_first; |
|
|
if (strip_underscore && mbuffer[skip_first] == '_') |
|
|
++skip_first; |
|
|
|
|
|
if (skip_first > i) |
|
|
skip_first = i; |
|
|
|
|
|
mbuffer[i] = 0; |
|
|
result = demangle_symbol (mbuffer + skip_first); |
|
|
if (result) |
|
|
{ |
|
|
if (mbuffer[0] == '.') |
|
|
putc ('.', stdout); |
|
|
fputs (result, stdout); |
|
|
free (result); |
|
|
} |
|
|
else |
|
|
fputs (mbuffer, stdout); |
|
|
|
|
|
fflush (stdout); |
|
|
} |
|
|
if (c == EOF) |
|
|
break; |
|
|
putchar (c); |
|
|
fflush (stdout); |
|
|
} |
|
|
} |
|
|
|
|
|
return (0); |
|
|
} |
|
|
|
|
|
static void |
|
|
fatal (str) |
|
|
const char *str; |
|
|
{ |
|
|
fprintf (stderr, "%s: %s\n", program_name, str); |
|
|
exit (1); |
|
|
} |
|
|
|
|
|
PTR |
|
|
xmalloc (size) |
|
|
size_t size; |
|
|
{ |
|
|
register PTR value = (PTR) malloc (size); |
|
|
if (value == 0) |
|
|
fatal ("virtual memory exhausted"); |
|
|
return value; |
|
|
} |
|
|
|
|
|
PTR |
|
|
xrealloc (ptr, size) |
|
|
PTR ptr; |
|
|
size_t size; |
|
|
{ |
|
|
register PTR value = (PTR) realloc (ptr, size); |
|
|
if (value == 0) |
|
|
fatal ("virtual memory exhausted"); |
|
|
return value; |
|
|
} |
|
|
#endif /* main */ |
|