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. */
30 /* Individual register groups. */
35 enum reggroup_type type;
39 reggroup_new (const char *name, enum reggroup_type type)
41 struct reggroup *group = XNEW (struct reggroup);
48 /* Register group attributes. */
51 reggroup_name (struct reggroup *group)
57 reggroup_type (struct reggroup *group)
62 /* A linked list of groups for the given architecture. */
66 struct reggroup *group;
67 struct reggroup_el *next;
72 struct reggroup_el *first;
73 struct reggroup_el **last;
76 static struct gdbarch_data *reggroups_data;
79 reggroups_init (struct gdbarch *gdbarch)
81 struct reggroups *groups = GDBARCH_OBSTACK_ZALLOC (gdbarch,
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);
110 /* ULGH, called during architecture initialization. Patch
112 groups = (struct reggroups *) reggroups_init (gdbarch);
113 deprecated_set_gdbarch_data (gdbarch, reggroups_data, groups);
115 add_group (groups, group,
116 GDBARCH_OBSTACK_ZALLOC (gdbarch, struct reggroup_el));
119 /* The default register groups for an architecture. */
121 static struct reggroups default_groups = { NULL, &default_groups.first };
123 /* A register group iterator. */
126 reggroup_next (struct gdbarch *gdbarch, struct reggroup *last)
128 struct reggroups *groups;
129 struct reggroup_el *el;
131 /* Don't allow this function to be called during architecture
132 creation. If there are no groups, use the default groups list. */
133 groups = (struct reggroups *) gdbarch_data (gdbarch, reggroups_data);
134 gdb_assert (groups != NULL);
135 if (groups->first == NULL)
136 groups = &default_groups;
138 /* Return the first/next reggroup. */
140 return groups->first->group;
141 for (el = groups->first; el != NULL; el = el->next)
143 if (el->group == last)
145 if (el->next != NULL)
146 return el->next->group;
154 /* See reggroups.h. */
157 reggroup_prev (struct gdbarch *gdbarch, struct reggroup *curr)
159 struct reggroups *groups;
160 struct reggroup_el *el;
161 struct reggroup *prev;
163 /* Don't allow this function to be called during architecture
164 creation. If there are no groups, use the default groups list. */
165 groups = (struct reggroups *) gdbarch_data (gdbarch, reggroups_data);
166 gdb_assert (groups != NULL);
167 if (groups->first == NULL)
168 groups = &default_groups;
171 for (el = groups->first; el != NULL; el = el->next)
173 gdb_assert (el->group != NULL);
174 if (el->group == curr)
183 /* Is REGNUM a member of REGGROUP? */
185 default_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
186 struct reggroup *group)
192 if (gdbarch_register_name (gdbarch, regnum) == NULL
193 || *gdbarch_register_name (gdbarch, regnum) == '\0')
195 if (group == all_reggroup)
197 vector_p = TYPE_VECTOR (register_type (gdbarch, regnum));
198 float_p = TYPE_CODE (register_type (gdbarch, regnum)) == TYPE_CODE_FLT;
199 raw_p = regnum < gdbarch_num_regs (gdbarch);
200 if (group == float_reggroup)
202 if (group == vector_reggroup)
204 if (group == general_reggroup)
205 return (!vector_p && !float_p);
206 if (group == save_reggroup || group == restore_reggroup)
211 /* Dump out a table of register groups for the current architecture. */
214 reggroups_dump (struct gdbarch *gdbarch, struct ui_file *file)
216 struct reggroup *group = NULL;
227 name = reggroup_name (group);
228 fprintf_unfiltered (file, " %-10s", name);
239 switch (reggroup_type (group))
244 case INTERNAL_REGGROUP:
248 internal_error (__FILE__, __LINE__, _("bad switch"));
251 fprintf_unfiltered (file, " %-10s", type);
254 /* Note: If you change this, be sure to also update the
257 fprintf_unfiltered (file, "\n");
259 group = reggroup_next (gdbarch, group);
261 while (group != NULL);
265 maintenance_print_reggroups (char *args, int from_tty)
267 struct gdbarch *gdbarch = get_current_arch ();
270 reggroups_dump (gdbarch, gdb_stdout);
275 if (!file.open (args, "w"))
276 perror_with_name (_("maintenance print reggroups"));
277 reggroups_dump (gdbarch, &file);
281 /* Pre-defined register groups. */
282 static struct reggroup general_group = { "general", USER_REGGROUP };
283 static struct reggroup float_group = { "float", USER_REGGROUP };
284 static struct reggroup system_group = { "system", USER_REGGROUP };
285 static struct reggroup vector_group = { "vector", USER_REGGROUP };
286 static struct reggroup all_group = { "all", USER_REGGROUP };
287 static struct reggroup save_group = { "save", INTERNAL_REGGROUP };
288 static struct reggroup restore_group = { "restore", INTERNAL_REGGROUP };
290 struct reggroup *const general_reggroup = &general_group;
291 struct reggroup *const float_reggroup = &float_group;
292 struct reggroup *const system_reggroup = &system_group;
293 struct reggroup *const vector_reggroup = &vector_group;
294 struct reggroup *const all_reggroup = &all_group;
295 struct reggroup *const save_reggroup = &save_group;
296 struct reggroup *const restore_reggroup = &restore_group;
298 extern initialize_file_ftype _initialize_reggroup; /* -Wmissing-prototypes */
301 _initialize_reggroup (void)
303 reggroups_data = gdbarch_data_register_post_init (reggroups_init);
305 /* The pre-defined list of groups. */
306 add_group (&default_groups, general_reggroup, XNEW (struct reggroup_el));
307 add_group (&default_groups, float_reggroup, XNEW (struct reggroup_el));
308 add_group (&default_groups, system_reggroup, XNEW (struct reggroup_el));
309 add_group (&default_groups, vector_reggroup, XNEW (struct reggroup_el));
310 add_group (&default_groups, all_reggroup, XNEW (struct reggroup_el));
311 add_group (&default_groups, save_reggroup, XNEW (struct reggroup_el));
312 add_group (&default_groups, restore_reggroup, XNEW (struct reggroup_el));
314 add_cmd ("reggroups", class_maintenance,
315 maintenance_print_reggroups, _("\
316 Print the internal register group names.\n\
317 Takes an optional file parameter."),
318 &maintenanceprintlist);