This is the mail archive of the gdb-patches@sourceware.org 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: [PATCH:gdb/mi] Update a specified list of variable objects


 > > Actually it's probably better to use isdigit like below
 > 
 > In fact, it's probably even easier than than. Note this code from
 > mi_cmd_var_create:
 > 
 >   if (strcmp (name, "-") == 0)
 >     {
 >       xfree (name);
 >       name = varobj_gen_name ();
 >     }
 >   else if (!isalpha (*name))
 >     error (_("mi_cmd_var_create: name of object must begin with a letter"));
 > 
 > with this in mind,
 > 
 > 
 > > +      print_values = PRINT_NO_VALUES;
 > > +  else if (argc == 2 && isdigit (*argv[0]))
 > > +    {
 > > +      optind = 1;
 > > +      print_values = mi_parse_values_option (argv[0]);
 > > +    }
 > 
 > can be written like this:
 > 
 >   else if (argc == 2 && (isdigit (*argv[0]) || *argv[0] == '-'))
 >     {
 >       optind = 1;
 >       print_values = mi_parse_values_option (argv[0]);
 >     }

"-var-update --all-values var1 var2" doesn't work in this case.  I see
a couple of shortcomings with my patch too now:  "-var-update 0 var1 var2" doesn't work
and "-var-update" with no argument givese a segmentation fault.

 > >    else
 > > -    name = (argv[1]);
 > > +    {
 > > +      while (1)
 > > +       {
 > > +         int opt = mi_getopt ("mi_cmd_var_update",
 > > +                              argc, argv, opts, &optind, &optarg);
 > 
 > And this code can be dropped. What do you think?

This is a few lines shorter but what if someone wants to add another option?
mi_getopt provides an extensible solution.

I'm not really worried which approach is used.  Since the general idea seems
to be acceptable, I'll write some tests and documentation.  Then you can code
it a different way if you wish and the only requirement will be that the tests
pass.

-- 
Nick                                           http://users.snap.net.nz/~nickrob


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