1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380
|
/* Copyright (C) 1986-2024 Free Software Foundation, Inc.
This file is part of GDB.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include "cli/cli-cmds.h"
#include "regcache.h"
#include "gdbsupport/def-vector.h"
#include "valprint.h"
#include "remote.h"
#include "reggroups.h"
#include "target.h"
#include "gdbarch.h"
#include "inferior.h"
/* Dump registers from regcache, used for dumping raw registers and
cooked registers. */
class register_dump_regcache : public register_dump
{
public:
register_dump_regcache (regcache *regcache, bool dump_pseudo)
: register_dump (regcache->arch ()), m_regcache (regcache),
m_dump_pseudo (dump_pseudo)
{
}
protected:
int num_additional_headers () override
{ return 1; }
void additional_headers (ui_out *out) override
{
out->table_header (0, ui_left, "value",
m_dump_pseudo ? "Cooked value" : "Raw value");
}
void dump_reg (ui_out *out, int regnum) override
{
if (regnum < gdbarch_num_regs (m_gdbarch) || m_dump_pseudo)
{
auto size = register_size (m_gdbarch, regnum);
if (size == 0)
return;
gdb::byte_vector buf (size);
auto status = m_regcache->cooked_read (regnum, buf.data ());
if (status == REG_UNKNOWN)
out->field_string ("value", "<invalid>");
else if (status == REG_UNAVAILABLE)
out->field_string ("value", "<unavailable>");
else
{
string_file str;
print_hex_chars (&str, buf.data (), size,
gdbarch_byte_order (m_gdbarch), true);
out->field_stream ("value", str);
}
}
else
{
/* Just print "<cooked>" for pseudo register when
regcache_dump_raw. */
out->field_string ("value", "<cooked>");
}
}
private:
regcache *m_regcache;
/* Dump pseudo registers or not. */
const bool m_dump_pseudo;
};
/* Dump from reg_buffer, used when there is no thread or
registers. */
class register_dump_reg_buffer : public register_dump, reg_buffer
{
public:
register_dump_reg_buffer (gdbarch *gdbarch, bool dump_pseudo)
: register_dump (gdbarch), reg_buffer (gdbarch, dump_pseudo)
{
}
protected:
int num_additional_headers () override
{ return 1; }
void additional_headers (ui_out *out) override
{
out->table_header (0, ui_left, "value",
m_has_pseudo ? "Cooked value" : "Raw value");
}
void dump_reg (ui_out *out, int regnum) override
{
if (regnum < gdbarch_num_regs (m_gdbarch) || m_has_pseudo)
{
auto size = register_size (m_gdbarch, regnum);
if (size == 0)
return;
auto status = get_register_status (regnum);
gdb_assert (status != REG_VALID);
if (status == REG_UNKNOWN)
out->field_string ("value", "<invalid>");
else
out->field_string ("value", "<unavailable>");
}
else
{
/* Just print "<cooked>" for pseudo register when
regcache_dump_raw. */
out->field_string ("value", "<cooked>");
}
}
};
/* For "maint print registers". */
class register_dump_none : public register_dump
{
public:
register_dump_none (gdbarch *arch)
: register_dump (arch)
{}
protected:
int num_additional_headers () override
{ return 0; }
void additional_headers (ui_out *out) override
{ }
void dump_reg (ui_out *out, int regnum) override
{}
};
/* For "maint print remote-registers". */
class register_dump_remote : public register_dump
{
public:
register_dump_remote (gdbarch *arch)
: register_dump (arch)
{}
protected:
int num_additional_headers () override
{ return 3; }
void additional_headers (ui_out *out) override
{
out->table_header (7, ui_left, "remnum", "Rmt Nr");
out->table_header (11, ui_left, "goffset", "g/G Offset");
out->table_header (3, ui_left, "expedited", "Expedited");
}
void dump_reg (ui_out *out, int regnum) override
{
int pnum, poffset;
if (regnum < gdbarch_num_regs (m_gdbarch)
&& remote_register_number_and_offset (m_gdbarch, regnum,
&pnum, &poffset))
{
out->field_signed ("remnum", pnum);
out->field_signed ("goffset", poffset);
if (remote_register_is_expedited (regnum))
out->field_string ("expedited", "yes");
else
out->field_skip ("expedited");
}
else
{
out->field_skip ("remnum");
out->field_skip ("goffset");
out->field_skip ("expedited");
}
}
};
/* For "maint print register-groups". */
class register_dump_groups : public register_dump
{
public:
register_dump_groups (gdbarch *arch)
: register_dump (arch)
{}
protected:
int num_additional_headers () override
{ return 1; }
void additional_headers (ui_out *out) override
{
out->table_header (0, ui_left, "groups", "Groups");
}
void dump_reg (ui_out *out, int regnum) override
{
string_file file;
const char *sep = "";
for (const struct reggroup *group : gdbarch_reggroups (m_gdbarch))
{
if (gdbarch_register_reggroup_p (m_gdbarch, regnum, group))
{
gdb_printf (&file, "%s%s", sep, group->name ());
sep = ",";
}
}
out->field_stream ("groups", file);
}
};
enum regcache_dump_what
{
regcache_dump_none, regcache_dump_raw,
regcache_dump_cooked, regcache_dump_groups,
regcache_dump_remote
};
/* Helper for the various maint commands that print registers. ARGS
is the arguments passed to the command. WHAT_TO_DUMP indicates
exactly which registers to display. COMMAND is the command name,
used in error messages. */
static void
regcache_print (const char *args, enum regcache_dump_what what_to_dump,
const char *command)
{
/* Where to send output. */
stdio_file file;
std::optional<ui_out_redirect_pop> redirect;
if (args != nullptr)
{
if (!file.open (args, "w"))
perror_with_name (command);
redirect.emplace (current_uiout, &file);
}
std::unique_ptr<register_dump> dump;
std::unique_ptr<regcache> regs;
gdbarch *gdbarch;
if (target_has_registers ())
gdbarch = get_thread_regcache (inferior_thread ())->arch ();
else
gdbarch = current_inferior ()->arch ();
const char *name;
switch (what_to_dump)
{
case regcache_dump_none:
dump = std::make_unique<register_dump_none> (gdbarch);
name = "Registers";
break;
case regcache_dump_remote:
dump = std::make_unique<register_dump_remote> (gdbarch);
name = "RegisterRemote";
break;
case regcache_dump_groups:
dump = std::make_unique<register_dump_groups> (gdbarch);
name = "RegisterGroups";
break;
case regcache_dump_raw:
case regcache_dump_cooked:
{
name = "RegisterDump";
auto dump_pseudo = (what_to_dump == regcache_dump_cooked);
if (target_has_registers ())
dump = (std::make_unique<register_dump_regcache>
(get_thread_regcache (inferior_thread ()), dump_pseudo));
else
{
/* For the benefit of "maint print registers" & co when
debugging an executable, allow dumping a regcache even when
there is no thread selected / no registers. */
dump = std::make_unique<register_dump_reg_buffer> (gdbarch,
dump_pseudo);
}
}
break;
}
dump->dump (current_uiout, name);
}
static void
maintenance_print_registers (const char *args, int from_tty)
{
regcache_print (args, regcache_dump_none, "maintenance print registers");
}
static void
maintenance_print_raw_registers (const char *args, int from_tty)
{
regcache_print (args, regcache_dump_raw, "maintenance print raw-registers");
}
static void
maintenance_print_cooked_registers (const char *args, int from_tty)
{
regcache_print (args, regcache_dump_cooked,
"maintenance print cooked-registers");
}
static void
maintenance_print_register_groups (const char *args, int from_tty)
{
regcache_print (args, regcache_dump_groups,
"maintenance print register-groups");
}
static void
maintenance_print_remote_registers (const char *args, int from_tty)
{
regcache_print (args, regcache_dump_remote,
"maintenance print remote-registers");
}
void _initialize_regcache_dump ();
void
_initialize_regcache_dump ()
{
add_cmd ("registers", class_maintenance, maintenance_print_registers,
_("Print the internal register configuration.\n"
"Takes an optional file parameter."), &maintenanceprintlist);
add_cmd ("raw-registers", class_maintenance,
maintenance_print_raw_registers,
_("Print the internal register configuration "
"including raw values.\n"
"Takes an optional file parameter."), &maintenanceprintlist);
add_cmd ("cooked-registers", class_maintenance,
maintenance_print_cooked_registers,
_("Print the internal register configuration "
"including cooked values.\n"
"Takes an optional file parameter."), &maintenanceprintlist);
add_cmd ("register-groups", class_maintenance,
maintenance_print_register_groups,
_("Print the internal register configuration "
"including each register's group.\n"
"Takes an optional file parameter."),
&maintenanceprintlist);
add_cmd ("remote-registers", class_maintenance,
maintenance_print_remote_registers, _("\
Print the internal register configuration.\n\
Usage: maintenance print remote-registers [FILE]\n\
The remote register number and g/G packets offset are included,\n\
as well as which registers were sent in the last stop reply packet\n\
(i.e., expedited)."),
&maintenanceprintlist);
}
|