public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Lancelot SIX <lsix@lancelotsix.com>
To: Simon Marchi <simon.marchi@efficios.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH 3/4] gdb: add type::length / type::set_length
Date: Wed, 21 Sep 2022 15:01:44 +0000	[thread overview]
Message-ID: <20220921150144.s62znyu4ws356aro@ubuntu.lan> (raw)
In-Reply-To: <20220916150836.527213-3-simon.marchi@efficios.com>

Hi,

On Fri, Sep 16, 2022 at 11:08:35AM -0400, Simon Marchi via Gdb-patches wrote:
> From: Simon Marchi <simon.marchi@polymtl.ca>
> 
> Add the `length` and `set_length` methods on `struct type`, in order to remove
> the `TYPE_LENGTH` macro.  In this patch, the macro is changed to use the
> getter, so all the call sites of the macro that are used as a setter are
> changed to use the setter method directly.  The next patch will remove the
> macro completely.
> 
> Change-Id: Id1090244f15c9856969b9be5006aefe8d8897ca4
> ---
>  gdb/ada-lang.c            | 47 +++++++++++++-------------
>  gdb/coffread.c            | 14 ++++----
>  gdb/cp-valprint.c         |  2 +-
>  gdb/ctfread.c             | 10 +++---
>  gdb/dwarf2/read.c         | 44 ++++++++++--------------
>  gdb/eval.c                |  2 +-
>  gdb/f-valprint.c          |  6 ++--
>  gdb/gdbtypes.c            | 71 ++++++++++++++++++++-------------------
>  gdb/gdbtypes.h            | 16 +++++++--
>  gdb/mdebugread.c          |  4 +--
>  gdb/opencl-lang.c         |  2 +-
>  gdb/rust-lang.c           |  5 ++-
>  gdb/stabsread.c           | 10 +++---
>  gdb/target-descriptions.c |  2 +-
>  14 files changed, 119 insertions(+), 116 deletions(-)
> 
> diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
> index d0b13a6bed2..06eab777f57 100644
> --- a/gdb/ada-lang.c
> +++ b/gdb/ada-lang.c
> @@ -2165,7 +2165,7 @@ ada_type_of_array (struct value *arr, int bounds)
>  		  int array_bitsize =
>  			(hi - lo + 1) * TYPE_FIELD_BITSIZE (elt_type, 0);
>  
> -		  TYPE_LENGTH (array_type) = (array_bitsize + 7) / 8;
> +		  array_type->set_length ((array_bitsize + 7) / 8);

Do you think that while at it you could also replace the 7 and 8
literals with appropriate configured values?

    array_type->set_length ((array_bitsize + HOST_CHAR_BIT - 1)
                            / HOST_CHAR_BIT);

This is not directly linked to what you are changing, might be done in
a separate patch.

>  		}
>  	    }
>  	}
> diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
> index 843e0efb321..1bead475f5f 100644
> --- a/gdb/gdbtypes.c
> +++ b/gdb/gdbtypes.c
> @@ -1307,12 +1307,11 @@ update_static_array_size (struct type *type)
>  	     special, it's still just a single element array) so do
>  	     consider that case when touching this code.  */
>  	  LONGEST element_count = std::abs (high_bound - low_bound + 1);
> -	  TYPE_LENGTH (type)
> -	    = ((std::abs (stride) * element_count) + 7) / 8;
> +	  type->set_length (((std::abs (stride) * element_count) + 7) / 8);

Same here.

>  	}
>        else
> -	TYPE_LENGTH (type) =
> -	  TYPE_LENGTH (element_type) * (high_bound - low_bound + 1);
> +	type->set_length (TYPE_LENGTH (element_type)
> +			  * (high_bound - low_bound + 1));
>  
>        /* If this array's element is itself an array with a bit stride,
>  	 then we want to update this array's bit stride to reflect the
> diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
> index 6f4b2d61ca8..6d12a489b15 100644
> --- a/gdb/gdbtypes.h
> +++ b/gdb/gdbtypes.h
> @@ -1443,7 +1453,7 @@ struct type
>    bool bit_size_differs_p () const
>    {
>      return (main_type->type_specific_field == TYPE_SPECIFIC_INT
> -	    && main_type->type_specific.int_stuff.bit_size != 8 * length);
> +	    && main_type->type_specific.int_stuff.bit_size != 8 * length ());

Same, HOST_CHAR_BIT * length ()

>    }

Best,
Lancelot.

  parent reply	other threads:[~2022-09-21 15:01 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-16 15:08 [PATCH 1/4] gdb: add type::target_type / type::set_target_type Simon Marchi
2022-09-16 15:08 ` [PATCH 2/4] gdb: remove TYPE_TARGET_TYPE Simon Marchi
2022-09-21 14:37   ` Lancelot SIX
2022-09-21 15:01     ` Simon Marchi
2022-09-21 14:57   ` Tom Tromey
2022-09-21 15:02     ` Simon Marchi
2022-09-16 15:08 ` [PATCH 3/4] gdb: add type::length / type::set_length Simon Marchi
2022-09-21 15:00   ` Tom Tromey
2022-09-21 15:01   ` Lancelot SIX [this message]
2022-09-21 16:44     ` Tom Tromey
2022-09-21 17:00       ` Simon Marchi
2022-09-21 18:48       ` Lancelot SIX
2022-09-17  9:48 ` [RESEND PATCH 4/4] gdb: remove TYPE_LENGTH Simon Marchi
2022-09-21 15:03   ` Tom Tromey
2022-09-21 15:04     ` Simon Marchi
2022-09-21 14:52 ` [PATCH 1/4] gdb: add type::target_type / type::set_target_type Tom Tromey
2022-09-21 14:55 ` Tom Tromey

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=20220921150144.s62znyu4ws356aro@ubuntu.lan \
    --to=lsix@lancelotsix.com \
    --cc=gdb-patches@sourceware.org \
    --cc=simon.marchi@efficios.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).