This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCHv2] gdb: Rewrite argument handling for user-defined commands


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



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]