2002-08-09 Andrew Cagney <cagney@redhat.com>

* regcache.c: Include "gdbcmd.h"
(_initialize_regcache): Add commands "maintenance print
registers", "maintenance print raw-registers" and "maintenance
print cooked-registers".
(enum regcache_dump_what): Define.
(dump_endian_bytes): New function.
(regcache_dump): New function.
(regcache_print): New function.
(maintenance_print_registers): New function.
(maintenance_print_raw_registers): New function.
(maintenance_print_cooked_registers): New function.
* Makefile.in (regcache.o): Update dependencies.
This commit is contained in:
Andrew Cagney 2002-08-10 00:36:46 +00:00
parent cb3d25d11f
commit af030b9af8
5 changed files with 283 additions and 2 deletions

View File

@ -1,3 +1,18 @@
2002-08-09 Andrew Cagney <cagney@redhat.com>
* regcache.c: Include "gdbcmd.h"
(_initialize_regcache): Add commands "maintenance print
registers", "maintenance print raw-registers" and "maintenance
print cooked-registers".
(enum regcache_dump_what): Define.
(dump_endian_bytes): New function.
(regcache_dump): New function.
(regcache_print): New function.
(maintenance_print_registers): New function.
(maintenance_print_raw_registers): New function.
(maintenance_print_cooked_registers): New function.
* Makefile.in (regcache.o): Update dependencies.
2002-08-09 Michael Snyder <msnyder@redhat.com>
* mips-tdep.c (ROUND_DOWN, ROUND_UP): Move to global scope.

View File

@ -1495,7 +1495,7 @@ frv-tdep.o: frv-tdep.c $(defs_h) $(inferior_h) $(symfile_h) $(gdbcore_h) \
$(arch_utils_h) $(regcache_h)
regcache.o: regcache.c $(defs_h) $(inferior_h) $(target_h) $(gdbarch_h) \
$(gdbcmd_h) $(regcache_h) $(gdb_assert_h) $(gdb_string_h)
$(gdbcmd_h) $(regcache_h) $(gdb_assert_h) $(gdb_string_h) $(gdbcmd_h)
fork-child.o: fork-child.c $(gdb_wait_h) $(defs_h) $(gdbcore_h) \
$(inferior_h) $(target_h) $(terminal_h) $(gdbthread_h) $(gdb_string_h)

View File

@ -1,10 +1,15 @@
2002-08-09 Andrew Cagney <cagney@redhat.com>
* gdb.texinfo (Maintenance Commands): Document "maint print
registers", "maint print raw-registers" and "maint print
cooked-registers".
2002-08-08 Grace Sainsbury <graces@redhat.com>
From Mark Salter:
* gdb.texinfo (Protocol): Document T packet extension to
allow watchpoint address reporting.
2002-08-03 Andrew Cagney <ac131313@redhat.com>
* gdb.texinfo (Dump/Restore Files): Move `[]' to outside of @var.

View File

@ -14195,6 +14195,18 @@ Shared library events.
@end table
@kindex maint print registers
@kindex maint print raw-registers
@kindex maint print cooked-registers
@item @anchor{maint print registers}maint print registers
@itemx @anchor{maint print raw-registers}maint print raw-registers
@itemx @anchor{maint print cooked-registers}maint print cooked-registers
Print @value{GDBN}'s internal register structure. @samp{maint print
raw-registers} includes the raw register cache value while @samp{maint
print cooked-registers} includes the cooked register value.
Takes an optional file parameter.
@end table

View File

@ -28,6 +28,7 @@
#include "regcache.h"
#include "gdb_assert.h"
#include "gdb_string.h"
#include "gdbcmd.h" /* For maintenanceprintlist. */
/*
* DATA STRUCTURE
@ -1185,6 +1186,237 @@ build_regcache (void)
register_valid = deprecated_grub_regcache_for_register_valid (current_regcache);
}
static void
dump_endian_bytes (struct ui_file *file, enum bfd_endian endian,
const unsigned char *buf, long len)
{
int i;
switch (endian)
{
case BFD_ENDIAN_BIG:
for (i = 0; i < len; i++)
fprintf_unfiltered (file, "%02x", buf[i]);
break;
case BFD_ENDIAN_LITTLE:
for (i = len - 1; i >= 0; i--)
fprintf_unfiltered (file, "%02x", buf[i]);
break;
default:
internal_error (__FILE__, __LINE__, "Bad switch");
}
}
enum regcache_dump_what
{
regcache_dump_none, regcache_dump_raw, regcache_dump_cooked
};
static void
regcache_dump (struct regcache *regcache, struct ui_file *file,
enum regcache_dump_what what_to_dump)
{
struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
int regnum;
int footnote_nr = 0;
int footnote_register_size = 0;
int footnote_register_offset = 0;
int footnote_register_type_name_null = 0;
long register_offset = 0;
unsigned char *buf = alloca (regcache->descr->max_register_size);
#if 0
fprintf_unfiltered (file, "legacy_p %d\n", regcache->descr->legacy_p);
fprintf_unfiltered (file, "nr_raw_registers %d\n",
regcache->descr->nr_raw_registers);
fprintf_unfiltered (file, "nr_cooked_registers %d\n",
regcache->descr->nr_cooked_registers);
fprintf_unfiltered (file, "sizeof_raw_registers %ld\n",
regcache->descr->sizeof_raw_registers);
fprintf_unfiltered (file, "sizeof_raw_register_valid_p %ld\n",
regcache->descr->sizeof_raw_register_valid_p);
fprintf_unfiltered (file, "max_register_size %ld\n",
regcache->descr->max_register_size);
fprintf_unfiltered (file, "NUM_REGS %d\n", NUM_REGS);
fprintf_unfiltered (file, "NUM_PSEUDO_REGS %d\n", NUM_PSEUDO_REGS);
#endif
gdb_assert (regcache->descr->nr_cooked_registers
== (NUM_REGS + NUM_PSEUDO_REGS));
for (regnum = -1; regnum < regcache->descr->nr_cooked_registers; regnum++)
{
/* Name. */
if (regnum < 0)
fprintf_unfiltered (file, " %-10s", "Name");
else
{
const char *p = REGISTER_NAME (regnum);
if (p == NULL)
p = "";
else if (p[0] == '\0')
p = "''";
fprintf_unfiltered (file, " %-10s", p);
}
/* Number. */
if (regnum < 0)
fprintf_unfiltered (file, " %4s", "Nr");
else
fprintf_unfiltered (file, " %4d", regnum);
/* Relative number. */
if (regnum < 0)
fprintf_unfiltered (file, " %4s", "Rel");
else if (regnum < NUM_REGS)
fprintf_unfiltered (file, " %4d", regnum);
else
fprintf_unfiltered (file, " %4d", (regnum - NUM_REGS));
/* Offset. */
if (regnum < 0)
fprintf_unfiltered (file, " %6s ", "Offset");
else
{
fprintf_unfiltered (file, " %6ld",
regcache->descr->register_offset[regnum]);
if (register_offset != regcache->descr->register_offset[regnum])
{
if (!footnote_register_offset)
footnote_register_offset = ++footnote_nr;
fprintf_unfiltered (file, "*%d", footnote_register_offset);
}
else
fprintf_unfiltered (file, " ");
register_offset = (regcache->descr->register_offset[regnum]
+ regcache->descr->sizeof_register[regnum]);
}
/* Size. */
if (regnum < 0)
fprintf_unfiltered (file, " %5s ", "Size");
else
{
fprintf_unfiltered (file, " %5ld",
regcache->descr->sizeof_register[regnum]);
if ((regcache->descr->sizeof_register[regnum]
!= REGISTER_RAW_SIZE (regnum))
|| (regcache->descr->sizeof_register[regnum]
!= REGISTER_VIRTUAL_SIZE (regnum))
|| (regcache->descr->sizeof_register[regnum]
!= TYPE_LENGTH (REGISTER_VIRTUAL_TYPE (regnum)))
)
{
if (!footnote_register_size)
footnote_register_size = ++footnote_nr;
fprintf_unfiltered (file, "*%d", footnote_register_size);
}
else
fprintf_unfiltered (file, " ");
}
/* Type. */
if (regnum < 0)
fprintf_unfiltered (file, " %-20s", "Type");
else
{
static const char blt[] = "builtin_type";
const char *t = TYPE_NAME (REGISTER_VIRTUAL_TYPE (regnum));
if (t == NULL)
{
char *n;
if (!footnote_register_type_name_null)
footnote_register_type_name_null = ++footnote_nr;
xasprintf (&n, "*%d", footnote_register_type_name_null);
make_cleanup (xfree, n);
t = n;
}
/* Chop a leading builtin_type. */
if (strncmp (t, blt, strlen (blt)) == 0)
t += strlen (blt);
fprintf_unfiltered (file, " %-20s", t);
}
/* Value, raw. */
if (what_to_dump == regcache_dump_raw)
{
if (regnum < 0)
fprintf_unfiltered (file, "Raw value");
else if (regnum >= regcache->descr->nr_raw_registers)
fprintf_unfiltered (file, "<cooked>");
else if (!regcache_valid_p (regcache, regnum))
fprintf_unfiltered (file, "<invalid>");
else
{
regcache_raw_read (regcache, regnum, buf);
fprintf_unfiltered (file, "0x");
dump_endian_bytes (file, TARGET_BYTE_ORDER, buf,
REGISTER_RAW_SIZE (regnum));
}
}
/* Value, cooked. */
if (what_to_dump == regcache_dump_cooked)
{
if (regnum < 0)
fprintf_unfiltered (file, "Cooked value");
else
{
regcache_cooked_read (regcache, regnum, buf);
fprintf_unfiltered (file, "0x");
dump_endian_bytes (file, TARGET_BYTE_ORDER, buf,
REGISTER_VIRTUAL_SIZE (regnum));
}
}
fprintf_unfiltered (file, "\n");
}
if (footnote_register_size)
fprintf_unfiltered (file, "*%d: Inconsistent register sizes.\n",
footnote_register_size);
if (footnote_register_offset)
fprintf_unfiltered (file, "*%d: Inconsistent register offsets.\n",
footnote_register_offset);
if (footnote_register_type_name_null)
fprintf_unfiltered (file,
"*%d: Register type's name NULL.\n",
footnote_register_type_name_null);
do_cleanups (cleanups);
}
static void
regcache_print (char *args, enum regcache_dump_what what_to_dump)
{
if (args == NULL)
regcache_dump (current_regcache, gdb_stdout, what_to_dump);
else
{
struct ui_file *file = gdb_fopen (args, "w");
if (file == NULL)
perror_with_name ("maintenance print architecture");
regcache_dump (current_regcache, file, what_to_dump);
ui_file_delete (file);
}
}
static void
maintenance_print_registers (char *args, int from_tty)
{
regcache_print (args, regcache_dump_none);
}
static void
maintenance_print_raw_registers (char *args, int from_tty)
{
regcache_print (args, regcache_dump_raw);
}
static void
maintenance_print_cooked_registers (char *args, int from_tty)
{
regcache_print (args, regcache_dump_cooked);
}
void
_initialize_regcache (void)
{
@ -1201,4 +1433,21 @@ _initialize_regcache (void)
/* Initialize the thread/process associated with the current set of
registers. For now, -1 is special, and means `no current process'. */
registers_ptid = pid_to_ptid (-1);
add_cmd ("registers", class_maintenance,
maintenance_print_registers,
"Print the internal register configuration.\
Takes an optional file parameter.",
&maintenanceprintlist);
add_cmd ("raw-registers", class_maintenance,
maintenance_print_raw_registers,
"Print the internal register configuration including raw values.\
Takes an optional file parameter.",
&maintenanceprintlist);
add_cmd ("cooked-registers", class_maintenance,
maintenance_print_cooked_registers,
"Print the internal register configuration including cooked values.\
Takes an optional file parameter.",
&maintenanceprintlist);
}