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