]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/reggroups.c
2005-02-14 Andrew Cagney <cagney@gnu.org>
[thirdparty/binutils-gdb.git] / gdb / reggroups.c
CommitLineData
b59ff9d5
AC
1/* Register groupings for GDB, the GNU debugger.
2
7e6d0ac8 3 Copyright 2002, 2003 Free Software Foundation, Inc.
b59ff9d5
AC
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);
7e6d0ac8 106
b59ff9d5
AC
107 if (groups == NULL)
108 {
109 /* ULGH, called during architecture initialization. Patch
110 things up. */
111 groups = reggroups_init (gdbarch);
030f20e1 112 deprecated_set_gdbarch_data (gdbarch, reggroups_data, groups);
b59ff9d5 113 }
6c7d17ba
AC
114 add_group (groups, group,
115 GDBARCH_OBSTACK_ZALLOC (gdbarch, struct reggroup_el));
b59ff9d5
AC
116}
117
6c7d17ba
AC
118/* The default register groups for an architecture. */
119
120static struct reggroups default_groups = { NULL, &default_groups.first };
b59ff9d5 121
6c7d17ba 122/* A register group iterator. */
b59ff9d5 123
6c7d17ba
AC
124struct reggroup *
125reggroup_next (struct gdbarch *gdbarch, struct reggroup *last)
b59ff9d5 126{
6c7d17ba
AC
127 struct reggroups *groups;
128 struct reggroup_el *el;
7e6d0ac8 129
b59ff9d5 130 /* Don't allow this function to be called during architecture
6c7d17ba
AC
131 creation. If there are no groups, use the default groups list. */
132 groups = gdbarch_data (gdbarch, reggroups_data);
b59ff9d5 133 gdb_assert (groups != NULL);
6c7d17ba
AC
134 if (groups->first == NULL)
135 groups = &default_groups;
136
9dd5f34f 137 /* Return the first/next reggroup. */
6c7d17ba
AC
138 if (last == NULL)
139 return groups->first->group;
140 for (el = groups->first; el != NULL; el = el->next)
141 {
142 if (el->group == last)
9dd5f34f
AC
143 {
144 if (el->next != NULL)
145 return el->next->group;
146 else
147 return NULL;
148 }
6c7d17ba
AC
149 }
150 return NULL;
b59ff9d5
AC
151}
152
153/* Is REGNUM a member of REGGROUP? */
154int
155default_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
156 struct reggroup *group)
157{
158 int vector_p;
159 int float_p;
160 int raw_p;
7e6d0ac8 161
b59ff9d5
AC
162 if (REGISTER_NAME (regnum) == NULL
163 || *REGISTER_NAME (regnum) == '\0')
164 return 0;
165 if (group == all_reggroup)
166 return 1;
167 vector_p = TYPE_VECTOR (register_type (gdbarch, regnum));
168 float_p = TYPE_CODE (register_type (gdbarch, regnum)) == TYPE_CODE_FLT;
9b5e151c
AC
169 /* FIXME: cagney/2003-04-13: Can't yet use gdbarch_num_regs
170 (gdbarch), as not all architectures are multi-arch. */
171 raw_p = regnum < NUM_REGS;
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;
6c7d17ba 195 if (group == NULL)
b59ff9d5
AC
196 name = "Group";
197 else
6c7d17ba 198 name = reggroup_name (group);
b59ff9d5
AC
199 fprintf_unfiltered (file, " %-10s", name);
200 }
201
202 /* Group type. */
203 {
204 const char *type;
6c7d17ba 205 if (group == NULL)
b59ff9d5
AC
206 type = "Type";
207 else
208 {
6c7d17ba 209 switch (reggroup_type (group))
b59ff9d5
AC
210 {
211 case USER_REGGROUP:
212 type = "user";
213 break;
214 case INTERNAL_REGGROUP:
215 type = "internal";
216 break;
217 default:
e2e0b3e5 218 internal_error (__FILE__, __LINE__, _("bad switch"));
b59ff9d5
AC
219 }
220 }
221 fprintf_unfiltered (file, " %-10s", type);
222 }
223
224 /* Note: If you change this, be sure to also update the
225 documentation. */
226
227 fprintf_unfiltered (file, "\n");
6c7d17ba
AC
228
229 group = reggroup_next (gdbarch, group);
b59ff9d5 230 }
6c7d17ba 231 while (group != NULL);
b59ff9d5
AC
232}
233
234static void
235maintenance_print_reggroups (char *args, int from_tty)
236{
237 if (args == NULL)
238 reggroups_dump (current_gdbarch, gdb_stdout);
239 else
240 {
241 struct ui_file *file = gdb_fopen (args, "w");
242 if (file == NULL)
e2e0b3e5 243 perror_with_name (_("maintenance print reggroups"));
b59ff9d5
AC
244 reggroups_dump (current_gdbarch, file);
245 ui_file_delete (file);
246 }
247}
248
249/* Pre-defined register groups. */
250static struct reggroup general_group = { "general", USER_REGGROUP };
251static struct reggroup float_group = { "float", USER_REGGROUP };
252static struct reggroup system_group = { "system", USER_REGGROUP };
253static struct reggroup vector_group = { "vector", USER_REGGROUP };
254static struct reggroup all_group = { "all", USER_REGGROUP };
255static struct reggroup save_group = { "save", INTERNAL_REGGROUP };
256static struct reggroup restore_group = { "restore", INTERNAL_REGGROUP };
257
258struct reggroup *const general_reggroup = &general_group;
259struct reggroup *const float_reggroup = &float_group;
260struct reggroup *const system_reggroup = &system_group;
261struct reggroup *const vector_reggroup = &vector_group;
262struct reggroup *const all_reggroup = &all_group;
263struct reggroup *const save_reggroup = &save_group;
264struct reggroup *const restore_reggroup = &restore_group;
265
b9362cc7
AC
266extern initialize_file_ftype _initialize_reggroup; /* -Wmissing-prototypes */
267
b59ff9d5
AC
268void
269_initialize_reggroup (void)
270{
030f20e1 271 reggroups_data = gdbarch_data_register_post_init (reggroups_init);
b59ff9d5
AC
272
273 /* The pre-defined list of groups. */
6c7d17ba
AC
274 add_group (&default_groups, general_reggroup, XMALLOC (struct reggroup_el));
275 add_group (&default_groups, float_reggroup, XMALLOC (struct reggroup_el));
276 add_group (&default_groups, system_reggroup, XMALLOC (struct reggroup_el));
277 add_group (&default_groups, vector_reggroup, XMALLOC (struct reggroup_el));
278 add_group (&default_groups, all_reggroup, XMALLOC (struct reggroup_el));
279 add_group (&default_groups, save_reggroup, XMALLOC (struct reggroup_el));
280 add_group (&default_groups, restore_reggroup, XMALLOC (struct reggroup_el));
b59ff9d5
AC
281
282 add_cmd ("reggroups", class_maintenance,
283 maintenance_print_reggroups, "\
284Print the internal register group names.\n\
285Takes an optional file parameter.",
286 &maintenanceprintlist);
287
288}