Re: [PATCH 06/24] Fix "set enum-command value garbage"

Pedro Alves
2019-05-24T11:39:11Z

On 5/23/19 8:13 PM, Sergio Durigan Junior wrote:
> On Wednesday, May 22 2019, Pedro Alves wrote:
>
>> With enum commands, we currently fail to notice garbage after the
>> value.
>>
>> Currently:
>>
>> (gdb) set print entry-values compact foo
>> (gdb) show print entry-values foo
>> Printing of function arguments at function entry is "compact".
>>
>> After this fix:
>>
>> (gdb) set print entry-values compact foo
>> Garbage after item: "foo"
>
> I think it would be clearer to specify which item here, otherwise the
> user might think that the item is "foo". Maybe:
>
> Invalid data after item "compact": "foo"
>
> What do you think? Otherwise, LGTM. Thanks.

Agreed. I'm changing the code like this:

diff --git c/gdb/cli/cli-setshow.c w/gdb/cli/cli-setshow.c
index 9d6479ffca2..47e50941e3b 100644
--- c/gdb/cli/cli-setshow.c
+++ w/gdb/cli/cli-setshow.c
@@ -413,9 +413,10 @@ do_set_command (const char *arg, int from_tty, struct cmd_list_element *c)
if (nmatches > 1)
error (_("Ambiguous item \"%s\"."), arg);

- arg = skip_spaces (arg + len);
- if (*arg != '\0')
- error (_("Garbage after item: \"%s\""), arg);
+ const char *after = skip_spaces (arg + len);
+ if (*after != '\0')
+ error (_("Garbage after item \"%.*s\": \"%s\""),
+ len, arg, after);

Also changed the test like this, in patch #9:

--- i/gdb/testsuite/gdb.base/settings.exp
+++ w/gdb/testsuite/gdb.base/settings.exp
@@ -378,7 +378,13 @@ proc_with_prefix test-enum {} {

# Valid value followed by garbage.
gdb_test "$set_cmd xxx 1" \
- "Garbage after item: \"1\""
+ "Garbage after item \"xxx\": \"1\""
+ # Valid value followed by garbage, with extra spaces.
+ gdb_test "$set_cmd xxx 1" \
+ "Garbage after item \"xxx\": \"1\""
+ # Abbreviated value followed by garbage.
+ gdb_test "$set_cmd xx 1" \
+ "Garbage after item \"xx\": \"1\""

Thanks,
Pedro Alves