Patchwork [10/25] Adjust code generated by regformats/regdat.sh

login
register
mail settings
Submitter Yao Qi
Date June 12, 2017, 8:41 a.m.
Message ID <1497256916-4958-11-git-send-email-yao.qi@linaro.org>
Download mbox | patch
Permalink /patch/20922/
State New
Headers show

Comments

Yao Qi - June 12, 2017, 8:41 a.m.
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";

  ...
}

gdb:

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

	* regformats/regdat.sh: Adjust code order.
---
 gdb/regformats/regdat.sh | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)
Pedro Alves - June 20, 2017, 11:09 a.m.
On 06/12/2017 09:41 AM, Yao Qi wrote:
> 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,
> 

The rationale misses stating why is this better than the status quo.
I presume this helps following patches?

Thanks,
Pedro Alves
Yao Qi - June 21, 2017, 2:28 p.m.
Pedro Alves <palves@redhat.com> writes:

> The rationale misses stating why is this better than the status quo.
> I presume this helps following patches?

Yes, it paves the way for patch 11.  I'll add it in the commit log.

Patch

diff --git a/gdb/regformats/regdat.sh b/gdb/regformats/regdat.sh
index 651f703..2c764cd 100755
--- a/gdb/regformats/regdat.sh
+++ b/gdb/regformats/regdat.sh
@@ -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]);