From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id v9hlA+Prg2qKWS4AWB0awg (envelope-from ) for ; Tue, 18 Aug 2026 01:21:39 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=GbZaj2LO; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id F03F91E033; Tue, 18 Aug 2026 01:21:38 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-3.1 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_SBL_CSS autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [IPv6:2620:52:6:3111::32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 434C11E033 for ; Tue, 18 Aug 2026 01:21:38 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9FE774BA2E3D for ; Tue, 18 Aug 2026 05:21:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9FE774BA2E3D Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=GbZaj2LO Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 64CDA4BA2E2C for ; Tue, 18 Aug 2026 05:21:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 64CDA4BA2E2C Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 64CDA4BA2E2C Authentication-Results: sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1787030471; cv=none; b=KnK2C1BZ6E3A5STqz9qyMNTaChJksqo/wPFOwxQ2L3Ix7E6jWEGqp8AwjvNbSAXVEG/A6YU1q71ti95yo1HYC5FzxXaBO48wAtCHZnSOVwocRo/2kPf8Xq6wUfpUAvhbVGbEikv1/u63O+XqTtrze1RfRH1jFMafgw3T49/02Ck= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1787030471; c=relaxed/simple; bh=OiBiR2VynBv8qgn9ZZj634mRtQMtLgfwK0QYBpX4Ulg=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=rmKsn2+AzlLm1s68ONf85E1H/a/BkdxEkK6uZFpELh/NUtvGrEedP0mIiAl5PO3ViErx62/dbnZ1q4VRDOp8mGNOUa6MiQsIEQaqr/0/4qBUhe2M2Aapgkwtn/DDrD1ji0ksK1S49lxZ0o3bQ6yI0to1a6tJPg0084D8q89x1Og= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=GbZaj2LO DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 64CDA4BA2E2C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1787030471; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zvpkviDcSuJ4DtAdl7NFoUf1rCV5biyfYfauqjLxtZk=; b=GbZaj2LOMibUe1n9ngc/1Lc5Z/7F4T2lE/e2hgReGMdz9Y+neVSKuZhoO1CZSm1Wb1M0oK KoTVNdO1yRN2ROsuNd8Na1d72RZ/PSnr8JpC+/u4fXlfWjJMXKJbmKqCcBSDQEvWSzqciR oz7nyp9I3sPktXIyO9I8ykC4/r+mx5w= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-630-Cd35NY3PPAKF43l8r2sE5g-1; Tue, 18 Aug 2026 01:21:08 -0400 X-MC-Unique: Cd35NY3PPAKF43l8r2sE5g-1 X-Mimecast-MFC-AGG-ID: Cd35NY3PPAKF43l8r2sE5g_1787030467 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A4A691955EAE; Tue, 18 Aug 2026 05:21:07 +0000 (UTC) Received: from f44-mesa-1 (unknown [10.22.88.13]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C0B241956042; Tue, 18 Aug 2026 05:21:06 +0000 (UTC) Date: Mon, 17 Aug 2026 22:21:04 -0700 From: Kevin Buettner To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: Re: [PATCH 1/2] gdb: fix crash when pretty printing anonymous struct with base class Message-ID: <20260817222104.0181be66@f44-mesa-1> In-Reply-To: <20260817145907.142300-1-simon.marchi@efficios.com> References: <20260817145907.142300-1-simon.marchi@efficios.com> Organization: Red Hat MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: -nstvirehbgblAitnL9pMBHiZC_GwQh-2Bu7OX0EqT8_1787030467 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit 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~public-inbox=simark.ca@sourceware.org On Mon, 17 Aug 2026 10:59:01 -0400 Simon Marchi wrote: > As I was reviewing another patch, I was wondering if we allowed > type->name() to be nullptr. The answer is yes, but there are some spots > that don't check for nullptr, when they should. Claude came up with a > reproducer that inspired the included test case. It is arguably a > corner case, but it makes GDB crash. > > The crash happens when trying to pretty-print (with "set print pretty > on") a value of an anonymous struct type that has a base. Given this: > > struct base > { > int a; > }; > > struct : base > { > int b; > } v4 = { { 1 }, 2 }; > > We get: > > $ ./gdb -nx -q --data-directory=data-directory testsuite/outputs/gdb.cp/anon-struct/anon-struct -ex "with print pretty -- p v4" > Reading symbols from testsuite/outputs/gdb.cp/anon-struct/anon-struct... > $1 = { > = { > a = 1 > }, > /home/smarchi/src/binutils-gdb/gdb/ui-file.h:77:30: runtime error: null pointer passed as argument 1, which is declared to never be null > > The crash happens here: > > #4 0x00007ffff600dec8 in __ubsan_handle_nonnull_arg_abort () from /usr/lib/libubsan.so.1 > #5 0x00005555637daa35 in ui_file::puts (this=0x7c1ff1c022d0, str=0x0) at /home/smarchi/src/binutils-gdb/gdb/ui-file.h:77 > #6 0x0000555566f2b0ab in gdb_puts (linebuffer=0x0, stream=0x7c1ff1c022d0) at /home/smarchi/src/binutils-gdb/gdb/utils.c:1912 > #7 0x00005555644e5cd4 in cp_print_value_fields (val=0x7d0ff1c2aa00, stream=0x7c1ff1c022d0, recurse=0, options=0x7bfff094acb0, dont_print_vb=0x0, dont_print_statmem=0) at /home/smarchi/src/binutils-gdb/gdb/cp-valprint.c:213 > #8 0x00005555640de708 in c_value_print_struct (val=0x7d0ff1c2aa00, stream=0x7c1ff1c022d0, recurse=0, options=0x7bfff094acb0) at /home/smarchi/src/binutils-gdb/gdb/c-valprint.c:385 > #9 0x00005555640df215 in c_value_print_inner (val=0x7d0ff1c2aa00, stream=0x7c1ff1c022d0, recurse=0, options=0x7bfff094acb0) at /home/smarchi/src/binutils-gdb/gdb/c-valprint.c:441 > #10 0x000055556563828c in language_defn::value_print_inner (this=0x5555734a0700 , val=0x7d0ff1c2aa00, stream=0x7c1ff1c022d0, recurse=0, options=0x7bfff094acb0) at /home/smarchi/src/binutils-gdb/gdb/language.c:658 > #11 0x0000555566fb7749 in common_val_print (value=0x7d0ff1c2aa00, stream=0x7c1ff1c022d0, recurse=0, options=0x7bfff094aa70, language=0x5555734a0700 ) at /home/smarchi/src/binutils-gdb/gdb/valprint.c:1120 > > when we try to print the nullptr type name: > > if (options->prettyformat) > { > gdb_printf (stream, "\n"); > print_spaces (2 + 2 * recurse, stream); > gdb_puts ("members of ", stream); > gdb_puts (type->name (), stream); > gdb_puts (":", stream); > } > > Fix it by using type->safe_name() instead of type->name(). This results > in: > > $1 = { > = { > a = 1 > }, > members of : > b = 2 > } > > Claude pointed out that p-valprint.c has more or less the same code, so > I changed it there too, but I did not write a test for that one. > Both parts LGTM. Approved-By: Kevin Buettner