aboutsummaryrefslogtreecommitdiff
path: root/gdb/gdbserver/regcache.c
diff options
context:
space:
mode:
authorYao Qi <yao.qi@linaro.org>2017-09-05 09:54:52 +0100
committerYao Qi <yao.qi@linaro.org>2017-09-05 09:54:52 +0100
commitf7000548a2b79d7e5cb924468117ca4245e6b820 (patch)
tree67f9fdac040944ddf81ddd3058d6bea134796432 /gdb/gdbserver/regcache.c
parentc9a5e2a5b2b20d83f60026459d3a6b68481566c9 (diff)
downloadgdb-f7000548a2b79d7e5cb924468117ca4245e6b820.zip
gdb-f7000548a2b79d7e5cb924468117ca4245e6b820.tar.gz
gdb-f7000548a2b79d7e5cb924468117ca4245e6b820.tar.bz2
Use VEC for target_desc.reg_defs
Nowadays, target_desc.reg_defs is a pointer points to a pre-generated array, which is not flexible. This patch changes it from an array to a VEC so that GDBserver can create target descriptions dynamically later. Instead of using pre-generated array, the -generated.c calls VEC_safe_push to add each register to vector. Since target_desc.reg_defs is used in IPA, we need to build common/vec.c for IPA too. gdb/gdbserver: 2017-09-05 Yao Qi <yao.qi@linaro.org> * Makefile.in (IPA_OBJS): Add vec-ipa.o * regcache.c (get_thread_regcache): Use VEC_length. (init_register_cache): Likewise. (regcache_cpy): Likewise. (registers_to_string): Iterate reg_defs via VEC_iterate. (find_regno): Likewise. (find_register_by_number): Use VEC_index. (register_size): Call find_register_by_number. (register_data): Call find_register_by_number. (supply_regblock): Use VEC_length. (regcache_raw_read_unsigned): Likewise. * tdesc.c (init_target_desc): Iterate reg_defs via VEC_iterate. (default_description): Update initializer. (copy_target_description): Don't update field num_registers. * tdesc.h (struct target_desc) <reg_defs>: Change it to VEC. <num_registers>: Remove. gdb: 2017-09-05 Yao Qi <yao.qi@linaro.org> * regformats/regdat.sh: Update generated code.
Diffstat (limited to 'gdb/gdbserver/regcache.c')
-rw-r--r--gdb/gdbserver/regcache.c34
1 files changed, 19 insertions, 15 deletions
diff --git a/gdb/gdbserver/regcache.c b/gdb/gdbserver/regcache.c
index 9b837e7..43e78a5 100644
--- a/gdb/gdbserver/regcache.c
+++ b/gdb/gdbserver/regcache.c
@@ -54,7 +54,7 @@ get_thread_regcache (struct thread_info *thread, int fetch)
current_thread = thread;
/* Invalidate all registers, to prevent stale left-overs. */
memset (regcache->register_status, REG_UNAVAILABLE,
- regcache->tdesc->num_registers);
+ VEC_length (tdesc_reg_p, regcache->tdesc->reg_defs));
fetch_inferior_registers (regcache, -1);
current_thread = saved_thread;
regcache->registers_valid = 1;
@@ -145,9 +145,9 @@ init_register_cache (struct regcache *regcache,
= (unsigned char *) xcalloc (1, tdesc->registers_size);
regcache->registers_owned = 1;
regcache->register_status
- = (unsigned char *) xmalloc (tdesc->num_registers);
+ = (unsigned char *) xmalloc (VEC_length (tdesc_reg_p, tdesc->reg_defs));
memset ((void *) regcache->register_status, REG_UNAVAILABLE,
- tdesc->num_registers);
+ VEC_length (tdesc_reg_p, tdesc->reg_defs));
#else
gdb_assert_not_reached ("can't allocate memory from the heap");
#endif
@@ -204,7 +204,7 @@ regcache_cpy (struct regcache *dst, struct regcache *src)
#ifndef IN_PROCESS_AGENT
if (dst->register_status != NULL && src->register_status != NULL)
memcpy (dst->register_status, src->register_status,
- src->tdesc->num_registers);
+ VEC_length (tdesc_reg_p, src->tdesc->reg_defs));
#endif
dst->registers_valid = src->registers_valid;
}
@@ -218,8 +218,9 @@ registers_to_string (struct regcache *regcache, char *buf)
unsigned char *registers = regcache->registers;
const struct target_desc *tdesc = regcache->tdesc;
int i;
+ reg *reg;
- for (i = 0; i < tdesc->num_registers; i++)
+ for (i = 0; VEC_iterate (tdesc_reg_p, tdesc->reg_defs, i, reg); i++)
{
if (regcache->register_status[i] == REG_VALID)
{
@@ -257,22 +258,23 @@ int
find_regno (const struct target_desc *tdesc, const char *name)
{
int i;
+ reg *reg;
- for (i = 0; i < tdesc->num_registers; i++)
- if (strcmp (name, tdesc->reg_defs[i].name) == 0)
+ for (i = 0; VEC_iterate (tdesc_reg_p, tdesc->reg_defs, i, reg); i++)
+ if (strcmp (name, reg->name) == 0)
return i;
internal_error (__FILE__, __LINE__, "Unknown register %s requested",
name);
}
+#endif
+
struct reg *
find_register_by_number (const struct target_desc *tdesc, int n)
{
- return &tdesc->reg_defs[n];
+ return VEC_index (tdesc_reg_p, tdesc->reg_defs, n);
}
-#endif
-
#ifndef IN_PROCESS_AGENT
static void
free_register_cache_thread (struct thread_info *thread)
@@ -312,7 +314,7 @@ register_cache_size (const struct target_desc *tdesc)
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. */
@@ -326,7 +328,8 @@ regcache_register_size (const struct regcache *regcache, int n)
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.
@@ -385,7 +388,7 @@ supply_regblock (struct regcache *regcache, const void *buf)
{
int i;
- for (i = 0; i < tdesc->num_registers; i++)
+ for (i = 0; i < VEC_length (tdesc_reg_p, tdesc->reg_defs); i++)
regcache->register_status[i] = REG_VALID;
}
#endif
@@ -399,7 +402,7 @@ supply_regblock (struct regcache *regcache, const void *buf)
{
int i;
- for (i = 0; i < tdesc->num_registers; i++)
+ for (i = 0; i < VEC_length (tdesc_reg_p, tdesc->reg_defs); i++)
regcache->register_status[i] = REG_UNAVAILABLE;
}
#endif
@@ -431,7 +434,8 @@ regcache_raw_read_unsigned (struct regcache *regcache, int regnum,
int size;
gdb_assert (regcache != NULL);
- gdb_assert (regnum >= 0 && regnum < regcache->tdesc->num_registers);
+ gdb_assert (regnum >= 0
+ && regnum < VEC_length (tdesc_reg_p, regcache->tdesc->reg_defs));
size = register_size (regcache->tdesc, regnum);