1 /* Register groupings for GDB, the GNU debugger.
3 Copyright (C) 2002-2017 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 /* Register group attributes. */
52 reggroup_name (struct reggroup *group)
58 reggroup_type (struct reggroup *group)
63 /* A linked list of groups for the given architecture. */
67 struct reggroup *group;
68 struct reggroup_el *next;
73 struct reggroup_el *first;
74 struct reggroup_el **last;
77 static struct gdbarch_data *reggroups_data;
80 reggroups_init (struct obstack *obstack)
82 struct reggroups *groups = OBSTACK_ZALLOC (obstack, struct reggroups);
84 groups->last = &groups->first;
88 /* Add a register group (with attribute values) to the pre-defined
92 add_group (struct reggroups *groups, struct reggroup *group,
93 struct reggroup_el *el)
95 gdb_assert (group != NULL);
99 groups->last = &el->next;
103 reggroup_add (struct gdbarch *gdbarch, struct reggroup *group)
105 struct reggroups *groups
106 = (struct reggroups *) gdbarch_data (gdbarch, reggroups_data);
108 add_group (groups, group,
109 GDBARCH_OBSTACK_ZALLOC (gdbarch, struct reggroup_el));
112 /* The default register groups for an architecture. */
114 static struct reggroups default_groups = { NULL, &default_groups.first };
116 /* A register group iterator. */
119 reggroup_next (struct gdbarch *gdbarch, struct reggroup *last)
121 struct reggroups *groups;
122 struct reggroup_el *el;
124 /* Don't allow this function to be called during architecture
125 creation. If there are no groups, use the default groups list. */
126 groups = (struct reggroups *) gdbarch_data (gdbarch, reggroups_data);
127 gdb_assert (groups != NULL);
128 if (groups->first == NULL)
129 groups = &default_groups;
131 /* Return the first/next reggroup. */
133 return groups->first->group;
134 for (el = groups->first; el != NULL; el = el->next)
136 if (el->group == last)
138 if (el->next != NULL)
139 return el->next->group;
147 /* See reggroups.h. */
150 reggroup_prev (struct gdbarch *gdbarch, struct reggroup *curr)
152 struct reggroups *groups;
153 struct reggroup_el *el;
154 struct reggroup *prev;
156 /* Don't allow this function to be called during architecture
157 creation. If there are no groups, use the default groups list. */
158 groups = (struct reggroups *) gdbarch_data (gdbarch, reggroups_data);
159 gdb_assert (groups != NULL);
160 if (groups->first == NULL)
161 groups = &default_groups;
164 for (el = groups->first; el != NULL; el = el->next)
166 gdb_assert (el->group != NULL);
167 if (el->group == curr)
176 /* Is REGNUM a member of REGGROUP? */
178 default_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
179 struct reggroup *group)
185 if (gdbarch_register_name (gdbarch, regnum) == NULL
186 || *gdbarch_register_name (gdbarch, regnum) == '\0')
188 if (group == all_reggroup)
190 vector_p = TYPE_VECTOR (register_type (gdbarch, regnum));
191 float_p = TYPE_CODE (register_type (gdbarch, regnum)) == TYPE_CODE_FLT;
192 raw_p = regnum < gdbarch_num_regs (gdbarch);
193 if (group == float_reggroup)
195 if (group == vector_reggroup)
197 if (group == general_reggroup)
198 return (!vector_p && !float_p);
199 if (group == save_reggroup || group == restore_reggroup)
204 /* Dump out a table of register groups for the current architecture. */
207 reggroups_dump (struct gdbarch *gdbarch, struct ui_file *file)
209 struct reggroup *group = NULL;
220 name = reggroup_name (group);
221 fprintf_unfiltered (file, " %-10s", name);
232 switch (reggroup_type (group))
237 case INTERNAL_REGGROUP:
241 internal_error (__FILE__, __LINE__, _("bad switch"));
244 fprintf_unfiltered (file, " %-10s", type);
247 /* Note: If you change this, be sure to also update the
250 fprintf_unfiltered (file, "\n");
252 group = reggroup_next (gdbarch, group);
254 while (group != NULL);
258 maintenance_print_reggroups (const char *args, int from_tty)
260 struct gdbarch *gdbarch = get_current_arch ();
263 reggroups_dump (gdbarch, gdb_stdout);
268 if (!file.open (args, "w"))
269 perror_with_name (_("maintenance print reggroups"));
270 reggroups_dump (gdbarch, &file);
274 /* Pre-defined register groups. */
275 static struct reggroup general_group = { "general", USER_REGGROUP };
276 static struct reggroup float_group = { "float", USER_REGGROUP };
277 static struct reggroup system_group = { "system", USER_REGGROUP };
278 static struct reggroup vector_group = { "vector", USER_REGGROUP };
279 static struct reggroup all_group = { "all", USER_REGGROUP };
280 static struct reggroup save_group = { "save", INTERNAL_REGGROUP };
281 static struct reggroup restore_group = { "restore", INTERNAL_REGGROUP };
283 struct reggroup *const general_reggroup = &general_group;
284 struct reggroup *const float_reggroup = &float_group;
285 struct reggroup *const system_reggroup = &system_group;
286 struct reggroup *const vector_reggroup = &vector_group;
287 struct reggroup *const all_reggroup = &all_group;
288 struct reggroup *const save_reggroup = &save_group;
289 struct reggroup *const restore_reggroup = &restore_group;
292 _initialize_reggroup (void)
294 reggroups_data = gdbarch_data_register_pre_init (reggroups_init);
296 /* The pre-defined list of groups. */
297 add_group (&default_groups, general_reggroup, XNEW (struct reggroup_el));
298 add_group (&default_groups, float_reggroup, XNEW (struct reggroup_el));
299 add_group (&default_groups, system_reggroup, XNEW (struct reggroup_el));
300 add_group (&default_groups, vector_reggroup, XNEW (struct reggroup_el));
301 add_group (&default_groups, all_reggroup, XNEW (struct reggroup_el));
302 add_group (&default_groups, save_reggroup, XNEW (struct reggroup_el));
303 add_group (&default_groups, restore_reggroup, XNEW (struct reggroup_el));
305 add_cmd ("reggroups", class_maintenance,
306 maintenance_print_reggroups, _("\
307 Print the internal register group names.\n\
308 Takes an optional file parameter."),
309 &maintenanceprintlist);