]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/reggroups.c
2007-10-22 Markus Deuling <deuling@de.ibm.com>
[thirdparty/binutils-gdb.git] / gdb / reggroups.c
CommitLineData
b59ff9d5
AC
1/* Register groupings for GDB, the GNU debugger.
2
6aba47ca 3 Copyright (C) 2002, 2003, 2007 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
a9762ec7 11 the Free Software Foundation; either version 3 of the License, or
b59ff9d5
AC
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
a9762ec7 20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
b59ff9d5
AC
21
22#include "defs.h"
23#include "reggroups.h"
24#include "gdbtypes.h"
25#include "gdb_assert.h"
26#include "regcache.h"
27#include "command.h"
28#include "gdbcmd.h" /* For maintenanceprintlist. */
29
30/* Individual register groups. */
31
32struct reggroup
33{
34 const char *name;
35 enum reggroup_type type;
36};
37
38struct reggroup *
39reggroup_new (const char *name, enum reggroup_type type)
40{
41 struct reggroup *group = XMALLOC (struct reggroup);
42 group->name = name;
43 group->type = type;
44 return group;
45}
46
47/* Register group attributes. */
48
49const char *
50reggroup_name (struct reggroup *group)
51{
52 return group->name;
53}
54
55enum reggroup_type
56reggroup_type (struct reggroup *group)
57{
58 return group->type;
59}
60
6c7d17ba
AC
61/* A linked list of groups for the given architecture. */
62
63struct reggroup_el
64{
65 struct reggroup *group;
66 struct reggroup_el *next;
67};
b59ff9d5
AC
68
69struct reggroups
70{
6c7d17ba
AC
71 struct reggroup_el *first;
72 struct reggroup_el **last;
b59ff9d5
AC
73};
74
75static struct gdbarch_data *reggroups_data;
76
77static void *
78reggroups_init (struct gdbarch *gdbarch)
79{
6c7d17ba
AC
80 struct reggroups *groups = GDBARCH_OBSTACK_ZALLOC (gdbarch,
81 struct reggroups);
82 groups->last = &groups->first;
b59ff9d5
AC
83 return groups;
84}
85
b59ff9d5 86/* Add a register group (with attribute values) to the pre-defined
6c7d17ba 87 list. */
b59ff9d5
AC
88
89static void
6c7d17ba
AC
90add_group (struct reggroups *groups, struct reggroup *group,
91 struct reggroup_el *el)
b59ff9d5
AC
92{
93 gdb_assert (group != NULL);
6c7d17ba
AC
94 el->group = group;
95 el->next = NULL;
96 (*groups->last) = el;
97 groups->last = &el->next;
b59ff9d5
AC
98}
99
100void
101reggroup_add (struct gdbarch *gdbarch, struct reggroup *group)
102{
103 struct reggroups *groups = gdbarch_data (gdbarch, reggroups_data);
7e6d0ac8 104
b59ff9d5
AC
105 if (groups == NULL)
106 {
107 /* ULGH, called during architecture initialization. Patch
108 things up. */
109 groups = reggroups_init (gdbarch);
030f20e1 110 deprecated_set_gdbarch_data (gdbarch, reggroups_data, groups);
b59ff9d5 111 }
6c7d17ba
AC
112 add_group (groups, group,
113 GDBARCH_OBSTACK_ZALLOC (gdbarch, struct reggroup_el));
b59ff9d5
AC
114}
115
6c7d17ba
AC
116/* The default register groups for an architecture. */
117
118static struct reggroups default_groups = { NULL, &default_groups.first };
b59ff9d5 119
6c7d17ba 120/* A register group iterator. */
b59ff9d5 121
6c7d17ba
AC
122struct reggroup *
123reggroup_next (struct gdbarch *gdbarch, struct reggroup *last)
b59ff9d5 124{
6c7d17ba
AC
125 struct reggroups *groups;
126 struct reggroup_el *el;
7e6d0ac8 127
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;
7e6d0ac8 159
c9f4d572
UW
160 if (gdbarch_register_name (current_gdbarch, regnum) == NULL
161 || *gdbarch_register_name (current_gdbarch, regnum) == '\0')
b59ff9d5
AC
162 return 0;
163 if (group == all_reggroup)
164 return 1;
165 vector_p = TYPE_VECTOR (register_type (gdbarch, regnum));
166 float_p = TYPE_CODE (register_type (gdbarch, regnum)) == TYPE_CODE_FLT;
9b5e151c
AC
167 /* FIXME: cagney/2003-04-13: Can't yet use gdbarch_num_regs
168 (gdbarch), as not all architectures are multi-arch. */
f57d151a 169 raw_p = regnum < gdbarch_num_regs (current_gdbarch);
b59ff9d5
AC
170 if (group == float_reggroup)
171 return float_p;
172 if (group == vector_reggroup)
173 return vector_p;
174 if (group == general_reggroup)
175 return (!vector_p && !float_p);
176 if (group == save_reggroup || group == restore_reggroup)
177 return raw_p;
178 return 0;
179}
180
181/* Dump out a table of register groups for the current architecture. */
182
183static void
184reggroups_dump (struct gdbarch *gdbarch, struct ui_file *file)
185{
6c7d17ba 186 struct reggroup *group = NULL;
7e6d0ac8 187
b59ff9d5
AC
188 do
189 {
190 /* Group name. */
191 {
192 const char *name;
6c7d17ba 193 if (group == NULL)
b59ff9d5
AC
194 name = "Group";
195 else
6c7d17ba 196 name = reggroup_name (group);
b59ff9d5
AC
197 fprintf_unfiltered (file, " %-10s", name);
198 }
199
200 /* Group type. */
201 {
202 const char *type;
6c7d17ba 203 if (group == NULL)
b59ff9d5
AC
204 type = "Type";
205 else
206 {
6c7d17ba 207 switch (reggroup_type (group))
b59ff9d5
AC
208 {
209 case USER_REGGROUP:
210 type = "user";
211 break;
212 case INTERNAL_REGGROUP:
213 type = "internal";
214 break;
215 default:
e2e0b3e5 216 internal_error (__FILE__, __LINE__, _("bad switch"));
b59ff9d5
AC
217 }
218 }
219 fprintf_unfiltered (file, " %-10s", type);
220 }
221
222 /* Note: If you change this, be sure to also update the
223 documentation. */
224
225 fprintf_unfiltered (file, "\n");
6c7d17ba
AC
226
227 group = reggroup_next (gdbarch, group);
b59ff9d5 228 }
6c7d17ba 229 while (group != NULL);
b59ff9d5
AC
230}
231
232static void
233maintenance_print_reggroups (char *args, int from_tty)
234{
235 if (args == NULL)
236 reggroups_dump (current_gdbarch, gdb_stdout);
237 else
238 {
239 struct ui_file *file = gdb_fopen (args, "w");
240 if (file == NULL)
e2e0b3e5 241 perror_with_name (_("maintenance print reggroups"));
b59ff9d5
AC
242 reggroups_dump (current_gdbarch, file);
243 ui_file_delete (file);
244 }
245}
246
247/* Pre-defined register groups. */
248static struct reggroup general_group = { "general", USER_REGGROUP };
249static struct reggroup float_group = { "float", USER_REGGROUP };
250static struct reggroup system_group = { "system", USER_REGGROUP };
251static struct reggroup vector_group = { "vector", USER_REGGROUP };
252static struct reggroup all_group = { "all", USER_REGGROUP };
253static struct reggroup save_group = { "save", INTERNAL_REGGROUP };
254static struct reggroup restore_group = { "restore", INTERNAL_REGGROUP };
255
256struct reggroup *const general_reggroup = &general_group;
257struct reggroup *const float_reggroup = &float_group;
258struct reggroup *const system_reggroup = &system_group;
259struct reggroup *const vector_reggroup = &vector_group;
260struct reggroup *const all_reggroup = &all_group;
261struct reggroup *const save_reggroup = &save_group;
262struct reggroup *const restore_reggroup = &restore_group;
263
b9362cc7
AC
264extern initialize_file_ftype _initialize_reggroup; /* -Wmissing-prototypes */
265
b59ff9d5
AC
266void
267_initialize_reggroup (void)
268{
030f20e1 269 reggroups_data = gdbarch_data_register_post_init (reggroups_init);
b59ff9d5
AC
270
271 /* The pre-defined list of groups. */
6c7d17ba
AC
272 add_group (&default_groups, general_reggroup, XMALLOC (struct reggroup_el));
273 add_group (&default_groups, float_reggroup, XMALLOC (struct reggroup_el));
274 add_group (&default_groups, system_reggroup, XMALLOC (struct reggroup_el));
275 add_group (&default_groups, vector_reggroup, XMALLOC (struct reggroup_el));
276 add_group (&default_groups, all_reggroup, XMALLOC (struct reggroup_el));
277 add_group (&default_groups, save_reggroup, XMALLOC (struct reggroup_el));
278 add_group (&default_groups, restore_reggroup, XMALLOC (struct reggroup_el));
b59ff9d5
AC
279
280 add_cmd ("reggroups", class_maintenance,
1a966eab 281 maintenance_print_reggroups, _("\
b59ff9d5 282Print the internal register group names.\n\
1a966eab 283Takes an optional file parameter."),
b59ff9d5
AC
284 &maintenanceprintlist);
285
286}