1 /* Basic C++ demangling support for GDB.
2 Copyright 1991, 1992, 1996, 1999 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., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
23 /* This file contains support code for C++ demangling that is common
24 to a styles of demangling, and GDB specific. */
30 #include "gdb_string.h"
32 /* Select the default C++ demangling style to use. The default is "auto",
33 which allows gdb to attempt to pick an appropriate demangling style for
34 the executable it has loaded. It can be set to a specific style ("gnu",
35 "lucid", "arm", "hp", etc.) in which case gdb will never attempt to do auto
36 selection of the style unless you do an explicit "set demangle auto".
37 To select one of these as the default, set DEFAULT_DEMANGLING_STYLE in
38 the appropriate target configuration file. */
40 #ifndef DEFAULT_DEMANGLING_STYLE
41 #define DEFAULT_DEMANGLING_STYLE AUTO_DEMANGLING_STYLE_STRING
44 extern void _initialize_demangler (void);
46 /* String name for the current demangling style. Set by the
47 "set demangle-style" command, printed as part of the output by the
48 "show demangle-style" command. */
50 static char *current_demangling_style_string;
52 static void set_demangling_command (char *, int, struct cmd_list_element *);
54 /* Set current demangling style. Called by the "set demangle-style"
55 command after it has updated the current_demangling_style_string to
56 match what the user has entered.
58 If the user has entered a string that matches a known demangling style
59 name in the demanglers[] array then just leave the string alone and update
60 the current_demangling_style enum value to match.
62 If the user has entered a string that doesn't match, including an empty
63 string, then print a list of the currently known styles and restore
64 the current_demangling_style_string to match the current_demangling_style
67 Note: Assumes that current_demangling_style_string always points to
68 a malloc'd string, even if it is a null-string. */
71 set_demangling_command (char *ignore, int from_tty, struct cmd_list_element *c)
73 const struct demangler_engine *dem;
75 /* First just try to match whatever style name the user supplied with
76 one of the known ones. Don't bother special casing for an empty
77 name, we just treat it as any other style name that doesn't match.
78 If we match, update the current demangling style enum. */
80 for (dem = libiberty_demanglers;
81 dem->demangling_style != unknown_demangling;
84 if (STREQ (current_demangling_style_string,
85 dem->demangling_style_name))
87 current_demangling_style = dem->demangling_style;
92 /* Check to see if we found a match. If not, gripe about any non-empty
93 style name and supply a list of valid ones. FIXME: This should
94 probably be done with some sort of completion and with help. */
96 if (dem->demangling_style == unknown_demangling)
98 if (*current_demangling_style_string != '\0')
100 printf_unfiltered ("Unknown demangling style `%s'.\n",
101 current_demangling_style_string);
103 printf_unfiltered ("The currently understood settings are:\n\n");
104 for (dem = libiberty_demanglers;
105 dem->demangling_style != unknown_demangling;
108 printf_unfiltered ("%-10s %s\n", dem->demangling_style_name,
109 dem->demangling_style_doc);
110 if (dem->demangling_style == current_demangling_style)
112 xfree (current_demangling_style_string);
113 current_demangling_style_string =
114 savestring (dem->demangling_style_name,
115 strlen (dem->demangling_style_name));
118 if (current_demangling_style == unknown_demangling)
120 /* This can happen during initialization if gdb is compiled with
121 a DEMANGLING_STYLE value that is unknown, so pick the first
122 one as the default. */
123 current_demangling_style = libiberty_demanglers[0].demangling_style;
124 current_demangling_style_string =
126 libiberty_demanglers[0].demangling_style_name,
127 strlen (libiberty_demanglers[0].demangling_style_name));
128 warning ("`%s' style demangling chosen as the default.\n",
129 current_demangling_style_string);
134 /* Fake a "set demangle-style" command. */
137 set_demangling_style (char *style)
139 if (current_demangling_style_string != NULL)
141 xfree (current_demangling_style_string);
143 current_demangling_style_string = savestring (style, strlen (style));
144 set_demangling_command ((char *) NULL, 0, (struct cmd_list_element *) NULL);
147 /* In order to allow a single demangler executable to demangle strings
148 using various common values of CPLUS_MARKER, as well as any specific
149 one set at compile time, we maintain a string containing all the
150 commonly used ones, and check to see if the marker we are looking for
151 is in that string. CPLUS_MARKER is usually '$' on systems where the
152 assembler can deal with that. Where the assembler can't, it's usually
153 '.' (but on many systems '.' is used for other things). We put the
154 current defined CPLUS_MARKER first (which defaults to '$'), followed
155 by the next most common value, followed by an explicit '$' in case
156 the value of CPLUS_MARKER is not '$'.
158 We could avoid this if we could just get g++ to tell us what the actual
159 cplus marker character is as part of the debug information, perhaps by
160 ensuring that it is the character that terminates the gcc<n>_compiled
161 marker symbol (FIXME). */
163 static char cplus_markers[] =
164 {CPLUS_MARKER, '.', '$', '\0'};
167 is_cplus_marker (int c)
169 return c && strchr (cplus_markers, c) != NULL;
173 _initialize_demangler (void)
175 struct cmd_list_element *set, *show;
177 set = add_set_cmd ("demangle-style", class_support, var_string_noescape,
178 (char *) ¤t_demangling_style_string,
179 "Set the current C++ demangling style.\n\
180 Use `set demangle-style' without arguments for a list of demangling styles.",
182 show = add_show_from_set (set, &showlist);
183 set->function.sfunc = set_demangling_command;
185 /* Set the default demangling style chosen at compilation time. */
186 set_demangling_style (DEFAULT_DEMANGLING_STYLE);
187 set_cplus_marker_for_demangling (CPLUS_MARKER);