From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2111) id 22150395CC20; Thu, 30 Apr 2020 16:22:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 22150395CC20 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Hannes Domani To: gdb-cvs@sourceware.org Subject: [binutils-gdb] Calculate size of array of stubbed type X-Act-Checkin: binutils-gdb X-Git-Author: Hannes Domani X-Git-Refname: refs/heads/master X-Git-Oldrev: d5cf82c0d7a7b13727a2f26425afc9051656a716 X-Git-Newrev: ee9d1e5f76033cd8432713a76381ade76697df04 Message-Id: <20200430162232.22150395CC20@sourceware.org> Date: Thu, 30 Apr 2020 16:22:32 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 30 Apr 2020 16:22:32 -0000 https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=ee9d1e5f76033cd8432713a76381ade76697df04 commit ee9d1e5f76033cd8432713a76381ade76697df04 Author: Hannes Domani Date: Mon Apr 27 13:14:24 2020 +0200 Calculate size of array of stubbed type 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. Diff: --- gdb/ChangeLog | 6 ++++++ gdb/gdbtypes.c | 14 ++++++++++++++ gdb/testsuite/ChangeLog | 8 ++++++++ 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 ++++++++++++++++++++++ 7 files changed, 126 insertions(+) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index d9f2b2c6f6b..3a8d2448e3a 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,9 @@ +2020-04-30 Hannes Domani + + PR gdb/18706 + * gdbtypes.c (check_typedef): Calculate size of array of + stubbed type. + 2020-04-30 Hannes Domani PR gdb/15559 diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c index 73984357338..6648dc4d678 100644 --- a/gdb/gdbtypes.c +++ b/gdb/gdbtypes.c @@ -2873,6 +2873,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/ChangeLog b/gdb/testsuite/ChangeLog index 6b25cd8a51b..e2bf45b3e3b 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,11 @@ +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. + 2020-04-30 Hannes Domani * gdb.python/py-format-string.exp: Adjust pretty_arrays expected 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 00000000000..281d70de4f8 --- /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 00000000000..c43d35b634b --- /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 00000000000..5006633246b --- /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 00000000000..8eda4bd1dd7 --- /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() +{ +}