1 /* TID parsing for GDB, the GNU debugger.
3 Copyright (C) 2015-2016 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/>. */
23 #include "cli/cli-utils.h"
27 /* Issue an invalid thread ID error, pointing at STRING, the invalid
29 extern void ATTRIBUTE_NORETURN 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
37 struct thread_info *parse_thread_id (const char *tidstr, const char **end);
39 /* Parse a thread ID or a thread range list.
41 A range will be of the form
43 <inferior_num>.<thread_number1>-<thread_number2>
45 and will represent all the threads of inferior INFERIOR_NUM with
46 number between THREAD_NUMBER1 and THREAD_NUMBER2, inclusive.
47 <inferior_num> can also be omitted, as in
49 <thread_number1>-<thread_number2>
51 in which case GDB infers the inferior number from the default
52 passed to the constructor or to the last call to the init
54 class tid_range_parser
57 /* Default construction. Must call init before calling get_*. */
58 tid_range_parser () {}
60 /* Calls init automatically. See init for description of
62 tid_range_parser (const char *tidlist, int default_inferior);
64 /* Reinitialize a tid_range_parser. TIDLIST is the string to be
65 parsed. DEFAULT_INFERIOR is the inferior number to assume if a
66 non-qualified thread ID is found. */
67 void init (const char *tidlist, int default_inferior);
69 /* Parse a thread ID or a thread range list.
71 This function is designed to be called iteratively. While
72 processing a thread ID range list, at each call it will return
73 (in the INF_NUM and THR_NUM output parameters) the next thread ID
74 in the range (irrespective of whether the thread actually
77 At the beginning of parsing a thread range, the char pointer
78 PARSER->m_cur_tok will be advanced past <thread_number1> and left
79 pointing at the '-' token. Subsequent calls will not advance the
80 pointer until the range is completed. The call that completes
81 the range will advance the pointer past <thread_number2>.
83 This function advances through the input string for as long you
84 call it. Once the end of the input string is reached, a call to
85 finished returns false (see below).
87 E.g., with list: "1.2 3.4-6":
89 1st call: *INF_NUM=1; *THR_NUM=2 (finished==0)
90 2nd call: *INF_NUM=3; *THR_NUM=4 (finished==0)
91 3rd call: *INF_NUM=3; *THR_NUM=5 (finished==0)
92 4th call: *INF_NUM=3; *THR_NUM=6 (finished==1)
94 Returns true if a thread/range is parsed successfully, false
96 bool get_tid (int *inf_num, int *thr_num);
98 /* Like get_tid, but return a thread ID range per call, rather then
101 If the next element in the list is a single thread ID, then
102 *THR_START and *THR_END are set to the same value.
104 E.g.,. with list: "1.2 3.4-6"
106 1st call: *INF_NUM=1; *THR_START=2; *THR_END=2 (finished==0)
107 2nd call: *INF_NUM=3; *THR_START=4; *THR_END=6 (finished==1)
109 Returns true if parsed a thread/range successfully, false
111 bool get_tid_range (int *inf_num, int *thr_start, int *thr_end);
113 /* Returns true if processing a star wildcard (e.g., "1.*")
115 bool in_star_range () const;
117 /* Returns true if parsing has completed. */
118 bool finished () const;
120 /* Return the current token being parsed. When parsing has
121 finished, this points past the last parsed token. */
122 const char *cur_tok () const;
124 /* When parsing a range, advance past the final token in the
128 /* True if the TID last parsed was explicitly inferior-qualified.
129 IOW, whether the spec specified an inferior number
131 bool tid_is_qualified () const;
134 /* No need for these. They are intentionally not defined anywhere. */
135 tid_range_parser (const tid_range_parser &);
136 tid_range_parser &operator= (const tid_range_parser &);
138 bool get_tid_or_range (int *inf_num, int *thr_start, int *thr_end);
140 /* The possible states of the tid range parser's state machine,
141 indicating what sub-component are we expecting. */
144 /* Parsing the inferior number. */
147 /* Parsing the thread number or thread number range. */
150 /* Parsing a star wildcard thread range. E.g., "1.*". */
154 /* The string being parsed. When parsing has finished, this points
155 past the last parsed token. */
156 const char *m_cur_tok;
158 /* The range parser state when we're parsing the thread number
160 number_or_range_parser m_range_parser;
162 /* Last inferior number returned. */
165 /* True if the TID last parsed was explicitly inferior-qualified.
166 IOW, whether the spec specified an inferior number
170 /* The inferior number to assume if the TID is not qualified. */
171 int m_default_inferior;
175 /* Accept a string-form list of thread IDs such as is accepted by
176 tid_range_parser. Return true if the INF_NUM.THR.NUM thread is in
177 the list. DEFAULT_INFERIOR is the inferior number to assume if a
178 non-qualified thread ID is found in the list.
180 By definition, an empty list includes all threads. This is to be
181 interpreted as typing a command such as "info threads" with no
183 extern int tid_is_in_list (const char *list, int default_inferior,
184 int inf_num, int thr_num);
186 #endif /* TID_PARSE_H */