* 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
* Re: report valid values for all errors for enum variables...
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
0 siblings, 1 reply; 6+ messages in thread
From: Daniel Jacobowitz @ 2003-10-28 4:03 UTC (permalink / raw)
To: gdb-patches
On Mon, Oct 27, 2003 at 06:03:45PM -0800, Jim Ingham wrote:
> 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.
>
I like it. In fact, I really, really, really like it :)
This is OK.
--
Daniel Jacobowitz
MontaVista Software Debian GNU/Linux Developer
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: report valid values for all errors for enum variables...
2003-10-28 4:03 ` Daniel Jacobowitz
@ 2003-10-28 16:08 ` Andrew Cagney
2003-10-28 19:35 ` Jim Ingham
0 siblings, 1 reply; 6+ messages in thread
From: Andrew Cagney @ 2003-10-28 16:08 UTC (permalink / raw)
To: Daniel Jacobowitz, Jim Ingham; +Cc: gdb-patches
Jim,
Since you're looking a that code, can you please tweak it so that it
uses a mem_file instead of the 1024 byte stack buffer.
Is there a test case?
Andrew
+ /* 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++)
{
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: report valid values for all errors for enum variables...
2003-10-28 16:08 ` Andrew Cagney
@ 2003-10-28 19:35 ` Jim Ingham
2003-10-29 15:15 ` Andrew Cagney
0 siblings, 1 reply; 6+ messages in thread
From: Jim Ingham @ 2003-10-28 19:35 UTC (permalink / raw)
To: Andrew Cagney; +Cc: Daniel Jacobowitz, gdb-patches
[-- Attachment #1: Type: text/plain, Size: 18 bytes --]
Sure, how 'bout:
[-- Attachment #2: var_enum.patch --]
[-- Type: application/octet-stream, Size: 3125 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 19:31:08 -0000
*************** do_setshow_command (char *arg, int from_
*** 197,252 ****
{
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)
! strcat (msg, ", ");
! strcat (msg, c->enums[i]);
}
! 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:
--- 197,257 ----
{
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. */
! struct ui_file *tmp_error_stream = mem_fileopen ();
! make_cleanup_ui_file_delete (tmp_error_stream);
!
! if (arg == NULL)
! fprintf_unfiltered (tmp_error_stream, "Requires an argument.");
! else if (nmatches <= 0)
! fprintf_unfiltered (tmp_error_stream, "Undefined item: \"%s\".", arg);
! else if (nmatches > 1)
! fprintf_unfiltered (tmp_error_stream, "Ambiguous item \"%s\".", arg);
! fprintf_unfiltered (tmp_error_stream, " Valid values are ");
for (i = 0; c->enums[i]; i++)
{
if (i != 0)
! fprintf_unfiltered (tmp_error_stream, ", ");
! fprintf_unfiltered (tmp_error_stream, c->enums[i]);
}
! fprintf_unfiltered (tmp_error_stream, ".");
! error_stream (tmp_error_stream);
}
}
break;
default:
[-- Attachment #3: Type: text/plain, Size: 911 bytes --]
Jim
On Oct 27, 2003, at 8:45 AM, Andrew Cagney wrote:
> Jim,
>
> Since you're looking a that code, can you please tweak it so that it
> uses a mem_file instead of the 1024 byte stack buffer.
>
> Is there a test case?
>
> Andrew
>
> + /* 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++)
> {
>
>
--
Jim Ingham jingham@apple.com
Developer Tools
Apple Computer
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: report valid values for all errors for enum variables...
2003-10-28 19:35 ` Jim Ingham
@ 2003-10-29 15:15 ` Andrew Cagney
2003-10-29 19:03 ` Jim Ingham
0 siblings, 1 reply; 6+ messages in thread
From: Andrew Cagney @ 2003-10-29 15:15 UTC (permalink / raw)
To: Jim Ingham; +Cc: Daniel Jacobowitz, gdb-patches
> Sure, how 'bout:
Yep! But you'll need to switch some of the fprintf_unfiltered's to
fputs_unfiltered before committing. Otherwize the build will barf due
to -Wformat-nonliteral warnings.
thanks,
Andrew
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: report valid values for all errors for enum variables...
2003-10-29 15:15 ` Andrew Cagney
@ 2003-10-29 19:03 ` Jim Ingham
0 siblings, 0 replies; 6+ messages in thread
From: Jim Ingham @ 2003-10-29 19:03 UTC (permalink / raw)
To: Andrew Cagney; +Cc: Daniel Jacobowitz, gdb-patches
Presumably only the line:
fprintf_unfiltered (tmp_error_stream, c->enums[i]);
since that is the only fprintf with a non-string literal format string.
If I change this one, I get no warnings with -Wformat-nonliteral.
Jim
On Oct 28, 2003, at 7:13 AM, Andrew Cagney wrote:
>> Sure, how 'bout:
>
> Yep! But you'll need to switch some of the fprintf_unfiltered's to
> fputs_unfiltered before committing. Otherwize the build will barf due
> to -Wformat-nonliteral warnings.
>
> thanks,
> Andrew
>
>
>
--
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