3 Copyright (C) 2011-2019 Free Software Foundation, Inc.
5 This file is part of GDB.
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.
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.
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/>. */
20 #ifndef CLI_CLI_UTILS_H
21 #define CLI_CLI_UTILS_H
23 /* *PP is a string denoting a number. Get the number. Advance *PP
24 after the string and any trailing whitespace.
26 The string can either be a number, or "$" followed by the name of a
27 convenience variable, or ("$" or "$$") followed by digits.
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. */
32 extern int get_number_trailer (const char **pp
, int trailer
);
34 /* Convenience. Like get_number_trailer, but with no TRAILER. */
36 extern int get_number (const char **);
38 /* Like the above, but takes a non-const "char **". */
40 extern int get_number (char **);
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');
46 /* Structure to hold the values of the options used by the 'info
47 variables' command and other similar commands. These correspond to the
50 struct info_print_options
53 char *type_regexp
= nullptr;
55 ~info_print_options ()
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
66 extern void extract_info_print_options (info_print_options
*opts
,
69 /* Throws an error telling the user that ARGS starts with an option
70 unrecognized by COMMAND. */
72 extern void report_unrecognized_option_error (const char *command
,
76 /* Builds the help string for a command documented by PREFIX,
77 followed by the extract_info_print_args help for ENTITY_KIND. */
79 const char *info_print_args_help (const char *prefix
,
80 const char *entity_kind
);
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,
88 class number_or_range_parser
91 /* Default construction. Must call init before calling
93 number_or_range_parser () {}
95 /* Calls init automatically. */
96 number_or_range_parser (const char *string
);
98 /* STRING is the string to be parsed. */
99 void init (const char *string
);
101 /* While processing a range, this fuction is called iteratively; At
102 each call it will return the next value in the range.
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>. */
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
);
117 /* Returns true if parsing has completed. */
118 bool finished () const;
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
; }
125 /* True when parsing a range. */
126 bool in_range () const
127 { return m_in_range
; }
129 /* When parsing a range, the final value in the range. */
130 int end_value () const
131 { return m_end_value
; }
133 /* When parsing a range, skip past the final token in the range. */
136 gdb_assert (m_in_range
);
137 m_cur_tok
= m_end_ptr
;
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
&);
146 /* The string being parsed. When parsing has finished, this points
147 past the last parsed token. */
148 const char *m_cur_tok
;
150 /* Last value returned. */
153 /* When parsing a range, the final value in the range. */
156 /* When parsing a range, a pointer past the final token in the
158 const char *m_end_ptr
;
160 /* True when parsing a range. */
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
168 By definition, an empty list includes all numbers. This is to
169 be interpreted as typing a command such as "delete break" with
172 extern int number_is_in_list (const char *list
, int number
);
174 /* Reverse S to the last non-whitespace character without skipping past
177 extern const char *remove_trailing_whitespace (const char *start
,
180 /* Same, for non-const S. */
183 remove_trailing_whitespace (const char *start
, char *s
)
185 return (char *) remove_trailing_whitespace (start
, (const char *) s
);
188 /* A helper function to extract an argument from *ARG. An argument is
189 delimited by whitespace. The return value is empty if no argument
192 extern std::string
extract_arg (char **arg
);
194 /* A const-correct version of the above. */
196 extern std::string
extract_arg (const char **arg
);
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,
201 0 otherwise. If the argument is found, it updates *STR to point
202 past the argument and past any whitespace following the
204 extern int check_for_argument (const char **str
, const char *arg
, int arg_len
);
206 /* Same as above, but ARG's length is computed. */
209 check_for_argument (const char **str
, const char *arg
)
211 return check_for_argument (str
, arg
, strlen (arg
));
214 /* Same, for non-const STR. */
217 check_for_argument (char **str
, const char *arg
, int arg_len
)
219 return check_for_argument (const_cast<const char **> (str
),
224 check_for_argument (char **str
, const char *arg
)
226 return check_for_argument (str
, arg
, strlen (arg
));
229 /* qcs_flags struct groups the -q, -c, and -s flags parsed by "thread
230 apply" and "frame apply" commands */
239 /* Validate FLAGS. Throws an error if both FLAGS->CONT and
240 FLAGS->SILENT are true. WHICH_COMMAND is included in the error
242 extern void validate_flags_qcs (const char *which_command
, qcs_flags
*flags
);
244 #endif /* CLI_CLI_UTILS_H */
This page took 0.03426 seconds and 4 git commands to generate.