1 /* Register groupings for GDB, the GNU debugger.
3 Copyright (C) 2002-2018 Free Software Foundation, Inc.
5 Contributed by Red Hat.
7 This file is part of GDB.
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
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
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.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
23 #include "arch-utils.h"
24 #include "reggroups.h"
28 #include "gdbcmd.h" /* For maintenanceprintlist. */
29 #include "gdb_obstack.h"
31 /* Individual register groups. */
36 enum reggroup_type type;
40 reggroup_new (const char *name, enum reggroup_type type)
42 struct reggroup *group = XNEW (struct reggroup);
49 /* See reggroups.h. */
52 reggroup_gdbarch_new (struct gdbarch *gdbarch, const char *name,
53 enum reggroup_type type)
55 struct reggroup *group = GDBARCH_OBSTACK_ZALLOC (gdbarch,
58 group->name = gdbarch_obstack_strdup (gdbarch, name);
63 /* Register group attributes. */
66 reggroup_name (struct reggroup *group)
72 reggroup_type (struct reggroup *group)
77 /* A linked list of groups for the given architecture. */
81 struct reggroup *group;
82 struct reggroup_el *next;
87 struct reggroup_el *first;
88 struct reggroup_el **last;
91 static struct gdbarch_data *reggroups_data;
94 reggroups_init (struct obstack *obstack)
96 struct reggroups *groups = OBSTACK_ZALLOC (obstack, struct reggroups);
98 groups->last = &groups->first;
102 /* Add a register group (with attribute values) to the pre-defined
106 add_group (struct reggroups *groups, struct reggroup *group,
107 struct reggroup_el *el)
109 gdb_assert (group != NULL);
112 (*groups->last) = el;
113 groups->last = &el->next;
117 reggroup_add (struct gdbarch *gdbarch, struct reggroup *group)
119 struct reggroups *groups
120 = (struct reggroups *) gdbarch_data (gdbarch, reggroups_data);
122 add_group (groups, group,
123 GDBARCH_OBSTACK_ZALLOC (gdbarch, struct reggroup_el));
126 /* The default register groups for an architecture. */
128 static struct reggroups default_groups = { NULL, &default_groups.first };
130 /* A register group iterator. */
133 reggroup_next (struct gdbarch *gdbarch, struct reggroup *last)
135 struct reggroups *groups;
136 struct reggroup_el *el;
138 /* Don't allow this function to be called during architecture
139 creation. If there are no groups, use the default groups list. */
140 groups = (struct reggroups *) gdbarch_data (gdbarch, reggroups_data);
141 gdb_assert (groups != NULL);
142 if (groups->first == NULL)
143 groups = &default_groups;
145 /* Return the first/next reggroup. */
147 return groups->first->group;
148 for (el = groups->first; el != NULL; el = el->next)
150 if (el->group == last)
152 if (el->next != NULL)
153 return el->next->group;
161 /* See reggroups.h. */
164 reggroup_prev (struct gdbarch *gdbarch, struct reggroup *curr)
166 struct reggroups *groups;
167 struct reggroup_el *el;
168 struct reggroup *prev;
170 /* Don't allow this function to be called during architecture
171 creation. If there are no groups, use the default groups list. */
172 groups = (struct reggroups *) gdbarch_data (gdbarch, reggroups_data);
173 gdb_assert (groups != NULL);
174 if (groups->first == NULL)
175 groups = &default_groups;
178 for (el = groups->first; el != NULL; el = el->next)
180 gdb_assert (el->group != NULL);
181 if (el->group == curr)
190 /* Is REGNUM a member of REGGROUP? */
192 default_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
193 struct reggroup *group)
199 if (gdbarch_register_name (gdbarch, regnum) == NULL
200 || *gdbarch_register_name (gdbarch, regnum) == '\0')
202 if (group == all_reggroup)
204 vector_p = TYPE_VECTOR (register_type (gdbarch, regnum));
205 float_p = (TYPE_CODE (register_type (gdbarch, regnum)) == TYPE_CODE_FLT
206 || (TYPE_CODE (register_type (gdbarch, regnum))
207 == TYPE_CODE_DECFLOAT));
208 raw_p = regnum < gdbarch_num_regs (gdbarch);
209 if (group == float_reggroup)
211 if (group == vector_reggroup)
213 if (group == general_reggroup)
214 return (!vector_p && !float_p);
215 if (group == save_reggroup || group == restore_reggroup)
220 /* See reggroups.h. */
223 reggroup_find (struct gdbarch *gdbarch, const char *name)
225 struct reggroup *group;
227 for (group = reggroup_next (gdbarch, NULL);
229 group = reggroup_next (gdbarch, group))
231 if (strcmp (name, reggroup_name (group)) == 0)
237 /* Dump out a table of register groups for the current architecture. */
240 reggroups_dump (struct gdbarch *gdbarch, struct ui_file *file)
242 struct reggroup *group = NULL;
253 name = reggroup_name (group);
254 fprintf_unfiltered (file, " %-10s", name);
265 switch (reggroup_type (group))
270 case INTERNAL_REGGROUP:
274 internal_error (__FILE__, __LINE__, _("bad switch"));
277 fprintf_unfiltered (file, " %-10s", type);
280 /* Note: If you change this, be sure to also update the
283 fprintf_unfiltered (file, "\n");
285 group = reggroup_next (gdbarch, group);
287 while (group != NULL);
291 maintenance_print_reggroups (const char *args, int from_tty)
293 struct gdbarch *gdbarch = get_current_arch ();
296 reggroups_dump (gdbarch, gdb_stdout);
301 if (!file.open (args, "w"))
302 perror_with_name (_("maintenance print reggroups"));
303 reggroups_dump (gdbarch, &file);
307 /* Pre-defined register groups. */
308 static struct reggroup general_group = { "general", USER_REGGROUP };
309 static struct reggroup float_group = { "float", USER_REGGROUP };
310 static struct reggroup system_group = { "system", USER_REGGROUP };
311 static struct reggroup vector_group = { "vector", USER_REGGROUP };
312 static struct reggroup all_group = { "all", USER_REGGROUP };
313 static struct reggroup save_group = { "save", INTERNAL_REGGROUP };
314 static struct reggroup restore_group = { "restore", INTERNAL_REGGROUP };
316 struct reggroup *const general_reggroup = &general_group;
317 struct reggroup *const float_reggroup = &float_group;
318 struct reggroup *const system_reggroup = &system_group;
319 struct reggroup *const vector_reggroup = &vector_group;
320 struct reggroup *const all_reggroup = &all_group;
321 struct reggroup *const save_reggroup = &save_group;
322 struct reggroup *const restore_reggroup = &restore_group;
325 _initialize_reggroup (void)
327 reggroups_data = gdbarch_data_register_pre_init (reggroups_init);
329 /* The pre-defined list of groups. */
330 add_group (&default_groups, general_reggroup, XNEW (struct reggroup_el));
331 add_group (&default_groups, float_reggroup, XNEW (struct reggroup_el));
332 add_group (&default_groups, system_reggroup, XNEW (struct reggroup_el));
333 add_group (&default_groups, vector_reggroup, XNEW (struct reggroup_el));
334 add_group (&default_groups, all_reggroup, XNEW (struct reggroup_el));
335 add_group (&default_groups, save_reggroup, XNEW (struct reggroup_el));
336 add_group (&default_groups, restore_reggroup, XNEW (struct reggroup_el));
338 add_cmd ("reggroups", class_maintenance,
339 maintenance_print_reggroups, _("\
340 Print the internal register group names.\n\
341 Takes an optional file parameter."),
342 &maintenanceprintlist);