From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from sonic313-20.consmr.mail.ir2.yahoo.com (sonic313-20.consmr.mail.ir2.yahoo.com [77.238.179.187]) by sourceware.org (Postfix) with ESMTPS id 65E1F3892007 for ; Thu, 30 Apr 2020 13:10:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 65E1F3892007 X-YMail-OSG: 37SZkRMVM1ni.NGRP8kYWEjeEEad8nh0fCJhr7FGv2z9vN8uhIVkFDz8iohzXWg 09Vk06FlmzxgOZP1D4rlduDwBf_zW05rs8w9fNg.Xpb2n2Wl2EPtjcczd_6DAdGLYCZprqMadDm1 6oLuENtEXzvcWZZ1271.bF4XNzfIq33kIQC6RqjeUZhDCfIpafJJEkm_FfMuw4Ayi6lrdPU.jAWP mEUMVZJ4mUPWMQjHZ.Ospxm9aiXBTJdQhtOT4t_CgcFrLj.cHdqxdZZCCeBxwmVlM_xQLCzVknGd dIX7E1pnXUNmW3HdU_I0YIKBsSSMXUGVi89WXjpIlcY31gG5FYcucPF0hgbLaVylcVJCgeSXU1VG Z3o5KGEx7wmqR_danErK6ZjND5QDaYrGj2q8YOcxk3eJCRt8nmYzcWyytW_UD5CMN_k2OyKIfMO9 mnwaKuKTKQhddU8NT8w.3LoHbXiP_SeWPPS5AmrUOLxjEO.BM9tAG1jQvQTe3BIv76ERijhkAhUp lZXxJH0JynapUHZaBFw9Rt0HFzqWUqQqGkwPF8qh6dy1cI0l_DMn6G7M4nor.EoZ.QDsKIwnmlRF uVQaox4OFr4NpGsZxYZkgUVpBSx4xBXgu9mptDrHIKi4q3bC.4di7mD315tZE_YvzzgWPkrrdTp5 ixa67WyKdBQNOyjMlzMOhjGeIlsmCoEGP0pSz634ycBqhjQf1xJStmAouI2pomvrrdBJb.TSarv9 OHT2bukjnndtVBUN97Z79.PiTy29MM87nGL_t1L33rbbfs_YcZRPXsfgsbhjTnrt17Nec0WleSuf fO1ckJ4.0P8EVX3yr8e1RoQHRrsKXv7i2hQR3Yx_WtZ5L996UZ_gCUWn059UwyznYGJBMuO3safq B4Q5EzW5aehiJ6b4x6SWMC44E1UE9aPLFHMh.uS8HdryF7052AbX.Xn7D8XKuhJc1zVlEYvspLeS l70R9JgFT3pPGGPNiKOmTUoa3.lT_EVU6ylR37aifcSN3UJan.AzLTkBnEc_HgzV_3KQvlbcrCVk CCbrwD1nOSB8CV59FEoQEt0VJ8Xo4u_8sRyIJlCCgP143Omr.NysGLRRgAF6iBbgDJQ0qnqsIbes _iHdAnRWG0bCWepDUeu5XVAcn4d_ePFAPAz74PiC_K0sZ08Rlc3szCTt4t_8Cnkx9n8hhg61mDIA k9iQcmdVbIrbvF3x8tl_35KX2m2AFJaf9677ZjarTeO856fDBziZ4FP1jffj1eqZPz2KCb7VznSi 9ftBaiNdF88uJtXftozWbTdWsCEERb1DXeXNX7s1CB2ZVfDcMQ7nTHB_Uynl34ArE8n0eSwsESx_ btYCim67iXukr0FBqj_ZcP1VPI4ErC9XVf2eRqfpJBYWo81K.hBcAc.BdPQst6pWuw9Ukh6kBwHW 3cITaztwnEcGPhCBMK.ClYlpcktnILHHV Received: from sonic.gate.mail.ne1.yahoo.com by sonic313.consmr.mail.ir2.yahoo.com with HTTP; Thu, 30 Apr 2020 13:10:24 +0000 Received: by smtp432.mail.ir2.yahoo.com (VZM Hermes SMTP Server) with ESMTPA ID 9eccecb5ec80aeb8ec1bdf23ff92e6ab; Thu, 30 Apr 2020 13:10:19 +0000 (UTC) From: Hannes Domani To: gdb-patches@sourceware.org Subject: [PATCH v2][PR gdb/18706] Calculate size of array of stubbed type Date: Thu, 30 Apr 2020 15:09:54 +0200 Message-Id: <20200430130954.15121-1-ssbssa@yahoo.de> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Antivirus: Avast (VPS 200429-0, 04/29/2020), Outbound message X-Antivirus-Status: Clean References: <20200430130954.15121-1-ssbssa.ref@yahoo.de> X-Spam-Status: No, score=-18.6 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, 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: Thu, 30 Apr 2020 13:10:35 -0000 Sizes of stubbed types are calculated on demand in check_typedef, so the same must also be done for arrays of stubbed types. 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 in the class definition. For these stubbed types, the size must be recalculated once the full definition is available. gdb/ChangeLog: 2020-04-30 Hannes Domani PR gdb/18706 * gdbtypes.c (check_typedef): Calculate size of array of stubbed type. gdb/testsuite/ChangeLog: 2020-04-30 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. --- v2: - Remove redundant checks for TYPE_NFIELDS and TYPE_CODE_RANGE in array type. - Extended description in the commit message and test. --- gdb/gdbtypes.c | 14 +++++++++++ gdb/testsuite/gdb.cp/stub-array-size.cc | 25 ++++++++++++++++++++ gdb/testsuite/gdb.cp/stub-array-size.exp | 30 ++++++++++++++++++++++++ gdb/testsuite/gdb.cp/stub-array-size.h | 21 +++++++++++++++++ gdb/testsuite/gdb.cp/stub-array-size2.cc | 22 +++++++++++++++++ 5 files changed, 112 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..f1633d8db4 100644 --- a/gdb/gdbtypes.c +++ b/gdb/gdbtypes.c @@ -2637,6 +2637,20 @@ 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) + { + struct type *range_type = check_typedef (TYPE_INDEX_TYPE (type)); + if (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..c43d35b634 --- /dev/null +++ b/gdb/testsuite/gdb.cp/stub-array-size.exp @@ -0,0 +1,30 @@ +# 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. + +# Test size of arrays of stubbed types (structures where the full definition +# is not immediately available). + +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