Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Simon Marchi <simark@simark.ca>
To: Alan Hayward <Alan.Hayward@arm.com>,
	"gdb-patches@sourceware.org" <gdb-patches@sourceware.org>
Cc: nd <nd@arm.com>
Subject: Re: [PATCH] Use visitors for make_gdb_type
Date: Mon, 29 Jan 2018 02:24:00 -0000	[thread overview]
Message-ID: <c54fb9a2-868e-8a91-ba90-66999e4be1de@simark.ca> (raw)
In-Reply-To: <F07C9294-69B0-4735-A13E-5D8FF608C8C6@arm.com>

On 2018-01-26 10:30 AM, Alan Hayward wrote:
> I appear to still have email issues - previous post had the tabs stripped out.
> Hoping this version is ok. Apologies.

Hi Alan,

I was able to apply it correctly.
> This patch implements the suggestion in the review for
> [PATCH v2 6/8] Create xml from target descriptions.
> 
> Remove the make_gdb_type functions from the tdesc_type_ classes.
> Replace with a static make_gdb_type function that uses a element
> visitor called gdb_type_creator.
> 
> I've defined gdb_type_creator inside make_gdb_type because it shouldn't
> be needed outside the function.
> 
> The method of creating the types has not changed.
> 
> This patch will allow a future patch to commonise the tdesc_types with
> gdbserver without having to move any gdb_type functionality.
> 
> Alan.

make_gdb_type_union & co could be methods of gdb_type_creator and access gdbarch
directly.  I think it would make sense to have all the knowledge of the tdesc type
to gdb type conversion inside that class.

> -  type *make_gdb_type (struct gdbarch *gdbarch) const override
> +static type *
> +make_gdb_type (struct gdbarch *gdbarch, struct tdesc_type *ttype)
> +{
> +  class gdb_type_creator : public tdesc_element_visitor
>    {
> -    type *gdb_type = tdesc_find_type (gdbarch, this->name.c_str ());
> -    if (gdb_type != NULL)
> -      return gdb_type;
> +  public:
> +    gdb_type_creator (struct gdbarch *gdbarch)
> +      : m_gdbarch (gdbarch)
> +    {}
>  
> -    switch (this->kind)
> +    type *get_type ()
>      {
> -      case TDESC_TYPE_STRUCT:
> -	return make_gdb_type_struct (gdbarch);
> -      case TDESC_TYPE_UNION:
> -	return make_gdb_type_union (gdbarch);
> -      case TDESC_TYPE_FLAGS:
> -	return make_gdb_type_flags (gdbarch);
> -      case TDESC_TYPE_ENUM:
> -	return make_gdb_type_enum (gdbarch);
> +      return m_type;
>      }
>  
> -    internal_error (__FILE__, __LINE__,
> -		    "Type \"%s\" has an unknown kind %d",
> -		    this->name.c_str (), this->kind);
> +    void visit_pre (const target_desc *e)
> +    {}

I think we should have empty default implementations of these visit functions in the
base class, instead of having to declare them empty when unnecessary.  Maybe Yao had
a reason not to do this initially?

In any case, make sure to mark the overriden methods with the "override" keyword.  Using
clang:

/home/simark/src/binutils-gdb/gdb/target-descriptions.c:416:10: error: 'visit_pre' overrides a member function but is not marked 'override' [-Werror,-Winconsistent-missing-override]
    void visit_pre (const target_desc *e)
         ^
/home/simark/src/binutils-gdb/gdb/target-descriptions.c:48:16: note: overridden virtual function is here
  virtual void visit_pre (const target_desc *e) = 0;
               ^
/home/simark/src/binutils-gdb/gdb/target-descriptions.c:419:10: error: 'visit_post' overrides a member function but is not marked 'override' [-Werror,-Winconsistent-missing-override]
    void visit_post (const target_desc *e)
         ^
/home/simark/src/binutils-gdb/gdb/target-descriptions.c:49:16: note: overridden virtual function is here
  virtual void visit_post (const target_desc *e) = 0;
               ^
/home/simark/src/binutils-gdb/gdb/target-descriptions.c:422:10: error: 'visit_pre' overrides a member function but is not marked 'override' [-Werror,-Winconsistent-missing-override]
    void visit_pre (const tdesc_feature *e)
         ^
/home/simark/src/binutils-gdb/gdb/target-descriptions.c:51:16: note: overridden virtual function is here
  virtual void visit_pre (const tdesc_feature *e) = 0;
               ^
/home/simark/src/binutils-gdb/gdb/target-descriptions.c:425:10: error: 'visit_post' overrides a member function but is not marked 'override' [-Werror,-Winconsistent-missing-override]
    void visit_post (const tdesc_feature *e)
         ^
/home/simark/src/binutils-gdb/gdb/target-descriptions.c:52:16: note: overridden virtual function is here
  virtual void visit_post (const tdesc_feature *e) = 0;
               ^
/home/simark/src/binutils-gdb/gdb/target-descriptions.c:544:10: error: 'visit' overrides a member function but is not marked 'override' [-Werror,-Winconsistent-missing-override]
    void visit (const tdesc_reg *reg)
         ^
/home/simark/src/binutils-gdb/gdb/target-descriptions.c:58:16: note: overridden virtual function is here
  virtual void visit (const tdesc_reg *e) = 0;
               ^

Otherwise, LGTM.

Thanks,

Simon


  reply	other threads:[~2018-01-29  2:24 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <a06ab31b-0144-82fe-5d29-4e81016990d3@arm.com>
2018-01-26 15:30 ` Alan Hayward
2018-01-29  2:24   ` Simon Marchi [this message]
2018-01-29  9:30     ` Philipp Rudo
2018-01-29 15:31       ` Alan Hayward
2018-01-29 16:13         ` Simon Marchi
2018-01-29 16:54           ` Yao Qi
2018-01-30 15:16             ` Alan Hayward
2018-02-05 16:21               ` Simon Marchi

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=c54fb9a2-868e-8a91-ba90-66999e4be1de@simark.ca \
    --to=simark@simark.ca \
    --cc=Alan.Hayward@arm.com \
    --cc=gdb-patches@sourceware.org \
    --cc=nd@arm.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