From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from progateway7-pub.mail.pro1.eigbox.com (gproxy5-pub.mail.unifiedlayer.com [67.222.38.55]) by sourceware.org (Postfix) with ESMTPS id 23DBC3858C50 for ; Mon, 17 Apr 2023 15:47:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 23DBC3858C50 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com Received: from cmgw14.mail.unifiedlayer.com (unknown [10.0.90.129]) by progateway7.mail.pro1.eigbox.com (Postfix) with ESMTP id 779F510041F56 for ; Mon, 17 Apr 2023 15:47:40 +0000 (UTC) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTP id oR4upG6oikRKkoR4upDWbs; Mon, 17 Apr 2023 15:47:40 +0000 X-Authority-Reason: nr=8 X-Authority-Analysis: v=2.4 cv=cJglDnSN c=1 sm=1 tr=0 ts=643d6a1c a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=dLZJa+xiwSxG16/P+YVxDGlgEgI=:19 a=dKHAf1wccvYA:10:nop_rcvd_month_year a=Qbun_eYptAEA:10:endurance_base64_authed_username_1 a=CCpqsmhAAAAA:8 a=R_j6H_oDBDMfqpZrC1MA:9 a=ul9cdbp4aOFLsgKbc677:22 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Type:MIME-Version:Message-ID:In-Reply-To:Date:References :Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=v+ULg9C4uiOt6F8jLFWFadj3RsBH2ASHUvYDwYkDUDA=; b=NVXGhCugIlMOekfpKAeAOWRT1L xYHVH95zwJ/jPWJi0uYjHe9zqjtbFtGXWJ6zOH7B6M4SkX3VNLavXunVkh82BaBPGmlPqZTPsl0wQ 3CqjmvSX/Jz5qfndXxESzVhE0; Received: from 71-211-191-82.hlrn.qwest.net ([71.211.191.82]:52258 helo=murgatroyd) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1poR4u-001126-3X; Mon, 17 Apr 2023 09:47:40 -0600 From: Tom Tromey To: Andrew Burgess via Gdb-patches Cc: Andrew Burgess Subject: Re: [PATCH] gdb: add support for %V to printf command References: <775f2ae1297bff92b09c3b6a58596a5e65f212eb.1680178345.git.aburgess@redhat.com> X-Attribution: Tom Date: Mon, 17 Apr 2023 09:47:39 -0600 In-Reply-To: <775f2ae1297bff92b09c3b6a58596a5e65f212eb.1680178345.git.aburgess@redhat.com> (Andrew Burgess via Gdb-patches's message of "Thu, 30 Mar 2023 13:22:10 +0100") Message-ID: <87bkjm4ijo.fsf@tromey.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain 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.191.82 X-Source-L: No X-Exim-ID: 1poR4u-001126-3X X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 71-211-191-82.hlrn.qwest.net (murgatroyd) [71.211.191.82]:52258 X-Source-Auth: tom+tromey.com X-Email-Count: 5 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3019.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,JMQ_SPF_NEUTRAL,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: >>>>> "Andrew" == Andrew Burgess via Gdb-patches writes: Andrew> This commit adds a new format for the printf and dprintf commands: Andrew> '%V'. This new format takes any GDB expression and formats it as a Andrew> string, just as GDB would for a 'print' command, e.g.: Thank you for doing this. I'm definitely a fan of the idea. Andrew> --- a/gdb/printcmd.c Andrew> +++ b/gdb/printcmd.c Andrew> @@ -2733,7 +2733,7 @@ ui_printf (const char *arg, struct ui_file *stream) Andrew> if (*s++ != '"') Andrew> error (_("Bad format string, missing '\"'.")); Andrew> - format_pieces fpieces (&s); Andrew> + format_pieces fpieces (&s, false, true); I was going to ask if there is a spot that sets gdb_extensions=false and the new flag=true. This setting seems odd to me, but I didn't dig through to find out why it's needed. Andrew> + string_file buffer; Andrew> + print_formatted (val_args[i], 0, &print_opts, &buffer); Andrew> + gdb_puts (buffer.string ().c_str ()); Why is a second stream needed here? Like, couldn't print_formatted be called with 'stream'? Wouldn't that preserve any styling done by print_formatted? Or is the intention to strip styling? Andrew> + if (f[1] == '[') Andrew> + { Andrew> + const char *tmp; Andrew> + for (tmp = f; *tmp != ']' && *tmp != '\0'; ++tmp) Andrew> + ; Andrew> + if (*tmp == ']') Andrew> + f = tmp; strchr if it simplifies things. I didn't dig into this either, but I don't think %V could work in dprintf's call or agent modes. So, maybe gdb should reject this somewhere. Or maybe this is already done by the default setting in the constructor? Tom