Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Andrew Burgess <aburgess@redhat.com>
To: Tom Tromey <tromey@adacore.com>, gdb-patches@sourceware.org
Cc: Tom Tromey <tromey@adacore.com>
Subject: Re: [PATCH] Remove ada_value_slice
Date: Wed, 10 Jun 2026 19:38:11 +0100	[thread overview]
Message-ID: <87qzmep7fw.fsf@redhat.com> (raw)
In-Reply-To: <20260605215104.656469-1-tromey@adacore.com>

Tom Tromey <tromey@adacore.com> writes:

> ada_value_slice and ada_value_slice_from_ptr are nearly identical.
> From what I can tell, the former can be removed without any problem.

I tried running the testsuite adding a print out at the call site where
ada_value_slice used to be called.  I ran gdb.ada/*.exp and
gdb.dwarf2/*.exp and didn't see the call site being hit once.  Which is
not great.

I looked at the history of these two functions, and they are both added
in commit 0b5d8877912034b2af0c548afbb794e4dcd07fbd, so clearly at one
point there was an expectation that these would do different things.  If
they do the same now, then I wonder if that's intentional, or a mistake
because one code path was never used?

However, I'm curious about some of the differences between these two
functions ....

> -
> -  return value_cast (slice_type,
> -		     value_slice (array, low, *high_pos - *low_pos + 1));

In ada_value_slice_from_ptr  the final return is:

  base = value_as_address (array_ptr) + (*low_pos - *base_low_pos) * stride;
  return value_at_lazy (slice_type, base);

The value_as_address call, for an array, will end up calling
coerce_array, which is:

  struct value *
  coerce_array (struct value *arg)
  {
    struct type *type;
  
    arg = coerce_ref (arg);
    type = check_typedef (arg->type ());
  
    switch (type->code ())
      {
      case TYPE_CODE_ARRAY:
        if (!type->is_vector () && current_language->c_style_arrays_p ())
  	arg = value_coerce_array (arg);
        break;
      case TYPE_CODE_FUNC:
        arg = value_coerce_function (arg);
        break;
      }
    return arg;
  }

Notice that for TYPE_CODE_ARRAY we only actually do anything when
c_style_arrays_p() is true, which it isn't for Ada.  So we're not going
to convert the array into a pointer, which means (I think) that the
value_at_lazy isn't going to do what you want.  I suspect this is why
there are two, very similar functions.

What are your thoughts?

Thanks,
Andrew


      reply	other threads:[~2026-06-10 18:38 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-05 21:51 Tom Tromey
2026-06-10 18:38 ` Andrew Burgess [this message]

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=87qzmep7fw.fsf@redhat.com \
    --to=aburgess@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=tromey@adacore.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