Regenerate tree using Autoconf 2.64 and Automake 1.11.
[deliverable/binutils-gdb.git] / gdb / reggroups.c
1 /* Register groupings for GDB, the GNU debugger.
2
3 Copyright (C) 2002, 2003, 2007, 2008, 2009 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 3 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, see <http://www.gnu.org/licenses/>. */
21
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. */
30
31 /* Individual register groups. */
32
33 struct reggroup
34 {
35 const char *name;
36 enum reggroup_type type;
37 };
38
39 struct reggroup *
40 reggroup_new (const char *name, enum reggroup_type type)
41 {
42 struct reggroup *group = XMALLOC (struct reggroup);
43 group->name = name;
44 group->type = type;
45 return group;
46 }
47
48 /* Register group attributes. */
49
50 const char *
51 reggroup_name (struct reggroup *group)
52 {
53 return group->name;
54 }
55
56 enum reggroup_type
57 reggroup_type (struct reggroup *group)
58 {
59 return group->type;
60 }
61
62 /* A linked list of groups for the given architecture. */
63
64 struct reggroup_el
65 {
66 struct reggroup *group;
67 struct reggroup_el *next;
68 };
69
70 struct reggroups
71 {
72 struct reggroup_el *first;
73 struct reggroup_el **last;
74 };
75
76 static struct gdbarch_data *reggroups_data;
77
78 static void *
79 reggroups_init (struct gdbarch *gdbarch)
80 {
81 struct reggroups *groups = GDBARCH_OBSTACK_ZALLOC (gdbarch,
82 struct reggroups);
83 groups->last = &groups->first;
84 return groups;
85 }
86
87 /* Add a register group (with attribute values) to the pre-defined
88 list. */
89
90 static void
91 add_group (struct reggroups *groups, struct reggroup *group,
92 struct reggroup_el *el)
93 {
94 gdb_assert (group != NULL);
95 el->group = group;
96 el->next = NULL;
97 (*groups->last) = el;
98 groups->last = &el->next;
99 }
100
101 void
102 reggroup_add (struct gdbarch *gdbarch, struct reggroup *group)
103 {
104 struct reggroups *groups = gdbarch_data (gdbarch, reggroups_data);
105
106 if (groups == NULL)
107 {
108 /* ULGH, called during architecture initialization. Patch
109 things up. */
110 groups = reggroups_init (gdbarch);
111 deprecated_set_gdbarch_data (gdbarch, reggroups_data, groups);
112 }
113 add_group (groups, group,
114 GDBARCH_OBSTACK_ZALLOC (gdbarch, struct reggroup_el));
115 }
116
117 /* The default register groups for an architecture. */
118
119 static struct reggroups default_groups = { NULL, &default_groups.first };
120
121 /* A register group iterator. */
122
123 struct reggroup *
124 reggroup_next (struct gdbarch *gdbarch, struct reggroup *last)
125 {
126 struct reggroups *groups;
127 struct reggroup_el *el;
128
129 /* Don't allow this function to be called during architecture
130 creation. If there are no groups, use the default groups list. */
131 groups = gdbarch_data (gdbarch, reggroups_data);
132 gdb_assert (groups != NULL);
133 if (groups->first == NULL)
134 groups = &default_groups;
135
136 /* Return the first/next reggroup. */
137 if (last == NULL)
138 return groups->first->group;
139 for (el = groups->first; el != NULL; el = el->next)
140 {
141 if (el->group == last)
142 {
143 if (el->next != NULL)
144 return el->next->group;
145 else
146 return NULL;
147 }
148 }
149 return NULL;
150 }
151
152 /* Is REGNUM a member of REGGROUP? */
153 int
154 default_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
155 struct reggroup *group)
156 {
157 int vector_p;
158 int float_p;
159 int raw_p;
160
161 if (gdbarch_register_name (gdbarch, regnum) == NULL
162 || *gdbarch_register_name (gdbarch, regnum) == '\0')
163 return 0;
164 if (group == all_reggroup)
165 return 1;
166 vector_p = TYPE_VECTOR (register_type (gdbarch, regnum));
167 float_p = TYPE_CODE (register_type (gdbarch, regnum)) == TYPE_CODE_FLT;
168 raw_p = regnum < gdbarch_num_regs (gdbarch);
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
182 static void
183 reggroups_dump (struct gdbarch *gdbarch, struct ui_file *file)
184 {
185 struct reggroup *group = NULL;
186
187 do
188 {
189 /* Group name. */
190 {
191 const char *name;
192 if (group == NULL)
193 name = "Group";
194 else
195 name = reggroup_name (group);
196 fprintf_unfiltered (file, " %-10s", name);
197 }
198
199 /* Group type. */
200 {
201 const char *type;
202 if (group == NULL)
203 type = "Type";
204 else
205 {
206 switch (reggroup_type (group))
207 {
208 case USER_REGGROUP:
209 type = "user";
210 break;
211 case INTERNAL_REGGROUP:
212 type = "internal";
213 break;
214 default:
215 internal_error (__FILE__, __LINE__, _("bad switch"));
216 }
217 }
218 fprintf_unfiltered (file, " %-10s", type);
219 }
220
221 /* Note: If you change this, be sure to also update the
222 documentation. */
223
224 fprintf_unfiltered (file, "\n");
225
226 group = reggroup_next (gdbarch, group);
227 }
228 while (group != NULL);
229 }
230
231 static void
232 maintenance_print_reggroups (char *args, int from_tty)
233 {
234 struct gdbarch *gdbarch = get_current_arch ();
235
236 if (args == NULL)
237 reggroups_dump (gdbarch, gdb_stdout);
238 else
239 {
240 struct cleanup *cleanups;
241 struct ui_file *file = gdb_fopen (args, "w");
242 if (file == NULL)
243 perror_with_name (_("maintenance print reggroups"));
244 cleanups = make_cleanup_ui_file_delete (file);
245 reggroups_dump (gdbarch, file);
246 do_cleanups (cleanups);
247 }
248 }
249
250 /* Pre-defined register groups. */
251 static struct reggroup general_group = { "general", USER_REGGROUP };
252 static struct reggroup float_group = { "float", USER_REGGROUP };
253 static struct reggroup system_group = { "system", USER_REGGROUP };
254 static struct reggroup vector_group = { "vector", USER_REGGROUP };
255 static struct reggroup all_group = { "all", USER_REGGROUP };
256 static struct reggroup save_group = { "save", INTERNAL_REGGROUP };
257 static struct reggroup restore_group = { "restore", INTERNAL_REGGROUP };
258
259 struct reggroup *const general_reggroup = &general_group;
260 struct reggroup *const float_reggroup = &float_group;
261 struct reggroup *const system_reggroup = &system_group;
262 struct reggroup *const vector_reggroup = &vector_group;
263 struct reggroup *const all_reggroup = &all_group;
264 struct reggroup *const save_reggroup = &save_group;
265 struct reggroup *const restore_reggroup = &restore_group;
266
267 extern initialize_file_ftype _initialize_reggroup; /* -Wmissing-prototypes */
268
269 void
270 _initialize_reggroup (void)
271 {
272 reggroups_data = gdbarch_data_register_post_init (reggroups_init);
273
274 /* The pre-defined list of groups. */
275 add_group (&default_groups, general_reggroup, XMALLOC (struct reggroup_el));
276 add_group (&default_groups, float_reggroup, XMALLOC (struct reggroup_el));
277 add_group (&default_groups, system_reggroup, XMALLOC (struct reggroup_el));
278 add_group (&default_groups, vector_reggroup, XMALLOC (struct reggroup_el));
279 add_group (&default_groups, all_reggroup, XMALLOC (struct reggroup_el));
280 add_group (&default_groups, save_reggroup, XMALLOC (struct reggroup_el));
281 add_group (&default_groups, restore_reggroup, XMALLOC (struct reggroup_el));
282
283 add_cmd ("reggroups", class_maintenance,
284 maintenance_print_reggroups, _("\
285 Print the internal register group names.\n\
286 Takes an optional file parameter."),
287 &maintenanceprintlist);
288
289 }
This page took 0.03592 seconds and 4 git commands to generate.