Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH v2][PR gdb/18706] Calculate size of array of stubbed type
       [not found] <20200430130954.15121-1-ssbssa.ref@yahoo.de>
@ 2020-04-30 13:09 ` Hannes Domani
  2020-04-30 16:14   ` Simon Marchi
  0 siblings, 1 reply; 4+ messages in thread
From: Hannes Domani @ 2020-04-30 13:09 UTC (permalink / raw)
  To: gdb-patches

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  <ssbssa@yahoo.de>

	PR gdb/18706
	* gdbtypes.c (check_typedef): Calculate size of array of stubbed type.

gdb/testsuite/ChangeLog:

2020-04-30  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.
---
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 <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..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 <http://www.gnu.org/licenses/>.
+
+# 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 <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



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2][PR gdb/18706] Calculate size of array of stubbed type
  2020-04-30 13:09 ` [PATCH v2][PR gdb/18706] Calculate size of array of stubbed type Hannes Domani
@ 2020-04-30 16:14   ` Simon Marchi
  2020-04-30 16:23     ` Hannes Domani
  0 siblings, 1 reply; 4+ messages in thread
From: Simon Marchi @ 2020-04-30 16:14 UTC (permalink / raw)
  To: Hannes Domani, gdb-patches

On 2020-04-30 9:09 a.m., Hannes Domani via Gdb-patches wrote:
> 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.

Thanks, this is OK.

Simon



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2][PR gdb/18706] Calculate size of array of stubbed type
  2020-04-30 16:14   ` Simon Marchi
@ 2020-04-30 16:23     ` Hannes Domani
  2020-04-30 22:01       ` Tom de Vries
  0 siblings, 1 reply; 4+ messages in thread
From: Hannes Domani @ 2020-04-30 16:23 UTC (permalink / raw)
  To: Gdb-patches

 Am Donnerstag, 30. April 2020, 18:14:26 MESZ hat Simon Marchi <simark@simark.ca> Folgendes geschrieben:

> On 2020-04-30 9:09 a.m., Hannes Domani via Gdb-patches wrote:
>
> > 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.
>
>
> Thanks, this is OK.

Pushed, thanks.


Hannes


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2][PR gdb/18706] Calculate size of array of stubbed type
  2020-04-30 16:23     ` Hannes Domani
@ 2020-04-30 22:01       ` Tom de Vries
  0 siblings, 0 replies; 4+ messages in thread
From: Tom de Vries @ 2020-04-30 22:01 UTC (permalink / raw)
  To: Hannes Domani, Gdb-patches

On 30-04-2020 18:23, Hannes Domani via Gdb-patches wrote:
>  Am Donnerstag, 30. April 2020, 18:14:26 MESZ hat Simon Marchi <simark@simark.ca> Folgendes geschrieben:
> 
>> On 2020-04-30 9:09 a.m., Hannes Domani via Gdb-patches wrote:
>>
>>> 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.
>>
>>
>> Thanks, this is OK.
> 
> Pushed, thanks.

Hi,

This caused:
...
FAIL: gdb.fortran/array-slices.exp: test 2: p array
FAIL: gdb.fortran/array-slices.exp: test 3: p array
FAIL: gdb.fortran/array-slices.exp: test 4: p array
FAIL: gdb.fortran/array-slices.exp: test 5: p array
FAIL: gdb.fortran/array-slices.exp: test 7: p array
FAIL: gdb.fortran/array-slices.exp: test 8: p array
FAIL: gdb.fortran/vla-alloc-assoc.exp: print deallocated vla1
FAIL: gdb.fortran/vla-alloc-assoc.exp: print deallocated vla2
FAIL: gdb.fortran/vla-type.exp: print twov before allocated
FAIL: gdb.fortran/vla-type.exp: print twov%ivla1 before allocated
FAIL: gdb.fortran/vla-ptype.exp: ptype pvla(5, 45, 20) not associated
FAIL: gdb.fortran/vla-ptype.exp: ptype vla1(3, 6, 9) not allocated
FAIL: gdb.fortran/vla-ptype.exp: ptype vla2(5, 45, 20) not allocated
FAIL: gdb.fortran/derived-type-striding.exp: p point_dimension
FAIL: gdb.fortran/derived-type-striding.exp: p point_mixed_dimension
FAIL: gdb.fortran/vla-value-sub.exp: print passed array1 in foo (passed
sub-array)
FAIL: gdb.fortran/vla-value-sub.exp: print array1(5, 5) after filled in
foo (passed sub-array)
FAIL: gdb.fortran/vla-value-sub.exp: print array2 in foo after it was
filled (passed sub-array)
FAIL: gdb.fortran/vla-value-sub.exp: print array2 in foo after it was
mofified in debugger (passed sub-array)
FAIL: gdb.fortran/vla-ptype-sub.exp: ptype array1(3, 3) (passed sub-array)
FAIL: gdb.fortran/vla-ptype-sub.exp: ptype array2(4, 4, 4) (passed
sub-array)
FAIL: gdb.fortran/vla-value.exp: print undefined pvla
FAIL: gdb.fortran/vla-value.exp: print pvla(5, 45, 20) after deassociated
FAIL: gdb.fortran/vla-value.exp: print pvla(7, 45, 14) after dissasociated
FAIL: gdb.fortran/vla-value.exp: print vla1 after deassociated
FAIL: gdb.fortran/vla-value.exp: print allocated vla1(3,6,9) after
specific assignment (deallocated)
FAIL: gdb.fortran/vla-value.exp: print allocated vla1(1,3,8) after
specific assignment (deallocated)
FAIL: gdb.fortran/vla-value.exp: print allocated vla1(9,9,9) after
assignment in debugger (deallocated)
FAIL: gdb.mi/mi-vla-fortran.exp: evaluate not allocated vla, before
allocation (unexpected output)
FAIL: gdb.mi/mi-vla-fortran.exp: eval variable vla1_not_allocated
(unexpected output)
FAIL: gdb.mi/mi-vla-fortran.exp: get children of vla1_not_allocated
(unexpected output)
FAIL: gdb.mi/mi-vla-fortran.exp: evaluate not allocated vla, after
deallocation (unexpected output)
FAIL: gdb.mi/mi-vla-fortran.exp: evaluate vla pointer set to null
(unexpected output)
...

Thanks,
- Tom



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-04-30 22:01 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20200430130954.15121-1-ssbssa.ref@yahoo.de>
2020-04-30 13:09 ` [PATCH v2][PR gdb/18706] Calculate size of array of stubbed type Hannes Domani
2020-04-30 16:14   ` Simon Marchi
2020-04-30 16:23     ` Hannes Domani
2020-04-30 22:01       ` Tom de Vries

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox