Commit | Line | Data |
---|---|---|
e9cafbcc TT |
1 | /* CLI utilities. |
2 | ||
42a4f53d | 3 | Copyright (C) 2011-2019 Free Software Foundation, Inc. |
e9cafbcc TT |
4 | |
5 | This file is part of GDB. | |
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 | ||
1a5c2598 TT |
20 | #ifndef CLI_CLI_UTILS_H |
21 | #define CLI_CLI_UTILS_H | |
e9cafbcc | 22 | |
5d5658a1 PA |
23 | /* *PP is a string denoting a number. Get the number. Advance *PP |
24 | after the string and any trailing whitespace. | |
e9cafbcc | 25 | |
5d5658a1 PA |
26 | The string can either be a number, or "$" followed by the name of a |
27 | convenience variable, or ("$" or "$$") followed by digits. | |
28 | ||
29 | TRAILER is a character which can be found after the number; most | |
30 | commonly this is `-'. If you don't want a trailer, use \0. */ | |
31 | ||
32 | extern int get_number_trailer (const char **pp, int trailer); | |
33 | ||
34 | /* Convenience. Like get_number_trailer, but with no TRAILER. */ | |
e9cafbcc | 35 | |
f1735a53 | 36 | extern int get_number (const char **); |
e799154c | 37 | |
f1735a53 | 38 | /* Like the above, but takes a non-const "char **". */ |
e799154c | 39 | |
e9cafbcc TT |
40 | extern int get_number (char **); |
41 | ||
9d0faba9 PA |
42 | /* Like get_number_trailer, but works with ULONGEST, and throws on |
43 | error instead of returning 0. */ | |
44 | extern ULONGEST get_ulongest (const char **pp, int trailer = '\0'); | |
45 | ||
b16507e0 AB |
46 | /* Structure to hold the values of the options used by the 'info |
47 | variables' command and other similar commands. These correspond to the | |
48 | -q and -t options. */ | |
49 | ||
50 | struct info_print_options | |
51 | { | |
52 | int quiet = false; | |
53 | char *type_regexp = nullptr; | |
54 | ||
55 | ~info_print_options () | |
56 | { | |
57 | xfree (type_regexp); | |
58 | } | |
59 | }; | |
60 | ||
61 | /* Extract options from ARGS for commands like 'info variables', placing | |
62 | the options into OPTS. ARGS is updated to point to the first character | |
63 | after the options, or, if there is nothing after the options, then ARGS | |
64 | is set to nullptr. */ | |
65 | ||
66 | extern void extract_info_print_options (info_print_options *opts, | |
67 | const char **args); | |
0d4cad90 PW |
68 | |
69 | /* Throws an error telling the user that ARGS starts with an option | |
70 | unrecognized by COMMAND. */ | |
71 | ||
72 | extern void report_unrecognized_option_error (const char *command, | |
73 | const char *args); | |
74 | ||
75 | ||
76 | /* Builds the help string for a command documented by PREFIX, | |
77 | followed by the extract_info_print_args help for ENTITY_KIND. */ | |
78 | ||
79 | const char *info_print_args_help (const char *prefix, | |
80 | const char *entity_kind); | |
81 | ||
bfd28288 PA |
82 | /* Parse a number or a range. |
83 | A number will be of the form handled by get_number. | |
84 | A range will be of the form <number1> - <number2>, and | |
85 | will represent all the integers between number1 and number2, | |
86 | inclusive. */ | |
197f0a60 | 87 | |
bfd28288 | 88 | class number_or_range_parser |
197f0a60 | 89 | { |
bfd28288 PA |
90 | public: |
91 | /* Default construction. Must call init before calling | |
92 | get_next. */ | |
93 | number_or_range_parser () {} | |
94 | ||
95 | /* Calls init automatically. */ | |
96 | number_or_range_parser (const char *string); | |
97 | ||
98 | /* STRING is the string to be parsed. */ | |
99 | void init (const char *string); | |
100 | ||
101 | /* While processing a range, this fuction is called iteratively; At | |
102 | each call it will return the next value in the range. | |
103 | ||
104 | At the beginning of parsing a range, the char pointer | |
105 | STATE->m_cur_tok will be advanced past <number1> and left | |
106 | pointing at the '-' token. Subsequent calls will not advance the | |
107 | pointer until the range is completed. The call that completes | |
108 | the range will advance the pointer past <number2>. */ | |
109 | int get_number (); | |
110 | ||
111 | /* Setup internal state such that get_next() returns numbers in the | |
112 | START_VALUE to END_VALUE range. END_PTR is where the string is | |
113 | advanced to when get_next() returns END_VALUE. */ | |
114 | void setup_range (int start_value, int end_value, | |
115 | const char *end_ptr); | |
116 | ||
117 | /* Returns true if parsing has completed. */ | |
529c08b2 | 118 | bool finished () const; |
bfd28288 PA |
119 | |
120 | /* Return the string being parsed. When parsing has finished, this | |
121 | points past the last parsed token. */ | |
122 | const char *cur_tok () const | |
123 | { return m_cur_tok; } | |
124 | ||
125 | /* True when parsing a range. */ | |
126 | bool in_range () const | |
127 | { return m_in_range; } | |
128 | ||
129 | /* When parsing a range, the final value in the range. */ | |
130 | int end_value () const | |
131 | { return m_end_value; } | |
132 | ||
133 | /* When parsing a range, skip past the final token in the range. */ | |
134 | void skip_range () | |
135 | { | |
136 | gdb_assert (m_in_range); | |
137 | m_cur_tok = m_end_ptr; | |
529c08b2 | 138 | m_in_range = false; |
bfd28288 PA |
139 | } |
140 | ||
141 | private: | |
142 | /* No need for these. They are intentionally not defined anywhere. */ | |
143 | number_or_range_parser (const number_or_range_parser &); | |
144 | number_or_range_parser &operator= (const number_or_range_parser &); | |
145 | ||
197f0a60 TT |
146 | /* The string being parsed. When parsing has finished, this points |
147 | past the last parsed token. */ | |
bfd28288 | 148 | const char *m_cur_tok; |
197f0a60 TT |
149 | |
150 | /* Last value returned. */ | |
bfd28288 | 151 | int m_last_retval; |
197f0a60 TT |
152 | |
153 | /* When parsing a range, the final value in the range. */ | |
bfd28288 | 154 | int m_end_value; |
197f0a60 TT |
155 | |
156 | /* When parsing a range, a pointer past the final token in the | |
157 | range. */ | |
bfd28288 | 158 | const char *m_end_ptr; |
197f0a60 | 159 | |
bfd28288 PA |
160 | /* True when parsing a range. */ |
161 | bool m_in_range; | |
197f0a60 TT |
162 | }; |
163 | ||
aea5b279 MS |
164 | /* Accept a number and a string-form list of numbers such as is |
165 | accepted by get_number_or_range. Return TRUE if the number is | |
166 | in the list. | |
167 | ||
168 | By definition, an empty list includes all numbers. This is to | |
169 | be interpreted as typing a command such as "delete break" with | |
170 | no arguments. */ | |
171 | ||
e799154c | 172 | extern int number_is_in_list (const char *list, int number); |
aea5b279 | 173 | |
c00f8484 KS |
174 | /* Reverse S to the last non-whitespace character without skipping past |
175 | START. */ | |
176 | ||
63160a43 PA |
177 | extern const char *remove_trailing_whitespace (const char *start, |
178 | const char *s); | |
179 | ||
180 | /* Same, for non-const S. */ | |
181 | ||
182 | static inline char * | |
183 | remove_trailing_whitespace (const char *start, char *s) | |
184 | { | |
185 | return (char *) remove_trailing_whitespace (start, (const char *) s); | |
186 | } | |
55aa24fb SDJ |
187 | |
188 | /* A helper function to extract an argument from *ARG. An argument is | |
cb791d59 TT |
189 | delimited by whitespace. The return value is empty if no argument |
190 | was found. */ | |
55aa24fb | 191 | |
cb791d59 | 192 | extern std::string extract_arg (char **arg); |
55aa24fb | 193 | |
cb791d59 | 194 | /* A const-correct version of the above. */ |
b5be8ce0 | 195 | |
cb791d59 | 196 | extern std::string extract_arg (const char **arg); |
b5be8ce0 | 197 | |
e6f0bce7 HZ |
198 | /* A helper function that looks for an argument at the start of a |
199 | string. The argument must also either be at the end of the string, | |
200 | or be followed by whitespace. Returns 1 if it finds the argument, | |
cbba3ecd PA |
201 | 0 otherwise. If the argument is found, it updates *STR to point |
202 | past the argument and past any whitespace following the | |
203 | argument. */ | |
63160a43 PA |
204 | extern int check_for_argument (const char **str, const char *arg, int arg_len); |
205 | ||
9d0faba9 PA |
206 | /* Same as above, but ARG's length is computed. */ |
207 | ||
208 | static inline int | |
209 | check_for_argument (const char **str, const char *arg) | |
210 | { | |
211 | return check_for_argument (str, arg, strlen (arg)); | |
212 | } | |
213 | ||
63160a43 PA |
214 | /* Same, for non-const STR. */ |
215 | ||
216 | static inline int | |
217 | check_for_argument (char **str, const char *arg, int arg_len) | |
218 | { | |
219 | return check_for_argument (const_cast<const char **> (str), | |
220 | arg, arg_len); | |
221 | } | |
e6f0bce7 | 222 | |
9d0faba9 PA |
223 | static inline int |
224 | check_for_argument (char **str, const char *arg) | |
225 | { | |
226 | return check_for_argument (str, arg, strlen (arg)); | |
227 | } | |
228 | ||
5d707134 PA |
229 | /* qcs_flags struct groups the -q, -c, and -s flags parsed by "thread |
230 | apply" and "frame apply" commands */ | |
529c08b2 PW |
231 | |
232 | struct qcs_flags | |
233 | { | |
5d707134 PA |
234 | int quiet = false; |
235 | int cont = false; | |
236 | int silent = false; | |
529c08b2 PW |
237 | }; |
238 | ||
5d707134 PA |
239 | /* Validate FLAGS. Throws an error if both FLAGS->CONT and |
240 | FLAGS->SILENT are true. WHICH_COMMAND is included in the error | |
241 | message. */ | |
242 | extern void validate_flags_qcs (const char *which_command, qcs_flags *flags); | |
243 | ||
1a5c2598 | 244 | #endif /* CLI_CLI_UTILS_H */ |