]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/demangle.c
* symfile.h (INLINE_ADD_PSYMBOL): Default this to 0 and possibly
[thirdparty/binutils-gdb.git] / gdb / demangle.c
CommitLineData
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
5This file is part of GDB.
6
7This program is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2 of the License, or
10(at your option) any later version.
11
12This program is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with this program; if not, write to the Free Software
6c9638b4 19Foundation, 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
46static 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
51static 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
2dbde378
FF
73/* set current demangling style. called by the "set demangling" command
74 after it has updated the current_demangling_style_string to match
75 what the user has entered.
76
77 if the user has entered a string that matches a known demangling style
78 name in the demanglers[] array then just leave the string alone and update
79 the current_demangling_style enum value to match.
80
81 if the user has entered a string that doesn't match, including an empty
82 string, then print a list of the currently known styles and restore
83 the current_demangling_style_string to match the current_demangling_style
84 enum value.
85
86 Note: Assumes that current_demangling_style_string always points to
87 a malloc'd string, even if it is a null-string. */
88
89static void
719d9abb
JK
90set_demangling_command (ignore, from_tty, c)
91 char *ignore;
92 int from_tty;
93 struct cmd_list_element *c;
2dbde378
FF
94{
95 const struct demangler *dem;
96
97 /* First just try to match whatever style name the user supplied with
98 one of the known ones. Don't bother special casing for an empty
99 name, we just treat it as any other style name that doesn't match.
100 If we match, update the current demangling style enum. */
101
102 for (dem = demanglers; dem -> demangling_style_name != NULL; dem++)
103 {
2e4964ad
FF
104 if (STREQ (current_demangling_style_string,
105 dem -> demangling_style_name))
2dbde378
FF
106 {
107 current_demangling_style = dem -> demangling_style;
108 break;
109 }
110 }
111
112 /* Check to see if we found a match. If not, gripe about any non-empty
113 style name and supply a list of valid ones. FIXME: This should
114 probably be done with some sort of completion and with help. */
115
116 if (dem -> demangling_style_name == NULL)
117 {
118 if (*current_demangling_style_string != '\0')
119 {
199b2450 120 printf_unfiltered ("Unknown demangling style `%s'.\n",
2dbde378
FF
121 current_demangling_style_string);
122 }
199b2450 123 printf_unfiltered ("The currently understood settings are:\n\n");
2dbde378
FF
124 for (dem = demanglers; dem -> demangling_style_name != NULL; dem++)
125 {
199b2450 126 printf_unfiltered ("%-10s %s\n", dem -> demangling_style_name,
2dbde378
FF
127 dem -> demangling_style_doc);
128 if (dem -> demangling_style == current_demangling_style)
129 {
130 free (current_demangling_style_string);
131 current_demangling_style_string =
bb6247c6
JK
132 savestring (dem -> demangling_style_name,
133 strlen (dem -> demangling_style_name));
2dbde378
FF
134 }
135 }
136 if (current_demangling_style == unknown_demangling)
137 {
138 /* This can happen during initialization if gdb is compiled with
139 a DEMANGLING_STYLE value that is unknown, so pick the first
140 one as the default. */
141 current_demangling_style = demanglers[0].demangling_style;
142 current_demangling_style_string =
bb6247c6
JK
143 savestring (demanglers[0].demangling_style_name,
144 strlen (demanglers[0].demangling_style_name));
2dbde378
FF
145 warning ("`%s' style demangling chosen as the default.\n",
146 current_demangling_style_string);
147 }
148 }
149}
150
151/* Fake a "set demangling" command. */
152
153void
154set_demangling_style (style)
155 char *style;
156{
157 if (current_demangling_style_string != NULL)
158 {
159 free (current_demangling_style_string);
160 }
bb6247c6 161 current_demangling_style_string = savestring (style, strlen (style));
2dbde378
FF
162 set_demangling_command ((char *) NULL, 0);
163}
164
165void
166_initialize_demangler ()
167{
168 struct cmd_list_element *set, *show;
169
170 set = add_set_cmd ("demangle-style", class_support, var_string_noescape,
171 (char *) &current_demangling_style_string,
9aa3aa8c
JK
172 "Set the current C++ demangling style.\n\
173Use `set demangle-style' without arguments for a list of demangling styles.",
2dbde378
FF
174 &setlist);
175 show = add_show_from_set (set, &showlist);
719d9abb 176 set -> function.sfunc = set_demangling_command;
2dbde378
FF
177
178 /* Set the default demangling style chosen at compilation time. */
d23639b2 179 set_demangling_style (DEFAULT_DEMANGLING_STYLE);
e87c29c8 180 set_cplus_marker_for_demangling (CPLUS_MARKER);
2dbde378 181}