morse(6): correct email for original author
[dragonfly.git] / contrib / gdb-7 / gdb / reggroups.c
blob28cde21f5093c7807d77bf22854bb110fd9bb222
1 /* Register groupings for GDB, the GNU debugger.
3 Copyright (C) 2002-2013 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/>. */
22 #include "defs.h"
23 #include "arch-utils.h"
24 #include "reggroups.h"
25 #include "gdbtypes.h"
26 #include "gdb_assert.h"
27 #include "regcache.h"
28 #include "command.h"
29 #include "gdbcmd.h" /* For maintenanceprintlist. */
31 /* Individual register groups. */
33 struct reggroup
35 const char *name;
36 enum reggroup_type type;
39 struct reggroup *
40 reggroup_new (const char *name, enum reggroup_type type)
42 struct reggroup *group = XMALLOC (struct reggroup);
44 group->name = name;
45 group->type = type;
46 return group;
49 /* Register group attributes. */
51 const char *
52 reggroup_name (struct reggroup *group)
54 return group->name;
57 enum reggroup_type
58 reggroup_type (struct reggroup *group)
60 return group->type;
63 /* A linked list of groups for the given architecture. */
65 struct reggroup_el
67 struct reggroup *group;
68 struct reggroup_el *next;
71 struct reggroups
73 struct reggroup_el *first;
74 struct reggroup_el **last;
77 static struct gdbarch_data *reggroups_data;
79 static void *
80 reggroups_init (struct gdbarch *gdbarch)
82 struct reggroups *groups = GDBARCH_OBSTACK_ZALLOC (gdbarch,
83 struct reggroups);
85 groups->last = &groups->first;
86 return groups;
89 /* Add a register group (with attribute values) to the pre-defined
90 list. */
92 static void
93 add_group (struct reggroups *groups, struct reggroup *group,
94 struct reggroup_el *el)
96 gdb_assert (group != NULL);
97 el->group = group;
98 el->next = NULL;
99 (*groups->last) = el;
100 groups->last = &el->next;
103 void
104 reggroup_add (struct gdbarch *gdbarch, struct reggroup *group)
106 struct reggroups *groups = gdbarch_data (gdbarch, reggroups_data);
108 if (groups == NULL)
110 /* ULGH, called during architecture initialization. Patch
111 things up. */
112 groups = 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. */
125 struct reggroup *
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 = 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. */
139 if (last == NULL)
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;
147 else
148 return NULL;
151 return NULL;
154 /* Is REGNUM a member of REGGROUP? */
156 default_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
157 struct reggroup *group)
159 int vector_p;
160 int float_p;
161 int raw_p;
163 if (gdbarch_register_name (gdbarch, regnum) == NULL
164 || *gdbarch_register_name (gdbarch, regnum) == '\0')
165 return 0;
166 if (group == all_reggroup)
167 return 1;
168 vector_p = TYPE_VECTOR (register_type (gdbarch, regnum));
169 float_p = TYPE_CODE (register_type (gdbarch, regnum)) == TYPE_CODE_FLT;
170 raw_p = regnum < gdbarch_num_regs (gdbarch);
171 if (group == float_reggroup)
172 return float_p;
173 if (group == vector_reggroup)
174 return vector_p;
175 if (group == general_reggroup)
176 return (!vector_p && !float_p);
177 if (group == save_reggroup || group == restore_reggroup)
178 return raw_p;
179 return 0;
182 /* Dump out a table of register groups for the current architecture. */
184 static void
185 reggroups_dump (struct gdbarch *gdbarch, struct ui_file *file)
187 struct reggroup *group = NULL;
191 /* Group name. */
193 const char *name;
195 if (group == NULL)
196 name = "Group";
197 else
198 name = reggroup_name (group);
199 fprintf_unfiltered (file, " %-10s", name);
202 /* Group type. */
204 const char *type;
206 if (group == NULL)
207 type = "Type";
208 else
210 switch (reggroup_type (group))
212 case USER_REGGROUP:
213 type = "user";
214 break;
215 case INTERNAL_REGGROUP:
216 type = "internal";
217 break;
218 default:
219 internal_error (__FILE__, __LINE__, _("bad switch"));
222 fprintf_unfiltered (file, " %-10s", type);
225 /* Note: If you change this, be sure to also update the
226 documentation. */
228 fprintf_unfiltered (file, "\n");
230 group = reggroup_next (gdbarch, group);
232 while (group != NULL);
235 static void
236 maintenance_print_reggroups (char *args, int from_tty)
238 struct gdbarch *gdbarch = get_current_arch ();
240 if (args == NULL)
241 reggroups_dump (gdbarch, gdb_stdout);
242 else
244 struct cleanup *cleanups;
245 struct ui_file *file = gdb_fopen (args, "w");
247 if (file == NULL)
248 perror_with_name (_("maintenance print reggroups"));
249 cleanups = make_cleanup_ui_file_delete (file);
250 reggroups_dump (gdbarch, file);
251 do_cleanups (cleanups);
255 /* Pre-defined register groups. */
256 static struct reggroup general_group = { "general", USER_REGGROUP };
257 static struct reggroup float_group = { "float", USER_REGGROUP };
258 static struct reggroup system_group = { "system", USER_REGGROUP };
259 static struct reggroup vector_group = { "vector", USER_REGGROUP };
260 static struct reggroup all_group = { "all", USER_REGGROUP };
261 static struct reggroup save_group = { "save", INTERNAL_REGGROUP };
262 static struct reggroup restore_group = { "restore", INTERNAL_REGGROUP };
264 struct reggroup *const general_reggroup = &general_group;
265 struct reggroup *const float_reggroup = &float_group;
266 struct reggroup *const system_reggroup = &system_group;
267 struct reggroup *const vector_reggroup = &vector_group;
268 struct reggroup *const all_reggroup = &all_group;
269 struct reggroup *const save_reggroup = &save_group;
270 struct reggroup *const restore_reggroup = &restore_group;
272 extern initialize_file_ftype _initialize_reggroup; /* -Wmissing-prototypes */
274 void
275 _initialize_reggroup (void)
277 reggroups_data = gdbarch_data_register_post_init (reggroups_init);
279 /* The pre-defined list of groups. */
280 add_group (&default_groups, general_reggroup, XMALLOC (struct reggroup_el));
281 add_group (&default_groups, float_reggroup, XMALLOC (struct reggroup_el));
282 add_group (&default_groups, system_reggroup, XMALLOC (struct reggroup_el));
283 add_group (&default_groups, vector_reggroup, XMALLOC (struct reggroup_el));
284 add_group (&default_groups, all_reggroup, XMALLOC (struct reggroup_el));
285 add_group (&default_groups, save_reggroup, XMALLOC (struct reggroup_el));
286 add_group (&default_groups, restore_reggroup, XMALLOC (struct reggroup_el));
288 add_cmd ("reggroups", class_maintenance,
289 maintenance_print_reggroups, _("\
290 Print the internal register group names.\n\
291 Takes an optional file parameter."),
292 &maintenanceprintlist);