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] |
Hi, 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); typedef void (*gdb_option_help_ftype) (struct ui_file *stream, int option); 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}, GDB_OPTION_NULL }; 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. I have attached a patch which works (on insight), and I would appreciate comments. Keith
Attachment:
options.patch
Description: Text document
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |