Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@polymtl.ca>
To: Pedro Alves <palves@redhat.com>
Cc: Simon Marchi <simon.marchi@ericsson.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH 2/3] Error out immediatly when using if command without args in command list
Date: Mon, 04 Sep 2017 17:15:00 -0000	[thread overview]
Message-ID: <56cb55e5c6eace9d680d432d68cfcda9@polymtl.ca> (raw)
In-Reply-To: <e8da1d9d-3bb3-13c4-a37e-b66fe1e71934@redhat.com>

On 2017-09-04 14:35, Pedro Alves wrote:
> On 09/02/2017 10:36 PM, Simon Marchi wrote:
>> When using "if" (or while) without args directly on gdb's command 
>> line,
>> you get this:
>> 
>>   (gdb) if
>>   if/while commands require arguments
>> 
>> When doing the same when entering a command list, you only get an 
>> error
>> when the command is executed, when parse_exp_in_context_1 fails to
>> evaluate the expression.
>> 
>>   (gdb) define foo
>>   Type commands for definition of "foo".
>>   End with a line saying just "end".
>>   >if
>>    >end
>>   >end
>>   (gdb) foo
>>   Argument required (expression to compute).
>> 
>> I think it would make more sense to error out when inputting the 
>> command
>> list directly:
>> 
>>   (gdb) define foo
>>   Type commands for definition of "foo".
>>   End with a line saying just "end".
>>   >if
>>   if/while commands require arguments.
>> 
>> The only required change is to check whether args is an empty string 
>> in
>> build_command_line.
>> 
> 
> LGTM.  Tiny nit further below.
> 
> BTW, as a potential improvement, we could consider also not
> canceling the whole command definition, but instead go back to
> expecting  another line.  It's a bit annoying to have to type
> everything from scratch.  I've run into that occasionally with
> tracepoints, like:
> 
>  (gdb) trace foo
>  (gdb) actions
>  Enter actions for tracepoint 1, one per line.
>  End with a line saying just "end".
>  >collect ...
>  >collect ...
>  > #... several lines later:
>  >endd  # whoops, a typo.
>  `endd' is not a tracepoint action, or is ambiguous.
>  (gdb) # bah, have to start over.
> 
> Instead of:
> 
>  (gdb) trace foo
>  (gdb) actions
>  Enter actions for tracepoint 1, one per line.
>  End with a line saying just "end".
>  >collect ...
>  >collect ...
>  > #... several lines later:
>  >endd
>  `endd' is not a tracepoint action, or is ambiguous.
>  >end
> (gdb)
> 
> The same safety net applied to if/while typos might be useful.
> Just an idea.

I thought about the same thing.  We just need to make it clear that the 
erroneous command didn't make it in the command list.

>> --- a/gdb/cli/cli-script.c
>> +++ b/gdb/cli/cli-script.c
>> @@ -147,7 +147,8 @@ build_command_line (enum command_control_type 
>> type, const char *args)
>>  {
>>    struct command_line *cmd;
>> 
>> -  if (args == NULL && (type == if_control || type == while_control))
>> +  if ((args == NULL || strlen (args) == 0)
>> +      && (type == if_control || type == while_control))
>>      error (_("if/while commands require arguments."));
>>    gdb_assert (args != NULL);
> 
> Nit: might not make a difference with modern compilers, though
> the canonical way to check for entry string would be:
> 
>   *args == '\0'

Ok, I'm pushing now with that changed.

Thanks,
Simon


  reply	other threads:[~2017-09-04 17:15 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-02 21:36 [PATCH 0/3] Tiny patches related to command lines Simon Marchi
2017-09-02 21:37 ` [PATCH 1/3] Move command lines types/declarations to cli-script.h Simon Marchi
2017-09-04 12:28   ` Pedro Alves
2017-09-02 21:37 ` [PATCH 2/3] Error out immediatly when using if command without args in command list Simon Marchi
2017-09-04 12:35   ` Pedro Alves
2017-09-04 17:15     ` Simon Marchi [this message]
2017-09-02 21:37 ` [PATCH 3/3] Add tests for loop_break and loop_continue commands Simon Marchi
2017-09-04 12:36   ` Pedro Alves
2017-09-04 17:16     ` Simon Marchi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=56cb55e5c6eace9d680d432d68cfcda9@polymtl.ca \
    --to=simon.marchi@polymtl.ca \
    --cc=gdb-patches@sourceware.org \
    --cc=palves@redhat.com \
    --cc=simon.marchi@ericsson.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox