1 /* Copyright (C) 1986-2017 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/>. */
21 #include "common/def-vector.h"
24 #include "reggroups.h"
27 /* Dump registers from regcache, used for dumping raw registers and
30 class register_dump_regcache : public register_dump
33 register_dump_regcache (regcache *regcache, bool dump_pseudo)
34 : register_dump (regcache->arch ()), m_regcache (regcache),
35 m_dump_pseudo (dump_pseudo)
40 void dump_reg (ui_file *file, int regnum) override
45 fprintf_unfiltered (file, "Cooked value");
47 fprintf_unfiltered (file, "Raw value");
51 if (regnum < gdbarch_num_regs (m_gdbarch) || m_dump_pseudo)
53 auto size = register_size (m_gdbarch, regnum);
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>");
67 print_hex_chars (file, buf.data (), size,
68 gdbarch_byte_order (m_gdbarch), true);
73 /* Just print "<cooked>" for pseudo register when
75 fprintf_unfiltered (file, "<cooked>");
83 /* Dump pseudo registers or not. */
84 const bool m_dump_pseudo;
87 /* Dump from reg_buffer, used when there is no thread or
90 class register_dump_reg_buffer : public register_dump, reg_buffer
93 register_dump_reg_buffer (gdbarch *gdbarch, bool dump_pseudo)
94 : register_dump (gdbarch), reg_buffer (gdbarch, dump_pseudo)
99 void dump_reg (ui_file *file, int regnum) override
104 fprintf_unfiltered (file, "Cooked value");
106 fprintf_unfiltered (file, "Raw value");
110 if (regnum < gdbarch_num_regs (m_gdbarch) || m_has_pseudo)
112 auto size = register_size (m_gdbarch, regnum);
117 auto status = get_register_status (regnum);
119 gdb_assert (status != REG_VALID);
121 if (status == REG_UNKNOWN)
122 fprintf_unfiltered (file, "<invalid>");
124 fprintf_unfiltered (file, "<unavailable>");
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
141 register_dump_none (gdbarch *arch)
142 : register_dump (arch)
146 void dump_reg (ui_file *file, int regnum) override
150 /* For "maint print remote-registers". */
152 class register_dump_remote : public register_dump
155 register_dump_remote (gdbarch *arch)
156 : register_dump (arch)
160 void dump_reg (ui_file *file, int regnum) override
164 fprintf_unfiltered (file, "Rmt Nr g/G Offset");
166 else if (regnum < gdbarch_num_regs (m_gdbarch))
170 if (remote_register_number_and_offset (m_gdbarch, regnum,
172 fprintf_unfiltered (file, "%7d %11d", pnum, poffset);
177 /* For "maint print register-groups". */
179 class register_dump_groups : public register_dump
182 register_dump_groups (gdbarch *arch)
183 : register_dump (arch)
187 void dump_reg (ui_file *file, int regnum) override
190 fprintf_unfiltered (file, "Groups");
193 const char *sep = "";
194 struct reggroup *group;
196 for (group = reggroup_next (m_gdbarch, 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));
211 enum regcache_dump_what
213 regcache_dump_none, regcache_dump_raw,
214 regcache_dump_cooked, regcache_dump_groups,
219 regcache_print (const char *args, enum regcache_dump_what what_to_dump)
221 /* Where to send output. */
229 if (!file.open (args, "w"))
230 perror_with_name (_("maintenance print architecture"));
234 std::unique_ptr<register_dump> dump;
235 std::unique_ptr<regcache> regs;
238 if (target_has_registers)
239 gdbarch = get_current_regcache ()->arch ();
241 gdbarch = target_gdbarch ();
243 switch (what_to_dump)
245 case regcache_dump_none:
246 dump.reset (new register_dump_none (gdbarch));
248 case regcache_dump_remote:
249 dump.reset (new register_dump_remote (gdbarch));
251 case regcache_dump_groups:
252 dump.reset (new register_dump_groups (gdbarch));
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 (),
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 (),
278 maintenance_print_registers (const char *args, int from_tty)
280 regcache_print (args, regcache_dump_none);
284 maintenance_print_raw_registers (const char *args, int from_tty)
286 regcache_print (args, regcache_dump_raw);
290 maintenance_print_cooked_registers (const char *args, int from_tty)
292 regcache_print (args, regcache_dump_cooked);
296 maintenance_print_register_groups (const char *args, int from_tty)
298 regcache_print (args, regcache_dump_groups);
302 maintenance_print_remote_registers (const char *args, int from_tty)
304 regcache_print (args, regcache_dump_remote);
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);