Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: Andrew Burgess <andrew.burgess@embecosm.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCHv5 4/4] gdb/fortran: Add support for Fortran array slices at the GDB prompt
Date: Tue, 20 Oct 2020 14:45:49 -0600	[thread overview]
Message-ID: <87pn5ciq2q.fsf@tromey.com> (raw)
In-Reply-To: <7832c05de858cfc8bf4b6abba4332523d0547805.1602439661.git.andrew.burgess@embecosm.com> (Andrew Burgess's message of "Sun, 11 Oct 2020 19:12:13 +0100")

>>>>> "Andrew" == Andrew Burgess <andrew.burgess@embecosm.com> writes:

Andrew> The problem is that, as I see it, the current value contents model
Andrew> assumes that an object base address will be the lowest address within
Andrew> that object, and that the contents of the object start at this base
Andrew> address and occupy the TYPE_LENGTH bytes after that.

Andrew> ( We do have the embedded_offset, which is used for C++ sub-classes,
Andrew> such that an object can start at some offset from the content buffer,
Andrew> however, the assumption that the object then occupies the next
Andrew> TYPE_LENGTH bytes is still true within GDB. )

Relatedly, we had a bug for a while where the Python val-print code
could be given just a virtual base of an object, and it would then try
to examine memory outside this buffer.

I've also considered separating values from memory in some ways.

Here's something weird in gdb... debug this program:

    #include <stdio.h>
    char b[] = "hello";
    struct x {
      char *x;
    };
    int main()
    {
      struct x val; val.x = b;
      printf("%s\n", val.x);
      b[1] = 'q';
      printf("%s\n", val.x);
      return 0;
    }

If you stop at the first printf and "print val" you get:

    (gdb) p val
    $1 = {
      x = 0x40200c <b> "hello"
    }

Then at the second you can see:

    (gdb) p val
    $2 = {
      x = 0x40200c <b> "hqllo"
    }
    (gdb) p $1
    $3 = {
      x = 0x40200c <b> "hqllo"
    }

That is, the apparent value of the string in "$1" changed.  This happens
because the value only holds the pointer, the contents are read during
printing.

So, sometimes I've wondered if we want to fix that, by say attaching
more memory to the value, say as it is printed.

Another thing I've considered is maybe letting multiple values share
some memory (to avoid duplicating large arrays); or maybe going the
other way and lazily populating arrays when they are used purely as
intermediate values.

Kind of random thoughts, though I suppose the lazy array thing is
similar to something you've done in this patch.

Andrew> Where this hack will show through to the user is if they ask for the
Andrew> address of an array in their program with a negative array stride, the
Andrew> address they get from GDB will not match the address that would be
Andrew> computed within the Fortran program.

Calls for a second hack ;)

FWIW I don't think I really have a problem with your proposed hack.

Andrew> +  /* Create a new offset calculator for TYPE, which is either an array or a
Andrew> +     string.  */
Andrew> +  fortran_array_offset_calculator (struct type *type)

Single-argument constructors should normally be explicit.

Andrew> +/* A base class used by fortran_array_walker.  */
Andrew> +class fortran_array_walker_base_impl
Andrew> +{
Andrew> +public:

A class with only public methods (and no data) can just be a "struct".

Andrew> +  /* Constructor.  */
Andrew> +  explicit fortran_array_walker_base_impl ()
Andrew> +  { /* Nothing.  */ }

Doesn't need the constructor.

Andrew> +/* A class to wrap up the process of iterating over a multi-dimensional
Andrew> +   Fortran array.  IMPL is used to specialise what happens as we walk over
Andrew> +   the array.  See class FORTRAN_ARRAY_WALKER_BASE_IMPL (above) for the
Andrew> +   methods than can be used to customise the array walk.  */
Andrew> +template<typename Impl>
Andrew> +class fortran_array_walker

This seems to mix compile-time- and runtime- polymorphism.

Maybe the idea was not to have virtual methods?  But in that case this:

Andrew> +  /* Ensure that Impl is derived from the required base class.  This just
Andrew> +     ensures that all of the required API methods are available and have a
Andrew> +     sensible default implementation.  */
Andrew> +  gdb_static_assert ((std::is_base_of<fortran_array_walker_base_impl,Impl>::value));

... seems weird.  I guess the idea is to use method hiding as a kind of
static overriding?  But if any method is missing, compilation will just
fail anyway.

Tom

  parent reply	other threads:[~2020-10-20 20:45 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-13 12:58 [PATCH 0/8] Fortran Array Slicing and Striding Support Andrew Burgess
2020-08-13 12:58 ` [PATCH 1/8] gdbsupport: Provide global operators |=, &=, and ^= for enum bit flags Andrew Burgess
2020-08-15 17:16   ` Tom Tromey
2020-08-16  9:13     ` Andrew Burgess
2020-08-17 10:40     ` Andrew Burgess
2020-08-20 16:00       ` Pedro Alves
2020-08-21 14:49       ` Pedro Alves
2020-08-21 15:57         ` Andrew Burgess
2020-08-21 18:10           ` Pedro Alves
2020-08-13 12:58 ` [PATCH 2/8] gdbsupport: Make function arguments constant in enum-flags.h Andrew Burgess
2020-08-15 19:45   ` Tom Tromey
2020-08-16  9:08     ` Andrew Burgess
2020-08-13 12:58 ` [PATCH 3/8] gdb/fortran: Clean up array/string expression evaluation Andrew Burgess
2020-08-13 12:58 ` [PATCH 4/8] gdb/fortran: Move Fortran expression handling into f-lang.c Andrew Burgess
2020-08-13 12:58 ` [PATCH 5/8] gdb/fortran: Change whitespace when printing arrays Andrew Burgess
2020-08-13 12:58 ` [PATCH 6/8] gdb: Convert enum range_type to a bit field enum Andrew Burgess
2020-08-13 12:58 ` [PATCH 7/8] gdb/testsuite: Add missing expected results Andrew Burgess
2020-08-13 12:58 ` [PATCH 8/8] gdb/fortran: Add support for Fortran array slices at the GDB prompt Andrew Burgess
2020-08-13 13:31   ` Eli Zaretskii
2020-08-26 14:49 ` [PATCHv2 00/10] Fortran Array Slicing and Striding Support Andrew Burgess
2020-08-26 14:49   ` [PATCHv2 01/10] Rewrite valid-expr.h's internals in terms of the detection idiom (C++17/N4502) Andrew Burgess
2020-08-26 14:49   ` [PATCHv2 02/10] Use type_instance_flags more throughout Andrew Burgess
2020-08-26 14:49   ` [PATCHv2 03/10] Rewrite enum_flags, add unit tests, fix problems Andrew Burgess
2020-08-26 14:49   ` [PATCHv2 04/10] gdb: additional changes to make use of type_instance_flags more Andrew Burgess
2020-08-26 14:49   ` [PATCHv2 05/10] gdb/fortran: Clean up array/string expression evaluation Andrew Burgess
2020-09-19  8:53     ` Andrew Burgess
2020-08-26 14:49   ` [PATCHv2 06/10] gdb/fortran: Move Fortran expression handling into f-lang.c Andrew Burgess
2020-09-19  8:53     ` Andrew Burgess
2020-08-26 14:49   ` [PATCHv2 07/10] gdb/fortran: Change whitespace when printing arrays Andrew Burgess
2020-09-19  8:54     ` Andrew Burgess
2020-08-26 14:49   ` [PATCHv2 08/10] gdb: Convert enum range_type to a bit field enum Andrew Burgess
2020-08-26 14:49   ` [PATCHv2 09/10] gdb/testsuite: Add missing expected results Andrew Burgess
2020-09-18  9:53     ` Andrew Burgess
2020-08-26 14:49   ` [PATCHv2 10/10] gdb/fortran: Add support for Fortran array slices at the GDB prompt Andrew Burgess
2020-08-26 17:02     ` Eli Zaretskii
2020-09-19  9:47   ` [PATCHv3 0/2] Fortran Array Slicing and Striding Support Andrew Burgess
2020-09-19  9:48     ` [PATCHv3 1/2] gdb: Convert enum range_type to a bit field enum Andrew Burgess
2020-09-19 13:50       ` Simon Marchi
2020-09-19  9:48     ` [PATCHv3 2/2] gdb/fortran: Add support for Fortran array slices at the GDB prompt Andrew Burgess
2020-09-19 10:03       ` Eli Zaretskii
2020-09-28  9:40     ` [PATCHv4 0/3] Fortran Array Slicing and Striding Support Andrew Burgess
2020-09-28  9:40       ` [PATCHv4 1/3] gdb: Convert enum range_type to a bit field enum Andrew Burgess
2020-09-28  9:40       ` [PATCHv4 2/3] gdb: rename 'enum range_type' to 'enum range_flag' Andrew Burgess
2020-09-28  9:40       ` [PATCHv4 3/3] gdb/fortran: Add support for Fortran array slices at the GDB prompt Andrew Burgess
2020-09-28  9:52         ` Eli Zaretskii via Gdb-patches
2020-10-11 18:12       ` [PATCHv5 0/4] Fortran Array Slicing and Striding Support Andrew Burgess
2020-10-11 18:12         ` [PATCHv5 1/4] gdb: Convert enum range_type to a bit field enum Andrew Burgess
2020-10-20 20:16           ` Tom Tromey
2020-10-11 18:12         ` [PATCHv5 2/4] gdb: rename 'enum range_type' to 'enum range_flag' Andrew Burgess
2020-10-20 20:16           ` Tom Tromey
2020-10-11 18:12         ` [PATCHv5 3/4] gdb/fortran: add support for parsing array strides in expressions Andrew Burgess
2020-10-12 13:21           ` Simon Marchi
2020-10-20 20:17           ` Tom Tromey
2020-10-22 10:42           ` Andrew Burgess
2020-10-11 18:12         ` [PATCHv5 4/4] gdb/fortran: Add support for Fortran array slices at the GDB prompt Andrew Burgess
2020-10-12 14:10           ` Simon Marchi
2020-10-20 20:45           ` Tom Tromey [this message]
2020-10-29 11:08             ` Andrew Burgess
2020-10-31 22:16           ` [PATCHv6] " Andrew Burgess
2020-11-12 12:09             ` Andrew Burgess
2020-11-12 18:58             ` Tom Tromey
2020-11-19 11:56             ` Andrew Burgess

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=87pn5ciq2q.fsf@tromey.com \
    --to=tom@tromey.com \
    --cc=andrew.burgess@embecosm.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