1 1.1 christos /* Header file for simulator argument handling. 2 1.1.1.10 christos Copyright (C) 1997-2024 Free Software Foundation, Inc. 3 1.1 christos Contributed by Cygnus Support. 4 1.1 christos 5 1.1 christos This file is part of GDB, the GNU debugger. 6 1.1 christos 7 1.1 christos This program is free software; you can redistribute it and/or modify 8 1.1 christos it under the terms of the GNU General Public License as published by 9 1.1 christos the Free Software Foundation; either version 3 of the License, or 10 1.1 christos (at your option) any later version. 11 1.1 christos 12 1.1 christos This program is distributed in the hope that it will be useful, 13 1.1 christos but WITHOUT ANY WARRANTY; without even the implied warranty of 14 1.1 christos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 1.1 christos GNU General Public License for more details. 16 1.1 christos 17 1.1 christos You should have received a copy of the GNU General Public License 18 1.1 christos along with this program. If not, see <http://www.gnu.org/licenses/>. */ 19 1.1 christos 20 1.1 christos #ifndef SIM_OPTIONS_H 21 1.1 christos #define SIM_OPTIONS_H 22 1.1 christos 23 1.1 christos #include "getopt.h" 24 1.1 christos 25 1.1 christos /* ARGV option support. 26 1.1 christos 27 1.1 christos Options for the standalone simulator are parsed by sim_open since 28 1.1 christos sim_open handles the large majority of them and it also parses the 29 1.1 christos options when invoked by gdb [or any external program]. 30 1.1 christos 31 1.1 christos For OPTION_HANDLER: arg#2 is the processor to apply to option to 32 1.1 christos (all if NULL); arg#3 is the option index; arg#4 is the option's 33 1.1 christos argument, NULL if optional and missing; arg#5 is nonzero if a 34 1.1 christos command is being interpreted. */ 35 1.1 christos 36 1.1.1.3 christos typedef SIM_RC (OPTION_HANDLER) (SIM_DESC, sim_cpu *, int, char *, int); 37 1.1 christos 38 1.1 christos /* Declare option handlers with a macro so it's usable on k&r systems. */ 39 1.1.1.3 christos #define DECLARE_OPTION_HANDLER(fn) SIM_RC fn (SIM_DESC, sim_cpu *, int, char *, int) 40 1.1 christos 41 1.1 christos typedef struct { 42 1.1 christos 43 1.1 christos /* The long option information. */ 44 1.1 christos 45 1.1 christos struct option opt; 46 1.1 christos 47 1.1 christos /* The short option with the same meaning ('\0' if none). 48 1.1 christos 49 1.1 christos For short options, when OPT.VAL is non-zero, it, instead of 50 1.1 christos SHORTOPT is passed to HANDLER. 51 1.1 christos 52 1.1 christos For example, for the below: 53 1.1 christos 54 1.1 christos { {"dc", no_argument, NULL, OPTION_VALUE}, 55 1.1 christos 'd', NULL, "<<description>>", HANDLER}, 56 1.1 christos { {NULL, no_argument, NULL, OPTION_VALUE}, 57 1.1 christos 'e', NULL, "<<description>>", HANDLER}, 58 1.1 christos 59 1.1 christos the options --dc, -d and -e all result in OPTION_VALUE being 60 1.1 christos passed into HANDLER. */ 61 1.1 christos 62 1.1 christos char shortopt; 63 1.1 christos 64 1.1 christos /* The name of the argument (NULL if none). */ 65 1.1 christos 66 1.1 christos const char *arg; 67 1.1 christos 68 1.1 christos /* The documentation string. 69 1.1 christos 70 1.1 christos If DOC is NULL, this option name is listed as a synonym for the 71 1.1 christos previous option. 72 1.1 christos 73 1.1 christos If DOC and DOC_NAME are the empty string (i.e. ""), this option 74 1.1 christos is not listed in usage and help messages. 75 1.1 christos 76 1.1 christos For example, given the aliased options --dc, --dp and -d, then: 77 1.1 christos 78 1.1 christos { {"dc", no_argument, NULL, OPTION_DC}, 79 1.1 christos 'd', NULL, "<<description>>", HANDLER}, 80 1.1 christos { {"dp", no_argument, NULL, OPTION_DP}, 81 1.1 christos '\0', NULL, NULL, HANDLER}, 82 1.1 christos 83 1.1 christos will list ``-d, --dc, --dp <<description>>'' */ 84 1.1 christos 85 1.1 christos const char *doc; 86 1.1 christos 87 1.1 christos /* A function to process the option. */ 88 1.1 christos 89 1.1 christos OPTION_HANDLER *handler; 90 1.1 christos 91 1.1 christos /* The documentation name. Used when generating usage and help 92 1.1 christos messages. 93 1.1 christos 94 1.1 christos If DOC and DOC_NAME are the empty string (i.e. ""), this option 95 1.1 christos is not listed in usage and help messages. 96 1.1 christos 97 1.1 christos If DOC_NAME is a non-empty string then it, insted of OPT.NAME, is 98 1.1 christos listed as the name of the option in usage and help messages. 99 1.1 christos 100 1.1 christos For example, given the options --set-pc and --set-sp, then: 101 1.1 christos 102 1.1 christos { {"set-pc", no_argument, NULL, OPTION_SET_PC}, 103 1.1 christos '\0', NULL, "<<description>>", HANDLER, "--set-REGNAME" }, 104 1.1 christos { {"set-sp", no_argument, NULL, OPTION_SET_SP}, 105 1.1 christos '\0', NULL, "", HANDLER, "" }, 106 1.1 christos 107 1.1 christos will list ``--set-REGNAME <<description>>". */ 108 1.1 christos 109 1.1 christos const char *doc_name; 110 1.1 christos 111 1.1 christos } OPTION; 112 1.1 christos 113 1.1 christos /* All options that don't have a short form equivalent begin with this for 114 1.1 christos `val'. 130 isn't special, just some non-ASCII value to begin at. 115 1.1 christos Modules needn't worry about collisions here, the code dynamically assigned 116 1.1 christos the actual numbers used and then passes the original value to the option 117 1.1 christos handler. */ 118 1.1 christos #define OPTION_START 130 119 1.1 christos 120 1.1 christos /* Identify valid option in the table */ 121 1.1 christos #define OPTION_VALID_P(O) ((O)->opt.name != NULL || (O)->shortopt != '\0') 122 1.1 christos 123 1.1 christos /* List of options added by various modules. */ 124 1.1 christos typedef struct option_list { 125 1.1 christos struct option_list *next; 126 1.1 christos const OPTION *options; 127 1.1 christos } OPTION_LIST; 128 1.1 christos 129 1.1 christos /* Add a set of options to the simulator. 130 1.1 christos CPU is the cpu the options apply to or NULL for all cpus. 131 1.1 christos TABLE is an array of OPTIONS terminated by a NULL `opt.name' entry. */ 132 1.1.1.3 christos SIM_RC sim_add_option_table (SIM_DESC sd, sim_cpu *cpu, const OPTION *table); 133 1.1 christos 134 1.1 christos /* Install handler for the standard options. */ 135 1.1 christos MODULE_INSTALL_FN standard_install; 136 1.1 christos 137 1.1 christos /* Called by sim_open to parse the arguments. */ 138 1.1.1.5 christos SIM_RC sim_parse_args (SIM_DESC sd, char * const *argv); 139 1.1 christos 140 1.1 christos /* Print help messages for the options. IS_COMMAND is non-zero when 141 1.1 christos this function is called from the command line interpreter. */ 142 1.1.1.3 christos void sim_print_help (SIM_DESC sd, int is_command); 143 1.1 christos 144 1.1.1.9 christos /* Print version information for the program. IS_COMMAND is non-zero when 145 1.1.1.9 christos this function is called from the command line interpreter. */ 146 1.1.1.9 christos void sim_print_version (SIM_DESC sd, int is_command); 147 1.1.1.9 christos 148 1.1 christos /* Try to parse the command as if it is an option, Only fail when 149 1.1 christos totally unsuccessful */ 150 1.1.1.4 christos SIM_RC sim_args_command (SIM_DESC sd, const char *cmd); 151 1.1 christos 152 1.1 christos #endif /* SIM_OPTIONS_H */ 153