1 /* Register groupings for GDB, the GNU debugger.
3 Copyright (C) 2002, 2003, 2007, 2008, 2009, 2010
4 Free Software Foundation, Inc.
6 Contributed by Red Hat.
8 This file is part of GDB.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>. */
24 #include "arch-utils.h"
25 #include "reggroups.h"
27 #include "gdb_assert.h"
30 #include "gdbcmd.h" /* For maintenanceprintlist. */
32 /* Individual register groups. */
37 enum reggroup_type type;
41 reggroup_new (const char *name, enum reggroup_type type)
43 struct reggroup *group = XMALLOC (struct reggroup);
50 /* Register group attributes. */
53 reggroup_name (struct reggroup *group)
59 reggroup_type (struct reggroup *group)
64 /* A linked list of groups for the given architecture. */
68 struct reggroup *group;
69 struct reggroup_el *next;
74 struct reggroup_el *first;
75 struct reggroup_el **last;
78 static struct gdbarch_data *reggroups_data;
81 reggroups_init (struct gdbarch *gdbarch)
83 struct reggroups *groups = GDBARCH_OBSTACK_ZALLOC (gdbarch,
86 groups->last = &groups->first;
90 /* Add a register group (with attribute values) to the pre-defined
94 add_group (struct reggroups *groups, struct reggroup *group,
95 struct reggroup_el *el)
97 gdb_assert (group != NULL);
100 (*groups->last) = el;
101 groups->last = &el->next;
105 reggroup_add (struct gdbarch *gdbarch, struct reggroup *group)
107 struct reggroups *groups = gdbarch_data (gdbarch, reggroups_data);
111 /* ULGH, called during architecture initialization. Patch
113 groups = reggroups_init (gdbarch);
114 deprecated_set_gdbarch_data (gdbarch, reggroups_data, groups);
116 add_group (groups, group,
117 GDBARCH_OBSTACK_ZALLOC (gdbarch, struct reggroup_el));
120 /* The default register groups for an architecture. */
122 static struct reggroups default_groups = { NULL, &default_groups.first };
124 /* A register group iterator. */
127 reggroup_next (struct gdbarch *gdbarch, struct reggroup *last)
129 struct reggroups *groups;
130 struct reggroup_el *el;
132 /* Don't allow this function to be called during architecture
133 creation. If there are no groups, use the default groups list. */
134 groups = gdbarch_data (gdbarch, reggroups_data);
135 gdb_assert (groups != NULL);
136 if (groups->first == NULL)
137 groups = &default_groups;
139 /* Return the first/next reggroup. */
141 return groups->first->group;
142 for (el = groups->first; el != NULL; el = el->next)
144 if (el->group == last)
146 if (el->next != NULL)
147 return el->next->group;
155 /* Is REGNUM a member of REGGROUP? */
157 default_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
158 struct reggroup *group)
164 if (gdbarch_register_name (gdbarch, regnum) == NULL
165 || *gdbarch_register_name (gdbarch, regnum) == '\0')
167 if (group == all_reggroup)
169 vector_p = TYPE_VECTOR (register_type (gdbarch, regnum));
170 float_p = TYPE_CODE (register_type (gdbarch, regnum)) == TYPE_CODE_FLT;
171 raw_p = regnum < gdbarch_num_regs (gdbarch);
172 if (group == float_reggroup)
174 if (group == vector_reggroup)
176 if (group == general_reggroup)
177 return (!vector_p && !float_p);
178 if (group == save_reggroup || group == restore_reggroup)
183 /* Dump out a table of register groups for the current architecture. */
186 reggroups_dump (struct gdbarch *gdbarch, struct ui_file *file)
188 struct reggroup *group = NULL;
199 name = reggroup_name (group);
200 fprintf_unfiltered (file, " %-10s", name);
211 switch (reggroup_type (group))
216 case INTERNAL_REGGROUP:
220 internal_error (__FILE__, __LINE__, _("bad switch"));
223 fprintf_unfiltered (file, " %-10s", type);
226 /* Note: If you change this, be sure to also update the
229 fprintf_unfiltered (file, "\n");
231 group = reggroup_next (gdbarch, group);
233 while (group != NULL);
237 maintenance_print_reggroups (char *args, int from_tty)
239 struct gdbarch *gdbarch = get_current_arch ();
242 reggroups_dump (gdbarch, gdb_stdout);
245 struct cleanup *cleanups;
246 struct ui_file *file = gdb_fopen (args, "w");
249 perror_with_name (_("maintenance print reggroups"));
250 cleanups = make_cleanup_ui_file_delete (file);
251 reggroups_dump (gdbarch, file);
252 do_cleanups (cleanups);
256 /* Pre-defined register groups. */
257 static struct reggroup general_group = { "general", USER_REGGROUP };
258 static struct reggroup float_group = { "float", USER_REGGROUP };
259 static struct reggroup system_group = { "system", USER_REGGROUP };
260 static struct reggroup vector_group = { "vector", USER_REGGROUP };
261 static struct reggroup all_group = { "all", USER_REGGROUP };
262 static struct reggroup save_group = { "save", INTERNAL_REGGROUP };
263 static struct reggroup restore_group = { "restore", INTERNAL_REGGROUP };
265 struct reggroup *const general_reggroup = &general_group;
266 struct reggroup *const float_reggroup = &float_group;
267 struct reggroup *const system_reggroup = &system_group;
268 struct reggroup *const vector_reggroup = &vector_group;
269 struct reggroup *const all_reggroup = &all_group;
270 struct reggroup *const save_reggroup = &save_group;
271 struct reggroup *const restore_reggroup = &restore_group;
273 extern initialize_file_ftype _initialize_reggroup; /* -Wmissing-prototypes */
276 _initialize_reggroup (void)
278 reggroups_data = gdbarch_data_register_post_init (reggroups_init);
280 /* The pre-defined list of groups. */
281 add_group (&default_groups, general_reggroup, XMALLOC (struct reggroup_el));
282 add_group (&default_groups, float_reggroup, XMALLOC (struct reggroup_el));
283 add_group (&default_groups, system_reggroup, XMALLOC (struct reggroup_el));
284 add_group (&default_groups, vector_reggroup, XMALLOC (struct reggroup_el));
285 add_group (&default_groups, all_reggroup, XMALLOC (struct reggroup_el));
286 add_group (&default_groups, save_reggroup, XMALLOC (struct reggroup_el));
287 add_group (&default_groups, restore_reggroup, XMALLOC (struct reggroup_el));
289 add_cmd ("reggroups", class_maintenance,
290 maintenance_print_reggroups, _("\
291 Print the internal register group names.\n\
292 Takes an optional file parameter."),
293 &maintenanceprintlist);