GDB (xrefs)
/tmp/gdb-8.1/gdb/reggroups.c
Go to the documentation of this file.
1 /* Register groupings for GDB, the GNU debugger.
2 
3  Copyright (C) 2002-2018 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 "regcache.h"
27 #include "command.h"
28 #include "gdbcmd.h" /* For maintenanceprintlist. */
29 #include "gdb_obstack.h"
30 
31 /* Individual register groups. */
32 
33 struct reggroup
34 {
35  const char *name;
37 };
38 
39 struct reggroup *
40 reggroup_new (const char *name, enum reggroup_type type)
41 {
42  struct reggroup *group = XNEW (struct reggroup);
43 
44  group->name = name;
45  group->type = type;
46  return group;
47 }
48 
49 /* See reggroups.h. */
50 
51 struct reggroup *
52 reggroup_gdbarch_new (struct gdbarch *gdbarch, const char *name,
53  enum reggroup_type type)
54 {
55  struct reggroup *group = GDBARCH_OBSTACK_ZALLOC (gdbarch,
56  struct reggroup);
57 
59  group->type = type;
60  return group;
61 }
62 
63 /* Register group attributes. */
64 
65 const char *
66 reggroup_name (struct reggroup *group)
67 {
68  return group->name;
69 }
70 
71 enum reggroup_type
72 reggroup_type (struct reggroup *group)
73 {
74  return group->type;
75 }
76 
77 /* A linked list of groups for the given architecture. */
78 
80 {
81  struct reggroup *group;
82  struct reggroup_el *next;
83 };
84 
85 struct reggroups
86 {
87  struct reggroup_el *first;
88  struct reggroup_el **last;
89 };
90 
92 
93 static void *
94 reggroups_init (struct obstack *obstack)
95 {
96  struct reggroups *groups = OBSTACK_ZALLOC (obstack, struct reggroups);
97 
98  groups->last = &groups->first;
99  return groups;
100 }
101 
102 /* Add a register group (with attribute values) to the pre-defined
103  list. */
104 
105 static void
106 add_group (struct reggroups *groups, struct reggroup *group,
107  struct reggroup_el *el)
108 {
109  gdb_assert (group != NULL);
110  el->group = group;
111  el->next = NULL;
112  (*groups->last) = el;
113  groups->last = &el->next;
114 }
115 
116 void
117 reggroup_add (struct gdbarch *gdbarch, struct reggroup *group)
118 {
119  struct reggroups *groups
121 
122  add_group (groups, group,
124 }
125 
126 /* The default register groups for an architecture. */
127 
128 static struct reggroups default_groups = { NULL, &default_groups.first };
129 
130 /* A register group iterator. */
131 
132 struct reggroup *
133 reggroup_next (struct gdbarch *gdbarch, struct reggroup *last)
134 {
135  struct reggroups *groups;
136  struct reggroup_el *el;
137 
138  /* Don't allow this function to be called during architecture
139  creation. If there are no groups, use the default groups list. */
140  groups = (struct reggroups *) gdbarch_data (gdbarch, reggroups_data);
141  gdb_assert (groups != NULL);
142  if (groups->first == NULL)
143  groups = &default_groups;
144 
145  /* Return the first/next reggroup. */
146  if (last == NULL)
147  return groups->first->group;
148  for (el = groups->first; el != NULL; el = el->next)
149  {
150  if (el->group == last)
151  {
152  if (el->next != NULL)
153  return el->next->group;
154  else
155  return NULL;
156  }
157  }
158  return NULL;
159 }
160 
161 /* See reggroups.h. */
162 
163 struct reggroup *
164 reggroup_prev (struct gdbarch *gdbarch, struct reggroup *curr)
165 {
166  struct reggroups *groups;
167  struct reggroup_el *el;
168  struct reggroup *prev;
169 
170  /* Don't allow this function to be called during architecture
171  creation. If there are no groups, use the default groups list. */
172  groups = (struct reggroups *) gdbarch_data (gdbarch, reggroups_data);
173  gdb_assert (groups != NULL);
174  if (groups->first == NULL)
175  groups = &default_groups;
176 
177  prev = NULL;
178  for (el = groups->first; el != NULL; el = el->next)
179  {
180  gdb_assert (el->group != NULL);
181  if (el->group == curr)
182  return prev;
183  prev = el->group;
184  }
185  if (curr == NULL)
186  return prev;
187  return NULL;
188 }
189 
190 /* Is REGNUM a member of REGGROUP? */
191 int
193  struct reggroup *group)
194 {
195  int vector_p;
196  int float_p;
197  int raw_p;
198 
199  if (gdbarch_register_name (gdbarch, regnum) == NULL
200  || *gdbarch_register_name (gdbarch, regnum) == '\0')
201  return 0;
202  if (group == all_reggroup)
203  return 1;
204  vector_p = TYPE_VECTOR (register_type (gdbarch, regnum));
206  raw_p = regnum < gdbarch_num_regs (gdbarch);
207  if (group == float_reggroup)
208  return float_p;
209  if (group == vector_reggroup)
210  return vector_p;
211  if (group == general_reggroup)
212  return (!vector_p && !float_p);
213  if (group == save_reggroup || group == restore_reggroup)
214  return raw_p;
215  return 0;
216 }
217 
218 /* See reggroups.h. */
219 
220 reggroup *
221 reggroup_find (struct gdbarch *gdbarch, const char *name)
222 {
223  struct reggroup *group;
224 
225  for (group = reggroup_next (gdbarch, NULL);
226  group != NULL;
227  group = reggroup_next (gdbarch, group))
228  {
229  if (strcmp (name, reggroup_name (group)) == 0)
230  return group;
231  }
232  return NULL;
233 }
234 
235 /* Dump out a table of register groups for the current architecture. */
236 
237 static void
238 reggroups_dump (struct gdbarch *gdbarch, struct ui_file *file)
239 {
240  struct reggroup *group = NULL;
241 
242  do
243  {
244  /* Group name. */
245  {
246  const char *name;
247 
248  if (group == NULL)
249  name = "Group";
250  else
251  name = reggroup_name (group);
252  fprintf_unfiltered (file, " %-10s", name);
253  }
254 
255  /* Group type. */
256  {
257  const char *type;
258 
259  if (group == NULL)
260  type = "Type";
261  else
262  {
263  switch (reggroup_type (group))
264  {
265  case USER_REGGROUP:
266  type = "user";
267  break;
268  case INTERNAL_REGGROUP:
269  type = "internal";
270  break;
271  default:
272  internal_error (__FILE__, __LINE__, _("bad switch"));
273  }
274  }
275  fprintf_unfiltered (file, " %-10s", type);
276  }
277 
278  /* Note: If you change this, be sure to also update the
279  documentation. */
280 
281  fprintf_unfiltered (file, "\n");
282 
283  group = reggroup_next (gdbarch, group);
284  }
285  while (group != NULL);
286 }
287 
288 static void
289 maintenance_print_reggroups (const char *args, int from_tty)
290 {
291  struct gdbarch *gdbarch = get_current_arch ();
292 
293  if (args == NULL)
295  else
296  {
297  stdio_file file;
298 
299  if (!file.open (args, "w"))
300  perror_with_name (_("maintenance print reggroups"));
301  reggroups_dump (gdbarch, &file);
302  }
303 }
304 
305 /* Pre-defined register groups. */
306 static struct reggroup general_group = { "general", USER_REGGROUP };
307 static struct reggroup float_group = { "float", USER_REGGROUP };
308 static struct reggroup system_group = { "system", USER_REGGROUP };
309 static struct reggroup vector_group = { "vector", USER_REGGROUP };
310 static struct reggroup all_group = { "all", USER_REGGROUP };
311 static struct reggroup save_group = { "save", INTERNAL_REGGROUP };
312 static struct reggroup restore_group = { "restore", INTERNAL_REGGROUP };
313 
318 struct reggroup *const all_reggroup = &all_group;
321 
322 void
324 {
326 
327  /* The pre-defined list of groups. */
335 
336  add_cmd ("reggroups", class_maintenance,
338 Print the internal register group names.\n\
339 Takes an optional file parameter."),
341 
342 }
void reggroup_add(struct gdbarch *gdbarch, struct reggroup *group)
Definition: reggroups.c:117
struct reggroup_el ** last
Definition: reggroups.c:88
struct reggroup * reggroup_new(const char *name, enum reggroup_type type)
Definition: reggroups.c:40
static struct reggroup save_group
Definition: reggroups.c:311
static struct reggroup system_group
Definition: reggroups.c:308
static struct reggroup all_group
Definition: reggroups.c:310
struct reggroup * reggroup_prev(struct gdbarch *gdbarch, struct reggroup *curr)
Definition: reggroups.c:164
static struct reggroup vector_group
Definition: reggroups.c:309
const char * name
Definition: reggroups.c:35
void internal_error(const char *file, int line, const char *fmt,...)
Definition: errors.c:50
struct cmd_list_element * add_cmd(const char *name, enum command_class theclass, const char *doc, struct cmd_list_element **list)
Definition: cli-decode.c:262
static struct reggroup restore_group
Definition: reggroups.c:312
struct reggroup *const restore_reggroup
Definition: reggroups.c:320
struct gdbarch_data * gdbarch_data_register_pre_init(gdbarch_data_pre_init_ftype *pre_init)
Definition: gdbarch.c:5130
int gdbarch_num_regs(struct gdbarch *gdbarch)
Definition: gdbarch.c:2039
struct reggroup *const all_reggroup
Definition: reggroups.c:318
#define _(String)
Definition: gdb_locale.h:35
#define GDBARCH_OBSTACK_ZALLOC(GDBARCH, TYPE)
Definition: gdbarch.h:1709
#define XNEW(T)
Definition: poison.h:109
char * gdbarch_obstack_strdup(struct gdbarch *arch, const char *string)
Definition: gdbarch.c:486
struct reggroup *const float_reggroup
Definition: reggroups.c:315
const char *const name
Definition: aarch64-tdep.c:76
reggroup_type
Definition: reggroups.h:28
static struct gdbarch_data * reggroups_data
Definition: reggroups.c:91
struct reggroup *const general_reggroup
Definition: reggroups.c:314
static struct reggroups default_groups
Definition: reggroups.c:128
struct reggroup_el * first
Definition: reggroups.c:87
static void reggroups_dump(struct gdbarch *gdbarch, struct ui_file *file)
Definition: reggroups.c:238
enum reggroup_type type
Definition: reggroups.c:36
struct reggroup *const system_reggroup
Definition: reggroups.c:316
struct type * register_type(struct gdbarch *gdbarch, int regnum)
Definition: regcache.c:152
static void maintenance_print_reggroups(const char *args, int from_tty)
Definition: reggroups.c:289
void fprintf_unfiltered(struct ui_file *stream, const char *format,...)
Definition: utils.c:2018
#define TYPE_VECTOR(t)
Definition: gdbtypes.h:252
struct reggroup * group
Definition: reggroups.c:81
Definition: gdbtypes.h:749
struct gdbarch * get_current_arch(void)
Definition: arch-utils.c:798
static const char * type
Definition: language.c:113
const char * gdbarch_register_name(struct gdbarch *gdbarch, int regnr)
Definition: gdbarch.c:2282
int regnum
Definition: aarch64-tdep.c:77
struct reggroup *const vector_reggroup
Definition: reggroups.c:317
struct reggroup_el * next
Definition: reggroups.c:82
struct cmd_list_element * maintenanceprintlist
Definition: cli-cmds.c:143
void _initialize_reggroup(void)
Definition: reggroups.c:323
static struct reggroup float_group
Definition: reggroups.c:307
enum reggroup_type reggroup_type(struct reggroup *group)
Definition: reggroups.c:72
#define gdb_assert(expr)
Definition: gdb_assert.h:32
reggroup * reggroup_find(struct gdbarch *gdbarch, const char *name)
Definition: reggroups.c:221
static void add_group(struct reggroups *groups, struct reggroup *group, struct reggroup_el *el)
Definition: reggroups.c:106
struct reggroup * reggroup_gdbarch_new(struct gdbarch *gdbarch, const char *name, enum reggroup_type type)
Definition: reggroups.c:52
void void void void void void void void void perror_with_name(const char *string) ATTRIBUTE_NORETURN
Definition: utils.c:692
static struct reggroup general_group
Definition: reggroups.c:306
#define TYPE_CODE(thistype)
Definition: gdbtypes.h:1238
bool open(const char *name, const char *mode)
Definition: ui-file.c:171
static void * reggroups_init(struct obstack *obstack)
Definition: reggroups.c:94
int default_register_reggroup_p(struct gdbarch *gdbarch, int regnum, struct reggroup *group)
Definition: reggroups.c:192
struct reggroup * reggroup_next(struct gdbarch *gdbarch, struct reggroup *last)
Definition: reggroups.c:133
struct reggroup *const save_reggroup
Definition: reggroups.c:319
#define OBSTACK_ZALLOC(OBSTACK, TYPE)
Definition: gdb_obstack.h:27
const char * reggroup_name(struct reggroup *group)
Definition: reggroups.c:66
#define gdb_stdout
Definition: utils.h:340