From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from sonic304-22.consmr.mail.ir2.yahoo.com (sonic304-22.consmr.mail.ir2.yahoo.com [77.238.179.147]) by sourceware.org (Postfix) with ESMTPS id C3A533870845 for ; Mon, 27 Apr 2020 11:42:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org C3A533870845 X-YMail-OSG: m6W6GpIVM1mKG94a5I2eW79YDcUbucLCH1kQnr7jPy2ySs4dn15teYTe7jNRl9D yz_u4pcEGniLGejaBNkKvenN1XDNtW5fp9S8x29HTUbCDClml49Z6nSKmxsTtzyVjFHf56hg6PRt _JwoCum58oMhAVQUhlDCr9lMVrQgkIhtDLQPHP8G9Nun1AAeWbAi5RswE1tqgvN2PsbVHlgv1arL 9MGAYOfxctCd2bZBHZUgfXiHI.8tNK.aUcaai1.r6doTTCwbsrraFK0Don4qJAeuGNGJUgVrP3Pq lxP4ICMvjcgRxyLoIPJCLYaveQgnB3ndxOVtYy.YH0D2Nv_dXCWtQ_V7WP4.6PM5y9lz0TGt_kUk gTKXXEmiHHxsjbkueqjA8Er6Du3qsPdv7YBv7eI5qqc81.1r_QqDi3NnsTJv2cd_v5jWvNZURPY. hzCdlPbxmhkY_y8j0Zqzkz.LAyYiOWasavgD.jw2pxIiolAPSfmk0S2zpWX26HWmEjamDE1JoHoi pf4H1pC.dXsaoSNeiSAXJMWLL_P_f0BnlhuUj5Bkq1llLmp8pyImtxV8hUDsJ0vWh3VF4T8HfDms 560LYWLtqs._du2.TuLS1bj.hD9YeBBPqYy.70.MeLuZkbVkwxue5hIgG9CpTwbjsinhIsGrw7Tb RANVsPJX16.3EVE2jY7mJ5LQlmrHpEfP8VJE7NuX0PhUzq9exdL1xxrmPll8ajVkULCjbShlxZUC O7n5m_GGM3YD8kmXbh88y1cBdTZFOH_50VQXOsnitARvGjLQlRx2TWSWAlmt7_sV5mbzsk1HFyJ9 EPs9fXrCPJW49db9BGHBQ_9hsTfoIoLD7zFrvbVsnmTCWc3QJE8116TITERsEMU.SD38TD6rxPAh Lgp.dIyWAwDH0oAZCbHp.AY15KtG7SevBf98hbzczMQ16u.Rk80NQgpziHE67Mtph7fwZ85u0zGG l462D4.j75RqwH4k725l5jDRgqrrEF98KgTnCK1A3Y..ch3wOsr6aRrPIAn0v74XBIkoAPZiCVnq 9b.89fAz.WGuCdaLx6GUPZIlbAXdULuMCsd3fpHSiDskU9meH7C75QOpkOK5C66Qi.Ae_V2bIrKH 3Gr5lX9VTD1Iwat3OcW7tNgeYJwGAyIg94bwC5f4SqwjN1_CoinJxmVYktOZlcjK8eMeu6XrJgHm b03CGcEtMs0qKj35tXRi85IFAgEpvD45_t.3axZrCDlrNh3BIm95bZKfIQxmS173LI7R8phx0J2r 9Pt45x64nY5Ox1_OvbZL7_EDY_ad84aA0IhXLjHGloJgvllWusDuInH1pOD5q1AZ68.BnuSH5XdR a8hmGP9kJaNYCBqEJcQGchqbl5qNbTrZbrEjRgRws4qcXAb9FI24Iza0lcehmspHbZ15T_vBMTLa Ma0z0xBIF2tAE13RkqwKl.GT_zH0FFL8M Received: from sonic.gate.mail.ne1.yahoo.com by sonic304.consmr.mail.ir2.yahoo.com with HTTP; Mon, 27 Apr 2020 11:42:09 +0000 Received: by smtp408.mail.ir2.yahoo.com (VZM Hermes SMTP Server) with ESMTPA ID 159b77d348f4f8c529c79efbbb070a60; Mon, 27 Apr 2020 11:42:08 +0000 (UTC) From: Hannes Domani To: gdb-patches@sourceware.org Subject: [PATCH][PR gdb/18706] Calculate size of array of stubbed type Date: Mon, 27 Apr 2020 13:41:54 +0200 Message-Id: <20200427114154.2275-1-ssbssa@yahoo.de> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Antivirus: Avast (VPS 200426-0, 04/26/2020), Outbound message X-Antivirus-Status: Clean References: <20200427114154.2275-1-ssbssa.ref@yahoo.de> X-Spam-Status: No, score=-18.5 required=5.0 tests=BAYES_00, 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, 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: Mon, 27 Apr 2020 11:42:14 -0000 Sizes of stubbed types are calculated on demand in check_typedef, so the same must also be done for arrays of stubbed types. gdb/ChangeLog: 2020-04-27 Hannes Domani PR gdb/18706 * gdbtypes.c (check_typedef): Calculate size of array of stubbed type. gdb/testsuite/ChangeLog: 2020-04-27 Hannes Domani PR gdb/18706 * gdb.cp/stub-array-size.cc: New test. * gdb.cp/stub-array-size.exp: New file. * gdb.cp/stub-array-size.h: New test. * gdb.cp/stub-array-size2.cc: New test. --- gdb/gdbtypes.c | 16 ++++++++++++++ gdb/testsuite/gdb.cp/stub-array-size.cc | 25 ++++++++++++++++++++++ gdb/testsuite/gdb.cp/stub-array-size.exp | 27 ++++++++++++++++++++++++ gdb/testsuite/gdb.cp/stub-array-size.h | 21 ++++++++++++++++++ gdb/testsuite/gdb.cp/stub-array-size2.cc | 22 +++++++++++++++++++ 5 files changed, 111 insertions(+) create mode 100644 gdb/testsuite/gdb.cp/stub-array-size.cc create mode 100644 gdb/testsuite/gdb.cp/stub-array-size.exp create mode 100644 gdb/testsuite/gdb.cp/stub-array-size.h 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) TYPE_LENGTH (type) = TYPE_LENGTH (target_type); TYPE_TARGET_STUB (type) = 0; } + else if (TYPE_CODE (type) == TYPE_CODE_ARRAY + && TYPE_NFIELDS (type) == 1) + { + struct type *range_type = check_typedef (TYPE_INDEX_TYPE (type)); + if (TYPE_CODE (range_type) == TYPE_CODE_RANGE + && has_static_range (TYPE_RANGE_DATA (range_type))) + { + ULONGEST len = 0; + LONGEST low_bound = TYPE_LOW_BOUND (range_type); + LONGEST high_bound = TYPE_HIGH_BOUND (range_type); + if (high_bound >= low_bound) + len = (high_bound - low_bound + 1) * TYPE_LENGTH (target_type); + TYPE_LENGTH (type) = len; + TYPE_TARGET_STUB (type) = 0; + } + } } type = make_qualified_type (type, instance_flags, NULL); diff --git a/gdb/testsuite/gdb.cp/stub-array-size.cc b/gdb/testsuite/gdb.cp/stub-array-size.cc new file mode 100644 index 0000000000..281d70de4f --- /dev/null +++ b/gdb/testsuite/gdb.cp/stub-array-size.cc @@ -0,0 +1,25 @@ +/* This testcase is part of GDB, the GNU debugger. + + 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. 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. If not, see . */ + +#include "stub-array-size.h" + +A a[10]; + +int main() +{ + return 0; +}; diff --git a/gdb/testsuite/gdb.cp/stub-array-size.exp b/gdb/testsuite/gdb.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. 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. If not, see . + +# This file is part of the gdb testsuite. + +if {[skip_cplus_tests]} { continue } + +standard_testfile .cc stub-array-size2.cc + +if {[prepare_for_testing "failed to prepare" $testfile "$srcfile $srcfile2" \ + {c++ debug}]} { + return -1 +} + +gdb_test "print sizeof(a)/sizeof(a\[0\])" "10" diff --git a/gdb/testsuite/gdb.cp/stub-array-size.h b/gdb/testsuite/gdb.cp/stub-array-size.h new file mode 100644 index 0000000000..5006633246 --- /dev/null +++ b/gdb/testsuite/gdb.cp/stub-array-size.h @@ -0,0 +1,21 @@ +/* This testcase is part of GDB, the GNU debugger. + + 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. 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. If not, see . */ + +struct A +{ + virtual ~A(); +}; diff --git a/gdb/testsuite/gdb.cp/stub-array-size2.cc b/gdb/testsuite/gdb.cp/stub-array-size2.cc new file mode 100644 index 0000000000..8eda4bd1dd --- /dev/null +++ b/gdb/testsuite/gdb.cp/stub-array-size2.cc @@ -0,0 +1,22 @@ +/* This testcase is part of GDB, the GNU debugger. + + 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. 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. If not, see . */ + +#include "stub-array-size.h" + +A::~A() +{ +} -- 2.26.2