Re: [PATCH 2/2] gdb: Allow parenthesis to group arguments to user-defined commands

Philippe Waroquiers
2018-08-30T21:19:42Z

On Wed, 2018-08-29 at 00:29 +0100, Andrew Burgess wrote:
>
> Maybe you could help me work through a few examples, in the following
> table I've outlined a few examples, and have the following questions:
>
> [1] What argument(s) would be passed under the new scheme?
> [2] What argument(s) would be passed under the new scheme?
> [3] How would I write {unsigned long} &var to pass this as a single
> argument? If with quotes, how does this relate to 1 & 2?
>
> | Input | Current Arguments(s) | Proposed Argument(s) |
> |----------------------+----------------------+----------------------|
> | a b | a | a |
> | | b | b |
> |----------------------+----------------------+----------------------|
> | "a b" | "a b" | [1] |
> |----------------------+----------------------+----------------------|
> | 'a b' | 'a b' | [2] |
> |----------------------+----------------------+----------------------|
> | {unsigned long} &var | {unsigned | |
> | | long} | N/A |
> | | &var | |
> |----------------------+----------------------+----------------------|
> | [3] | | |
> |----------------------+----------------------+----------------------|
>
> In general I'm happy to rework this part of GDB, but ideally I'd like
> some feedback from a global maintainer that such a change, which might
> would break backward compatibility, would be acceptable...

Humph, now I understand that user defined commands already handle
specially single and double quotes, as you explained above.
This seems not documented in the gdb documentation, which tells
that 'Note the arguments are text substitutions, so they may
reference variables, use complex expressions, or even perform inferior
functions calls.' I have not found a description of this single and double
quote behaviour.

Maybe the only thing we might need is something like:
$unquoted_arg1 or something like that to allow to remove the quotes
inside the user defined command, when desired ?
Or as you suggested, some new flags to the define command, such as
define some_command -unquote_arg3
would indicate that if arg3 is a single quoted argument as in your table
above, that it must be given without the quote to some_command.

For what concerns the parenthesis based solution, it looks to not work
for some cases.

E.g. if I want to pass one argument (I am using single quotes to show the args
I want in the below examples):
'a b) (c d'
then I need to use:
some_user_defined (a b) (c d)
but that is the same notation as if I want to pass 2 arguments
'a b' and 'c d'

So, the parenthesis mechanism would need escaping or something like that,
to allow a general grouping. As it stands now, it only works
based on the assumption that the content inside the parenthesis

Still, it looks strange to me that we introduce another mechanism
on top of the single/double quotes to quote.
And it would be nice if the mechanism used to quote args would
be compatible between user defined commands and native gdb commands.

I have not understood the reference given by Tom that expressions
are terminated with , and that parenthesis stops this termination.
Is that described somewhere in the doc ?
The doc (or an example if this is not documented) will help
me to understand.

Philippe