*** empty log message ***
[deliverable/binutils-gdb.git] / gdb / reggroups.c
CommitLineData
b59ff9d5
AC
1/* Register groupings for GDB, the GNU debugger.
2
4c38e0a4
JB
3 Copyright (C) 2002, 2003, 2007, 2008, 2009, 2010
4 Free Software Foundation, Inc.
b59ff9d5
AC
5
6 Contributed by Red Hat.
7
8 This file is part of GDB.
9
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
a9762ec7 12 the Free Software Foundation; either version 3 of the License, or
b59ff9d5
AC
13 (at your option) any later version.
14
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.
19
20 You should have received a copy of the GNU General Public License
a9762ec7 21 along with this program. If not, see <http://www.gnu.org/licenses/>. */
b59ff9d5
AC
22
23#include "defs.h"
e17c207e 24#include "arch-utils.h"
b59ff9d5
AC
25#include "reggroups.h"
26#include "gdbtypes.h"
27#include "gdb_assert.h"
28#include "regcache.h"
29#include "command.h"
30#include "gdbcmd.h" /* For maintenanceprintlist. */
31
32/* Individual register groups. */
33
34struct reggroup
35{
36 const char *name;
37 enum reggroup_type type;
38};
39
40struct reggroup *
41reggroup_new (const char *name, enum reggroup_type type)
42{
43 struct reggroup *group = XMALLOC (struct reggroup);
123f5f96 44
b59ff9d5
AC
45 group->name = name;
46 group->type = type;
47 return group;
48}
49
50/* Register group attributes. */
51
52const char *
53reggroup_name (struct reggroup *group)
54{
55 return group->name;
56}
57
58enum reggroup_type
59reggroup_type (struct reggroup *group)
60{
61 return group->type;
62}
63
6c7d17ba
AC
64/* A linked list of groups for the given architecture. */
65
66struct reggroup_el
67{
68 struct reggroup *group;
69 struct reggroup_el *next;
70};
b59ff9d5
AC
71
72struct reggroups
73{
6c7d17ba
AC
74 struct reggroup_el *first;
75 struct reggroup_el **last;
b59ff9d5
AC
76};
77
78static struct gdbarch_data *reggroups_data;
79
80static void *
81reggroups_init (struct gdbarch *gdbarch)
82{
6c7d17ba
AC
83 struct reggroups *groups = GDBARCH_OBSTACK_ZALLOC (gdbarch,
84 struct reggroups);
123f5f96 85
6c7d17ba 86 groups->last = &groups->first;
b59ff9d5
AC
87 return groups;
88}
89
b59ff9d5 90/* Add a register group (with attribute values) to the pre-defined
6c7d17ba 91 list. */
b59ff9d5
AC
92
93static void
6c7d17ba
AC
94add_group (struct reggroups *groups, struct reggroup *group,
95 struct reggroup_el *el)
b59ff9d5
AC
96{
97 gdb_assert (group != NULL);
6c7d17ba
AC
98 el->group = group;
99 el->next = NULL;
100 (*groups->last) = el;
101 groups->last = &el->next;
b59ff9d5
AC
102}
103
104void
105reggroup_add (struct gdbarch *gdbarch, struct reggroup *group)
106{
107 struct reggroups *groups = gdbarch_data (gdbarch, reggroups_data);
7e6d0ac8 108
b59ff9d5
AC
109 if (groups == NULL)
110 {
111 /* ULGH, called during architecture initialization. Patch
112 things up. */
113 groups = reggroups_init (gdbarch);
030f20e1 114 deprecated_set_gdbarch_data (gdbarch, reggroups_data, groups);
b59ff9d5 115 }
6c7d17ba
AC
116 add_group (groups, group,
117 GDBARCH_OBSTACK_ZALLOC (gdbarch, struct reggroup_el));
b59ff9d5
AC
118}
119
6c7d17ba
AC
120/* The default register groups for an architecture. */
121
122static struct reggroups default_groups = { NULL, &default_groups.first };
b59ff9d5 123
6c7d17ba 124/* A register group iterator. */
b59ff9d5 125
6c7d17ba
AC
126struct reggroup *
127reggroup_next (struct gdbarch *gdbarch, struct reggroup *last)
b59ff9d5 128{
6c7d17ba
AC
129 struct reggroups *groups;
130 struct reggroup_el *el;
7e6d0ac8 131
b59ff9d5 132 /* Don't allow this function to be called during architecture
6c7d17ba
AC
133 creation. If there are no groups, use the default groups list. */
134 groups = gdbarch_data (gdbarch, reggroups_data);
b59ff9d5 135 gdb_assert (groups != NULL);
6c7d17ba
AC
136 if (groups->first == NULL)
137 groups = &default_groups;
138
9dd5f34f 139 /* Return the first/next reggroup. */
6c7d17ba
AC
140 if (last == NULL)
141 return groups->first->group;
142 for (el = groups->first; el != NULL; el = el->next)
143 {
144 if (el->group == last)
9dd5f34f
AC
145 {
146 if (el->next != NULL)
147 return el->next->group;
148 else
149 return NULL;
150 }
6c7d17ba
AC
151 }
152 return NULL;
b59ff9d5
AC
153}
154
155/* Is REGNUM a member of REGGROUP? */
156int
157default_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
158 struct reggroup *group)
159{
160 int vector_p;
161 int float_p;
162 int raw_p;
7e6d0ac8 163
6bcde365
UW
164 if (gdbarch_register_name (gdbarch, regnum) == NULL
165 || *gdbarch_register_name (gdbarch, regnum) == '\0')
b59ff9d5
AC
166 return 0;
167 if (group == all_reggroup)
168 return 1;
169 vector_p = TYPE_VECTOR (register_type (gdbarch, regnum));
170 float_p = TYPE_CODE (register_type (gdbarch, regnum)) == TYPE_CODE_FLT;
6bcde365 171 raw_p = regnum < gdbarch_num_regs (gdbarch);
b59ff9d5
AC
172 if (group == float_reggroup)
173 return float_p;
174 if (group == vector_reggroup)
175 return vector_p;
176 if (group == general_reggroup)
177 return (!vector_p && !float_p);
178 if (group == save_reggroup || group == restore_reggroup)
179 return raw_p;
180 return 0;
181}
182
183/* Dump out a table of register groups for the current architecture. */
184
185static void
186reggroups_dump (struct gdbarch *gdbarch, struct ui_file *file)
187{
6c7d17ba 188 struct reggroup *group = NULL;
7e6d0ac8 189
b59ff9d5
AC
190 do
191 {
192 /* Group name. */
193 {
194 const char *name;
123f5f96 195
6c7d17ba 196 if (group == NULL)
b59ff9d5
AC
197 name = "Group";
198 else
6c7d17ba 199 name = reggroup_name (group);
b59ff9d5
AC
200 fprintf_unfiltered (file, " %-10s", name);
201 }
202
203 /* Group type. */
204 {
205 const char *type;
123f5f96 206
6c7d17ba 207 if (group == NULL)
b59ff9d5
AC
208 type = "Type";
209 else
210 {
6c7d17ba 211 switch (reggroup_type (group))
b59ff9d5
AC
212 {
213 case USER_REGGROUP:
214 type = "user";
215 break;
216 case INTERNAL_REGGROUP:
217 type = "internal";
218 break;
219 default:
e2e0b3e5 220 internal_error (__FILE__, __LINE__, _("bad switch"));
b59ff9d5
AC
221 }
222 }
223 fprintf_unfiltered (file, " %-10s", type);
224 }
225
226 /* Note: If you change this, be sure to also update the
227 documentation. */
228
229 fprintf_unfiltered (file, "\n");
6c7d17ba
AC
230
231 group = reggroup_next (gdbarch, group);
b59ff9d5 232 }
6c7d17ba 233 while (group != NULL);
b59ff9d5
AC
234}
235
236static void
237maintenance_print_reggroups (char *args, int from_tty)
238{
e17c207e
UW
239 struct gdbarch *gdbarch = get_current_arch ();
240
b59ff9d5 241 if (args == NULL)
e17c207e 242 reggroups_dump (gdbarch, gdb_stdout);
b59ff9d5
AC
243 else
244 {
724b958c 245 struct cleanup *cleanups;
b59ff9d5 246 struct ui_file *file = gdb_fopen (args, "w");
123f5f96 247
b59ff9d5 248 if (file == NULL)
e2e0b3e5 249 perror_with_name (_("maintenance print reggroups"));
724b958c 250 cleanups = make_cleanup_ui_file_delete (file);
e17c207e 251 reggroups_dump (gdbarch, file);
724b958c 252 do_cleanups (cleanups);
b59ff9d5
AC
253 }
254}
255
256/* Pre-defined register groups. */
257static struct reggroup general_group = { "general", USER_REGGROUP };
258static struct reggroup float_group = { "float", USER_REGGROUP };
259static struct reggroup system_group = { "system", USER_REGGROUP };
260static struct reggroup vector_group = { "vector", USER_REGGROUP };
261static struct reggroup all_group = { "all", USER_REGGROUP };
262static struct reggroup save_group = { "save", INTERNAL_REGGROUP };
263static struct reggroup restore_group = { "restore", INTERNAL_REGGROUP };
264
265struct reggroup *const general_reggroup = &general_group;
266struct reggroup *const float_reggroup = &float_group;
267struct reggroup *const system_reggroup = &system_group;
268struct reggroup *const vector_reggroup = &vector_group;
269struct reggroup *const all_reggroup = &all_group;
270struct reggroup *const save_reggroup = &save_group;
271struct reggroup *const restore_reggroup = &restore_group;
272
b9362cc7
AC
273extern initialize_file_ftype _initialize_reggroup; /* -Wmissing-prototypes */
274
b59ff9d5
AC
275void
276_initialize_reggroup (void)
277{
030f20e1 278 reggroups_data = gdbarch_data_register_post_init (reggroups_init);
b59ff9d5
AC
279
280 /* The pre-defined list of groups. */
6c7d17ba
AC
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));
b59ff9d5
AC
288
289 add_cmd ("reggroups", class_maintenance,
1a966eab 290 maintenance_print_reggroups, _("\
b59ff9d5 291Print the internal register group names.\n\
1a966eab 292Takes an optional file parameter."),
b59ff9d5
AC
293 &maintenanceprintlist);
294
295}
This page took 0.786125 seconds and 4 git commands to generate.