Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Joel Brobecker <brobecker@adacore.com>
To: Simon Marchi via Gdb-patches <gdb-patches@sourceware.org>
Cc: Simon Marchi <simon.marchi@efficios.com>
Subject: Re: [PATCH 2/4] gdb: make get_discrete_bounds return bool
Date: Sun, 6 Dec 2020 10:03:27 +0400	[thread overview]
Message-ID: <20201206060327.GA327270@adacore.com> (raw)
In-Reply-To: <20201123162120.3778679-3-simon.marchi@efficios.com>

Hi Simon,

On Mon, Nov 23, 2020 at 11:21:18AM -0500, Simon Marchi via Gdb-patches wrote:
> get_discrete_bounds currently has three possible return values (see its
> current doc for details).  It appears that for all callers, it would be
> sufficient to have a boolean "worked" / "didn't work" return value.
> 
> Change the return type of get_discrete_bounds to bool and adjust all
> callers.  Doing so simplifies the following patch.
> 
> gdb/ChangeLog:
> 
> 	* gdbtypes.h (get_discrete_bounds): Return bool, adjust all
> 	callers.
> 	* gdbtypes.c (get_discrete_bounds): Return bool.
> 
> Change-Id: Ie51feee23c75f0cd7939742604282d745db59172

A small reminder to remember to remove the Change-Id...

Other than that, the change looks good to me.

This is a very nice simplification of the interface, IMO, so thank you
for doing that. In reading the documentation prior to this change,
it was hard for me to wrap my head around what it the function was
really doing.  In trying to understand the initial motivation, I did
a bit of archeology, and it goes all the way back to the initial creation
of the sourceware repository (20 years ago already!), so no obvious
explanation from there.

> @@ -399,7 +399,7 @@ m2_language::value_print_inner (struct value *val, struct ui_file *stream,
>  
>  	  fputs_filtered ("{", stream);
>  
> -	  i = get_discrete_bounds (range, &low_bound, &high_bound);
> +	  i = get_discrete_bounds (range, &low_bound, &high_bound) ? 0 : -1;
>  	maybe_bad_bstring:
>  	  if (i < 0)
>  	    {

FTR, this hunk required a bit more context to investigate. We can see
that the change looks correct when looking at how variable "i" is
(mis)used:

          i = get_discrete_bounds (range, &low_bound, &high_bound) ? 0 : -1;
        maybe_bad_bstring:
          if (i < 0)
            {
              fputs_styled (_("<error value>"), metadata_style.style (),
                            stream);
              goto done;
            }

          for (i = low_bound; i <= high_bound; i++)

Because of the use of labels, it's hard to propose a simpler rewriting
which one would feel confident about without testing...


> diff --git a/gdb/p-valprint.c b/gdb/p-valprint.c
> index 428b2efc656..8f785b71ea4 100644
> --- a/gdb/p-valprint.c
> +++ b/gdb/p-valprint.c
> @@ -343,7 +343,8 @@ pascal_value_print_inner (struct value *val, struct ui_file *stream,
>  
>  	  fputs_filtered ("[", stream);
>  
> -	  int bound_info = get_discrete_bounds (range, &low_bound, &high_bound);
> +	  int bound_info = (get_discrete_bounds (range, &low_bound, &high_bound)
> +			    ? 0 : -1);
>  	  if (low_bound == 0 && high_bound == -1 && TYPE_LENGTH (type) > 0)
>  	    {
>  	      /* If we know the size of the set type, we can figure out the

Similar story here.

-- 
Joel

  reply	other threads:[~2020-12-06  6:03 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-23 16:21 [PATCH 0/4] Fix bug in value_subscript when range's high bound is not known Simon Marchi via Gdb-patches
2020-11-23 16:21 ` [PATCH 1/4] gdb: make discrete_position return optional Simon Marchi via Gdb-patches
2020-12-06  5:25   ` Joel Brobecker
2020-12-06  5:38   ` Joel Brobecker
2020-12-07 14:58     ` Simon Marchi via Gdb-patches
2020-12-08  3:06       ` Joel Brobecker
2020-12-08 11:41         ` Maciej W. Rozycki
2020-12-09 19:29           ` Simon Marchi via Gdb-patches
2020-12-09 19:53             ` Maciej W. Rozycki
2020-11-23 16:21 ` [PATCH 2/4] gdb: make get_discrete_bounds return bool Simon Marchi via Gdb-patches
2020-12-06  6:03   ` Joel Brobecker [this message]
2020-12-07 15:19     ` Simon Marchi via Gdb-patches
2020-11-23 16:21 ` [PATCH 3/4] gdb: split get_discrete_bounds in two Simon Marchi via Gdb-patches
2020-12-06  7:29   ` Joel Brobecker
2020-12-07 15:49     ` Simon Marchi via Gdb-patches
2020-11-23 16:21 ` [PATCH 4/4] gdb: fix value_subscript when array upper bound is not known Simon Marchi via Gdb-patches
2020-12-06  7:54   ` Joel Brobecker
2020-12-07 16:06     ` Simon Marchi via Gdb-patches
2020-12-08  3:14       ` Joel Brobecker
2020-12-09 18:50         ` Simon Marchi via Gdb-patches
2020-12-09 19:57     ` Simon Marchi via Gdb-patches

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=20201206060327.GA327270@adacore.com \
    --to=brobecker@adacore.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