Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Jim Ingham <jingham@apple.com>
To: gdb-patches@sources.redhat.com
Subject: report valid values for all errors for enum variables...
Date: Tue, 28 Oct 2003 02:02:00 -0000	[thread overview]
Message-ID: <F620E205-08EA-11D8-A22C-000A958F4C44@apple.com> (raw)

[-- 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

             reply	other threads:[~2003-10-28  2:02 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-10-28  2:02 Jim Ingham [this message]
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

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=F620E205-08EA-11D8-A22C-000A958F4C44@apple.com \
    --to=jingham@apple.com \
    --cc=gdb-patches@sources.redhat.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