From patchwork Thu Dec 25 07:02:38 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sockke X-Patchwork-Id: 127076 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id DFB6C4BA2E27 for ; Thu, 25 Dec 2025 07:03:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DFB6C4BA2E27 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=bytedance.com header.i=@bytedance.com header.a=rsa-sha256 header.s=2212171451 header.b=er5FwigM X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from sg-1-103.ptr.blmpb.com (sg-1-103.ptr.blmpb.com [118.26.132.103]) by sourceware.org (Postfix) with ESMTPS id D0F454BA2E05 for ; Thu, 25 Dec 2025 07:02:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D0F454BA2E05 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=bytedance.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D0F454BA2E05 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=118.26.132.103 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1766646173; cv=none; b=eaO5atqn4AKa+Eio2F/iJTWtjBNC5JZt8Kmx21eOCs1ZlPbMI+QXfObILE369dHk3Sn0Ty5a5CI8dHCfRvvF6QupSd7yZ1EhyueOWRQclm+FpLGI/sKdIM52+TyeF4ccwMOT0Pf3WGY56tcHRFhNOpKabeVs7NwceoscBBKyRL0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1766646173; c=relaxed/simple; bh=JsDy+pa6WakreArS2wmeNLp4L8Z/6IxSUO+0ZP47Zwc=; h=DKIM-Signature:To:From:Message-Id:Subject:Date:Mime-Version; b=fRppxObAbal2Vtv//hx9GkGqTEY3jfFk7tKVLpyFwKMPzREsRNi4DTXfNY1dBFyX0FSusDQVlcxycs/7tVhD3oS3DpO6bJzhWrY4kqHMFxYvUziTsetEl+QhVo14eXQBYHcB0Pz5K5J62F+Q8M7MI/QWdZxOeIsIRBfAt4ZyS8I= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D0F454BA2E05 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=2212171451; d=bytedance.com; t=1766646163; h=from:subject: mime-version:from:date:message-id:subject:to:cc:reply-to:content-type: mime-version:in-reply-to:message-id; bh=WgXvmJG2A7UVyOLZoWAmq3F6QsPZGeIxUBPKPsrXhIA=; b=er5FwigMn8K3y79uIo8n+GHgo+znl3HggNblmo/7RgXhc4TJO1FgiwTP97McKvdqyVXbwv ixStEd7iRc5b4TUzw1uNcOsfOpv/HHpSbUUnDnCNzo1QNGPdfhyx+Sc3YBWiHaHXNipMtV Ov7aTsl4Fes/5oxdllPVkw9s0dezXOFKMLStxSCdQqsMxh9p1i1KB4ZfPx4dT+h0HNdkzv jByatoS2c22Kk4jW/dnee+8Ln6x8JqTeGt0reJWibTCwxHmz4w2Y3Vdcn+gYLM8HaSP/y7 In+VnR/0N6fydN+LgGxlAnw96ySVPh4g/3vaVU1ZYT8ZH3ghIQjyGE9Z2h8LaQ== X-Mailer: git-send-email 2.20.1 Cc: , "Sockke" X-Original-From: Sockke To: From: "Sockke" Message-Id: <20251225070238.224671-1-liuke.gehry@bytedance.com> X-Lms-Return-Path: Subject: [PATCH v3] gdb/dwarf: fix assert failed for missing containing type Date: Thu, 25 Dec 2025 15:02:38 +0800 Mime-Version: 1.0 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED, SPF_HELO_NONE, SPF_PASS, TXREP, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~patchwork=sourceware.org@sourceware.org gdb/dwarf: fix assert failed for missing containing type This patch fixes an assertion failure that occurs when handling missing type units. If the TU referenced by a `DW_AT_containing_type` cannot be found (e.g., due to DWP overflow), the error type returned from the DWARF reader is incorrectly passed to `set_type_vptr_fieldno`, causing an assertion failure: gdb/gdbtypes.c:1919: internal-error: internal_type_vptr_fieldno: Assertion `type->code () == TYPE_CODE_STRUCT || type->code () == TYPE_CODE_UNION' failed. Reviewed-By: Keith Seitz --- gdb/dwarf2/read.c | 8 ++- .../gdb.dwarf2/missing-containing-type.exp | 71 +++++++++++++++++++ 2 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 gdb/testsuite/gdb.dwarf2/missing-containing-type.exp diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 4e2644ba..8daa80e3 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -11549,10 +11549,16 @@ process_structure_scope (struct die_info *die, struct dwarf2_cu *cu) "not found when defining class '%s'"), type->name () ? type->name () : ""); } - else + else if (t->code () == TYPE_CODE_STRUCT + || t->code () == TYPE_CODE_UNION) { set_type_vptr_fieldno (type, TYPE_VPTR_FIELDNO (t)); } + else + { + complaint (_("unable to retrieve the vptr from " + "this type '%s'"), TYPE_ERROR_NAME (t)); + } } else if (cu->producer_is_xlc ()) { diff --git a/gdb/testsuite/gdb.dwarf2/missing-containing-type.exp b/gdb/testsuite/gdb.dwarf2/missing-containing-type.exp new file mode 100644 index 00000000..301c8432 --- /dev/null +++ b/gdb/testsuite/gdb.dwarf2/missing-containing-type.exp @@ -0,0 +1,71 @@ +# Copyright 2025 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 . +load_lib dwarf.exp + +# This test can only be run on targets which support DWARF-2 and use gas. +require dwarf2_support + +require allow_cplus_tests + +standard_testfile main.c -dw4.S + +# Make some DWARF for the test. +set asm_file [standard_output_file $srcfile2] +Dwarf::assemble $asm_file { + cu {} { + DW_TAG_compile_unit { + DW_AT_language @DW_LANG_C_plus_plus + } { + declare_labels container_decl abase_client_type + DW_TAG_namespace { + DW_AT_name NS + } { + container_decl: DW_TAG_class_type { + DW_AT_signature 0x1122334455667788 DW_FORM_ref_sig8 + DW_AT_declaration 1 DW_FORM_flag + } { + abase_client_type: DW_TAG_class_type { + DW_AT_name C + DW_AT_byte_size 0x170 DW_FORM_sdata + DW_AT_containing_type :$container_decl + } { + DW_TAG_subprogram { DW_AT_name "~C" } + } + } + } + } + } + # The referenced TU has been lost. + #tu {} 0x1122334455667788 container_type { + # DW_TAG_type_unit { + # DW_AT_language @DW_LANG_C_plus_plus + # } { + # DW_AT_container_type: class_type { + # {DW_AT_name C} + # {DW_AT_byte_size 1 sdata} + # } + # } + #} +} + + +if { [prepare_for_testing "failed to prepare" ${testfile} \ + [list $srcfile $asm_file] {nodebug}] } { + return +} + +gdb_test_no_output "set language c++" + +gdb_test "ptype NS::C" "No symbol .*"