Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Philipp Rudo <prudo@linux.vnet.ibm.com>
To: Yao Qi <qiyaoltc@gmail.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [RFC 4/7] Share code in initialize_tdesc_ functions
Date: Tue, 16 May 2017 12:02:00 -0000	[thread overview]
Message-ID: <20170516140217.1f2d3c64@ThinkPad> (raw)
In-Reply-To: <20170511205504.cnufjdz6ehnml5wv@localhost>

Hi Yao,

On Thu, 11 May 2017 21:55:04 +0100
Yao Qi <qiyaoltc@gmail.com> wrote:

> diff --git a/gdb/target-descriptions.c b/gdb/target-descriptions.c
> index 754f15b..a81ae0d 100644
> --- a/gdb/target-descriptions.c
> +++ b/gdb/target-descriptions.c

[...]

> @@ -54,7 +57,10 @@ typedef struct tdesc_reg
>    char *name;
>  
>    /* The register number used by this target to refer to this
> -     register.  This is used for remote p/P packets and to determine
> +     register.  Positive number means it is got by increasing
> +     the previous register number by one.  Negative number means
> +     it is got from "regnum" attribute in the xml file.
> +     This is used for remote p/P packets and to determine
>       the ordering of registers in the remote g/G packets.  */
>    long target_regnum;

I'm not really sure if I like your idea with positive/negative regnums.  It
could easily lead to hard to find bugs because someone forgot a '-' somewhere.
I would prefer an extra field like 

bool explicit_regnum;
or
bool automatic_regnum;

[...]

> +/* Return the unique name of FEATURE.  The uniqueness means different
> +   target description features have different values.  This is used
> +   to differentiate different features with the same name.  */
> +
> +static std::string
> +tdesc_feature_unique_name (const struct tdesc_feature* feature)
> +{
> +  std::string name = std::string (feature->name);
> +
> +  if (name.compare ("org.gnu.gdb.arm.m-profile") == 0)
> +    {
> +      struct tdesc_reg *reg;
> +
> +      for (int ix = 0;
> +	   VEC_iterate (tdesc_reg_p, feature->registers, ix, reg);
> +	   ix++)
> +	if (reg->type != NULL && strcmp (reg->type, "arm_fpa_ext") == 0)
> +	  {
> +	    name.append ("_fpa");
> +	    break;
> +	  }
> +    }
> +  else if (name.compare ("org.gnu.gdb.arm.vfp") == 0)
> +    {
> +      name.append ("_");
> +      name.append (std::to_string (VEC_length (tdesc_reg_p,
> +					       feature->registers) - 1));
> +    }
> +  else if (name.compare ("org.gnu.gdb.i386.core") == 0)
> +    {
> +      struct tdesc_reg *reg = NULL;
> +
> +      for (int ix = 0;
> +	   VEC_iterate (tdesc_reg_p, feature->registers, ix, reg);
> +	   ix++)
> +	{
> +	  if (strcmp (reg->name, "ebp") == 0
> +	      || strcmp (reg->name, "rbp") == 0)
> +	    break;
> +	}
> +
> +      name.append ("_");
> +      if (strcmp (reg->name, "ebp") == 0)
> +	name.append ("i386");
> +      else
> +	{
> +	  if (strcmp (reg->type, "data_ptr") == 0)
> +	    name.append ("amd64");
> +	  else
> +	    name.append ("x32");
> +	}
> +    }
> +  else if (name.compare ("org.gnu.gdb.power.core") == 0)
> +    {
> +      struct tdesc_reg *reg = NULL;
> +      struct tdesc_reg *reg_mq = NULL;
> +      struct tdesc_reg *reg_r0 = NULL;
> +
> +      /* Four variants.  */
> +      for (int ix = 0;
> +	   VEC_iterate (tdesc_reg_p, feature->registers, ix, reg);
> +	   ix++)
> +	{
> +	  if (strcmp (reg->name, "r0") == 0)
> +	    reg_r0 = reg;
> +	  if (strcmp (reg->name, "mq") == 0)
> +	    reg_mq = reg;
> +
> +	  if (reg_r0 != NULL && reg_mq != NULL)
> +	    break;
> +	}
> +
> +      name.append ("_");
> +      if (reg_mq == NULL)
> +	name.append (std::to_string (reg_r0->bitsize));
> +      else
> +	{
> +	  if (reg_mq->target_regnum == -124)
> +	    name.append ("601");
> +	  else
> +	    name.append ("rs6000");
> +	}
> +    }
> +  else if (name.compare ("org.gnu.gdb.power.fpu") == 0)
> +    {
> +      struct tdesc_reg *reg = NULL;
> +
> +      /* Three variants.  */
> +      for (int ix = 0;
> +	   VEC_iterate (tdesc_reg_p, feature->registers, ix, reg);
> +	   ix++)
> +	{
> +	  if (strcmp (reg->name, "fpscr") == 0)
> +	    break;
> +	}
> +
> +      name.append ("_");
> +
> +      if (reg->target_regnum == -71)
> +	name.append ("rs6000");
> +      else
> +	name.append (std::to_string (reg->bitsize));
> +    }
> +  else if (name.compare ("org.gnu.gdb.power.linux") == 0)
> +    {
> +      struct tdesc_reg *reg = NULL;
> +
> +      for (int ix = 0;
> +	   VEC_iterate (tdesc_reg_p, feature->registers, ix, reg);
> +	   ix++)
> +	{
> +	  if (strcmp (reg->name, "orig_r3") == 0)
> +	    break;
> +	}
> +
> +      name.append (std::to_string (reg->bitsize));
> +    }
> +  else if (name.compare ("org.gnu.gdb.s390.linux") == 0)
> +    {
> +      struct tdesc_reg *reg = NULL;
> +      struct tdesc_reg *reg_orig_r2 = NULL;
> +      struct tdesc_reg *reg_sc = NULL;
> +      struct tdesc_reg *reg_lb = NULL;
> +
> +      /* Six variants.  */
> +      for (int ix = 0;
> +	   VEC_iterate (tdesc_reg_p, feature->registers, ix, reg);
> +	   ix++)
> +	{
> +	  if (strcmp (reg->name, "orig_r2") == 0)
> +	    reg_orig_r2 = reg;
> +	  if (strcmp (reg->name, "last_break") == 0)
> +	    reg_lb = reg;
> +	  if (strcmp (reg->name, "system_call") == 0)
> +	    reg_sc = reg;
> +
> +	  if (reg_orig_r2 != NULL && reg_sc != NULL && reg_lb != NULL)
> +	    break;
> +	}
> +
> +      name.append ("_");
> +      name.append (std::to_string (reg_orig_r2->bitsize));
> +
> +      if (reg_lb != NULL)
> +	{
> +	  name.append ("_");
> +
> +	  if (reg_sc == NULL)
> +	    name.append ("v1");
> +	  else
> +	    name.append ("v2");
> +	}
> +    }
> +  else if (name.compare ("org.gnu.gdb.s390.core") == 0)
> +    {
> +      struct tdesc_reg *reg = NULL;
> +      struct tdesc_reg *reg_r0 = NULL;
> +      struct tdesc_reg *reg_r0l = NULL;
> +
> +      /* Six variants.  */
> +      for (int ix = 0;
> +	   VEC_iterate (tdesc_reg_p, feature->registers, ix, reg);
> +	   ix++)
> +	{
> +	  if (strcmp (reg->name, "r0") == 0)
> +	    reg_r0 = reg;
> +	  if (strcmp (reg->name, "r0l") == 0)
> +	    reg_r0l = reg;
> +
> +	  if (reg_r0 != NULL && reg_r0l != NULL)
> +	    break;
> +	}
> +
> +      name.append ("_");
> +      if (reg_r0l != NULL)
> +	name.append ("s64");
> +      else
> +	name.append (std::to_string (reg_r0->bitsize));
> +    }
> +  else if (name.compare ("org.gnu.gdb.mips.cpu") == 0
> +	   || name.compare ("org.gnu.gdb.mips.cp0") == 0
> +	   || name.compare ("org.gnu.gdb.mips.fpu") == 0
> +	   || name.compare ("org.gnu.gdb.mips.dsp") == 0
> +	   || name.compare ("org.gnu.gdb.mips.linux") == 0)
> +    {
> +      struct tdesc_reg *reg = VEC_index (tdesc_reg_p, feature->registers, 0);
> +
> +      name.append (std::to_string (reg->bitsize));
> +    }
> +
> +  std::replace (name.begin (), name.end (), '.', '_');
> +  std::replace (name.begin (), name.end (), '-', '_');
> +
> +  return name;
> +}
> +

This function is actually the part I like least of your implementation.  Its
way to long and barely readable.  The way I understand, it is needed to create
unique macro and function names.  So why don't you simply use the filename of
the XML file where the feature is defined?  It already is unique.  Or use an
gdbarch hook so every architecture can decide for itself how to name them?

Philipp


  reply	other threads:[~2017-05-16 12:02 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-11 15:55 [RFC 0/7] Make GDB builtin target descriptions more flexible Yao Qi
2017-05-11 15:55 ` [RFC 2/7] Add unit test to builtin tdesc generated by xml Yao Qi
2017-05-16 12:00   ` Philipp Rudo
2017-05-16 15:46     ` Yao Qi
2017-05-17  9:09       ` Philipp Rudo
2017-05-17 16:06     ` Pedro Alves
2017-05-30  8:00       ` Philipp Rudo
2017-06-01 17:53         ` Philipp Rudo
2017-05-17 15:41   ` Pedro Alves
2017-05-18  9:54     ` Yao Qi
2017-05-18 11:34       ` Pedro Alves
2017-05-19 15:47         ` Yao Qi
2017-05-22  8:51           ` Yao Qi
2017-05-11 15:55 ` [RFC 5/7] Centralize i386 linux target descriptions Yao Qi
2017-05-11 15:55 ` [RFC 6/7] Lazily and dynamically create i386-linux " Yao Qi
2017-05-11 18:14   ` John Baldwin
2017-05-11 21:03     ` Yao Qi
2017-05-17 15:43   ` Pedro Alves
2017-05-18 15:12     ` Yao Qi
2017-05-19 10:15       ` Pedro Alves
2017-05-19 14:27         ` Yao Qi
2017-05-11 15:55 ` [RFC 3/7] Adjust the order of 32bit-linux.xml and 32bit-sse.xml in i386/i386-linux.xml Yao Qi
2017-05-11 15:55 ` [RFC 1/7] Move initialize_tdesc_mips* calls from mips-linux-nat.c to mips-linux-tdep.c Yao Qi
2017-05-11 15:55 ` [RFC 7/7] Remove builtin tdesc_i386_*_linux Yao Qi
2017-05-16 12:02   ` Philipp Rudo
2017-05-17 15:46   ` Pedro Alves
2017-05-11 16:06 ` [RFC 0/7] Make GDB builtin target descriptions more flexible Eli Zaretskii
2017-05-11 20:56   ` Yao Qi
2017-05-11 20:55 ` [RFC 4/7] Share code in initialize_tdesc_ functions Yao Qi
2017-05-16 12:02   ` Philipp Rudo [this message]
2017-05-17 15:43     ` Pedro Alves
2017-05-18 11:21       ` Yao Qi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170516140217.1f2d3c64@ThinkPad \
    --to=prudo@linux.vnet.ibm.com \
    --cc=gdb-patches@sourceware.org \
    --cc=qiyaoltc@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox