[PATCH 30/57][Arm][GAS] Add support for MVE instructions: vqmovnt, vqmovnb, vqmovunt...
[binutils-gdb.git] / gdb / regcache-dump.c
blob1bcf9c3d17adf81c8c81710e4b8ad72fb8648349
1 /* Copyright (C) 1986-2019 Free Software Foundation, Inc.
3 This file is part of GDB.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18 #include "defs.h"
19 #include "gdbcmd.h"
20 #include "regcache.h"
21 #include "common/def-vector.h"
22 #include "valprint.h"
23 #include "remote.h"
24 #include "reggroups.h"
25 #include "target.h"
27 /* Dump registers from regcache, used for dumping raw registers and
28 cooked registers. */
30 class register_dump_regcache : public register_dump
32 public:
33 register_dump_regcache (regcache *regcache, bool dump_pseudo)
34 : register_dump (regcache->arch ()), m_regcache (regcache),
35 m_dump_pseudo (dump_pseudo)
39 protected:
40 void dump_reg (ui_file *file, int regnum) override
42 if (regnum < 0)
44 if (m_dump_pseudo)
45 fprintf_unfiltered (file, "Cooked value");
46 else
47 fprintf_unfiltered (file, "Raw value");
49 else
51 if (regnum < gdbarch_num_regs (m_gdbarch) || m_dump_pseudo)
53 auto size = register_size (m_gdbarch, regnum);
55 if (size == 0)
56 return;
58 gdb::def_vector<gdb_byte> buf (size);
59 auto status = m_regcache->cooked_read (regnum, buf.data ());
61 if (status == REG_UNKNOWN)
62 fprintf_unfiltered (file, "<invalid>");
63 else if (status == REG_UNAVAILABLE)
64 fprintf_unfiltered (file, "<unavailable>");
65 else
67 print_hex_chars (file, buf.data (), size,
68 gdbarch_byte_order (m_gdbarch), true);
71 else
73 /* Just print "<cooked>" for pseudo register when
74 regcache_dump_raw. */
75 fprintf_unfiltered (file, "<cooked>");
80 private:
81 regcache *m_regcache;
83 /* Dump pseudo registers or not. */
84 const bool m_dump_pseudo;
87 /* Dump from reg_buffer, used when there is no thread or
88 registers. */
90 class register_dump_reg_buffer : public register_dump, reg_buffer
92 public:
93 register_dump_reg_buffer (gdbarch *gdbarch, bool dump_pseudo)
94 : register_dump (gdbarch), reg_buffer (gdbarch, dump_pseudo)
98 protected:
99 void dump_reg (ui_file *file, int regnum) override
101 if (regnum < 0)
103 if (m_has_pseudo)
104 fprintf_unfiltered (file, "Cooked value");
105 else
106 fprintf_unfiltered (file, "Raw value");
108 else
110 if (regnum < gdbarch_num_regs (m_gdbarch) || m_has_pseudo)
112 auto size = register_size (m_gdbarch, regnum);
114 if (size == 0)
115 return;
117 auto status = get_register_status (regnum);
119 gdb_assert (status != REG_VALID);
121 if (status == REG_UNKNOWN)
122 fprintf_unfiltered (file, "<invalid>");
123 else
124 fprintf_unfiltered (file, "<unavailable>");
126 else
128 /* Just print "<cooked>" for pseudo register when
129 regcache_dump_raw. */
130 fprintf_unfiltered (file, "<cooked>");
136 /* For "maint print registers". */
138 class register_dump_none : public register_dump
140 public:
141 register_dump_none (gdbarch *arch)
142 : register_dump (arch)
145 protected:
146 void dump_reg (ui_file *file, int regnum) override
150 /* For "maint print remote-registers". */
152 class register_dump_remote : public register_dump
154 public:
155 register_dump_remote (gdbarch *arch)
156 : register_dump (arch)
159 protected:
160 void dump_reg (ui_file *file, int regnum) override
162 if (regnum < 0)
164 fprintf_unfiltered (file, "Rmt Nr g/G Offset");
166 else if (regnum < gdbarch_num_regs (m_gdbarch))
168 int pnum, poffset;
170 if (remote_register_number_and_offset (m_gdbarch, regnum,
171 &pnum, &poffset))
172 fprintf_unfiltered (file, "%7d %11d", pnum, poffset);
177 /* For "maint print register-groups". */
179 class register_dump_groups : public register_dump
181 public:
182 register_dump_groups (gdbarch *arch)
183 : register_dump (arch)
186 protected:
187 void dump_reg (ui_file *file, int regnum) override
189 if (regnum < 0)
190 fprintf_unfiltered (file, "Groups");
191 else
193 const char *sep = "";
194 struct reggroup *group;
196 for (group = reggroup_next (m_gdbarch, NULL);
197 group != NULL;
198 group = reggroup_next (m_gdbarch, group))
200 if (gdbarch_register_reggroup_p (m_gdbarch, regnum, group))
202 fprintf_unfiltered (file,
203 "%s%s", sep, reggroup_name (group));
204 sep = ",";
211 enum regcache_dump_what
213 regcache_dump_none, regcache_dump_raw,
214 regcache_dump_cooked, regcache_dump_groups,
215 regcache_dump_remote
218 static void
219 regcache_print (const char *args, enum regcache_dump_what what_to_dump)
221 /* Where to send output. */
222 stdio_file file;
223 ui_file *out;
225 if (args == NULL)
226 out = gdb_stdout;
227 else
229 if (!file.open (args, "w"))
230 perror_with_name (_("maintenance print architecture"));
231 out = &file;
234 std::unique_ptr<register_dump> dump;
235 std::unique_ptr<regcache> regs;
236 gdbarch *gdbarch;
238 if (target_has_registers)
239 gdbarch = get_current_regcache ()->arch ();
240 else
241 gdbarch = target_gdbarch ();
243 switch (what_to_dump)
245 case regcache_dump_none:
246 dump.reset (new register_dump_none (gdbarch));
247 break;
248 case regcache_dump_remote:
249 dump.reset (new register_dump_remote (gdbarch));
250 break;
251 case regcache_dump_groups:
252 dump.reset (new register_dump_groups (gdbarch));
253 break;
254 case regcache_dump_raw:
255 case regcache_dump_cooked:
257 auto dump_pseudo = (what_to_dump == regcache_dump_cooked);
259 if (target_has_registers)
260 dump.reset (new register_dump_regcache (get_current_regcache (),
261 dump_pseudo));
262 else
264 /* For the benefit of "maint print registers" & co when
265 debugging an executable, allow dumping a regcache even when
266 there is no thread selected / no registers. */
267 dump.reset (new register_dump_reg_buffer (target_gdbarch (),
268 dump_pseudo));
271 break;
274 dump->dump (out);
277 static void
278 maintenance_print_registers (const char *args, int from_tty)
280 regcache_print (args, regcache_dump_none);
283 static void
284 maintenance_print_raw_registers (const char *args, int from_tty)
286 regcache_print (args, regcache_dump_raw);
289 static void
290 maintenance_print_cooked_registers (const char *args, int from_tty)
292 regcache_print (args, regcache_dump_cooked);
295 static void
296 maintenance_print_register_groups (const char *args, int from_tty)
298 regcache_print (args, regcache_dump_groups);
301 static void
302 maintenance_print_remote_registers (const char *args, int from_tty)
304 regcache_print (args, regcache_dump_remote);
307 void
308 _initialize_regcache_dump (void)
310 add_cmd ("registers", class_maintenance, maintenance_print_registers,
311 _("Print the internal register configuration.\n"
312 "Takes an optional file parameter."), &maintenanceprintlist);
313 add_cmd ("raw-registers", class_maintenance,
314 maintenance_print_raw_registers,
315 _("Print the internal register configuration "
316 "including raw values.\n"
317 "Takes an optional file parameter."), &maintenanceprintlist);
318 add_cmd ("cooked-registers", class_maintenance,
319 maintenance_print_cooked_registers,
320 _("Print the internal register configuration "
321 "including cooked values.\n"
322 "Takes an optional file parameter."), &maintenanceprintlist);
323 add_cmd ("register-groups", class_maintenance,
324 maintenance_print_register_groups,
325 _("Print the internal register configuration "
326 "including each register's group.\n"
327 "Takes an optional file parameter."),
328 &maintenanceprintlist);
329 add_cmd ("remote-registers", class_maintenance,
330 maintenance_print_remote_registers, _("\
331 Print the internal register configuration including each register's\n\
332 remote register number and buffer offset in the g/G packets.\n\
333 Takes an optional file parameter."),
334 &maintenanceprintlist);