fix typos in ada-lang.c comment
[deliverable/binutils-gdb.git] / gdb / reggroups.c
CommitLineData
b59ff9d5
AC
1/* Register groupings for GDB, the GNU debugger.
2
61baf725 3 Copyright (C) 2002-2017 Free Software Foundation, Inc.
b59ff9d5
AC
4
5 Contributed by Red Hat.
6
7 This file is part of GDB.
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
a9762ec7 11 the Free Software Foundation; either version 3 of the License, or
b59ff9d5
AC
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
a9762ec7 20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
b59ff9d5
AC
21
22#include "defs.h"
e17c207e 23#include "arch-utils.h"
b59ff9d5
AC
24#include "reggroups.h"
25#include "gdbtypes.h"
b59ff9d5
AC
26#include "regcache.h"
27#include "command.h"
28#include "gdbcmd.h" /* For maintenanceprintlist. */
29
30/* Individual register groups. */
31
32struct reggroup
33{
34 const char *name;
35 enum reggroup_type type;
36};
37
38struct reggroup *
39reggroup_new (const char *name, enum reggroup_type type)
40{
70ba0933 41 struct reggroup *group = XNEW (struct reggroup);
123f5f96 42
b59ff9d5
AC
43 group->name = name;
44 group->type = type;
45 return group;
46}
47
48/* Register group attributes. */
49
50const char *
51reggroup_name (struct reggroup *group)
52{
53 return group->name;
54}
55
56enum reggroup_type
57reggroup_type (struct reggroup *group)
58{
59 return group->type;
60}
61
6c7d17ba
AC
62/* A linked list of groups for the given architecture. */
63
64struct reggroup_el
65{
66 struct reggroup *group;
67 struct reggroup_el *next;
68};
b59ff9d5
AC
69
70struct reggroups
71{
6c7d17ba
AC
72 struct reggroup_el *first;
73 struct reggroup_el **last;
b59ff9d5
AC
74};
75
76static struct gdbarch_data *reggroups_data;
77
78static void *
79reggroups_init (struct gdbarch *gdbarch)
80{
6c7d17ba
AC
81 struct reggroups *groups = GDBARCH_OBSTACK_ZALLOC (gdbarch,
82 struct reggroups);
123f5f96 83
6c7d17ba 84 groups->last = &groups->first;
b59ff9d5
AC
85 return groups;
86}
87
b59ff9d5 88/* Add a register group (with attribute values) to the pre-defined
6c7d17ba 89 list. */
b59ff9d5
AC
90
91static void
6c7d17ba
AC
92add_group (struct reggroups *groups, struct reggroup *group,
93 struct reggroup_el *el)
b59ff9d5
AC
94{
95 gdb_assert (group != NULL);
6c7d17ba
AC
96 el->group = group;
97 el->next = NULL;
98 (*groups->last) = el;
99 groups->last = &el->next;
b59ff9d5
AC
100}
101
102void
103reggroup_add (struct gdbarch *gdbarch, struct reggroup *group)
104{
19ba03f4
SM
105 struct reggroups *groups
106 = (struct reggroups *) gdbarch_data (gdbarch, reggroups_data);
7e6d0ac8 107
b59ff9d5
AC
108 if (groups == NULL)
109 {
110 /* ULGH, called during architecture initialization. Patch
111 things up. */
19ba03f4 112 groups = (struct reggroups *) reggroups_init (gdbarch);
030f20e1 113 deprecated_set_gdbarch_data (gdbarch, reggroups_data, groups);
b59ff9d5 114 }
6c7d17ba
AC
115 add_group (groups, group,
116 GDBARCH_OBSTACK_ZALLOC (gdbarch, struct reggroup_el));
b59ff9d5
AC
117}
118
6c7d17ba
AC
119/* The default register groups for an architecture. */
120
121static struct reggroups default_groups = { NULL, &default_groups.first };
b59ff9d5 122
6c7d17ba 123/* A register group iterator. */
b59ff9d5 124
6c7d17ba
AC
125struct reggroup *
126reggroup_next (struct gdbarch *gdbarch, struct reggroup *last)
b59ff9d5 127{
6c7d17ba
AC
128 struct reggroups *groups;
129 struct reggroup_el *el;
7e6d0ac8 130
b59ff9d5 131 /* Don't allow this function to be called during architecture
6c7d17ba 132 creation. If there are no groups, use the default groups list. */
19ba03f4 133 groups = (struct reggroups *) gdbarch_data (gdbarch, reggroups_data);
b59ff9d5 134 gdb_assert (groups != NULL);
6c7d17ba
AC
135 if (groups->first == NULL)
136 groups = &default_groups;
137
9dd5f34f 138 /* Return the first/next reggroup. */
6c7d17ba
AC
139 if (last == NULL)
140 return groups->first->group;
141 for (el = groups->first; el != NULL; el = el->next)
142 {
143 if (el->group == last)
9dd5f34f
AC
144 {
145 if (el->next != NULL)
146 return el->next->group;
147 else
148 return NULL;
149 }
6c7d17ba
AC
150 }
151 return NULL;
b59ff9d5
AC
152}
153
55b40027
AB
154/* See reggroups.h. */
155
156struct reggroup *
157reggroup_prev (struct gdbarch *gdbarch, struct reggroup *curr)
158{
159 struct reggroups *groups;
160 struct reggroup_el *el;
161 struct reggroup *prev;
162
163 /* Don't allow this function to be called during architecture
164 creation. If there are no groups, use the default groups list. */
19ba03f4 165 groups = (struct reggroups *) gdbarch_data (gdbarch, reggroups_data);
55b40027
AB
166 gdb_assert (groups != NULL);
167 if (groups->first == NULL)
168 groups = &default_groups;
169
170 prev = NULL;
171 for (el = groups->first; el != NULL; el = el->next)
172 {
173 gdb_assert (el->group != NULL);
174 if (el->group == curr)
175 return prev;
176 prev = el->group;
177 }
178 if (curr == NULL)
179 return prev;
180 return NULL;
181}
182
b59ff9d5
AC
183/* Is REGNUM a member of REGGROUP? */
184int
185default_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
186 struct reggroup *group)
187{
188 int vector_p;
189 int float_p;
190 int raw_p;
7e6d0ac8 191
6bcde365
UW
192 if (gdbarch_register_name (gdbarch, regnum) == NULL
193 || *gdbarch_register_name (gdbarch, regnum) == '\0')
b59ff9d5
AC
194 return 0;
195 if (group == all_reggroup)
196 return 1;
197 vector_p = TYPE_VECTOR (register_type (gdbarch, regnum));
198 float_p = TYPE_CODE (register_type (gdbarch, regnum)) == TYPE_CODE_FLT;
6bcde365 199 raw_p = regnum < gdbarch_num_regs (gdbarch);
b59ff9d5
AC
200 if (group == float_reggroup)
201 return float_p;
202 if (group == vector_reggroup)
203 return vector_p;
204 if (group == general_reggroup)
205 return (!vector_p && !float_p);
206 if (group == save_reggroup || group == restore_reggroup)
207 return raw_p;
208 return 0;
209}
210
211/* Dump out a table of register groups for the current architecture. */
212
213static void
214reggroups_dump (struct gdbarch *gdbarch, struct ui_file *file)
215{
6c7d17ba 216 struct reggroup *group = NULL;
7e6d0ac8 217
b59ff9d5
AC
218 do
219 {
220 /* Group name. */
221 {
222 const char *name;
123f5f96 223
6c7d17ba 224 if (group == NULL)
b59ff9d5
AC
225 name = "Group";
226 else
6c7d17ba 227 name = reggroup_name (group);
b59ff9d5
AC
228 fprintf_unfiltered (file, " %-10s", name);
229 }
230
231 /* Group type. */
232 {
233 const char *type;
123f5f96 234
6c7d17ba 235 if (group == NULL)
b59ff9d5
AC
236 type = "Type";
237 else
238 {
6c7d17ba 239 switch (reggroup_type (group))
b59ff9d5
AC
240 {
241 case USER_REGGROUP:
242 type = "user";
243 break;
244 case INTERNAL_REGGROUP:
245 type = "internal";
246 break;
247 default:
e2e0b3e5 248 internal_error (__FILE__, __LINE__, _("bad switch"));
b59ff9d5
AC
249 }
250 }
251 fprintf_unfiltered (file, " %-10s", type);
252 }
253
254 /* Note: If you change this, be sure to also update the
255 documentation. */
256
257 fprintf_unfiltered (file, "\n");
6c7d17ba
AC
258
259 group = reggroup_next (gdbarch, group);
b59ff9d5 260 }
6c7d17ba 261 while (group != NULL);
b59ff9d5
AC
262}
263
264static void
34e5fa26 265maintenance_print_reggroups (const char *args, int from_tty)
b59ff9d5 266{
e17c207e
UW
267 struct gdbarch *gdbarch = get_current_arch ();
268
b59ff9d5 269 if (args == NULL)
e17c207e 270 reggroups_dump (gdbarch, gdb_stdout);
b59ff9d5
AC
271 else
272 {
d7e74731 273 stdio_file file;
123f5f96 274
d7e74731 275 if (!file.open (args, "w"))
e2e0b3e5 276 perror_with_name (_("maintenance print reggroups"));
d7e74731 277 reggroups_dump (gdbarch, &file);
b59ff9d5
AC
278 }
279}
280
281/* Pre-defined register groups. */
282static struct reggroup general_group = { "general", USER_REGGROUP };
283static struct reggroup float_group = { "float", USER_REGGROUP };
284static struct reggroup system_group = { "system", USER_REGGROUP };
285static struct reggroup vector_group = { "vector", USER_REGGROUP };
286static struct reggroup all_group = { "all", USER_REGGROUP };
287static struct reggroup save_group = { "save", INTERNAL_REGGROUP };
288static struct reggroup restore_group = { "restore", INTERNAL_REGGROUP };
289
290struct reggroup *const general_reggroup = &general_group;
291struct reggroup *const float_reggroup = &float_group;
292struct reggroup *const system_reggroup = &system_group;
293struct reggroup *const vector_reggroup = &vector_group;
294struct reggroup *const all_reggroup = &all_group;
295struct reggroup *const save_reggroup = &save_group;
296struct reggroup *const restore_reggroup = &restore_group;
297
298void
299_initialize_reggroup (void)
300{
030f20e1 301 reggroups_data = gdbarch_data_register_post_init (reggroups_init);
b59ff9d5
AC
302
303 /* The pre-defined list of groups. */
70ba0933
TT
304 add_group (&default_groups, general_reggroup, XNEW (struct reggroup_el));
305 add_group (&default_groups, float_reggroup, XNEW (struct reggroup_el));
306 add_group (&default_groups, system_reggroup, XNEW (struct reggroup_el));
307 add_group (&default_groups, vector_reggroup, XNEW (struct reggroup_el));
308 add_group (&default_groups, all_reggroup, XNEW (struct reggroup_el));
309 add_group (&default_groups, save_reggroup, XNEW (struct reggroup_el));
310 add_group (&default_groups, restore_reggroup, XNEW (struct reggroup_el));
b59ff9d5
AC
311
312 add_cmd ("reggroups", class_maintenance,
1a966eab 313 maintenance_print_reggroups, _("\
b59ff9d5 314Print the internal register group names.\n\
1a966eab 315Takes an optional file parameter."),
b59ff9d5
AC
316 &maintenanceprintlist);
317
318}
This page took 1.522118 seconds and 4 git commands to generate.