Patchwork [v2,06/24] Fix "set enum-command value garbage"

login
register
mail settings
Submitter Pedro Alves
Date May 30, 2019, 7:53 p.m.
Message ID <20190530195333.20448-7-palves@redhat.com>
Download mbox | patch
Permalink /patch/32931/
State New
Headers show

Comments

Pedro Alves - May 30, 2019, 7:53 p.m.
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 "compact": "foo"

gdb/ChangeLog:
yyyy-mm-dd  Pedro Alves  <palves@redhat.com>

	* cli/cli-setshow.c (do_set_command) <var_enum>: Detect garbage
	after item.
---
 gdb/cli/cli-setshow.c | 5 +++++
 1 file changed, 5 insertions(+)
Tom Tromey - June 3, 2019, 6:51 p.m.
>>>>> "Pedro" == Pedro Alves <palves@redhat.com> writes:

Pedro>  (gdb) set print entry-values compact foo
Pedro>   Garbage after item "compact": "foo"

In the crucial junk-vs-garbage wording war, junk is winning 9 to 2, so
perhaps its dominance should be continued.

I'm not totally sold on either of these phrasings but at the same time I
don't recall anybody ever complaining about them.

Tom
Pedro Alves - June 4, 2019, 9:52 p.m.
On 6/3/19 7:51 PM, Tom Tromey wrote:
>>>>>> "Pedro" == Pedro Alves <palves@redhat.com> writes:
> 
> Pedro>  (gdb) set print entry-values compact foo
> Pedro>   Garbage after item "compact": "foo"
> 
> In the crucial junk-vs-garbage wording war, junk is winning 9 to 2, so
> perhaps its dominance should be continued.
> 
> I'm not totally sold on either of these phrasings but at the same time I
> don't recall anybody ever complaining about them.

Ahaha, yeah..  Just following the trend here.  I've changed them to
say "junk", and adjusted the testcase as well.

Thanks,
Pedro Alves

Patch

diff --git a/gdb/cli/cli-setshow.c b/gdb/cli/cli-setshow.c
index 96d7bf5c3c0..47e50941e3b 100644
--- a/gdb/cli/cli-setshow.c
+++ b/gdb/cli/cli-setshow.c
@@ -413,6 +413,11 @@  do_set_command (const char *arg, int from_tty, struct cmd_list_element *c)
 	if (nmatches > 1)
 	  error (_("Ambiguous item \"%s\"."), arg);
 
+	const char *after = skip_spaces (arg + len);
+	if (*after != '\0')
+	  error (_("Garbage after item \"%.*s\": \"%s\""),
+		 len, arg, after);
+
 	if (*(const char **) c->var != match)
 	  {
 	    *(const char **) c->var = match;