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