This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
Re: Adding -file-list-exec-source-file command to GDB/MI
- From: Bob Rossi <bob_rossi at cox dot net>
- To: Andrew Cagney <ac131313 at redhat dot com>
- Cc: gdb-patches at sources dot redhat dot com
- Date: Wed, 2 Apr 2003 11:15:54 -0500
- Subject: Re: Adding -file-list-exec-source-file command to GDB/MI
- References: <20030329004109.GA7487@white> <3E87D445.70609@redhat.com>
> >enum mi_cmd_result
> >mi_cmd_file_list_exec_source_file(char *command, char **argv, int argc)
> >{
> > struct symtab_and_line st;
>
> See:
> http://sources.redhat.com/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gdb&pr=783
>
> Even though there are no arguments it will want to discard any "--". A
> mi_getopt() call to strip off any leading "--". I think you'll want to
> tweak that function so that calling it is easier - allow NULL OPT and
> OPTARG?
Ok, I've got all the changes down but this one.
Instead of changing mi_getopt, I wrote a wrapper function called
extern int mi_valid_noargs (const char *prefix, int argc, char **argv);
and put it in mi_getopt.[ch].
This function basically returns 1 if the arguments are valid for a
function that takes no arguments, and 0 otherwise.
What do you think?
The reason I like this solution is because the caller doesn't need to concern
itself with mi_getopt. So if the interface ever changes to mi_getopt,
there will be less spots to fix. Also, It keeps the client smaller and
less confusing.
Bob Rossi
The body looks something like this.
extern int mi_valid_noargs(const char *prefix, int argc, char **argv) {
int optind = 0;
char *optarg;
static struct mi_opt opts[] =
{
0
};
int opt = mi_getopt(prefix, argc, argv, opts, &optind, &optarg);
/* The end of the list was reached first try */
if ( opt == -1 )
return 1;
else
return 0;
}