#include <stdlib.h>
#include <string.h>
-/* The private data for the register cache. Note that we have one
- per inferior; this is primarily for simplicity, as the performance
- benefit is minimal. */
-
-struct inferior_regcache_data
-{
- int registers_valid;
- unsigned char *registers;
-};
-
static int register_bytes;
static struct reg *reg_defs;
const char **gdbserver_expedite_regs;
-static struct inferior_regcache_data *
-get_regcache (struct thread_info *inf, int fetch)
+struct regcache *
+get_thread_regcache (struct thread_info *thread, int fetch)
{
- struct inferior_regcache_data *regcache;
+ struct regcache *regcache;
- regcache = (struct inferior_regcache_data *) inferior_regcache_data (inf);
+ regcache = (struct regcache *) inferior_regcache_data (thread);
if (regcache == NULL)
fatal ("no register cache");
- /* FIXME - fetch registers for INF */
if (fetch && regcache->registers_valid == 0)
{
- fetch_inferior_registers (-1);
+ struct thread_info *saved_inferior = current_inferior;
+
+ current_inferior = thread;
+ fetch_inferior_registers (regcache, -1);
+ current_inferior = saved_inferior;
regcache->registers_valid = 1;
}
regcache_invalidate_one (struct inferior_list_entry *entry)
{
struct thread_info *thread = (struct thread_info *) entry;
- struct inferior_regcache_data *regcache;
+ struct regcache *regcache;
- regcache = (struct inferior_regcache_data *) inferior_regcache_data (thread);
+ regcache = (struct regcache *) inferior_regcache_data (thread);
if (regcache->registers_valid)
{
struct thread_info *saved_inferior = current_inferior;
current_inferior = thread;
- store_inferior_registers (-1);
+ store_inferior_registers (regcache, -1);
current_inferior = saved_inferior;
}
}
void
-regcache_invalidate ()
+regcache_invalidate (void)
{
for_each_inferior (&all_threads, regcache_invalidate_one);
}
-void *
+struct regcache *
new_register_cache (void)
{
- struct inferior_regcache_data *regcache;
+ struct regcache *regcache;
if (register_bytes == 0)
return NULL; /* The architecture hasn't been initialized yet. */
regcache = xmalloc (sizeof (*regcache));
- /* Make sure to zero-initialize the register cache when it is created,
- in case there are registers the target never fetches. This way they'll
- read as zero instead of garbage. */
+ /* Make sure to zero-initialize the register cache when it is
+ created, in case there are registers the target never
+ fetches. This way they'll read as zero instead of
+ garbage. */
regcache->registers = xcalloc (1, register_bytes);
regcache->registers_valid = 0;
}
void
-free_register_cache (void *regcache_p)
+free_register_cache (struct regcache *regcache)
{
- struct inferior_regcache_data *regcache
- = (struct inferior_regcache_data *) regcache_p;
-
if (regcache)
{
free (regcache->registers);
realloc_register_cache (struct inferior_list_entry *thread_p)
{
struct thread_info *thread = (struct thread_info *) thread_p;
+ struct regcache *regcache
+ = (struct regcache *) inferior_regcache_data (thread);
- free_register_cache (inferior_regcache_data (thread));
+ free_register_cache (regcache);
set_inferior_regcache_data (thread, new_register_cache ());
}
}
void
-registers_to_string (char *buf)
+registers_to_string (struct regcache *regcache, char *buf)
{
- unsigned char *registers = get_regcache (current_inferior, 1)->registers;
+ unsigned char *registers = regcache->registers;
convert_int_to_ascii (registers, buf, register_bytes);
}
void
-registers_from_string (char *buf)
+registers_from_string (struct regcache *regcache, char *buf)
{
int len = strlen (buf);
- unsigned char *registers = get_regcache (current_inferior, 1)->registers;
+ unsigned char *registers = regcache->registers;
if (len != register_bytes * 2)
{
}
static unsigned char *
-register_data (int n, int fetch)
+register_data (struct regcache *regcache, int n, int fetch)
{
- unsigned char *registers
- = get_regcache (current_inferior, fetch)->registers;
-
- return registers + (reg_defs[n].offset / 8);
+ return regcache->registers + (reg_defs[n].offset / 8);
}
void
-supply_register (int n, const void *buf)
+supply_register (struct regcache *regcache, int n, const void *buf)
{
- memcpy (register_data (n, 0), buf, register_size (n));
+ memcpy (register_data (regcache, n, 0), buf, register_size (n));
}
void
-supply_register_by_name (const char *name, const void *buf)
+supply_register_by_name (struct regcache *regcache,
+ const char *name, const void *buf)
{
- supply_register (find_regno (name), buf);
+ supply_register (regcache, find_regno (name), buf);
}
void
-collect_register (int n, void *buf)
+collect_register (struct regcache *regcache, int n, void *buf)
{
- memcpy (buf, register_data (n, 1), register_size (n));
+ memcpy (buf, register_data (regcache, n, 1), register_size (n));
}
void
-collect_register_as_string (int n, char *buf)
+collect_register_as_string (struct regcache *regcache, int n, char *buf)
{
- convert_int_to_ascii (register_data (n, 1), buf, register_size (n));
+ convert_int_to_ascii (register_data (regcache, n, 1),
+ buf, register_size (n));
}
void
-collect_register_by_name (const char *name, void *buf)
+collect_register_by_name (struct regcache *regcache,
+ const char *name, void *buf)
{
- collect_register (find_regno (name), buf);
+ collect_register (regcache, find_regno (name), buf);
}