From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2126) id 984AC385741C; Sat, 18 Jun 2022 16:43:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 984AC385741C Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom Tromey To: gdb-cvs@sourceware.org Subject: [binutils-gdb] Fix assertion failure in copy_type X-Act-Checkin: binutils-gdb X-Git-Author: Tom Tromey X-Git-Refname: refs/heads/master X-Git-Oldrev: fba1ac87dcb76e61f270d236f1e7c8aaec80f9c4 X-Git-Newrev: 8e2da165187907a570a33eee7e56ce16fc597a40 Message-Id: <20220618164351.984AC385741C@sourceware.org> Date: Sat, 18 Jun 2022 16:43:51 +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: Sat, 18 Jun 2022 16:43:51 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D8e2da1651879= 07a570a33eee7e56ce16fc597a40 commit 8e2da165187907a570a33eee7e56ce16fc597a40 Author: Tom Tromey Date: Sun Jun 5 11:28:10 2022 -0600 Fix assertion failure in copy_type =20 PR exp/20630 points out a simple way to cause an assertion failure in copy_type -- but this was found in the wild a few times as well. =20 copy_type only works for objfile-owned types, but there isn't a deep reason for this. This patch fixes the bug by updating copy_type to work for any sort of type. =20 Better would perhaps be to finally implement type GC, but I still haven't attempted this. =20 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=3D20630 Diff: --- gdb/gdbtypes.c | 21 +++++++++------------ gdb/testsuite/gdb.base/printcmds.exp | 3 +++ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c index 2a51372a037..c8f98554859 100644 --- a/gdb/gdbtypes.c +++ b/gdb/gdbtypes.c @@ -5796,27 +5796,24 @@ copy_type_recursive (struct objfile *objfile, } =20 /* Make a copy of the given TYPE, except that the pointer & reference - types are not preserved. - =20 - This function assumes that the given type has an associated objfile. - This objfile is used to allocate the new type. */ + types are not preserved. */ =20 struct type * copy_type (const struct type *type) { - struct type *new_type; - - gdb_assert (type->is_objfile_owned ()); - - new_type =3D alloc_type_copy (type); + struct type *new_type =3D alloc_type_copy (type); new_type->set_instance_flags (type->instance_flags ()); TYPE_LENGTH (new_type) =3D TYPE_LENGTH (type); memcpy (TYPE_MAIN_TYPE (new_type), TYPE_MAIN_TYPE (type), sizeof (struct main_type)); if (type->main_type->dyn_prop_list !=3D NULL) - new_type->main_type->dyn_prop_list - =3D copy_dynamic_prop_list (&type->objfile_owner ()->objfile_obstack, - type->main_type->dyn_prop_list); + { + struct obstack *storage =3D (type->is_objfile_owned () + ? &type->objfile_owner ()->objfile_obstack + : gdbarch_obstack (type->arch_owner ())); + new_type->main_type->dyn_prop_list + =3D copy_dynamic_prop_list (storage, type->main_type->dyn_prop_list); + } =20 return new_type; } diff --git a/gdb/testsuite/gdb.base/printcmds.exp b/gdb/testsuite/gdb.base/= printcmds.exp index 04d390d3658..c0c59c5c503 100644 --- a/gdb/testsuite/gdb.base/printcmds.exp +++ b/gdb/testsuite/gdb.base/printcmds.exp @@ -794,6 +794,9 @@ proc test_print_array_constants {} { gdb_test_escape_braces "print {{0,1,2},{3,4,5}}" " =3D {{0, 1, 2}, {3= , 4, 5}}" gdb_test "print {4,5,6}\[2\]" " =3D 6" gdb_test "print *&{4,5,6}\[1\]" "Attempt to take address of value not = located in memory." + + # This used to cause a crash. + gdb_test "print {unsigned char[]}{65}" " =3D 65 'A'" } =20 proc test_print_enums {} {