Commit | Line | Data |
---|---|---|
2dbde378 FF |
1 | /* Basic C++ demangling support for GDB. |
2 | Copyright 1991, 1992 Free Software Foundation, Inc. | |
3 | Written by Fred Fish at Cygnus Support. | |
4 | ||
5 | This file is part of GDB. | |
6 | ||
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. | |
11 | ||
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. | |
16 | ||
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. */ | |
20 | ||
21 | ||
22 | /* This file contains support code for C++ demangling that is common | |
23 | to a styles of demangling, and GDB specific. */ | |
24 | ||
25 | #include "defs.h" | |
26 | #include "command.h" | |
27 | #include "gdbcmd.h" | |
28 | #include "demangle.h" | |
29 | #include <string.h> | |
30 | ||
d23639b2 FF |
31 | /* Select the default C++ demangling style to use. The default is "auto", |
32 | which allows gdb to attempt to pick an appropriate demangling style for | |
33 | the executable it has loaded. It can be set to a specific style ("gnu", | |
34 | "lucid", "cfront", etc.) in which case gdb will never attempt to do auto | |
35 | selection of the style unless you do an explicit "set demangle auto". | |
36 | To select one of these as the default, set DEFAULT_DEMANGLING_STYLE in | |
37 | the appropriate target configuration file. */ | |
38 | ||
39 | #ifndef DEFAULT_DEMANGLING_STYLE | |
40 | # define DEFAULT_DEMANGLING_STYLE AUTO_DEMANGLING_STYLE_STRING | |
2dbde378 FF |
41 | #endif |
42 | ||
43 | /* The current demangling style in affect. Global so that the demangler | |
44 | can read it (FIXME: change the interface) */ | |
45 | ||
46 | enum demangling_styles current_demangling_style; | |
47 | ||
48 | /* String name for the current demangling style. Set by the "set demangling" | |
49 | command, printed as part of the output by the "show demangling" command. */ | |
50 | ||
51 | static char *current_demangling_style_string; | |
52 | ||
53 | /* List of supported demangling styles. Contains the name of the style as | |
54 | seen by the user, and the enum value that corresponds to that style. */ | |
55 | ||
56 | static const struct demangler | |
57 | { | |
58 | char *demangling_style_name; | |
59 | enum demangling_styles demangling_style; | |
60 | char *demangling_style_doc; | |
61 | } demanglers [] = | |
62 | { | |
63 | {AUTO_DEMANGLING_STYLE_STRING, | |
64 | auto_demangling, | |
65 | "Automatic selection based on executable"}, | |
66 | {GNU_DEMANGLING_STYLE_STRING, | |
67 | gnu_demangling, | |
68 | "GNU (g++) style demangling"}, | |
69 | {LUCID_DEMANGLING_STYLE_STRING, | |
70 | lucid_demangling, | |
71 | "Lucid (lcc) style demangling"}, | |
72 | {CFRONT_DEMANGLING_STYLE_STRING, | |
73 | cfront_demangling, | |
74 | "ARM (cfront) style demangling"}, | |
75 | {NULL, 0, NULL} | |
76 | }; | |
77 | ||
78 | /* show current demangling style. */ | |
79 | ||
80 | static void | |
81 | show_demangling_command (ignore, from_tty) | |
82 | char *ignore; | |
83 | int from_tty; | |
84 | { | |
85 | /* done automatically by show command. */ | |
86 | } | |
87 | ||
88 | ||
89 | /* set current demangling style. called by the "set demangling" command | |
90 | after it has updated the current_demangling_style_string to match | |
91 | what the user has entered. | |
92 | ||
93 | if the user has entered a string that matches a known demangling style | |
94 | name in the demanglers[] array then just leave the string alone and update | |
95 | the current_demangling_style enum value to match. | |
96 | ||
97 | if the user has entered a string that doesn't match, including an empty | |
98 | string, then print a list of the currently known styles and restore | |
99 | the current_demangling_style_string to match the current_demangling_style | |
100 | enum value. | |
101 | ||
102 | Note: Assumes that current_demangling_style_string always points to | |
103 | a malloc'd string, even if it is a null-string. */ | |
104 | ||
105 | static void | |
106 | set_demangling_command (ignore, from_tty) | |
107 | char *ignore; | |
108 | int from_tty; | |
109 | { | |
110 | const struct demangler *dem; | |
111 | ||
112 | /* First just try to match whatever style name the user supplied with | |
113 | one of the known ones. Don't bother special casing for an empty | |
114 | name, we just treat it as any other style name that doesn't match. | |
115 | If we match, update the current demangling style enum. */ | |
116 | ||
117 | for (dem = demanglers; dem -> demangling_style_name != NULL; dem++) | |
118 | { | |
119 | if (strcmp (current_demangling_style_string, | |
120 | dem -> demangling_style_name) == 0) | |
121 | { | |
122 | current_demangling_style = dem -> demangling_style; | |
123 | break; | |
124 | } | |
125 | } | |
126 | ||
127 | /* Check to see if we found a match. If not, gripe about any non-empty | |
128 | style name and supply a list of valid ones. FIXME: This should | |
129 | probably be done with some sort of completion and with help. */ | |
130 | ||
131 | if (dem -> demangling_style_name == NULL) | |
132 | { | |
133 | if (*current_demangling_style_string != '\0') | |
134 | { | |
135 | printf ("Unknown demangling style `%s'.\n", | |
136 | current_demangling_style_string); | |
137 | } | |
138 | printf ("The currently understood settings are:\n\n"); | |
139 | for (dem = demanglers; dem -> demangling_style_name != NULL; dem++) | |
140 | { | |
141 | printf ("%-10s %s\n", dem -> demangling_style_name, | |
142 | dem -> demangling_style_doc); | |
143 | if (dem -> demangling_style == current_demangling_style) | |
144 | { | |
145 | free (current_demangling_style_string); | |
146 | current_demangling_style_string = | |
147 | strdup (dem -> demangling_style_name); | |
148 | } | |
149 | } | |
150 | if (current_demangling_style == unknown_demangling) | |
151 | { | |
152 | /* This can happen during initialization if gdb is compiled with | |
153 | a DEMANGLING_STYLE value that is unknown, so pick the first | |
154 | one as the default. */ | |
155 | current_demangling_style = demanglers[0].demangling_style; | |
156 | current_demangling_style_string = | |
157 | strdup (demanglers[0].demangling_style_name); | |
158 | warning ("`%s' style demangling chosen as the default.\n", | |
159 | current_demangling_style_string); | |
160 | } | |
161 | } | |
162 | } | |
163 | ||
164 | /* Fake a "set demangling" command. */ | |
165 | ||
166 | void | |
167 | set_demangling_style (style) | |
168 | char *style; | |
169 | { | |
170 | if (current_demangling_style_string != NULL) | |
171 | { | |
172 | free (current_demangling_style_string); | |
173 | } | |
174 | current_demangling_style_string = strdup (style); | |
175 | set_demangling_command ((char *) NULL, 0); | |
176 | } | |
177 | ||
178 | void | |
179 | _initialize_demangler () | |
180 | { | |
181 | struct cmd_list_element *set, *show; | |
182 | ||
183 | set = add_set_cmd ("demangle-style", class_support, var_string_noescape, | |
184 | (char *) ¤t_demangling_style_string, | |
185 | "Set the current C++ demangling style.", | |
186 | &setlist); | |
187 | show = add_show_from_set (set, &showlist); | |
188 | set -> function.cfunc = set_demangling_command; | |
189 | show -> function.cfunc = show_demangling_command; | |
190 | ||
191 | /* Set the default demangling style chosen at compilation time. */ | |
d23639b2 | 192 | set_demangling_style (DEFAULT_DEMANGLING_STYLE); |
2dbde378 | 193 | } |