From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id ST2SBxjWgGBMSgAAWB0awg (envelope-from ) for ; Wed, 21 Apr 2021 21:49:12 -0400 Received: by simark.ca (Postfix, from userid 112) id 1155B1F104; Wed, 21 Apr 2021 21:49:12 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=0.4 required=5.0 tests=DKIM_SIGNED,MAILING_LIST_MULTI, RCVD_IN_BL_SPAMCOP_NET,T_DKIM_INVALID,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (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 simark.ca (Postfix) with ESMTPS id A4D241E54D for ; Wed, 21 Apr 2021 21:49:11 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 16BC23857810; Thu, 22 Apr 2021 01:49:11 +0000 (GMT) Received: from gateway36.websitewelcome.com (gateway36.websitewelcome.com [192.185.195.25]) by sourceware.org (Postfix) with ESMTPS id 665BF3857C74 for ; Thu, 22 Apr 2021 01:49:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 665BF3857C74 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=tom@tromey.com Received: from cm14.websitewelcome.com (cm14.websitewelcome.com [100.42.49.7]) by gateway36.websitewelcome.com (Postfix) with ESMTP id 0127F428784CD for ; Wed, 21 Apr 2021 20:49:07 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id ZOSolhIPhw11MZOSolAA2Z; Wed, 21 Apr 2021 20:49:06 -0500 X-Authority-Reason: nr=8 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=BJqbuG/UhqikhX964skc9ZBnCteAFB6n/sOQMuWpPfQ=; b=CnIC+vgbjULmmW1YouIEgyR+/C EQOG7sQq8TLecCEa5d4IyYmoJpzqdoSjjDbwo4r62GYQih/nYB447HkKNLbLm46c2Zu7Z53O2V2Ml o+7PONZdQuQg9t0ZTT3siX/CD; Received: from 71-211-182-15.hlrn.qwest.net ([71.211.182.15]:38242 helo=localhost.localdomain) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94) (envelope-from ) id 1lZOSo-003NGi-OI; Wed, 21 Apr 2021 19:49:06 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Subject: [PATCH] Fix ptype/o bug with "" Date: Wed, 21 Apr 2021 19:49:04 -0600 Message-Id: <20210422014904.3521301-1-tom@tromey.com> X-Mailer: git-send-email 2.26.2 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.182.15 X-Source-L: No X-Exim-ID: 1lZOSo-003NGi-OI X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 71-211-182-15.hlrn.qwest.net (localhost.localdomain) [71.211.182.15]:38242 X-Source-Auth: tom+tromey.com X-Email-Count: 1 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes 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: , Cc: Tom Tromey Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" I noticed that when using ptype/o, the "" text that may be emitted is indented incorrectly. This patch fixes the bug and adds a new test case. I also removed a stray backslash from ptype-offsets.exp that I noticed while writing the test. This seemed too trivial to warrant a separate patch. gdb/ChangeLog 2021-04-21 Tom Tromey * c-typeprint.c (c_type_print_base_struct_union): Use print_spaces_filtered_with_print_options. gdb/testsuite/ChangeLog 2021-04-21 Tom Tromey * gdb.base/ptype-offsets.cc (struct empty_member): New. (main): Use empty_member. * gdb.base/ptype-offsets.exp: Add new test. --- gdb/ChangeLog | 5 +++++ gdb/c-typeprint.c | 7 +++---- gdb/testsuite/ChangeLog | 6 ++++++ gdb/testsuite/gdb.base/ptype-offsets.cc | 7 +++++++ gdb/testsuite/gdb.base/ptype-offsets.exp | 17 ++++++++++++++++- 5 files changed, 37 insertions(+), 5 deletions(-) diff --git a/gdb/c-typeprint.c b/gdb/c-typeprint.c index f81f1c2c113..72616a59af0 100644 --- a/gdb/c-typeprint.c +++ b/gdb/c-typeprint.c @@ -1121,13 +1121,12 @@ c_type_print_base_struct_union (struct type *type, struct ui_file *stream, if (type->num_fields () == 0 && TYPE_NFN_FIELDS (type) == 0 && TYPE_TYPEDEF_FIELD_COUNT (type) == 0) { + print_spaces_filtered_with_print_options (level + 4, stream, flags); if (type->is_stub ()) - fprintf_filtered (stream, _("%*s%p[%p]\n"), - level + 4, "", + fprintf_filtered (stream, _("%p[%p]\n"), metadata_style.style ().ptr (), nullptr); else - fprintf_filtered (stream, _("%*s%p[%p]\n"), - level + 4, "", + fprintf_filtered (stream, _("%p[%p]\n"), metadata_style.style ().ptr (), nullptr); } diff --git a/gdb/testsuite/gdb.base/ptype-offsets.cc b/gdb/testsuite/gdb.base/ptype-offsets.cc index 4582af48cef..dc21e34752f 100644 --- a/gdb/testsuite/gdb.base/ptype-offsets.cc +++ b/gdb/testsuite/gdb.base/ptype-offsets.cc @@ -185,6 +185,12 @@ struct static_member int abc; }; +struct empty_member +{ + struct { } empty; + int an_int; +}; + int main (int argc, char *argv[]) { @@ -196,6 +202,7 @@ main (int argc, char *argv[]) struct asd f; uint8_t i; static_member stmember; + empty_member emember; return 0; } diff --git a/gdb/testsuite/gdb.base/ptype-offsets.exp b/gdb/testsuite/gdb.base/ptype-offsets.exp index f466db9a7f2..0a0bbc87062 100644 --- a/gdb/testsuite/gdb.base/ptype-offsets.exp +++ b/gdb/testsuite/gdb.base/ptype-offsets.exp @@ -336,7 +336,22 @@ gdb_test "ptype/o static_member" \ [string_to_regexp [multi_line \ "/* offset | size */ type = struct static_member \{" \ " static static_member Empty;" \ -"\/* 0 | 4 */ int abc;" \ +"/* 0 | 4 */ int abc;" \ "" \ " /* total size (bytes): 4 */" \ " \}"]] + +# Test that the "no data fields" text is indented properly. +gdb_test "ptype/o empty_member" \ + [string_to_regexp [multi_line \ +"/* offset | size */ type = struct empty_member \{" \ +"/* 0 | 1 */ struct {" \ +" " \ +"" \ +" /* total size (bytes): 1 */" \ +" } empty;" \ +"/* XXX 3-byte hole */" \ +"/* 4 | 4 */ int an_int;" \ +"" \ +" /* total size (bytes): 8 */" \ +" \}"]] -- 2.26.2