]>
Commit | Line | Data |
---|---|---|
b59ff9d5 AC |
1 | /* Register groupings for GDB, the GNU debugger. |
2 | ||
1d506c26 | 3 | Copyright (C) 2002-2024 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" | |
e17c207e | 23 | #include "arch-utils.h" |
b59ff9d5 AC |
24 | #include "reggroups.h" |
25 | #include "gdbtypes.h" | |
b59ff9d5 AC |
26 | #include "regcache.h" |
27 | #include "command.h" | |
ef0f16cc | 28 | #include "gdbcmd.h" |
bf31fd38 | 29 | #include "gdbsupport/gdb_obstack.h" |
b59ff9d5 | 30 | |
524ad5e3 AB |
31 | /* See reggroups.h. */ |
32 | ||
e7fe1011 | 33 | const reggroup * |
b59ff9d5 AC |
34 | reggroup_new (const char *name, enum reggroup_type type) |
35 | { | |
c30c0f06 | 36 | return new reggroup (name, type); |
b59ff9d5 AC |
37 | } |
38 | ||
f7efd549 SH |
39 | /* See reggroups.h. */ |
40 | ||
e7fe1011 | 41 | const reggroup * |
f7efd549 SH |
42 | reggroup_gdbarch_new (struct gdbarch *gdbarch, const char *name, |
43 | enum reggroup_type type) | |
44 | { | |
c30c0f06 AB |
45 | name = gdbarch_obstack_strdup (gdbarch, name); |
46 | return obstack_new<struct reggroup> (gdbarch_obstack (gdbarch), | |
47 | name, type); | |
f7efd549 SH |
48 | } |
49 | ||
b89f77be AB |
50 | /* A container holding all the register groups for a particular |
51 | architecture. */ | |
b59ff9d5 AC |
52 | |
53 | struct reggroups | |
54 | { | |
cb275538 TT |
55 | reggroups () |
56 | { | |
57 | /* Add the default groups. */ | |
58 | add (general_reggroup); | |
59 | add (float_reggroup); | |
60 | add (system_reggroup); | |
61 | add (vector_reggroup); | |
62 | add (all_reggroup); | |
63 | add (save_reggroup); | |
64 | add (restore_reggroup); | |
65 | } | |
66 | ||
67 | DISABLE_COPY_AND_ASSIGN (reggroups); | |
68 | ||
b89f77be AB |
69 | /* Add GROUP to the list of register groups. */ |
70 | ||
e7fe1011 | 71 | void add (const reggroup *group) |
b89f77be AB |
72 | { |
73 | gdb_assert (group != nullptr); | |
9454c9ce SM |
74 | |
75 | auto find_by_name = [group] (const reggroup *g) | |
76 | { | |
77 | return streq (group->name (), g->name ()); | |
78 | }; | |
79 | gdb_assert (std::find_if (m_groups.begin (), m_groups.end (), find_by_name) | |
80 | == m_groups.end ()); | |
b89f77be AB |
81 | |
82 | m_groups.push_back (group); | |
83 | } | |
84 | ||
85 | /* The number of register groups. */ | |
86 | ||
87 | std::vector<struct reggroup *>::size_type | |
88 | size () const | |
89 | { | |
90 | return m_groups.size (); | |
91 | } | |
92 | ||
93 | /* Return a reference to the list of all groups. */ | |
94 | ||
1bca9b1e | 95 | const std::vector<const struct reggroup *> & |
b89f77be AB |
96 | groups () const |
97 | { | |
98 | return m_groups; | |
99 | } | |
100 | ||
101 | private: | |
102 | /* The register groups. */ | |
1bca9b1e | 103 | std::vector<const struct reggroup *> m_groups; |
b59ff9d5 AC |
104 | }; |
105 | ||
524ad5e3 AB |
106 | /* Key used to lookup register group data from a gdbarch. */ |
107 | ||
cb275538 TT |
108 | static const registry<gdbarch>::key<reggroups> reggroups_data; |
109 | ||
110 | /* Get the reggroups for the architecture, creating if necessary. */ | |
111 | ||
112 | static reggroups * | |
113 | get_reggroups (struct gdbarch *gdbarch) | |
114 | { | |
115 | struct reggroups *groups = reggroups_data.get (gdbarch); | |
116 | if (groups == nullptr) | |
117 | groups = reggroups_data.emplace (gdbarch); | |
118 | return groups; | |
119 | } | |
b59ff9d5 | 120 | |
524ad5e3 | 121 | /* See reggroups.h. */ |
b59ff9d5 AC |
122 | |
123 | void | |
e7fe1011 | 124 | reggroup_add (struct gdbarch *gdbarch, const reggroup *group) |
b59ff9d5 | 125 | { |
cb275538 | 126 | struct reggroups *groups = get_reggroups (gdbarch); |
7e6d0ac8 | 127 | |
e7d69e72 | 128 | gdb_assert (groups != nullptr); |
b89f77be | 129 | gdb_assert (group != nullptr); |
e7d69e72 | 130 | |
b89f77be | 131 | groups->add (group); |
b59ff9d5 AC |
132 | } |
133 | ||
55b40027 | 134 | /* See reggroups.h. */ |
1bca9b1e AB |
135 | const std::vector<const reggroup *> & |
136 | gdbarch_reggroups (struct gdbarch *gdbarch) | |
55b40027 | 137 | { |
cb275538 | 138 | struct reggroups *groups = get_reggroups (gdbarch); |
b89f77be AB |
139 | gdb_assert (groups != nullptr); |
140 | gdb_assert (groups->size () > 0); | |
1bca9b1e | 141 | return groups->groups (); |
55b40027 AB |
142 | } |
143 | ||
524ad5e3 AB |
144 | /* See reggroups.h. */ |
145 | ||
b59ff9d5 AC |
146 | int |
147 | default_register_reggroup_p (struct gdbarch *gdbarch, int regnum, | |
dbf5d61b | 148 | const struct reggroup *group) |
b59ff9d5 AC |
149 | { |
150 | int vector_p; | |
151 | int float_p; | |
152 | int raw_p; | |
7e6d0ac8 | 153 | |
637b2f86 | 154 | if (*gdbarch_register_name (gdbarch, regnum) == '\0') |
b59ff9d5 AC |
155 | return 0; |
156 | if (group == all_reggroup) | |
157 | return 1; | |
bd63c870 | 158 | vector_p = register_type (gdbarch, regnum)->is_vector (); |
78134374 SM |
159 | float_p = (register_type (gdbarch, regnum)->code () == TYPE_CODE_FLT |
160 | || (register_type (gdbarch, regnum)->code () | |
7ed29001 | 161 | == TYPE_CODE_DECFLOAT)); |
6bcde365 | 162 | raw_p = regnum < gdbarch_num_regs (gdbarch); |
b59ff9d5 AC |
163 | if (group == float_reggroup) |
164 | return float_p; | |
165 | if (group == vector_reggroup) | |
166 | return vector_p; | |
167 | if (group == general_reggroup) | |
168 | return (!vector_p && !float_p); | |
169 | if (group == save_reggroup || group == restore_reggroup) | |
170 | return raw_p; | |
b89f77be | 171 | return 0; |
b59ff9d5 AC |
172 | } |
173 | ||
f7efd549 SH |
174 | /* See reggroups.h. */ |
175 | ||
2b72890e | 176 | const reggroup * |
f7efd549 SH |
177 | reggroup_find (struct gdbarch *gdbarch, const char *name) |
178 | { | |
1bca9b1e | 179 | for (const struct reggroup *group : gdbarch_reggroups (gdbarch)) |
f7efd549 | 180 | { |
c30c0f06 | 181 | if (strcmp (name, group->name ()) == 0) |
f7efd549 SH |
182 | return group; |
183 | } | |
184 | return NULL; | |
185 | } | |
186 | ||
b59ff9d5 AC |
187 | /* Dump out a table of register groups for the current architecture. */ |
188 | ||
189 | static void | |
190 | reggroups_dump (struct gdbarch *gdbarch, struct ui_file *file) | |
191 | { | |
1bca9b1e | 192 | static constexpr const char *fmt = " %-10s %-10s\n"; |
7e6d0ac8 | 193 | |
1bca9b1e AB |
194 | gdb_printf (file, fmt, "Group", "Type"); |
195 | ||
196 | for (const struct reggroup *group : gdbarch_reggroups (gdbarch)) | |
b59ff9d5 AC |
197 | { |
198 | /* Group name. */ | |
c30c0f06 | 199 | const char *name = group->name (); |
b89f77be | 200 | |
b59ff9d5 | 201 | /* Group type. */ |
1bca9b1e AB |
202 | const char *type; |
203 | ||
c30c0f06 | 204 | switch (group->type ()) |
1bca9b1e AB |
205 | { |
206 | case USER_REGGROUP: | |
207 | type = "user"; | |
208 | break; | |
209 | case INTERNAL_REGGROUP: | |
210 | type = "internal"; | |
211 | break; | |
212 | default: | |
f34652de | 213 | internal_error (_("bad switch")); |
1bca9b1e | 214 | } |
b59ff9d5 AC |
215 | |
216 | /* Note: If you change this, be sure to also update the | |
dda83cd7 | 217 | documentation. */ |
6c7d17ba | 218 | |
1bca9b1e | 219 | gdb_printf (file, fmt, name, type); |
b59ff9d5 | 220 | } |
b59ff9d5 AC |
221 | } |
222 | ||
524ad5e3 AB |
223 | /* Implement 'maintenance print reggroups' command. */ |
224 | ||
b59ff9d5 | 225 | static void |
34e5fa26 | 226 | maintenance_print_reggroups (const char *args, int from_tty) |
b59ff9d5 | 227 | { |
e17c207e UW |
228 | struct gdbarch *gdbarch = get_current_arch (); |
229 | ||
b59ff9d5 | 230 | if (args == NULL) |
e17c207e | 231 | reggroups_dump (gdbarch, gdb_stdout); |
b59ff9d5 AC |
232 | else |
233 | { | |
d7e74731 | 234 | stdio_file file; |
123f5f96 | 235 | |
d7e74731 | 236 | if (!file.open (args, "w")) |
e2e0b3e5 | 237 | perror_with_name (_("maintenance print reggroups")); |
d7e74731 | 238 | reggroups_dump (gdbarch, &file); |
b59ff9d5 AC |
239 | } |
240 | } | |
241 | ||
242 | /* Pre-defined register groups. */ | |
3a471c03 AB |
243 | static const reggroup general_group = { "general", USER_REGGROUP }; |
244 | static const reggroup float_group = { "float", USER_REGGROUP }; | |
245 | static const reggroup system_group = { "system", USER_REGGROUP }; | |
246 | static const reggroup vector_group = { "vector", USER_REGGROUP }; | |
247 | static const reggroup all_group = { "all", USER_REGGROUP }; | |
248 | static const reggroup save_group = { "save", INTERNAL_REGGROUP }; | |
249 | static const reggroup restore_group = { "restore", INTERNAL_REGGROUP }; | |
250 | ||
251 | const reggroup *const general_reggroup = &general_group; | |
252 | const reggroup *const float_reggroup = &float_group; | |
253 | const reggroup *const system_reggroup = &system_group; | |
254 | const reggroup *const vector_reggroup = &vector_group; | |
255 | const reggroup *const all_reggroup = &all_group; | |
256 | const reggroup *const save_reggroup = &save_group; | |
257 | const reggroup *const restore_reggroup = &restore_group; | |
b59ff9d5 | 258 | |
6c265988 | 259 | void _initialize_reggroup (); |
b59ff9d5 | 260 | void |
6c265988 | 261 | _initialize_reggroup () |
b59ff9d5 | 262 | { |
b59ff9d5 | 263 | add_cmd ("reggroups", class_maintenance, |
1a966eab | 264 | maintenance_print_reggroups, _("\ |
b59ff9d5 | 265 | Print the internal register group names.\n\ |
1a966eab | 266 | Takes an optional file parameter."), |
b59ff9d5 AC |
267 | &maintenanceprintlist); |
268 | ||
269 | } |