This is the mail archive of the 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: [RFC] Add option processing for external modules


Inspired by recent events, I've decided to make an attempt at "abstracting" option processing for gdb. This will allow us to whack all the Insight code from main.c, pushing us one step closer to completely separating insight and gdb.

I propose to add an options interface which looks like this:

typedef void (*gdb_option_callback_ftype) (int option, char *argv0, char *optarg);
[Drop the ``*'' so it is consistent with other ftype's]

typedef void (*gdb_option_help_ftype) (struct ui_file *stream, int option);
One reference point is sim/common/sim-options.[hc] (but don't take this to mean that I think GDB should have similar - the sim's startup module registraration mechanism is very macro centric at present :-().

Perhaphs put the code in the file options.[hc], gdbopt.[hc] or gdb-options.[hc] or ... (since the sim could use it?).

struct gdb_option
/* A standard struct option */
struct option option;

/* Callback when option.flag == NULL && option.val == GDB_OPTION_USE_CALLBACK */
gdb_option_callback_ftype callback;

/* Help callback for this option. */
gdb_option_help_ftype help;

/* Callback data. Passed to both the processing callback and the
help callback. */
int callback_data;

/* Register a single option */
extern void register_option (struct gdb_option *gopt);

/* Register an array of options terminated with GDB_OPTION_NULL. */
extern void register_options (struct gdb_option *gopts);

As an example, main() in gdbtk-main.c would do:

static struct gdb_option gdbtk_options[] =
{{"tclcommand", required_argument, 0, GDB_OPTION_USE_CALLBACK},
gdbtk_option_process, gdbtk_option_help, (int) GDBTK_OPTION_TCLCOMMAND},
{{"editor-command", required_argument, 0, GDB_OPTION_USE_CALLBACK},
gdbtk_option_process, gdbtk_option_help, (int) GDBTK_OPTION_EDITOR_COMMAND},
register_options (gdbtk_options);

The parameter GDB_OPTION_USE_CALLBACK tells the getopt loop in main.c to use the given callback. If this parameter is anything else, it behaves exactly the same as normal (if flag == NULL, this value is returned; if flag != NULL, *flag = parameter).

Ok, I know its kinda kludgy, piggy-backing on top of getopt, but I don't really want to write my own getopt or modify libiberty.
The sims had the same problem and ended up with a similar solution.

I have attached a patch which works (on insight), and I would appreciate comments.


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