This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Adding -file-list-exec-source-file command to GDB/MI


> >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;
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]