Bug 28115 - Support packed array encoded as DW_TAG_subrange_type
Summary: Support packed array encoded as DW_TAG_subrange_type
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: ada (show other bugs)
Version: HEAD
: P2 normal
Target Milestone: 12.1
Assignee: Tom Tromey
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-07-21 10:13 UTC by Tom de Vries
Modified: 2022-03-07 14:58 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:
Project(s) to access:
ssh public key:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tom de Vries 2021-07-21 10:13:29 UTC
With gcc-11, we have:
...
(gdb) print pa_ptr(3)^M
cannot subscript or call something of type `foo__packed_array_ptr'^M
(gdb) FAIL: gdb.ada/arrayptr.exp: scenario=minimal: print pa_ptr(3)
...

This happens in ada_funcall_operation::evaluate here:
...
  if (type->code () == TYPE_CODE_PTR)
    {
      switch (ada_check_typedef (TYPE_TARGET_TYPE (type))->code ())
...
because the case TYPE_CODE_RANGE is not handled.

The dwarf looks like:
...
 <2><1667>: Abbrev Number: 5 (DW_TAG_variable)
    <1668>   DW_AT_name        : pa_ptr
    <166f>   DW_AT_type        : <0x1638>
 <2><1638>: Abbrev Number: 4 (DW_TAG_typedef)
    <1639>   DW_AT_name        : foo__packed_array_ptr
    <1640>   DW_AT_type        : <0x1644>
 <2><1644>: Abbrev Number: 6 (DW_TAG_pointer_type)
    <1645>   DW_AT_byte_size   : 8
    <1646>   DW_AT_type        : <0x164a>
 <2><164a>: Abbrev Number: 7 (DW_TAG_subrange_type)
    <164b>   DW_AT_lower_bound : 0
    <164c>   DW_AT_upper_bound : 18 byte block: 9e 10 ff ff ff ff ff ff ff ff 3f 0 0 0 0 0 0 0  (DW_OP_implicit_value 16 byte block: ff ff ff ff ff ff ff ff 3f 0 0 0 0 0 0 0 )
    <165f>   DW_AT_name        : foo__packed_array
    <1663>   DW_AT_type        : <0x1720>
    <1667>   DW_AT_artificial  : 1
 <1><1720>: Abbrev Number: 15 (DW_TAG_base_type)
    <1721>   DW_AT_byte_size   : 16
    <1722>   DW_AT_encoding    : 7      (unsigned)
    <1723>   DW_AT_name        : (indirect string, offset: 0x204a): long_long_long_unsigned
    <1727>   DW_AT_artificial  : 1
...

A simple guess:
...
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index b098991612d..736007f737b 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -10605,6 +10605,8 @@ ada_funcall_operation::evaluate (struct type *expect_type,
            callee = ada_value_ind (callee);
          type = ada_check_typedef (TYPE_TARGET_TYPE (type));
          break;
+       case TYPE_CODE_RANGE:
+         break;
        default:
          error (_("cannot subscript or call something of type `%s'"),
                 ada_type_name (value_type (callee)));
...
turns this into:
...
(gdb) print pa_ptr(3)^M
That operation is not available on integers of more than 8 bytes.^M
(gdb)
...
which turns things into a duplicate of PR20991 - "__int128 type support".

Which is also how other related tests in the test-case fail.  But I don't understand ada well enough to known whether the patch is actually correct.

So at least for now, filing a separate PR.
Comment 1 Sourceware Commits 2021-07-21 12:19:56 UTC
The master branch has been updated by Tom de Vries <vries@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=0057a7ee0d963eb9aee5cdfb9d6da5279bc8caf9

commit 0057a7ee0d963eb9aee5cdfb9d6da5279bc8caf9
Author: Tom de Vries <tdevries@suse.de>
Date:   Wed Jul 21 14:19:51 2021 +0200

    [gdb/testsuite] Add KFAILs for gdb.ada FAILs with gcc-11
    
    With gcc-11 we run into:
    ...
    (gdb) print pa_ptr.all^M
    That operation is not available on integers of more than 8 bytes.^M
    (gdb) KFAIL: gdb.ada/arrayptr.exp: scenario=all: print pa_ptr.all (PRMS: gdb/20991)
    ...
    
    This is due to PR exp/20991 - "__int128 type support".  Mark this and similar
    FAILs as KFAIL.
    
    Also mark this FAIL:
    ....
    (gdb) print pa_ptr(3)^M
    cannot subscript or call something of type `foo__packed_array_ptr'^M
    (gdb) FAIL: gdb.ada/arrayptr.exp: scenario=minimal: print pa_ptr(3)
    ...
    as a KFAIL for PR ada/28115 - "Support packed array encoded as
    DW_TAG_subrange_type".
    
    Tested on x86_64-linux, with gcc-10 and gcc-11.
    
    gdb/testsuite/ChangeLog:
    
    2021-07-21  Tom de Vries  <tdevries@suse.de>
    
            * gdb.ada/arrayptr.exp: Add KFAILs for PR20991 and PR28115.
            * gdb.ada/exprs.exp: Add KFAILs for PR20991.
            * gdb.ada/packed_array_assign.exp: Same.
Comment 2 Sourceware Commits 2021-07-21 12:22:21 UTC
The gdb-11-branch branch has been updated by Tom de Vries <vries@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=f26101b199482bd13b5f9c45fb4f43a4eb8b16e6

commit f26101b199482bd13b5f9c45fb4f43a4eb8b16e6
Author: Tom de Vries <tdevries@suse.de>
Date:   Wed Jul 21 14:22:16 2021 +0200

    [gdb/testsuite] Add KFAILs for gdb.ada FAILs with gcc-11
    
    With gcc-11 we run into:
    ...
    (gdb) print pa_ptr.all^M
    That operation is not available on integers of more than 8 bytes.^M
    (gdb) KFAIL: gdb.ada/arrayptr.exp: scenario=all: print pa_ptr.all (PRMS: gdb/20991)
    ...
    
    This is due to PR exp/20991 - "__int128 type support".  Mark this and similar
    FAILs as KFAIL.
    
    Also mark this FAIL:
    ....
    (gdb) print pa_ptr(3)^M
    cannot subscript or call something of type `foo__packed_array_ptr'^M
    (gdb) FAIL: gdb.ada/arrayptr.exp: scenario=minimal: print pa_ptr(3)
    ...
    as a KFAIL for PR ada/28115 - "Support packed array encoded as
    DW_TAG_subrange_type".
    
    Tested on x86_64-linux, with gcc-10 and gcc-11.
    
    gdb/testsuite/ChangeLog:
    
    2021-07-21  Tom de Vries  <tdevries@suse.de>
    
            * gdb.ada/arrayptr.exp: Add KFAILs for PR20991 and PR28115.
            * gdb.ada/exprs.exp: Add KFAILs for PR20991.
            * gdb.ada/packed_array_assign.exp: Same.
Comment 3 Tom de Vries 2021-09-07 09:42:12 UTC
Hmm, this recent gcc commit looks interesting:
...
commit c0b03afeab4502da3040ef1ebbd28f826737fa8a
Author: Eric Botcazou <ebotcazou@adacore.com>
Date:   Mon Sep 6 11:16:08 2021 +0200

    Fix debug info for packed array types in Ada
    
    Packed array types are sometimes represented with integer types under the
    hood in Ada, but we nevertheless need to emit them as array types in the
    debug info so we have the types.get_array_descr_info langhook for this
    purpose; but it is not invoked from modified_type_die, which causes:
    
    FAIL: gdb.ada/arrayptr.exp: scenario=minimal: print pa_ptr.all
    FAIL: gdb.ada/arrayptr.exp: scenario=minimal: print pa_ptr.all(3)
    
    in the GDB testsuite.
    
    gcc/
            * dwarf2out.c (modified_type_die): Deal with all array types earlier
            and use local variable consistently throughout the function.
...
Comment 4 Tom Tromey 2022-02-28 20:33:48 UTC
With gcc 12 (random build of gcc trunk) this works:

# of expected passes		22

whereas with 11 (fedora 34 system gcc):

# of expected passes		19
# of unexpected failures	2
# of known failures		1


So I think this is a compiler bug.
I guess we could kfail it.
Comment 6 Sourceware Commits 2022-03-07 14:57:28 UTC
The master branch has been updated by Tom Tromey <tromey@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=47a39c6e18324360b3ef9b72f03e206417f2ce9c

commit 47a39c6e18324360b3ef9b72f03e206417f2ce9c
Author: Tom Tromey <tromey@adacore.com>
Date:   Mon Feb 28 13:42:03 2022 -0700

    Fix gdb.ada/arrayptr.exp results
    
    PR ada/28115 points out that gdb.ada/arrayptr.exp works with GNAT 12,
    but fails with minimal encodings in earlier versions.
    
    This patch updates the test to try to report the results correctly.  I
    tried this with the Fedora 34 system gcc (GCC 11) and with a GCC 12
    built from git trunk sometime relatively recently.
    
    Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=28115
Comment 7 Tom Tromey 2022-03-07 14:58:21 UTC
Fixed.