From: Hannes Domani <ssbssa@yahoo.de>
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 [thread overview]
Message-ID: <20200427114154.2275-1-ssbssa@yahoo.de> (raw)
In-Reply-To: <20200427114154.2275-1-ssbssa.ref@yahoo.de>
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 <ssbssa@yahoo.de>
PR gdb/18706
* gdbtypes.c (check_typedef): Calculate size of array of stubbed type.
gdb/testsuite/ChangeLog:
2020-04-27 Hannes Domani <ssbssa@yahoo.de>
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 <http://www.gnu.org/licenses/>. */
+
+#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 <http://www.gnu.org/licenses/>.
+
+# 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 <http://www.gnu.org/licenses/>. */
+
+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 <http://www.gnu.org/licenses/>. */
+
+#include "stub-array-size.h"
+
+A::~A()
+{
+}
--
2.26.2
next parent reply other threads:[~2020-04-27 11:42 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20200427114154.2275-1-ssbssa.ref@yahoo.de>
2020-04-27 11:41 ` Hannes Domani [this message]
2020-04-28 15:10 ` Simon Marchi
2020-04-29 12:47 ` Hannes Domani
2020-04-29 16:39 ` Simon Marchi
2020-04-29 16:58 ` Hannes Domani
2020-04-29 18:26 ` Simon Marchi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200427114154.2275-1-ssbssa@yahoo.de \
--to=ssbssa@yahoo.de \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox