From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 38904 invoked by alias); 8 Sep 2018 05:35:35 -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 38886 invoked by uid 89); 8 Sep 2018 05:35:35 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-7.6 required=5.0 tests=BAYES_00,GIT_PATCH_2,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 spammy=H*F:D*be, Here's, Heres, balanced X-HELO: mailsec117.isp.belgacom.be Received: from mailsec117.isp.belgacom.be (HELO mailsec117.isp.belgacom.be) (195.238.20.113) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 08 Sep 2018 05:35:31 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=skynet.be; i=@skynet.be; q=dns/txt; s=securemail; t=1536384931; x=1567920931; h=message-id:subject:from:to:cc:date:in-reply-to: references:mime-version:content-transfer-encoding; bh=Sz9FYSq6QGI/MXNvsEnZrBTkX0TdMl6qym0KFCBPg40=; b=jR1+jHqpHy0kG4XiBi58RQAniE0qH/kR8m+MqqLr41Sj4y3qyXiqUXs/ V0VCwV+iOzVdPoN/TE1AfpV7PNtgtA==; Received: from 232.142-134-109.adsl-dyn.isp.belgacom.be (HELO md) ([109.134.142.232]) by relay.skynet.be with ESMTP/TLS/AES256-GCM-SHA384; 08 Sep 2018 07:35:14 +0200 Message-ID: <1536384914.1459.11.camel@skynet.be> Subject: Re: [PATCHv2] gdb: Rewrite argument handling for user-defined commands From: Philippe Waroquiers To: Andrew Burgess , gdb-patches@sourceware.org Cc: Tom Tromey Date: Sat, 08 Sep 2018 05:35:00 -0000 In-Reply-To: <20180906232904.13286-1-andrew.burgess@embecosm.com> References: <20180906232904.13286-1-andrew.burgess@embecosm.com> Content-Type: text/plain; charset="UTF-8" Mime-Version: 1.0 Content-Transfer-Encoding: 8bit X-IsSubscribed: yes X-SW-Source: 2018-09/txt/msg00156.txt.bz2 On Fri, 2018-09-07 at 00:29 +0100, Andrew Burgess wrote: > Here's a new version of the quoting patch which now uses single and > double quotes for quoting arguments. > > I look forward to any feedback. > > Eli - I suspect that the documentation changes would need some work, > but you should probably wait to review, as I suspect this patch will > change again before it can be merged. > > Thanks, > Andrew > > --- > > This commit rewrites argument passing for user-defined commands. The > rewrite was inspired after this mailing list thread: > > https://sourceware.org/ml/gdb-patches/2018-08/msg00391.html > > The summary is that it was felt that in order to pass arguments that > include whitespace, then single or double quotes should be used for > quoting the argument. Tom felt that we need to support your initial suggestion (parenthesis quoting) for 'balanced expressions', as parenthesis are used in some other commands that are evaluating expressions. I can understand his point of view, see https://sourceware.org/ml/gdb-patches/2018-09/msg00007.html > > The problem is that currently, the quotes are included in the argument > that is passed into the user-defined command, so passing the argument > "1 + 1" will currently litterally pass "1 + 1" (including the quotes) > to GDB, which is no good if what you want to do is to pass an > expression. For this problem, an alternative solution is to have a new way to expand an argument : $argX expands the argument X with the quotes $arguX expands the argument X with the quotes. That allows to pass a quoted argument containing spaces, and use it in the user defined command without quotes where needed, and with quotes where needed : if the user defined command has to call another command (user defined or a native) that itself needs quoting, then use $argX, else use $arguX. In other words, how to handle a quoted arg is decided by the user command 'developer' (similarly to some native GDB commands). So, adder command would become print $argu1 + $argu2 + $argu3 See https://sourceware.org/ml/gdb-patches/2018-09/msg00005.html for a patch (only very limited manual testing done) implementing the arguX approach : (gdb)     define adder Type commands for definition of "adder". End with a line saying just "end". >       print $arg0 + $arg1 + $arg2 >     end (gdb) adder '1 + 5' 2 3 No symbol table is loaded.  Use the "file" command. (gdb) (gdb) define adder Redefine command "adder"? (y or n) y Type commands for definition of "adder". End with a line saying just "end". >print $argu0 + $argu1 + $argu2 >end (gdb) adder '1 + 5' 2 3              $4 = 11 (gdb)  > > This commit changes how quoting works so that the quotes are NOT now > included in the argument passed. If the user wants to include quotes, > they would now need to use nested quotes, so "\"abc\"" will pass the > argument "abc". > > It is also possible to use single quotes, so '"abc"' will also pass > the argument "abc". > > As currently there's no documentation for how quoting works in > user-defined commands this commit adds documentation for the new > behaviour. > > The big risk with this commit is that this does change how arguments > are passed to user-defined commands, and this might causes issues for > existing users. Yes, that has the potential to create a lot of backward incompatibility, which is not the case for the $arguX and/or the parenthesis approach you suggested initially. Philippe