Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* report valid values for all errors for enum variables...
@ 2003-10-28  2:02 Jim Ingham
  2003-10-28  4:03 ` Daniel Jacobowitz
  0 siblings, 1 reply; 6+ messages in thread
From: Jim Ingham @ 2003-10-28  2:02 UTC (permalink / raw)
  To: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 1046 bytes --]

Hi, all...

The set command for "var_enum" type gdb variables will give you a 
helpful error message if you say something like:

(gdb) set osabi
Requires an argument. Valid arguments are auto, default, none, Darwin, 
Darwin64.

But not if you do:

(gdb) set osabi Blubby
Undefined item: "Blubby"

It would be nice if folks didn't have to remember that osabi is an enum 
type variable, and they should go back and type "set osabi" with no 
arguments, etc.  The following patch makes it symmetrical, so you get:

(top-gdb) set osabi
Requires an argument. Valid values are auto, default, none, Darwin, 
Darwin64.
(top-gdb) set osabi foobar
Undefined item: "foobar". Valid values are auto, default, none, Darwin, 
Darwin64.
(top-gdb) set osabi Darw
Ambiguous item "Darw". Valid values are auto, default, none, Darwin, 
Darwin64.

Does this seem good?

2003-10-27  Jim Ingham  <jingham@apple.com>

         * cli/cli-setshow.c (do_setshow_command): For var_enum type 
variables,
	return the list of valid values for all errors, not just no argument.


[-- Attachment #2: var_enum.patch --]
[-- Type: application/octet-stream, Size: 2704 bytes --]

Index: cli-setshow.c
===================================================================
RCS file: /cvs/src/src/gdb/cli/cli-setshow.c,v
retrieving revision 1.13
diff -p -r1.13 cli-setshow.c
*** cli-setshow.c	4 Aug 2003 17:08:23 -0000	1.13
--- cli-setshow.c	28 Oct 2003 01:55:19 -0000
*************** do_setshow_command (char *arg, int from_
*** 197,211 ****
  	  {
  	    int i;
  	    int len;
! 	    int nmatches;
  	    const char *match = NULL;
  	    char *p;
  
! 	    /* if no argument was supplied, print an informative error message */
! 	    if (arg == NULL)
  	      {
  		char msg[1024];
! 		strcpy (msg, "Requires an argument. Valid arguments are ");
  		for (i = 0; c->enums[i]; i++)
  		  {
  		    if (i != 0)
--- 197,246 ----
  	  {
  	    int i;
  	    int len;
! 	    int nmatches = 0;
  	    const char *match = NULL;
  	    char *p;
  
! 	    if (arg != NULL)
  	      {
+ 		p = strchr (arg, ' ');
+ 		
+ 		if (p)
+ 		  len = p - arg;
+ 		else
+ 		  len = strlen (arg);
+ 		
+ 		nmatches = 0;
+ 		for (i = 0; c->enums[i]; i++)
+ 		  if (strncmp (arg, c->enums[i], len) == 0)
+ 		    {
+ 		      if (c->enums[i][len] == '\0')
+ 			{
+ 			  match = c->enums[i];
+ 			  nmatches = 1;
+ 			  break; /* exact match. */
+ 			}
+ 		      else
+ 			{
+ 			  match = c->enums[i];
+ 			  nmatches++;
+ 			}
+ 		    }
+ 	      }
+ 	    if (nmatches == 1)
+ 	      *(const char **) c->var = match;
+ 	    else
+ 	      {
+ 		/* If there was an error, print an informative
+ 		   error message.  */
  		char msg[1024];
! 		if (arg == NULL)
! 		  strcpy (msg, "Requires an argument.");
! 		else if (nmatches <= 0)
! 		  sprintf (msg, "Undefined item: \"%s\".", arg);		
! 		else if (nmatches > 1)
! 		  sprintf  (msg, "Ambiguous item \"%s\".", arg);
! 		strcat (msg, " Valid values are ");
  		for (i = 0; c->enums[i]; i++)
  		  {
  		    if (i != 0)
*************** do_setshow_command (char *arg, int from_
*** 215,252 ****
  		strcat (msg, ".");
  		error ("%s", msg);
  	      }
- 
- 	    p = strchr (arg, ' ');
- 
- 	    if (p)
- 	      len = p - arg;
- 	    else
- 	      len = strlen (arg);
- 
- 	    nmatches = 0;
- 	    for (i = 0; c->enums[i]; i++)
- 	      if (strncmp (arg, c->enums[i], len) == 0)
- 		{
- 		  if (c->enums[i][len] == '\0')
- 		    {
- 		      match = c->enums[i];
- 		      nmatches = 1;
- 		      break; /* exact match. */
- 		    }
- 		  else
- 		    {
- 		      match = c->enums[i];
- 		      nmatches++;
- 		    }
- 		}
- 
- 	    if (nmatches <= 0)
- 	      error ("Undefined item: \"%s\".", arg);
- 
- 	    if (nmatches > 1)
- 	      error ("Ambiguous item \"%s\".", arg);
- 
- 	    *(const char **) c->var = match;
  	  }
  	  break;
  	default:
--- 250,255 ----

[-- Attachment #3: Type: text/plain, Size: 103 bytes --]



Jim
--
Jim Ingham                                   jingham@apple.com
Developer Tools
Apple Computer

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2003-10-29 19:03 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-10-28  2:02 report valid values for all errors for enum variables Jim Ingham
2003-10-28  4:03 ` Daniel Jacobowitz
2003-10-28 16:08   ` Andrew Cagney
2003-10-28 19:35     ` Jim Ingham
2003-10-29 15:15       ` Andrew Cagney
2003-10-29 19:03         ` Jim Ingham

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox