More updated translations
[binutils-gdb.git] / gdb / tid-parse.h
blobf971f91b4f675a7d66405751edbbb239ba5e86ba
1 /* TID parsing for GDB, the GNU debugger.
3 Copyright (C) 2015-2024 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 GDB_TID_PARSE_H
21 #define GDB_TID_PARSE_H
23 #include "cli/cli-utils.h"
25 struct thread_info;
27 /* Issue an invalid thread ID error, pointing at STRING, the invalid
28 ID. */
29 [[noreturn]] extern void invalid_thread_id_error (const char *string);
31 /* Parse TIDSTR as a per-inferior thread ID, in either INF_NUM.THR_NUM
32 or THR_NUM form. In the latter case, the missing INF_NUM is filled
33 in from the current inferior. If ENDPTR is not NULL,
34 parse_thread_id stores the address of the first character after the
35 thread ID. Either a valid thread is returned, or an error is
36 thrown. */
37 struct thread_info *parse_thread_id (const char *tidstr, const char **end);
39 /* Return true if TIDSTR is pointing to a string that looks like a
40 thread-id. This doesn't mean that TIDSTR identifies a valid thread, but
41 the string does at least look like a valid thread-id. If END is not
42 NULL, parse_thread_id stores the address of the first character after
43 the thread-id into *END. */
45 bool is_thread_id (const char *tidstr, const char **end);
47 /* Parse a thread ID or a thread range list.
49 A range will be of the form
51 <inferior_num>.<thread_number1>-<thread_number2>
53 and will represent all the threads of inferior INFERIOR_NUM with
54 number between THREAD_NUMBER1 and THREAD_NUMBER2, inclusive.
55 <inferior_num> can also be omitted, as in
57 <thread_number1>-<thread_number2>
59 in which case GDB infers the inferior number from the default
60 passed to the constructor or to the last call to the init
61 function. */
62 class tid_range_parser
64 public:
65 /* Default construction. Must call init before calling get_*. */
66 tid_range_parser () {}
68 /* Calls init automatically. See init for description of
69 parameters. */
70 tid_range_parser (const char *tidlist, int default_inferior);
72 /* Reinitialize a tid_range_parser. TIDLIST is the string to be
73 parsed. DEFAULT_INFERIOR is the inferior number to assume if a
74 non-qualified thread ID is found. */
75 void init (const char *tidlist, int default_inferior);
77 /* Parse a thread ID or a thread range list.
79 This function is designed to be called iteratively. While
80 processing a thread ID range list, at each call it will return
81 (in the INF_NUM and THR_NUM output parameters) the next thread ID
82 in the range (irrespective of whether the thread actually
83 exists).
85 At the beginning of parsing a thread range, the char pointer
86 PARSER->m_cur_tok will be advanced past <thread_number1> and left
87 pointing at the '-' token. Subsequent calls will not advance the
88 pointer until the range is completed. The call that completes
89 the range will advance the pointer past <thread_number2>.
91 This function advances through the input string for as long you
92 call it. Once the end of the input string is reached, a call to
93 finished returns false (see below).
95 E.g., with list: "1.2 3.4-6":
97 1st call: *INF_NUM=1; *THR_NUM=2 (finished==0)
98 2nd call: *INF_NUM=3; *THR_NUM=4 (finished==0)
99 3rd call: *INF_NUM=3; *THR_NUM=5 (finished==0)
100 4th call: *INF_NUM=3; *THR_NUM=6 (finished==1)
102 Returns true if a thread/range is parsed successfully, false
103 otherwise. */
104 bool get_tid (int *inf_num, int *thr_num);
106 /* Like get_tid, but return a thread ID range per call, rather then
107 a single thread ID.
109 If the next element in the list is a single thread ID, then
110 *THR_START and *THR_END are set to the same value.
112 E.g.,. with list: "1.2 3.4-6"
114 1st call: *INF_NUM=1; *THR_START=2; *THR_END=2 (finished==0)
115 2nd call: *INF_NUM=3; *THR_START=4; *THR_END=6 (finished==1)
117 Returns true if parsed a thread/range successfully, false
118 otherwise. */
119 bool get_tid_range (int *inf_num, int *thr_start, int *thr_end);
121 /* Returns true if processing a star wildcard (e.g., "1.*")
122 range. */
123 bool in_star_range () const;
125 /* Returns true if processing a thread range (e.g., 1.2-3). */
126 bool in_thread_range () const;
128 /* Returns true if parsing has completed. */
129 bool finished () const;
131 /* Return the current token being parsed. When parsing has
132 finished, this points past the last parsed token. */
133 const char *cur_tok () const;
135 /* When parsing a range, advance past the final token in the
136 range. */
137 void skip_range ();
139 /* True if the TID last parsed was explicitly inferior-qualified.
140 IOW, whether the spec specified an inferior number
141 explicitly. */
142 bool tid_is_qualified () const;
144 private:
145 /* No need for these. They are intentionally not defined anywhere. */
146 tid_range_parser (const tid_range_parser &);
147 tid_range_parser &operator= (const tid_range_parser &);
149 bool get_tid_or_range (int *inf_num, int *thr_start, int *thr_end);
151 /* The possible states of the tid range parser's state machine,
152 indicating what sub-component are we expecting. */
153 enum
155 /* Parsing the inferior number. */
156 STATE_INFERIOR,
158 /* Parsing the thread number or thread number range. */
159 STATE_THREAD_RANGE,
161 /* Parsing a star wildcard thread range. E.g., "1.*". */
162 STATE_STAR_RANGE,
163 } m_state;
165 /* The string being parsed. When parsing has finished, this points
166 past the last parsed token. */
167 const char *m_cur_tok;
169 /* The range parser state when we're parsing the thread number
170 sub-component. */
171 number_or_range_parser m_range_parser;
173 /* Last inferior number returned. */
174 int m_inf_num;
176 /* True if the TID last parsed was explicitly inferior-qualified.
177 IOW, whether the spec specified an inferior number
178 explicitly. */
179 bool m_qualified;
181 /* The inferior number to assume if the TID is not qualified. */
182 int m_default_inferior;
186 /* Accept a string-form list of thread IDs such as is accepted by
187 tid_range_parser. Return true if the INF_NUM.THR.NUM thread is in
188 the list. DEFAULT_INFERIOR is the inferior number to assume if a
189 non-qualified thread ID is found in the list.
191 By definition, an empty list includes all threads. This is to be
192 interpreted as typing a command such as "info threads" with no
193 arguments. */
194 extern int tid_is_in_list (const char *list, int default_inferior,
195 int inf_num, int thr_num);
197 #endif /* GDB_TID_PARSE_H */