From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id pEHOE9shg2oWGi0AWB0awg (envelope-from ) for ; Mon, 17 Aug 2026 10:59:39 -0400 Received: by simark.ca (Postfix, from userid 112) id F166B1E0A3; Mon, 17 Aug 2026 10:59: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=-5.3 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED 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 4D9EF1E09E for ; Mon, 17 Aug 2026 10:59:37 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B1F2F4BA79B7 for ; Mon, 17 Aug 2026 14:59:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B1F2F4BA79B7 Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id D07C64BA23F3 for ; Mon, 17 Aug 2026 14:59:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D07C64BA23F3 Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=efficios.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=efficios.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D07C64BA23F3 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=158.69.221.121 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1786978751; cv=none; b=XhdPuC7gQHi/U1oR/cj/KmsOiYWS9DBksOC1+sOAWqDCcsKzYZkT1aEEgqiXAgCxRXc4eHHkm2eGTzTcLtSmWZD05z1brO+UKqAmy/x7wblgCpRN+s9sdgbTNteGdSxJG+8dqnLvVjSi9KIQaII0LFH67g1h9tZ2RNi+UcJ6QH4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1786978751; c=relaxed/simple; bh=LF2lfFas8VMtvbrVW6lb3E4t18Qn543Bdqs12wPAdHk=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=kwCveMmiMRoyhH1ieRNdNPGlf5Une+wcB5TSSVUqSMfP2F9n5GOmmIw6r5H3o73cXFT9GQgRNy9UwS3iWiR6xOxo4UysDRup9IkR6Nz6Eev9BNoEPVPF260V32Mmfp5h0D5I1GrPtE5cn/wRb+kJNuanXblLgbWFUxvfKfrfnt8= ARC-Authentication-Results: i=1; sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D07C64BA23F3 Received: by simark.ca (Postfix) id 71A521E09E; Mon, 17 Aug 2026 10:59:09 -0400 (EDT) From: Simon Marchi To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH 2/2] gdb: don't print trailing space after base classes in pretty format Date: Mon, 17 Aug 2026 10:59:02 -0400 Message-ID: <20260817145907.142300-2-simon.marchi@efficios.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260817145907.142300-1-simon.marchi@efficios.com> References: <20260817145907.142300-1-simon.marchi@efficios.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 After working on the previous patch, the formatting of the values printed in test gdb.cp/anon-struct-with-base.exp with "print pretty on" looks wrong to me. I think that with "print pretty on", the "" string should be on its own line. The closing curly brace should also be on its own line. As an exception, when a type has absolutely nothing in it, we print this, which seem reasonable: = {}, Concretely, this patch changes this: $ ./gdb -nx -q --data-directory=data-directory testsuite/outputs/gdb.cp/anon-struct-with-base/anon-struct-with-base -ex "with print pretty -- p v_no_data_base_data" -ex "with print pretty -- p v_no_data_base_no_data" -batch $1 = { = { a = 3 }, } $2 = { = {}, } to this: $ ./gdb -nx -q --data-directory=data-directory testsuite/outputs/gdb.cp/anon-struct-with-base/anon-struct-with-base -ex "with print pretty -- p v_no_data_base_data" -ex "with print pretty -- p v_no_data_base_no_data" -batch $1 = { = { a = 3 }, } $2 = { = {}, } Finally, this change also gets rid of some unnecessary trailing spaces printed after base classes. This is not really visible for users, but it is visible in the test changes. Change-Id: Ia1c28c8bf2c6a8442c2cb610e06058e4dac030b9 --- gdb/cp-valprint.c | 22 +++++++++++++++++-- .../gdb.cp/anon-struct-with-base.exp | 12 ++++++---- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/gdb/cp-valprint.c b/gdb/cp-valprint.c index d450e90e1e1d..bd9544307127 100644 --- a/gdb/cp-valprint.c +++ b/gdb/cp-valprint.c @@ -165,7 +165,21 @@ cp_print_value_fields (struct value *val, struct ui_file *stream, /* If there are no data fields, skip this part */ if (len == n_baseclasses || !len) - fprintf_styled (stream, metadata_style.style (), ""); + { + if (options->prettyformat && n_baseclasses > 0) + { + gdb_printf (stream, "\n"); + print_spaces (2 + 2 * recurse, stream); + } + + fprintf_styled (stream, metadata_style.style (), ""); + + if (options->prettyformat && n_baseclasses > 0) + { + gdb_printf (stream, "\n"); + print_spaces (2 * recurse, stream); + } + } else { size_t statmem_obstack_initial_size = 0; @@ -532,7 +546,11 @@ cp_print_value (struct value *val, struct ui_file *stream, 0); } } - gdb_puts (", ", stream); + + gdb_puts (",", stream); + + if (!options->prettyformat) + gdb_puts (" ", stream); flush_it: ; diff --git a/gdb/testsuite/gdb.cp/anon-struct-with-base.exp b/gdb/testsuite/gdb.cp/anon-struct-with-base.exp index 2ff7036198a2..1b9cf9f19020 100644 --- a/gdb/testsuite/gdb.cp/anon-struct-with-base.exp +++ b/gdb/testsuite/gdb.cp/anon-struct-with-base.exp @@ -39,7 +39,7 @@ gdb_test "with print pretty on -- print v_data_base_data" \ "$::valnum_re = \{" \ " = \{" \ " a = 1" \ - " \}, " \ + " \}," \ " members of :" \ " b = 2" \ "\}"] @@ -49,12 +49,14 @@ gdb_test "with print pretty on -- print v_no_data_base_data" \ "$::valnum_re = \{" \ " = \{" \ " a = 3" \ - " \}, \}"] + " \}," \ + " " \ + "\}"] gdb_test "with print pretty on -- print v_data_base_no_data" \ [multi_line \ "$::valnum_re = \{" \ - " = \{\}, " \ + " = \{\}," \ " members of :" \ " c = 4" \ "\}"] @@ -62,4 +64,6 @@ gdb_test "with print pretty on -- print v_data_base_no_data" \ gdb_test "with print pretty on -- print v_no_data_base_no_data" \ [multi_line \ "$::valnum_re = \{" \ - " = \{\}, \}"] + " = \{\}," \ + " " \ + "\}"] -- 2.55.0