From: Yao Qi Date: Tue, 5 Sep 2017 08:54:52 +0000 (+0100) Subject: Use VEC for target_desc.reg_defs X-Git-Tag: users/ARM/embedded-binutils-master-2017q4~1172 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f7000548a2b79d7e5cb924468117ca4245e6b820;p=platform%2Fupstream%2Fbinutils.git 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 * 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) : Change it to VEC. : Remove. gdb: 2017-09-05 Yao Qi * regformats/regdat.sh: Update generated code. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index c50afec..729a74f 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,9 @@ 2017-09-05 Yao Qi + * regformats/regdat.sh: Update generated code. + +2017-09-05 Yao Qi + * regformats/regdat.sh: Adjust code order. 2017-09-05 Simon Marchi diff --git a/gdb/gdbserver/ChangeLog b/gdb/gdbserver/ChangeLog index 6eb4936..8fa8ef1 100644 --- a/gdb/gdbserver/ChangeLog +++ b/gdb/gdbserver/ChangeLog @@ -1,3 +1,23 @@ +2017-09-05 Yao Qi + + * 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) : Change it to VEC. + : Remove. + 2017-09-04 Simon Marchi * Makefile.in (.SECONDARY): Define target. diff --git a/gdb/gdbserver/Makefile.in b/gdb/gdbserver/Makefile.in index e43a929..4161152 100644 --- a/gdb/gdbserver/Makefile.in +++ b/gdb/gdbserver/Makefile.in @@ -400,6 +400,7 @@ IPA_OBJS = \ tdesc-ipa.o \ tracepoint-ipa.o \ utils-ipa.o \ + vec-ipa.o \ ${IPA_DEPFILES} IPA_LIB = libinproctrace.so 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); diff --git a/gdb/gdbserver/tdesc.c b/gdb/gdbserver/tdesc.c index fdd35197..1b1882e 100644 --- a/gdb/gdbserver/tdesc.c +++ b/gdb/gdbserver/tdesc.c @@ -23,12 +23,13 @@ void init_target_desc (struct target_desc *tdesc) { int offset, i; + struct reg *reg; offset = 0; - for (i = 0; i < tdesc->num_registers; i++) + for (i = 0; VEC_iterate (tdesc_reg_p, tdesc->reg_defs, i, reg); i++) { - tdesc->reg_defs[i].offset = offset; - offset += tdesc->reg_defs[i].size; + reg->offset = offset; + offset += reg->size; } tdesc->registers_size = offset / 8; @@ -40,14 +41,13 @@ init_target_desc (struct target_desc *tdesc) #ifndef IN_PROCESS_AGENT -static const struct target_desc default_description = { 0 }; +static const struct target_desc default_description = { NULL, 0, NULL, NULL }; void copy_target_description (struct target_desc *dest, const struct target_desc *src) { dest->reg_defs = src->reg_defs; - dest->num_registers = src->num_registers; dest->expedite_regs = src->expedite_regs; dest->registers_size = src->registers_size; dest->xmltarget = src->xmltarget; diff --git a/gdb/gdbserver/tdesc.h b/gdb/gdbserver/tdesc.h index 0341278..424a2fd 100644 --- a/gdb/gdbserver/tdesc.h +++ b/gdb/gdbserver/tdesc.h @@ -21,17 +21,16 @@ struct reg; +typedef struct reg *tdesc_reg_p; +DEF_VEC_P(tdesc_reg_p); + /* A target description. */ struct target_desc { - /* An array of NUM_REGISTERS elements of register definitions that + /* A vector of elements of register definitions that describe the inferior's register set. */ - struct reg *reg_defs; - - /* The number of registers in inferior's register set (and thus in - the regcache). */ - int num_registers; + VEC(tdesc_reg_p) *reg_defs; /* The register cache size, in bytes. */ int registers_size; diff --git a/gdb/regformats/regdat.sh b/gdb/regformats/regdat.sh index 2c764cd..236cd93 100755 --- a/gdb/regformats/regdat.sh +++ b/gdb/regformats/regdat.sh @@ -131,8 +131,8 @@ do echo "{" echo " static struct target_desc tdesc_${name}_s;" echo " struct target_desc *result = &tdesc_${name}_s;" + echo " memset (result, 0, sizeof (*result));" - echo "static struct reg regs_${name}[] = {" continue elif test "${type}" = "xmltarget"; then xmltarget="${entry}" @@ -150,13 +150,17 @@ do echo "$0: $1 does not specify \`\`name''." 1>&2 exit 1 else - echo " { \"${entry}\", ${offset}, ${type} }," + echo " {struct reg *reg = XCNEW (struct reg);" + echo " reg->name = \"${entry}\";" + echo " reg->offset = ${offset};" + echo " reg->size = ${type};" + echo " VEC_safe_push (tdesc_reg_p, result->reg_defs, reg);" + echo " };" offset=`expr ${offset} + ${type}` i=`expr $i + 1` fi done -echo "};" echo echo "static const char *expedite_regs_${name}[] = { \"`echo ${expedite} | sed 's/,/", "/g'`\", 0 };" if test "${xmltarget}" = x; then @@ -178,9 +182,6 @@ fi echo cat <reg_defs = regs_${name}; - result->num_registers = sizeof (regs_${name}) / sizeof (regs_${name}[0]); - #ifndef IN_PROCESS_AGENT result->expedite_regs = expedite_regs_${name}; result->xmltarget = xmltarget_${name};