From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from outbound-ss-820.bluehost.com (outbound-ss-820.bluehost.com [69.89.24.241]) by sourceware.org (Postfix) with ESMTPS id 276D13857367 for ; Sun, 5 Jun 2022 17:30:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 276D13857367 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com Received: from cmgw15.mail.unifiedlayer.com (unknown [10.0.90.130]) by progateway2.mail.pro1.eigbox.com (Postfix) with ESMTP id 8954C10047D91 for ; Sun, 5 Jun 2022 17:30:38 +0000 (UTC) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTP id xu5GnSSUgkku4xu5GnfDVX; Sun, 05 Jun 2022 17:30:38 +0000 X-Authority-Reason: nr=8 X-Authority-Analysis: v=2.4 cv=NoQUz+RJ c=1 sm=1 tr=0 ts=629ce83e a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=dLZJa+xiwSxG16/P+YVxDGlgEgI=:19 a=JPEYwPQDsx4A:10:nop_rcvd_month_year a=Qbun_eYptAEA:10:endurance_base64_authed_username_1 a=CCpqsmhAAAAA:8 a=QIv3ko8KqvRXdXrrZB4A:9 a=ul9cdbp4aOFLsgKbc677:22 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Transfer-Encoding:MIME-Version:Message-Id:Date:Subject: Cc:To:From:Sender:Reply-To:Content-Type:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=pvGyOm+r4P7pTuVqsJKod/d84FM5ielLyxvDhEi7sGc=; b=lrbDnEn6l3/X8+AC9QeASIdDF7 X1qz78ZlvHntSqL+xkqtcn+dCA2B7zyNZPqRGS9gjDQAH8lbQelwZ09QLlr1Z25cG/r7zpYuvZmJi o+HsqTganIlSobyMa5vwDFyrp; Received: from 71-211-171-143.hlrn.qwest.net ([71.211.171.143]:45642 helo=prentzel.Home) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1nxu5F-001H5Z-Tj; Sun, 05 Jun 2022 11:30:37 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Fix assertion failure in copy_type Date: Sun, 5 Jun 2022 11:30:36 -0600 Message-Id: <20220605173036.1615746-1-tom@tromey.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 71.211.171.143 X-Source-L: No X-Exim-ID: 1nxu5F-001H5Z-Tj X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 71-211-171-143.hlrn.qwest.net (prentzel.Home) [71.211.171.143]:45642 X-Source-Auth: tom+tromey.com X-Email-Count: 1 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3030.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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: Sun, 05 Jun 2022 17:30:40 -0000 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. 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. Better would perhaps be to finally implement type GC, but I still haven't attempted this. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=20630 --- 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, } /* Make a copy of the given TYPE, except that the pointer & reference - types are not preserved. - - This function assumes that the given type has an associated objfile. - This objfile is used to allocate the new type. */ + types are not preserved. */ struct type * copy_type (const struct type *type) { - struct type *new_type; - - gdb_assert (type->is_objfile_owned ()); - - new_type = alloc_type_copy (type); + struct type *new_type = alloc_type_copy (type); new_type->set_instance_flags (type->instance_flags ()); TYPE_LENGTH (new_type) = TYPE_LENGTH (type); memcpy (TYPE_MAIN_TYPE (new_type), TYPE_MAIN_TYPE (type), sizeof (struct main_type)); if (type->main_type->dyn_prop_list != NULL) - new_type->main_type->dyn_prop_list - = copy_dynamic_prop_list (&type->objfile_owner ()->objfile_obstack, - type->main_type->dyn_prop_list); + { + struct obstack *storage = (type->is_objfile_owned () + ? &type->objfile_owner ()->objfile_obstack + : gdbarch_obstack (type->arch_owner ())); + new_type->main_type->dyn_prop_list + = copy_dynamic_prop_list (storage, type->main_type->dyn_prop_list); + } return new_type; } diff --git a/gdb/testsuite/gdb.base/printcmds.exp b/gdb/testsuite/gdb.base/printcmds.exp index 3260c8a3c09..2032d9d45a7 100644 --- a/gdb/testsuite/gdb.base/printcmds.exp +++ b/gdb/testsuite/gdb.base/printcmds.exp @@ -752,6 +752,9 @@ proc test_print_array_constants {} { gdb_test_escape_braces "print {{0,1,2},{3,4,5}}" " = {{0, 1, 2}, {3, 4, 5}}" gdb_test "print {4,5,6}\[2\]" " = 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}" " = 65 'A'" } proc test_print_enums {} { -- 2.34.1