/* Register support routines for the remote server for GDB.
- Copyright (C) 2001-2017 Free Software Foundation, Inc.
+ Copyright (C) 2001-2018 Free Software Foundation, Inc.
This file is part of GDB.
{
struct regcache *regcache;
- regcache = inferior_regcache_data (thread);
+ regcache = thread_regcache_data (thread);
/* Threads' regcaches are created lazily, because biarch targets add
the main thread/lwp before seeing it stop for the first time, and
gdb_assert (proc->tdesc != NULL);
regcache = new_register_cache (proc->tdesc);
- set_inferior_regcache_data (thread, regcache);
+ set_thread_regcache_data (thread, regcache);
}
if (fetch && regcache->registers_valid == 0)
current_thread = thread;
/* Invalidate all registers, to prevent stale left-overs. */
memset (regcache->register_status, REG_UNAVAILABLE,
- regcache->tdesc->num_registers);
+ regcache->tdesc->reg_defs.size ());
fetch_inferior_registers (regcache, -1);
current_thread = saved_thread;
regcache->registers_valid = 1;
{
struct regcache *regcache;
- regcache = inferior_regcache_data (thread);
+ regcache = thread_regcache_data (thread);
if (regcache == NULL)
return;
regcache->registers_valid = 0;
}
-static int
-regcache_invalidate_one (struct inferior_list_entry *entry,
- void *pid_p)
-{
- struct thread_info *thread = (struct thread_info *) entry;
- int pid = *(int *) pid_p;
-
- /* Only invalidate the regcaches of threads of this process. */
- if (ptid_get_pid (entry->id) == pid)
- regcache_invalidate_thread (thread);
-
- return 0;
-}
-
/* See regcache.h. */
void
regcache_invalidate_pid (int pid)
{
- find_inferior (&all_threads, regcache_invalidate_one, &pid);
+ /* Only invalidate the regcaches of threads of this process. */
+ for_each_thread (pid, regcache_invalidate_thread);
}
/* See regcache.h. */
regcache_invalidate (void)
{
/* Only update the threads of the current process. */
- int pid = ptid_get_pid (current_thread->entry.id);
+ int pid = current_thread->id.pid ();
regcache_invalidate_pid (pid);
}
= (unsigned char *) xcalloc (1, tdesc->registers_size);
regcache->registers_owned = 1;
regcache->register_status
- = (unsigned char *) xmalloc (tdesc->num_registers);
+ = (unsigned char *) xmalloc (tdesc->reg_defs.size ());
memset ((void *) regcache->register_status, REG_UNAVAILABLE,
- tdesc->num_registers);
+ tdesc->reg_defs.size ());
#else
gdb_assert_not_reached ("can't allocate memory from the heap");
#endif
#ifndef IN_PROCESS_AGENT
if (dst->register_status != NULL && src->register_status != NULL)
memcpy (dst->register_status, src->register_status,
- src->tdesc->num_registers);
+ src->tdesc->reg_defs.size ());
#endif
dst->registers_valid = src->registers_valid;
}
+/* Return a reference to the description of register N. */
+
+static const struct reg &
+find_register_by_number (const struct target_desc *tdesc, int n)
+{
+ return tdesc->reg_defs[n];
+}
#ifndef IN_PROCESS_AGENT
{
unsigned char *registers = regcache->registers;
const struct target_desc *tdesc = regcache->tdesc;
- int i;
- for (i = 0; i < tdesc->num_registers; i++)
+ for (int i = 0; i < tdesc->reg_defs.size (); ++i)
{
if (regcache->register_status[i] == REG_VALID)
{
int
find_regno (const struct target_desc *tdesc, const char *name)
{
- int i;
-
- for (i = 0; i < tdesc->num_registers; i++)
- if (strcmp (name, tdesc->reg_defs[i].name) == 0)
- return i;
+ for (int i = 0; i < tdesc->reg_defs.size (); ++i)
+ {
+ if (strcmp (name, find_register_by_number (tdesc, i).name) == 0)
+ return i;
+ }
internal_error (__FILE__, __LINE__, "Unknown register %s requested",
name);
}
-struct reg *
-find_register_by_number (const struct target_desc *tdesc, int n)
-{
- return &tdesc->reg_defs[n];
-}
-
-#endif
-
-#ifndef IN_PROCESS_AGENT
static void
free_register_cache_thread (struct thread_info *thread)
{
- struct regcache *regcache = inferior_regcache_data (thread);
+ struct regcache *regcache = thread_regcache_data (thread);
if (regcache != NULL)
{
regcache_invalidate_thread (thread);
free_register_cache (regcache);
- set_inferior_regcache_data (thread, NULL);
+ set_thread_regcache_data (thread, NULL);
}
}
-static void
-free_register_cache_thread_one (struct inferior_list_entry *entry)
-{
- struct thread_info *thread = (struct thread_info *) entry;
-
- free_register_cache_thread (thread);
-}
-
void
regcache_release (void)
{
/* Flush and release all pre-existing register caches. */
- for_each_inferior (&all_threads, free_register_cache_thread_one);
+ for_each_thread (free_register_cache_thread);
}
#endif
int
register_size (const struct target_desc *tdesc, int n)
{
- return tdesc->reg_defs[n].size / 8;
+ return find_register_by_number (tdesc, n).size / 8;
}
/* See common/common-regcache.h. */
static unsigned char *
register_data (struct regcache *regcache, int n, int fetch)
{
- return regcache->registers + regcache->tdesc->reg_defs[n].offset / 8;
+ return (regcache->registers
+ + find_register_by_number (regcache->tdesc, n).offset / 8);
}
/* Supply register N, whose contents are stored in BUF, to REGCACHE.
#endif
}
+#ifndef IN_PROCESS_AGENT
+
+/* Supply register called NAME with value zero to REGCACHE. */
+
+void
+supply_register_by_name_zeroed (struct regcache *regcache,
+ const char *name)
+{
+ supply_register_zeroed (regcache, find_regno (regcache->tdesc, name));
+}
+
+#endif
+
/* Supply the whole register set whose contents are stored in BUF, to
REGCACHE. If BUF is NULL, all the registers' values are recorded
as unavailable. */
{
int i;
- for (i = 0; i < tdesc->num_registers; i++)
+ for (i = 0; i < tdesc->reg_defs.size (); i++)
regcache->register_status[i] = REG_VALID;
}
#endif
{
int i;
- for (i = 0; i < tdesc->num_registers; i++)
+ for (i = 0; i < tdesc->reg_defs.size (); i++)
regcache->register_status[i] = REG_UNAVAILABLE;
}
#endif
int size;
gdb_assert (regcache != NULL);
- gdb_assert (regnum >= 0 && regnum < regcache->tdesc->num_registers);
+ gdb_assert (regnum >= 0
+ && regnum < regcache->tdesc->reg_defs.size ());
size = register_size (regcache->tdesc, regnum);