1 /* Basic C++ demangling support for GDB.
2 Copyright 1991, 1992 Free Software Foundation, Inc.
3 Written by Fred Fish at Cygnus Support.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
22 /* This file contains support code for C++ demangling that is common
23 to a styles of demangling, and GDB specific. */
31 #ifndef DEMANGLING_STYLE
32 # define DEMANGLING_STYLE GNU_DEMANGLING_STYLE_STRING
35 /* The current demangling style in affect. Global so that the demangler
36 can read it (FIXME: change the interface) */
38 enum demangling_styles current_demangling_style;
40 /* String name for the current demangling style. Set by the "set demangling"
41 command, printed as part of the output by the "show demangling" command. */
43 static char *current_demangling_style_string;
45 /* List of supported demangling styles. Contains the name of the style as
46 seen by the user, and the enum value that corresponds to that style. */
48 static const struct demangler
50 char *demangling_style_name;
51 enum demangling_styles demangling_style;
52 char *demangling_style_doc;
55 {AUTO_DEMANGLING_STYLE_STRING,
57 "Automatic selection based on executable"},
58 {GNU_DEMANGLING_STYLE_STRING,
60 "GNU (g++) style demangling"},
61 {LUCID_DEMANGLING_STYLE_STRING,
63 "Lucid (lcc) style demangling"},
64 {CFRONT_DEMANGLING_STYLE_STRING,
66 "ARM (cfront) style demangling"},
70 /* show current demangling style. */
73 show_demangling_command (ignore, from_tty)
77 /* done automatically by show command. */
81 /* set current demangling style. called by the "set demangling" command
82 after it has updated the current_demangling_style_string to match
83 what the user has entered.
85 if the user has entered a string that matches a known demangling style
86 name in the demanglers[] array then just leave the string alone and update
87 the current_demangling_style enum value to match.
89 if the user has entered a string that doesn't match, including an empty
90 string, then print a list of the currently known styles and restore
91 the current_demangling_style_string to match the current_demangling_style
94 Note: Assumes that current_demangling_style_string always points to
95 a malloc'd string, even if it is a null-string. */
98 set_demangling_command (ignore, from_tty)
102 const struct demangler *dem;
104 /* First just try to match whatever style name the user supplied with
105 one of the known ones. Don't bother special casing for an empty
106 name, we just treat it as any other style name that doesn't match.
107 If we match, update the current demangling style enum. */
109 for (dem = demanglers; dem -> demangling_style_name != NULL; dem++)
111 if (strcmp (current_demangling_style_string,
112 dem -> demangling_style_name) == 0)
114 current_demangling_style = dem -> demangling_style;
119 /* Check to see if we found a match. If not, gripe about any non-empty
120 style name and supply a list of valid ones. FIXME: This should
121 probably be done with some sort of completion and with help. */
123 if (dem -> demangling_style_name == NULL)
125 if (*current_demangling_style_string != '\0')
127 printf ("Unknown demangling style `%s'.\n",
128 current_demangling_style_string);
130 printf ("The currently understood settings are:\n\n");
131 for (dem = demanglers; dem -> demangling_style_name != NULL; dem++)
133 printf ("%-10s %s\n", dem -> demangling_style_name,
134 dem -> demangling_style_doc);
135 if (dem -> demangling_style == current_demangling_style)
137 free (current_demangling_style_string);
138 current_demangling_style_string =
139 strdup (dem -> demangling_style_name);
142 if (current_demangling_style == unknown_demangling)
144 /* This can happen during initialization if gdb is compiled with
145 a DEMANGLING_STYLE value that is unknown, so pick the first
146 one as the default. */
147 current_demangling_style = demanglers[0].demangling_style;
148 current_demangling_style_string =
149 strdup (demanglers[0].demangling_style_name);
150 warning ("`%s' style demangling chosen as the default.\n",
151 current_demangling_style_string);
156 /* Fake a "set demangling" command. */
159 set_demangling_style (style)
162 if (current_demangling_style_string != NULL)
164 free (current_demangling_style_string);
166 current_demangling_style_string = strdup (style);
167 set_demangling_command ((char *) NULL, 0);
171 _initialize_demangler ()
173 struct cmd_list_element *set, *show;
175 set = add_set_cmd ("demangle-style", class_support, var_string_noescape,
176 (char *) ¤t_demangling_style_string,
177 "Set the current C++ demangling style.",
179 show = add_show_from_set (set, &showlist);
180 set -> function.cfunc = set_demangling_command;
181 show -> function.cfunc = show_demangling_command;
183 /* Set the default demangling style chosen at compilation time. */
184 set_demangling_style (DEMANGLING_STYLE);