From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24773 invoked by alias); 28 Oct 2003 02:02:55 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 24594 invoked from network); 28 Oct 2003 02:02:53 -0000 Received: from unknown (HELO mail-out3.apple.com) (17.254.13.22) by sources.redhat.com with SMTP; 28 Oct 2003 02:02:53 -0000 Received: from mailgate1.apple.com (a17-128-100-225.apple.com [17.128.100.225]) by mail-out3.apple.com (8.12.10/8.12.9) with ESMTP id h9S22rrY007249 for ; Mon, 27 Oct 2003 18:02:53 -0800 (PST) Received: from scv3.apple.com (scv3.apple.com) by mailgate1.apple.com (Content Technologies SMTPRS 4.2.1) with ESMTP id for ; Mon, 27 Oct 2003 18:02:21 -0800 Received: from [17.201.22.245] (inghji6.apple.com [17.201.22.245]) by scv3.apple.com (8.12.9/8.12.9) with ESMTP id h9S22P0m017264 for ; Mon, 27 Oct 2003 18:02:25 -0800 (PST) Mime-Version: 1.0 (Apple Message framework v606) To: gdb-patches@sources.redhat.com Message-Id: Content-Type: multipart/mixed; boundary=Apple-Mail-2-952595688 From: Jim Ingham Subject: report valid values for all errors for enum variables... Date: Tue, 28 Oct 2003 02:02:00 -0000 X-SW-Source: 2003-10/txt/msg00801.txt.bz2 --Apple-Mail-2-952595688 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; format=flowed Content-length: 1046 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 * 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. --Apple-Mail-2-952595688 Content-Transfer-Encoding: 7bit Content-Type: application/octet-stream; x-unix-mode=0644; name="var_enum.patch" Content-Disposition: attachment; filename=var_enum.patch Content-length: 2704 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 ---- --Apple-Mail-2-952595688 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; format=flowed Content-length: 103 Jim -- Jim Ingham jingham@apple.com Developer Tools Apple Computer --Apple-Mail-2-952595688--