public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: "Maciej W. Rozycki" <macro@embecosm.com>
To: Andrew Burgess <aburgess@redhat.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH 5/6] Respect `set print array-indexes' with Fortran arrays
Date: Sat, 8 Jan 2022 16:27:03 +0000 (GMT)	[thread overview]
Message-ID: <alpine.DEB.2.20.2112151704470.10183@tpp.orcam.me.uk> (raw)
In-Reply-To: <20211215164924.GM175541@redhat.com>

On Wed, 15 Dec 2021, Andrew Burgess wrote:

> > Index: src/gdb/f-array-walker.h
> > ===================================================================
> > --- src.orig/gdb/f-array-walker.h
> > +++ src/gdb/f-array-walker.h
> > @@ -138,7 +138,8 @@ struct fortran_array_walker_base_impl
> >       true only when this is the last element that will be processed in
> >       this dimension.  */
> >    void process_dimension (std::function<void (struct type *, int, bool)> walk_1,
> > -			  struct type *elt_type, LONGEST elt_off, bool last_p)
> > +			  struct type *elt_type, LONGEST elt_off,
> > +			  struct type *, LONGEST, bool last_p)
> 
> I'd like to see the new arguments given names, and the comment
> extended to explain what they're for, given this is the base
> implementation from which others inherit it seems like this is the
> obvious place someone would look to figure this sort of thing out.

 That is the proper C++ syntax for unused parameters, preferred for GCC, 
the style of which we follow according to our wiki, which I double-checked 
on this occasion as I wrote this code, as far as C++ usage is concerned, 
over `__attribute__ ((__unused__))' since the switch to C++.  And I wasn't 
aware we chose to use `-Wno-unused' instead, which may not be as clean as 
the standard C++ syntax.  I think this divergence from the GCC C++ coding 
style needs to be clearly documented in our wiki.

 I've added the missing argument names then here and elsewhere (a viable 
alternative would be to have the argument names commented out).
  
> > @@ -223,6 +225,8 @@ class fortran_array_walker
> >      if (m_nss != m_ndimensions)
> >        {
> >  	struct type *subarray_type = TYPE_TARGET_TYPE (check_typedef (type));
> > +	gdb_assert (range_type->code () == TYPE_CODE_RANGE);
> 
> I think this assert should move up to immediately after we fetch
> range_type, I'm pretty sure that if range_type isn't TYPE_CODE_RANGE
> then the call to get_discrete_bounds will have already gone wrong.

 Well, I have checked and `get_discrete_bounds' looks prepared to several 
other types, specifically: TYPE_CODE_ENUM, TYPE_CODE_BOOL, TYPE_CODE_INT 
and TYPE_CODE_CHAR, so this assertion is only for TYPE_TARGET_TYPE really, 
so for clarity I've left it right before the invocation of the latter 
macro.

> > @@ -260,7 +264,8 @@ class fortran_array_walker
> >  		elt_type = resolve_dynamic_type (elt_type, {}, e_address);
> >  	      }
> >  
> > -	    m_impl.process_element (elt_type, elt_off, (i == upperbound));
> > +	    m_impl.process_element (elt_type, elt_off, range_type, i,
> > +				    i == upperbound);
> 
> This seems a little weird, you're passing the range_type through to
> the index_type parameter?  Is this really what you mean?

 It's a stupid oversight on my side; this should have been `index_type' in 
both legs of the conditional.  I have adjusted code accordingly (though 
it's now gone owing to the change described below).

> Assuming you mean to pass TYPE_TARGET_TYPE(range_type) here, then the
> index_type ends up being passed through to both process_element and
> process_dimension.  You then end up placing the index_type into a
> member variable within the m_impl.  I wonder if it would be better to
> pass the index_type to start_dimension, and stash it there, then we'd
> only need to pass the index value through maybe?  Or, maybe there
> would be problems with handling multi-dimensional arrays?  I guess
> it's pretty hard to actually uncover bugs in this area as the
> index_type is almost always the same I think....

 I chewed your thoughts over and realised that if we pass `index_type' via 
`start_dimension' then not only some code complication is removed, but if 
we stash it per-dimension, then we'll have no issue if we ever need to use 
different types for individual dimensions.  And the rank of an array is at 
most seven in Fortran, so it's not like it will consume a lot of memory.

 See v2 for how the result looks like.

  Maciej

  reply	other threads:[~2022-01-08 16:27 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-11 11:46 [PATCH 0/6] Make Fortran support respect more `set print' settings Maciej W. Rozycki
2021-12-11 11:47 ` [PATCH 1/6] Initialize `m_ndimensions' in the member initializer list Maciej W. Rozycki
2021-12-15 13:18   ` Andrew Burgess
2021-12-17 15:03     ` Maciej W. Rozycki
2021-12-11 11:47 ` [PATCH 2/6] Avoid redundant operations in `fortran_array_walker' Maciej W. Rozycki
2021-12-15 13:19   ` Andrew Burgess
2021-12-17 15:04     ` Maciej W. Rozycki
2021-12-11 11:47 ` [PATCH 3/6] Respect `set print repeats' with Fortran arrays Maciej W. Rozycki
2021-12-15 15:18   ` Andrew Burgess
2022-01-08 16:25     ` Maciej W. Rozycki
2021-12-11 11:47 ` [PATCH 4/6] Add `set print repeats' tests for C/C++ arrays Maciej W. Rozycki
2021-12-15 15:33   ` Andrew Burgess
2022-01-08 16:26     ` Maciej W. Rozycki
2021-12-11 11:47 ` [PATCH 5/6] Respect `set print array-indexes' with Fortran arrays Maciej W. Rozycki
2021-12-15 16:49   ` Andrew Burgess
2022-01-08 16:27     ` Maciej W. Rozycki [this message]
2021-12-11 11:48 ` [PATCH 6/6] Add `set print array-indexes' tests for C/C++ arrays Maciej W. Rozycki
2021-12-15 16:51   ` Andrew Burgess
2022-01-08 16:27     ` Maciej W. Rozycki

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=alpine.DEB.2.20.2112151704470.10183@tpp.orcam.me.uk \
    --to=macro@embecosm.com \
    --cc=aburgess@redhat.com \
    --cc=gdb-patches@sourceware.org \
    /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).