Adjust code generated by regformats/regdat.sh
authorYao Qi <yao.qi@linaro.org>
Tue, 5 Sep 2017 08:54:52 +0000 (09:54 +0100)
committerYao Qi <yao.qi@linaro.org>
Tue, 5 Sep 2017 08:54:52 +0000 (09:54 +0100)
regformats/regdat.sh generate some *-generated.c files when GDBserver
is built.  Each .c file has some static variables, which are only used
within function init_registers_XXX, like this,

static struct reg regs_i386_linux[] = {
  { "eax", 0, 32 },
  { "ecx", 32, 32 },
  ...
};

static const char *expedite_regs_i386_linux[] = { "ebp", "esp", "eip", 0 };
static const char *xmltarget_i386_linux = "i386-linux.xml";

void
init_registers_i386_linux (void)
{
  ...
}

This patch moves these static variables' definitions to function
init_registers_XXX, so the generated files look like this,

void
init_registers_i386_linux (void)
{
  static struct target_desc tdesc_i386_linux_s;
  struct target_desc *result = &tdesc_i386_linux_s;
static struct reg regs_i386_linux[] = {
  ...
};

static const char *expedite_regs_i386_linux[] = { "ebp", "esp", "eip", 0 };
static const char *xmltarget_i386_linux = "i386-linux.xml";

  ...
}

We want GDBserver create target descriptions dynamically in each
init_registers_XXXX functions, so this patch moves all the related code
into function init_registers_XXXX, so that the following patch can easily
change function init_registers_XXXX to create target description
dynamically, rather than using current pre-generated array.

gdb:

2017-09-05  Yao Qi  <yao.qi@linaro.org>

* regformats/regdat.sh: Adjust code order.

gdb/ChangeLog
gdb/regformats/regdat.sh

index 19882f04475d1082845920106a4a86260e571b90..c50afecc05785a7b6ed4c1c15c8c559d3e40324f 100644 (file)
@@ -1,3 +1,7 @@
+2017-09-05  Yao Qi  <yao.qi@linaro.org>
+
+       * regformats/regdat.sh: Adjust code order.
+
 2017-09-05  Simon Marchi  <simon.marchi@ericsson.com>
 
        * expprint.c (dump_subexp_body_standard): Use constant format
index 651f70392caa7890beb7acede0d087d4916fefac..2c764cde66b385363adf8519b967a88e8c5591c2 100755 (executable)
@@ -123,6 +123,15 @@ while do_read
 do
   if test "${type}" = "name"; then
     name="${entry}"
+
+    echo "const struct target_desc *tdesc_${name};"
+    echo ""
+    echo "void"
+    echo "init_registers_${name} (void)"
+    echo "{"
+    echo "  static struct target_desc tdesc_${name}_s;"
+    echo "  struct target_desc *result = &tdesc_${name}_s;"
+
     echo "static struct reg regs_${name}[] = {"
     continue
   elif test "${type}" = "xmltarget"; then
@@ -169,14 +178,6 @@ fi
 echo
 
 cat <<EOF
-const struct target_desc *tdesc_${name};
-
-void
-init_registers_${name} (void)
-{
-  static struct target_desc tdesc_${name}_s;
-  struct target_desc *result = &tdesc_${name}_s;
-
   result->reg_defs = regs_${name};
   result->num_registers = sizeof (regs_${name}) / sizeof (regs_${name}[0]);