From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 37887 invoked by alias); 15 Feb 2018 20:50:08 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 37670 invoked by uid 89); 15 Feb 2018 20:50:06 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.8 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=bob X-HELO: gateway22.websitewelcome.com Received: from gateway22.websitewelcome.com (HELO gateway22.websitewelcome.com) (192.185.47.100) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 15 Feb 2018 20:50:05 +0000 Received: from cm12.websitewelcome.com (cm12.websitewelcome.com [100.42.49.8]) by gateway22.websitewelcome.com (Postfix) with ESMTP id DC54622691 for ; Thu, 15 Feb 2018 14:50:03 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id mQTjeOxB6zzFjmQTje11He; Thu, 15 Feb 2018 14:50:03 -0600 Received: from 174-29-60-18.hlrn.qwest.net ([174.29.60.18]:46122 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89) (envelope-from ) id 1emQTj-003pYR-KL; Thu, 15 Feb 2018 14:50:03 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 2/3] Allow - in %p for printf Date: Thu, 15 Feb 2018 20:50:00 -0000 Message-Id: <20180215205001.337-3-tom@tromey.com> In-Reply-To: <20180215205001.337-1-tom@tromey.com> References: <20180215205001.337-1-tom@tromey.com> X-BWhitelist: no X-Source-L: No X-Exim-ID: 1emQTj-003pYR-KL X-Source-Sender: 174-29-60-18.hlrn.qwest.net (bapiya.Home) [174.29.60.18]:46122 X-Source-Auth: tom+tromey.com X-Email-Count: 3 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-SW-Source: 2018-02/txt/msg00210.txt.bz2 PR cli/19918 points out that a printf format like "%-5p" will cause a gdb crash. The bug is problem is that printf_pointer doesn't take the "-" flag into account. gdb/ChangeLog 2018-02-14 Tom Tromey PR cli/19918: * printcmd.c (printf_pointer): Allow "-" in format. gdb/testsuite/ChangeLog 2018-02-14 Tom Tromey PR cli/19918: * gdb.base/printcmds.exp (test_printf): Add printf test using '-' flag. --- gdb/ChangeLog | 5 +++++ gdb/printcmd.c | 5 +++-- gdb/testsuite/ChangeLog | 6 ++++++ gdb/testsuite/gdb.base/printcmds.exp | 4 ++++ 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/gdb/printcmd.c b/gdb/printcmd.c index 13b967f0a2..d2d13895f6 100644 --- a/gdb/printcmd.c +++ b/gdb/printcmd.c @@ -2399,8 +2399,9 @@ printf_pointer (struct ui_file *stream, const char *format, if (val != 0) *fmt_p++ = '#'; - /* Copy any width. */ - while (*p >= '0' && *p < '9') + /* Copy any width or flags. Only the "-" flag is needed -- see the + format_pieces constructor. */ + while (*p == '-' || (*p >= '0' && *p < '9')) *fmt_p++ = *p++; gdb_assert (*p == 'p' && *(p + 1) == '\0'); diff --git a/gdb/testsuite/gdb.base/printcmds.exp b/gdb/testsuite/gdb.base/printcmds.exp index 9402d97ef3..56cedb908f 100644 --- a/gdb/testsuite/gdb.base/printcmds.exp +++ b/gdb/testsuite/gdb.base/printcmds.exp @@ -776,6 +776,10 @@ proc test_printf {} { "" \ "create hibob command" gdb_test "hibob" "hi bob zzz.*y" "run hibob command" + + # PR cli/19918. + gdb_test "printf \"%-16dq\\n\", 0" "0 q" + gdb_test "printf \"%-16pq\\n\", 0" "\\(nil\\) q" } #Test printing DFP values with printf -- 2.13.6