From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from sonic302-20.consmr.mail.ir2.yahoo.com (sonic302-20.consmr.mail.ir2.yahoo.com [87.248.110.83]) by sourceware.org (Postfix) with ESMTPS id 0730D395A027 for ; Wed, 29 Apr 2020 12:47:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 0730D395A027 X-YMail-OSG: oBDX33gVM1k0a_i3m8.jF2O6ebZIBWKw_K_GeUIm3A41VVktXYI6ZtJxTlw.usH 1GZzq_0jqQ8Cnpc.zVOHvY8adNQhgjqPvvB3qUc6f0_eh3LidGZFd1vheq4lDbwwIixsOJ.sMuHq LOWnitCqmI.nwlzdq2lKAXUS7HcxJS6aI772HzLId_o91WcMfA7_GIMlQQgdgEC.03qEqPoWoeUM hrnnc84fm6TU9p1s3RqyCE6ZDLwfnJA343p5xY_KGtlU542CUDK1j0BPgCYJ9sApjm2AEcLHchUk 4AH2bMdmIbZ0l.gzGPkzGlUnuOZ7X4Lue.JhZYpTCzXw3EL5pNK0znDGwBtkB9nkvQltWt12OPCI dkk5wNFcYl91.FdrlDLCspJzZUJ6E2OqPcLordDZOZumhjjmtbtNGeEaAIPBWp5OGer2AzgF5p_r MwYotmoUnNxBIl3L2eHFuZ6ionWmidqMzvMdz6jjqrP5JYjXlRGsV.ttBUFbEWfQNuivYuwQPzYF QRcEjZ4V8FkPkU8rSkOhLg5XcYv8ExIr8bzkNW8c4YpIXctihbxPCvmW1TXTzhJytfVy0LiHq9O8 Rmz1iip0Iqc3SNbARDtIUIOUByh.mXzBr7wMUS7.C7qTIg5Krxo1Qe.kbcrh5BuMYdRc2pIBh3Sy DtQLaZEpwU8zvMrH1Od3FyTwNhDzeU42aj0WQvIixabT2AJ7lXRaRcUJg5JeJtVXShJLAjDVGHn. TK8lZAx8Q.1N.KwgLnx41DIM70F_yOPgFGTKrmyfZGeJK8KksA9_K4m025ShQAitA1ftEIiW.BQw 8DJSnLvvowz6JQDcRnoZFSwwKqXKODT.4kYMkCSbL_Kd9xNT0RfltHNVnTaUu_j748ZCcOb3jfM9 istDO.muhBj3x4aynoWH06jntKPTRuVxeioauD9sLw6TnhheXk9tr02gX7I007U0FqH_b_i0JS5J CHrKfkpekUREx2Dg3YXRFx46_EjIWw9qJ7BqRZzxmvc_v0JcV3QZSW1ob4USOMdzbJ.jXs0G4gZ8 ekmqAxQCudisie6QcZ9Qx6fNtazQWQijybqnd0BMOI_NApxXiGxicuxbzPOPeUdj89UgdrPMlZH3 hoZE9ySr3Rt6T01mP_g5ukJCIKN02zNAtamt_fEpf30eBvuQ17xv29YC54SHZJe1b2VBvTk2Ta4Q noAmf32edqzEeqir_FDZ.Ipue213zCrSPMfygGzIZWShHEfgBnx6PJ4s_RGObgJRPZQQHPfdCj1T 2OHBmIRGOE3ONPggpiYJAI0wsXwFqRJngimZ2BUeqMb_ecuJY01sNfDNDH62MH.udCPXu3WcIc_t ww8gdDVMdqhdnsTMv Received: from sonic.gate.mail.ne1.yahoo.com by sonic302.consmr.mail.ir2.yahoo.com with HTTP; Wed, 29 Apr 2020 12:47:19 +0000 Date: Wed, 29 Apr 2020 12:47:16 +0000 (UTC) From: Hannes Domani To: Gdb-patches Message-ID: <970532437.4157409.1588164436815@mail.yahoo.com> In-Reply-To: <82e2e5d4-f5e3-7a89-5bcb-bfe305c601e4@simark.ca> References: <20200427114154.2275-1-ssbssa.ref@yahoo.de> <20200427114154.2275-1-ssbssa@yahoo.de> <82e2e5d4-f5e3-7a89-5bcb-bfe305c601e4@simark.ca> Subject: Re: [PATCH][PR gdb/18706] Calculate size of array of stubbed type MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Mailer: WebService/1.1.15756 YMailNorrin Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:71.0) Gecko/20100101 Firefox/71.0 X-Spam-Status: No, score=-16.5 required=5.0 tests=BAYES_00, BODY_8BITS, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 29 Apr 2020 12:47:23 -0000 Am Dienstag, 28. April 2020, 17:10:29 MESZ hat Simon Marchi Folgendes geschrieben: > On 2020-04-27 7:41 a.m., Hannes Domani via Gdb-patches wrote: > > Sizes of stubbed types are calculated on demand in check_typedef, so th= e same > > must also be done for arrays of stubbed types. > > For the uninitiated, can you please explain what's happening here, which = types > are involved, which ones are stubs, and what that means.=C2=A0 That would= help me > understand what happens here and be confident that the patch is correct. Something like?: A stubbed type is usually a structure that has only been forward declared, = but can also happen if the structure has a virtual function that's not inline i= n the class definition. For these stubbed types, the size must be recalculated once the full defini= tion is available. > > > > gdb/ChangeLog: > > > > 2020-04-27=C2=A0 Hannes Domani=C2=A0 > > > >=C2=A0=C2=A0=C2=A0=C2=A0 PR gdb/18706 > >=C2=A0=C2=A0=C2=A0=C2=A0 * gdbtypes.c (check_typedef): Calculate size of= array of stubbed type. > > > > gdb/testsuite/ChangeLog: > > > > 2020-04-27=C2=A0 Hannes Domani=C2=A0 > > > >=C2=A0=C2=A0=C2=A0=C2=A0 PR gdb/18706 > >=C2=A0=C2=A0=C2=A0=C2=A0 * gdb.cp/stub-array-size.cc: New test. > >=C2=A0=C2=A0=C2=A0=C2=A0 * gdb.cp/stub-array-size.exp: New file. > >=C2=A0=C2=A0=C2=A0=C2=A0 * gdb.cp/stub-array-size.h: New test. > >=C2=A0=C2=A0=C2=A0=C2=A0 * gdb.cp/stub-array-size2.cc: New test. > > --- > >=C2=A0 gdb/gdbtypes.c=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0 | 16 ++++++++++++++ > >=C2=A0 gdb/testsuite/gdb.cp/stub-array-size.cc=C2=A0 | 25 ++++++++++++++= ++++++++ > >=C2=A0 gdb/testsuite/gdb.cp/stub-array-size.exp | 27 +++++++++++++++++++= +++++ > >=C2=A0 gdb/testsuite/gdb.cp/stub-array-size.h=C2=A0 | 21 +++++++++++++++= +++ > >=C2=A0 gdb/testsuite/gdb.cp/stub-array-size2.cc | 22 +++++++++++++++++++ > >=C2=A0 5 files changed, 111 insertions(+) > >=C2=A0 create mode 100644 gdb/testsuite/gdb.cp/stub-array-size.cc > >=C2=A0 create mode 100644 gdb/testsuite/gdb.cp/stub-array-size.exp > >=C2=A0 create mode 100644 gdb/testsuite/gdb.cp/stub-array-size.h > >=C2=A0 create mode 100644 gdb/testsuite/gdb.cp/stub-array-size2.cc > > > > diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c > > index 157b3c5e61..5e9de2ccb1 100644 > > --- a/gdb/gdbtypes.c > > +++ b/gdb/gdbtypes.c > > @@ -2637,6 +2637,22 @@ check_typedef (struct type *type) > >=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 TYPE_LENGTH (type) =3D TYPE_L= ENGTH (target_type); > >=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 TYPE_TARGET_STUB (type) =3D 0= ; > >=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 else if (TYPE_CODE (type) =3D=3D TYPE_C= ODE_ARRAY > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 && TYPE_NFIELDS= (type) =3D=3D 1) > > Why is the `TYPE_NFIELDS (type) =3D=3D 1` check necessary here? This is de define of TYPE_INDEX_TYPE: #define TYPE_INDEX_TYPE(type) TYPE_FIELD_TYPE (type, 0) So I assumed I had to check if the field exists before using it. This check is not always done (resolve_dynamic_array_or_string), sometimes with gdb_assert (is_dynamic_type_internal), or like I did (is_scalar_type_recursive). I don't know which is the most correct way. > > +=C2=A0=C2=A0=C2=A0 { > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 struct type *range_type =3D check_typed= ef (TYPE_INDEX_TYPE (type)); > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (TYPE_CODE (range_type) =3D=3D TYPE_= CODE_RANGE > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 && has_static_r= ange (TYPE_RANGE_DATA (range_type))) > > Is it possible to have an array type where the index type is not TYPE_COD= E_RANGE? > > If it is not, then we should assert `TYPE_CODE (range_type) =3D=3D TYPE_C= ODE_RANGE`.=C2=A0 If it > can be of another type, what are the other possibilities? Again here, this check is done differently in various functions. Either gdb_assert (resolve_dynamic_range), or explicit check (is_scalar_type_recursive). If I see these different approaches, I tend to use the safest myself. > > diff --git a/gdb/testsuite/gdb.cp/stub-array-size.exp b/gdb/testsuite/g= db.cp/stub-array-size.exp > > new file mode 100644 > > index 0000000000..cb486cd459 > > --- /dev/null > > +++ b/gdb/testsuite/gdb.cp/stub-array-size.exp > > @@ -0,0 +1,27 @@ > > +# Copyright 2020 Free Software Foundation, Inc. > > +# > > +# This program is free software; you can redistribute it and/or modify > > +# it under the terms of the GNU General Public License as published by > > +# the Free Software Foundation; either version 3 of the License, or > > +# (at your option) any later version. > > +# > > +# This program is distributed in the hope that it will be useful, > > +# but WITHOUT ANY WARRANTY; without even the implied warranty of > > +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.=C2=A0 See the > > +# GNU General Public License for more details. > > +# > > +# You should have received a copy of the GNU General Public License > > +# along with this program.=C2=A0 If not, see . > > + > > +# This file is part of the gdb testsuite. > > > Please add a short introductory comment that explains what this intends t= o test. Like?: Test size of arrays of stubbed types (structures where the full definition = is not immediately available). Hannes