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