]>
Commit | Line | Data |
---|---|---|
2dbde378 | 1 | /* Basic C++ demangling support for GDB. |
81afee37 | 2 | Copyright 1991, 1992, 1996 Free Software Foundation, Inc. |
2dbde378 FF |
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 | |
6c9638b4 | 19 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
2dbde378 FF |
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" | |
2b576293 | 29 | #include "gdb_string.h" |
2dbde378 | 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", | |
45364c8a | 34 | "lucid", "arm", etc.) in which case gdb will never attempt to do auto |
d23639b2 FF |
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 | ||
2dbde378 FF |
43 | /* String name for the current demangling style. Set by the "set demangling" |
44 | command, printed as part of the output by the "show demangling" command. */ | |
45 | ||
46 | static char *current_demangling_style_string; | |
47 | ||
48 | /* List of supported demangling styles. Contains the name of the style as | |
49 | seen by the user, and the enum value that corresponds to that style. */ | |
50 | ||
51 | static const struct demangler | |
52 | { | |
53 | char *demangling_style_name; | |
54 | enum demangling_styles demangling_style; | |
55 | char *demangling_style_doc; | |
56 | } demanglers [] = | |
57 | { | |
58 | {AUTO_DEMANGLING_STYLE_STRING, | |
59 | auto_demangling, | |
60 | "Automatic selection based on executable"}, | |
61 | {GNU_DEMANGLING_STYLE_STRING, | |
62 | gnu_demangling, | |
63 | "GNU (g++) style demangling"}, | |
64 | {LUCID_DEMANGLING_STYLE_STRING, | |
65 | lucid_demangling, | |
66 | "Lucid (lcc) style demangling"}, | |
45364c8a FF |
67 | {ARM_DEMANGLING_STYLE_STRING, |
68 | arm_demangling, | |
69 | "ARM style demangling"}, | |
6c7e40b4 | 70 | {NULL, unknown_demangling, NULL} |
2dbde378 FF |
71 | }; |
72 | ||
b607efe7 FF |
73 | static void |
74 | set_demangling_command PARAMS ((char *, int, struct cmd_list_element *)); | |
75 | ||
2dbde378 FF |
76 | /* set current demangling style. called by the "set demangling" command |
77 | after it has updated the current_demangling_style_string to match | |
78 | what the user has entered. | |
79 | ||
80 | if the user has entered a string that matches a known demangling style | |
81 | name in the demanglers[] array then just leave the string alone and update | |
82 | the current_demangling_style enum value to match. | |
83 | ||
84 | if the user has entered a string that doesn't match, including an empty | |
85 | string, then print a list of the currently known styles and restore | |
86 | the current_demangling_style_string to match the current_demangling_style | |
87 | enum value. | |
88 | ||
89 | Note: Assumes that current_demangling_style_string always points to | |
90 | a malloc'd string, even if it is a null-string. */ | |
91 | ||
92 | static void | |
719d9abb JK |
93 | set_demangling_command (ignore, from_tty, c) |
94 | char *ignore; | |
95 | int from_tty; | |
96 | struct cmd_list_element *c; | |
2dbde378 FF |
97 | { |
98 | const struct demangler *dem; | |
99 | ||
100 | /* First just try to match whatever style name the user supplied with | |
101 | one of the known ones. Don't bother special casing for an empty | |
102 | name, we just treat it as any other style name that doesn't match. | |
103 | If we match, update the current demangling style enum. */ | |
104 | ||
105 | for (dem = demanglers; dem -> demangling_style_name != NULL; dem++) | |
106 | { | |
2e4964ad FF |
107 | if (STREQ (current_demangling_style_string, |
108 | dem -> demangling_style_name)) | |
2dbde378 FF |
109 | { |
110 | current_demangling_style = dem -> demangling_style; | |
111 | break; | |
112 | } | |
113 | } | |
114 | ||
115 | /* Check to see if we found a match. If not, gripe about any non-empty | |
116 | style name and supply a list of valid ones. FIXME: This should | |
117 | probably be done with some sort of completion and with help. */ | |
118 | ||
119 | if (dem -> demangling_style_name == NULL) | |
120 | { | |
121 | if (*current_demangling_style_string != '\0') | |
122 | { | |
199b2450 | 123 | printf_unfiltered ("Unknown demangling style `%s'.\n", |
2dbde378 FF |
124 | current_demangling_style_string); |
125 | } | |
199b2450 | 126 | printf_unfiltered ("The currently understood settings are:\n\n"); |
2dbde378 FF |
127 | for (dem = demanglers; dem -> demangling_style_name != NULL; dem++) |
128 | { | |
199b2450 | 129 | printf_unfiltered ("%-10s %s\n", dem -> demangling_style_name, |
2dbde378 FF |
130 | dem -> demangling_style_doc); |
131 | if (dem -> demangling_style == current_demangling_style) | |
132 | { | |
133 | free (current_demangling_style_string); | |
134 | current_demangling_style_string = | |
bb6247c6 JK |
135 | savestring (dem -> demangling_style_name, |
136 | strlen (dem -> demangling_style_name)); | |
2dbde378 FF |
137 | } |
138 | } | |
139 | if (current_demangling_style == unknown_demangling) | |
140 | { | |
141 | /* This can happen during initialization if gdb is compiled with | |
142 | a DEMANGLING_STYLE value that is unknown, so pick the first | |
143 | one as the default. */ | |
144 | current_demangling_style = demanglers[0].demangling_style; | |
145 | current_demangling_style_string = | |
bb6247c6 JK |
146 | savestring (demanglers[0].demangling_style_name, |
147 | strlen (demanglers[0].demangling_style_name)); | |
2dbde378 FF |
148 | warning ("`%s' style demangling chosen as the default.\n", |
149 | current_demangling_style_string); | |
150 | } | |
151 | } | |
152 | } | |
153 | ||
154 | /* Fake a "set demangling" command. */ | |
155 | ||
156 | void | |
157 | set_demangling_style (style) | |
158 | char *style; | |
159 | { | |
160 | if (current_demangling_style_string != NULL) | |
161 | { | |
162 | free (current_demangling_style_string); | |
163 | } | |
bb6247c6 | 164 | current_demangling_style_string = savestring (style, strlen (style)); |
b607efe7 | 165 | set_demangling_command ((char *) NULL, 0, (struct cmd_list_element *) NULL); |
2dbde378 FF |
166 | } |
167 | ||
81afee37 FF |
168 | /* In order to allow a single demangler executable to demangle strings |
169 | using various common values of CPLUS_MARKER, as well as any specific | |
170 | one set at compile time, we maintain a string containing all the | |
171 | commonly used ones, and check to see if the marker we are looking for | |
172 | is in that string. CPLUS_MARKER is usually '$' on systems where the | |
173 | assembler can deal with that. Where the assembler can't, it's usually | |
174 | '.' (but on many systems '.' is used for other things). We put the | |
175 | current defined CPLUS_MARKER first (which defaults to '$'), followed | |
176 | by the next most common value, followed by an explicit '$' in case | |
177 | the value of CPLUS_MARKER is not '$'. | |
178 | ||
179 | We could avoid this if we could just get g++ to tell us what the actual | |
180 | cplus marker character is as part of the debug information, perhaps by | |
181 | ensuring that it is the character that terminates the gcc<n>_compiled | |
182 | marker symbol (FIXME). */ | |
183 | ||
184 | static char cplus_markers[] = { CPLUS_MARKER, '.', '$', '\0' }; | |
185 | ||
186 | int | |
187 | is_cplus_marker (c) | |
188 | int c; | |
189 | { | |
190 | return c && strchr (cplus_markers, c) != NULL; | |
191 | } | |
192 | ||
2dbde378 FF |
193 | void |
194 | _initialize_demangler () | |
195 | { | |
196 | struct cmd_list_element *set, *show; | |
197 | ||
198 | set = add_set_cmd ("demangle-style", class_support, var_string_noescape, | |
199 | (char *) ¤t_demangling_style_string, | |
9aa3aa8c JK |
200 | "Set the current C++ demangling style.\n\ |
201 | Use `set demangle-style' without arguments for a list of demangling styles.", | |
2dbde378 FF |
202 | &setlist); |
203 | show = add_show_from_set (set, &showlist); | |
719d9abb | 204 | set -> function.sfunc = set_demangling_command; |
2dbde378 FF |
205 | |
206 | /* Set the default demangling style chosen at compilation time. */ | |
d23639b2 | 207 | set_demangling_style (DEFAULT_DEMANGLING_STYLE); |
e87c29c8 | 208 | set_cplus_marker_for_demangling (CPLUS_MARKER); |
2dbde378 | 209 | } |