#include "gdb_string.h"
#include "gdbcmd.h" /* For maintenanceprintlist. */
#include "observer.h"
+#include "exceptions.h"
+#include "remote.h"
/*
* DATA STRUCTURE
{
if (gdbarch_register_reggroup_p (gdbarch, regnum, save_reggroup))
{
- int valid = cooked_read (src, regnum, buf);
+ enum register_status status = cooked_read (src, regnum, buf);
- if (valid)
+ if (status == REG_VALID)
+ memcpy (register_buffer (dst, regnum), buf,
+ register_size (gdbarch, regnum));
+ else
{
- memcpy (register_buffer (dst, regnum), buf,
+ gdb_assert (status != REG_UNKNOWN);
+
+ memset (register_buffer (dst, regnum), 0,
register_size (gdbarch, regnum));
- dst->register_status[regnum] = REG_VALID;
}
+ dst->register_status[regnum] = status;
}
}
}
}
}
-static int
+static enum register_status
do_cooked_read (void *src, int regnum, gdb_byte *buf)
{
struct regcache *regcache = src;
- if (regcache->register_status[regnum] == REG_UNKNOWN && regcache->readonly_p)
- /* Don't even think about fetching a register from a read-only
- cache when the register isn't yet valid. There isn't a target
- from which the register value can be fetched. */
- return 0;
- regcache_cooked_read (regcache, regnum, buf);
- return 1;
+ return regcache_cooked_read (regcache, regnum, buf);
}
-
void
regcache_cpy (struct regcache *dst, struct regcache *src)
{
{
struct regcache_list *list;
struct regcache *new_regcache;
+ struct address_space *aspace;
for (list = current_regcache; list; list = list->next)
if (ptid_equal (list->regcache->ptid, ptid)
&& get_regcache_arch (list->regcache) == gdbarch)
return list->regcache;
- new_regcache = regcache_xmalloc_1 (gdbarch,
- target_thread_address_space (ptid), 0);
+ /* For the benefit of "maint print registers" & co when debugging an
+ executable, allow dumping the regcache even when there is no
+ thread selected (target_thread_address_space internal-errors if
+ no address space is found). Note that normal user commands will
+ fail higher up on the call stack due to no
+ target_has_registers. */
+ aspace = (ptid_equal (null_ptid, ptid)
+ ? NULL
+ : target_thread_address_space (ptid));
+
+ new_regcache = regcache_xmalloc_1 (gdbarch, aspace, 0);
new_regcache->ptid = ptid;
- gdb_assert (new_regcache->aspace != NULL);
list = xmalloc (sizeof (struct regcache_list));
list->regcache = new_regcache;
alloca (0);
}
-void
+enum register_status
regcache_raw_read (struct regcache *regcache, int regnum, gdb_byte *buf)
{
gdb_assert (regcache != NULL && buf != NULL);
to the current thread. This switching shouldn't be necessary
only there is still only one target side register cache. Sigh!
On the bright side, at least there is a regcache object. */
- if (!regcache->readonly_p)
+ if (!regcache->readonly_p
+ && regcache_register_status (regcache, regnum) == REG_UNKNOWN)
{
- if (regcache_register_status (regcache, regnum) == REG_UNKNOWN)
- {
- struct cleanup *old_chain = save_inferior_ptid ();
+ struct cleanup *old_chain = save_inferior_ptid ();
- inferior_ptid = regcache->ptid;
- target_fetch_registers (regcache, regnum);
- do_cleanups (old_chain);
- }
-#if 0
- /* FIXME: cagney/2004-08-07: At present a number of targets
- forget (or didn't know that they needed) to set this leading to
- panics. Also is the problem that targets need to indicate
- that a register is in one of the possible states: valid,
- undefined, unknown. The last of which isn't yet
- possible. */
- gdb_assert (regcache_register_status (regcache, regnum) == REG_VALID);
-#endif
+ inferior_ptid = regcache->ptid;
+ target_fetch_registers (regcache, regnum);
+ do_cleanups (old_chain);
+
+ /* A number of targets can't access the whole set of raw
+ registers (because the debug API provides no means to get at
+ them). */
+ if (regcache->register_status[regnum] == REG_UNKNOWN)
+ regcache->register_status[regnum] = REG_UNAVAILABLE;
}
- /* Copy the value directly into the register cache. */
- memcpy (buf, register_buffer (regcache, regnum),
- regcache->descr->sizeof_register[regnum]);
+
+ if (regcache->register_status[regnum] != REG_VALID)
+ memset (buf, 0, regcache->descr->sizeof_register[regnum]);
+ else
+ memcpy (buf, register_buffer (regcache, regnum),
+ regcache->descr->sizeof_register[regnum]);
+
+ return regcache->register_status[regnum];
}
-void
+enum register_status
regcache_raw_read_signed (struct regcache *regcache, int regnum, LONGEST *val)
{
gdb_byte *buf;
+ enum register_status status;
gdb_assert (regcache != NULL);
gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
buf = alloca (regcache->descr->sizeof_register[regnum]);
- regcache_raw_read (regcache, regnum, buf);
- (*val) = extract_signed_integer
- (buf, regcache->descr->sizeof_register[regnum],
- gdbarch_byte_order (regcache->descr->gdbarch));
+ status = regcache_raw_read (regcache, regnum, buf);
+ if (status == REG_VALID)
+ *val = extract_signed_integer
+ (buf, regcache->descr->sizeof_register[regnum],
+ gdbarch_byte_order (regcache->descr->gdbarch));
+ else
+ *val = 0;
+ return status;
}
-void
+enum register_status
regcache_raw_read_unsigned (struct regcache *regcache, int regnum,
ULONGEST *val)
{
gdb_byte *buf;
+ enum register_status status;
gdb_assert (regcache != NULL);
gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
buf = alloca (regcache->descr->sizeof_register[regnum]);
- regcache_raw_read (regcache, regnum, buf);
- (*val) = extract_unsigned_integer
- (buf, regcache->descr->sizeof_register[regnum],
- gdbarch_byte_order (regcache->descr->gdbarch));
+ status = regcache_raw_read (regcache, regnum, buf);
+ if (status == REG_VALID)
+ *val = extract_unsigned_integer
+ (buf, regcache->descr->sizeof_register[regnum],
+ gdbarch_byte_order (regcache->descr->gdbarch));
+ else
+ *val = 0;
+ return status;
}
void
regcache_raw_write (regcache, regnum, buf);
}
-void
+enum register_status
regcache_cooked_read (struct regcache *regcache, int regnum, gdb_byte *buf)
{
gdb_assert (regnum >= 0);
gdb_assert (regnum < regcache->descr->nr_cooked_registers);
if (regnum < regcache->descr->nr_raw_registers)
- regcache_raw_read (regcache, regnum, buf);
+ return regcache_raw_read (regcache, regnum, buf);
else if (regcache->readonly_p
- && regnum < regcache->descr->nr_cooked_registers
- && regcache->register_status[regnum] == REG_VALID)
- /* Read-only register cache, and the cooked value was cached. */
- memcpy (buf, register_buffer (regcache, regnum),
- regcache->descr->sizeof_register[regnum]);
+ && regcache->register_status[regnum] != REG_UNKNOWN)
+ {
+ /* Read-only register cache, perhaps the cooked value was
+ cached? */
+ struct gdbarch *gdbarch = regcache->descr->gdbarch;
+
+ if (regcache->register_status[regnum] == REG_VALID)
+ memcpy (buf, register_buffer (regcache, regnum),
+ regcache->descr->sizeof_register[regnum]);
+ else
+ memset (buf, 0, regcache->descr->sizeof_register[regnum]);
+
+ return regcache->register_status[regnum];
+ }
else
- gdbarch_pseudo_register_read (regcache->descr->gdbarch, regcache,
- regnum, buf);
+ return gdbarch_pseudo_register_read (regcache->descr->gdbarch, regcache,
+ regnum, buf);
}
-void
+enum register_status
regcache_cooked_read_signed (struct regcache *regcache, int regnum,
LONGEST *val)
{
+ enum register_status status;
gdb_byte *buf;
gdb_assert (regcache != NULL);
gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_cooked_registers);
buf = alloca (regcache->descr->sizeof_register[regnum]);
- regcache_cooked_read (regcache, regnum, buf);
- (*val) = extract_signed_integer
- (buf, regcache->descr->sizeof_register[regnum],
- gdbarch_byte_order (regcache->descr->gdbarch));
+ status = regcache_cooked_read (regcache, regnum, buf);
+ if (status == REG_VALID)
+ *val = extract_signed_integer
+ (buf, regcache->descr->sizeof_register[regnum],
+ gdbarch_byte_order (regcache->descr->gdbarch));
+ else
+ *val = 0;
+ return status;
}
-void
+enum register_status
regcache_cooked_read_unsigned (struct regcache *regcache, int regnum,
ULONGEST *val)
{
+ enum register_status status;
gdb_byte *buf;
gdb_assert (regcache != NULL);
gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_cooked_registers);
buf = alloca (regcache->descr->sizeof_register[regnum]);
- regcache_cooked_read (regcache, regnum, buf);
- (*val) = extract_unsigned_integer
- (buf, regcache->descr->sizeof_register[regnum],
- gdbarch_byte_order (regcache->descr->gdbarch));
+ status = regcache_cooked_read (regcache, regnum, buf);
+ if (status == REG_VALID)
+ *val = extract_unsigned_integer
+ (buf, regcache->descr->sizeof_register[regnum],
+ gdbarch_byte_order (regcache->descr->gdbarch));
+ else
+ *val = 0;
+ return status;
}
void
typedef void (regcache_write_ftype) (struct regcache *regcache, int regnum,
const void *buf);
-static void
+static enum register_status
regcache_xfer_part (struct regcache *regcache, int regnum,
int offset, int len, void *in, const void *out,
- void (*read) (struct regcache *regcache, int regnum,
- gdb_byte *buf),
+ enum register_status (*read) (struct regcache *regcache,
+ int regnum,
+ gdb_byte *buf),
void (*write) (struct regcache *regcache, int regnum,
const gdb_byte *buf))
{
gdb_assert (len >= 0 && offset + len <= descr->sizeof_register[regnum]);
/* Something to do? */
if (offset + len == 0)
- return;
+ return REG_VALID;
/* Read (when needed) ... */
if (in != NULL
|| offset > 0
|| offset + len < descr->sizeof_register[regnum])
{
+ enum register_status status;
+
gdb_assert (read != NULL);
- read (regcache, regnum, reg);
+ status = read (regcache, regnum, reg);
+ if (status != REG_VALID)
+ return status;
}
/* ... modify ... */
if (in != NULL)
gdb_assert (write != NULL);
write (regcache, regnum, reg);
}
+
+ return REG_VALID;
}
-void
+enum register_status
regcache_raw_read_part (struct regcache *regcache, int regnum,
int offset, int len, gdb_byte *buf)
{
struct regcache_descr *descr = regcache->descr;
gdb_assert (regnum >= 0 && regnum < descr->nr_raw_registers);
- regcache_xfer_part (regcache, regnum, offset, len, buf, NULL,
- regcache_raw_read, regcache_raw_write);
+ return regcache_xfer_part (regcache, regnum, offset, len, buf, NULL,
+ regcache_raw_read, regcache_raw_write);
}
void
regcache_raw_read, regcache_raw_write);
}
-void
+enum register_status
regcache_cooked_read_part (struct regcache *regcache, int regnum,
int offset, int len, gdb_byte *buf)
{
struct regcache_descr *descr = regcache->descr;
gdb_assert (regnum >= 0 && regnum < descr->nr_cooked_registers);
- regcache_xfer_part (regcache, regnum, offset, len, buf, NULL,
- regcache_cooked_read, regcache_cooked_write);
+ return regcache_xfer_part (regcache, regnum, offset, len, buf, NULL,
+ regcache_cooked_read, regcache_cooked_write);
}
void
{
ULONGEST raw_val;
- regcache_cooked_read_unsigned (regcache,
- gdbarch_pc_regnum (gdbarch),
- &raw_val);
+ if (regcache_cooked_read_unsigned (regcache,
+ gdbarch_pc_regnum (gdbarch),
+ &raw_val) == REG_UNAVAILABLE)
+ throw_error (NOT_AVAILABLE_ERROR, _("PC register is not available"));
+
pc_val = gdbarch_addr_bits_remove (gdbarch, raw_val);
}
else
enum regcache_dump_what
{
regcache_dump_none, regcache_dump_raw,
- regcache_dump_cooked, regcache_dump_groups
+ regcache_dump_cooked, regcache_dump_groups,
+ regcache_dump_remote
};
static void
fprintf_unfiltered (file, "Cooked value");
else
{
- /* FIXME: no way for cooked reads to signal unavailable
- yet. */
- regcache_cooked_read (regcache, regnum, buf);
- fprintf_unfiltered (file, "0x");
- dump_endian_bytes (file,
- gdbarch_byte_order (gdbarch), buf,
- regcache->descr->sizeof_register[regnum]);
+ enum register_status status;
+
+ status = regcache_cooked_read (regcache, regnum, buf);
+ if (status == REG_UNKNOWN)
+ fprintf_unfiltered (file, "<invalid>");
+ else if (status == REG_UNAVAILABLE)
+ fprintf_unfiltered (file, "<unavailable>");
+ else
+ {
+ fprintf_unfiltered (file, "0x");
+ dump_endian_bytes (file,
+ gdbarch_byte_order (gdbarch), buf,
+ regcache->descr->sizeof_register[regnum]);
+ }
}
}
}
}
+ /* Remote packet configuration. */
+ if (what_to_dump == regcache_dump_remote)
+ {
+ if (regnum < 0)
+ {
+ fprintf_unfiltered (file, "Rmt Nr g/G Offset");
+ }
+ else if (regnum < regcache->descr->nr_raw_registers)
+ {
+ int pnum, poffset;
+
+ if (remote_register_number_and_offset (get_regcache_arch (regcache), regnum,
+ &pnum, &poffset))
+ fprintf_unfiltered (file, "%7d %11d", pnum, poffset);
+ }
+ }
+
fprintf_unfiltered (file, "\n");
}
regcache_print (args, regcache_dump_groups);
}
+static void
+maintenance_print_remote_registers (char *args, int from_tty)
+{
+ regcache_print (args, regcache_dump_remote);
+}
+
extern initialize_file_ftype _initialize_regcache; /* -Wmissing-prototype */
void
"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 including each register's\n\
+remote register number and buffer offset in the g/G packets.\n\
+Takes an optional file parameter."),
+ &maintenanceprintlist);
}