From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 53320 invoked by alias); 5 Jun 2019 21:25:33 -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 53312 invoked by uid 89); 5 Jun 2019 21:25:33 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-0.4 required=5.0 tests=BAYES_00,KAM_STOCKGEN,RCVD_IN_DNSWL_NONE autolearn=no version=3.3.1 spammy= X-HELO: mail-wr1-f68.google.com Received: from mail-wr1-f68.google.com (HELO mail-wr1-f68.google.com) (209.85.221.68) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 05 Jun 2019 21:25:32 +0000 Received: by mail-wr1-f68.google.com with SMTP id m3so243508wrv.2 for ; Wed, 05 Jun 2019 14:25:31 -0700 (PDT) Return-Path: Received: from ?IPv6:2001:8a0:f913:f700:4eeb:42ff:feef:f164? ([2001:8a0:f913:f700:4eeb:42ff:feef:f164]) by smtp.gmail.com with ESMTPSA id x11sm38492wmg.23.2019.06.05.14.25.29 (version=TLS1_3 cipher=AEAD-AES128-GCM-SHA256 bits=128/128); Wed, 05 Jun 2019 14:25:29 -0700 (PDT) Subject: Re: ui_out format strings for fields and styles (Re: [PATCH] Style "pwd" output) To: Tom Tromey References: <20190605020116.1550-1-tom@tromey.com> <1ee4bd6b-4cdf-f3a9-74af-0843bf123a8b@redhat.com> <87lfygi1x0.fsf@tromey.com> <32872d6a-15d6-9718-59ae-957694e114c9@redhat.com> <87imtjhj6b.fsf@tromey.com> <625cd0ba-058d-d4bf-8ba3-8676f335b0f3@redhat.com> <87blzbep47.fsf@tromey.com> Cc: gdb-patches@sourceware.org From: Pedro Alves Message-ID: <2180f72f-da10-5333-90a1-666ba3bd145e@redhat.com> Date: Wed, 05 Jun 2019 21:25:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: <87blzbep47.fsf@tromey.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-SW-Source: 2019-06/txt/msg00131.txt.bz2 On 6/5/19 9:47 PM, Tom Tromey wrote: >>>>>> "Pedro" == Pedro Alves writes: > > Pedro> Also, since gcc expects a pointer for %p, and we want to pass an > Pedro> enum for the style, I added a small pointer-wrapper hack -- see the > Pedro> ptr function. Yay C++. > > We could just remove the enum, move to passing pointers everywhere, and > convert the *_style objects to be pointers. This would streamline > things a bit; ... > and we could use nullptr to mean "keep the default". Yeah, that would %pN / %p] redundant/unnecessary... > > Another option would be to just add a ptr method to the _style objects, > so instead of ui_out_style_kind::VARIABLE you'd write variable_style.ptr (). ... and could thus end up with something like: current_uiout->message (_("%pS%s%pS %pS%s%pS\n"), address_style.style ().ptr (), tmp, nullptr, (msymbol.minsym->text_p () ? function_name_style.style ().ptr () : nullptr), MSYMBOL_PRINT_NAME (msymbol.minsym), nullptr); If you'd like to give this a try, please do feel free to push to the branch. > > Pedro> I've not been paying much attention to the styling patches, so I can't > Pedro> off hand tell which places would benefit the most from this. So I just > Pedro> grepped for _styled and replaced a couple spots. Likely there are better > Pedro> examples. > > There's my new patch and I have one more along those lines as well, but > a good existing one that was already deconstructed is in symfile.c: > > puts_filtered (_("Reading symbols from ")); > fputs_styled (name, file_name_style.style (), gdb_stdout); > puts_filtered ("...\n"); So that could be either: current_uiout->message (_("Reading symbols from %pS%s%pS...\n"), file_name_style.style ().ptr (), name, nullptr); or: current_uiout->message (_("Reading symbols from %ps...\n"), styled_string (ui_out_style_kind::FILENAME, name).ptr ()); or even: current_uiout->message (_("Reading symbols from %ps...\n"), styled_string (file_name_style.style (), name).ptr ()); > > Pedro> For the seemingly common case of printing a string variable > Pedro> with a style, I'm thinking that a specific formatter would > Pedro> be better. I'll post a follow up patch for that. > > I'm interested to see it. > Thanks, Pedro Alves