public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Document resolve_dynamic_type oddity
@ 2021-10-19 20:46 Tom Tromey
  2021-10-19 21:11 ` Christian Biesinger
  0 siblings, 1 reply; 4+ messages in thread
From: Tom Tromey @ 2021-10-19 20:46 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

Today I re-learned that resolve_dynamic_type can return a type for
which is_dynamic_type returns true.  This can happen for an array
whose elements have dynamic type -- the array is reported as dynamic,
but resolving the elements would be incorrect, because each element
might have a different type after resolution.

You can see the special case in resolve_dynamic_array_or_string:

  if (ary_dim != NULL && ary_dim->code () == TYPE_CODE_ARRAY)
...
  else
...

I looked into having the TYPE_CODE_ARRAY case in
is_dynamic_type_internal follow this same logic, but that breaks down
on the gdb.fortran/dynamic-ptype-whatis.exp test case.  In particular
this code in fortran_undetermined::evaluate:

  value *callee = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
  if (noside == EVAL_AVOID_SIDE_EFFECTS
      && is_dynamic_type (value_type (callee)))
    callee = std::get<0> (m_storage)->evaluate (nullptr, exp, EVAL_NORMAL);

... relies on is_dynamic_type returning true for such an array.

I wasn't really sure of the best way to fix this, so in the meantime I
wrote this patch, which documents the oddity so that I might have a
chance of remembering this in the future.
---
 gdb/gdbtypes.h | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index 4324641eb0d..62fbbc484a2 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -2666,12 +2666,21 @@ extern CORE_ADDR get_pointer_type_max (struct type *);
 /* * Resolve all dynamic values of a type e.g. array bounds to static values.
    ADDR specifies the location of the variable the type is bound to.
    If TYPE has no dynamic properties return TYPE; otherwise a new type with
-   static properties is returned.  */
+   static properties is returned.
+
+   For an array type, if the element type is dynamic, then that will
+   not be resolved.  This is done because each individual element may
+   have a different type when resolved (depending on the contents of
+   memory).  In this situation, 'is_dynamic_type' will still return
+   type for the return value of this function.  */
 extern struct type *resolve_dynamic_type
   (struct type *type, gdb::array_view<const gdb_byte> valaddr,
    CORE_ADDR addr);
 
-/* * Predicate if the type has dynamic values, which are not resolved yet.  */
+/* * Predicate if the type has dynamic values, which are not resolved yet.
+   See the caveat in 'resolve_dynamic_type' to understand a scenario
+   where an apparently-resolved type may still be considered
+   "dynamic".  */
 extern int is_dynamic_type (struct type *type);
 
 extern struct type *check_typedef (struct type *);
-- 
2.31.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Document resolve_dynamic_type oddity
  2021-10-19 20:46 [PATCH] Document resolve_dynamic_type oddity Tom Tromey
@ 2021-10-19 21:11 ` Christian Biesinger
  2021-10-20 17:59   ` Tom Tromey
  0 siblings, 1 reply; 4+ messages in thread
From: Christian Biesinger @ 2021-10-19 21:11 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

On Tue, Oct 19, 2021 at 4:47 PM Tom Tromey via Gdb-patches
<gdb-patches@sourceware.org> wrote:
> --- a/gdb/gdbtypes.h
> +++ b/gdb/gdbtypes.h
> @@ -2666,12 +2666,21 @@ extern CORE_ADDR get_pointer_type_max (struct type *);
>  /* * Resolve all dynamic values of a type e.g. array bounds to static values.
>     ADDR specifies the location of the variable the type is bound to.
>     If TYPE has no dynamic properties return TYPE; otherwise a new type with
> -   static properties is returned.  */
> +   static properties is returned.
> +
> +   For an array type, if the element type is dynamic, then that will
> +   not be resolved.  This is done because each individual element may
> +   have a different type when resolved (depending on the contents of
> +   memory).  In this situation, 'is_dynamic_type' will still return
> +   type for the return value of this function.  */

type -> true?

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Document resolve_dynamic_type oddity
  2021-10-19 21:11 ` Christian Biesinger
@ 2021-10-20 17:59   ` Tom Tromey
  2021-10-29 13:33     ` Tom Tromey
  0 siblings, 1 reply; 4+ messages in thread
From: Tom Tromey @ 2021-10-20 17:59 UTC (permalink / raw)
  To: Christian Biesinger; +Cc: Tom Tromey, gdb-patches

>>>>> "Christian" == Christian Biesinger <cbiesinger@google.com> writes:

>> +   type for the return value of this function.  */

Christian> type -> true?

Yeah, thanks for catching that.  I've updated my copy.

Tom

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Document resolve_dynamic_type oddity
  2021-10-20 17:59   ` Tom Tromey
@ 2021-10-29 13:33     ` Tom Tromey
  0 siblings, 0 replies; 4+ messages in thread
From: Tom Tromey @ 2021-10-29 13:33 UTC (permalink / raw)
  To: Tom Tromey via Gdb-patches; +Cc: Christian Biesinger, Tom Tromey

>>>>> "Tom" == Tom Tromey via Gdb-patches <gdb-patches@sourceware.org> writes:

>>>>> "Christian" == Christian Biesinger <cbiesinger@google.com> writes:
>>> +   type for the return value of this function.  */

Christian> type -> true?

Tom> Yeah, thanks for catching that.  I've updated my copy.

I'm checking this in now.

Tom

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-10-29 13:33 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-19 20:46 [PATCH] Document resolve_dynamic_type oddity Tom Tromey
2021-10-19 21:11 ` Christian Biesinger
2021-10-20 17:59   ` Tom Tromey
2021-10-29 13:33     ` Tom Tromey

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).