Commit | Line | Data |
---|---|---|
d26e3629 KY |
1 | /* The ptid_t type and common functions operating on it. |
2 | ||
61baf725 | 3 | Copyright (C) 1986-2017 Free Software Foundation, Inc. |
d26e3629 KY |
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 | ||
20 | #ifndef PTID_H | |
21 | #define PTID_H | |
22 | ||
9a2c3737 PA |
23 | /* The ptid struct is a collection of the various "ids" necessary for |
24 | identifying the inferior process/thread being debugged. This | |
25 | consists of the process id (pid), lightweight process id (lwp) and | |
26 | thread id (tid). When manipulating ptids, the constructors, | |
27 | accessors, and predicates declared in this file should be used. Do | |
c658158d PA |
28 | NOT access the struct ptid members directly. |
29 | ||
30 | process_stratum targets that handle threading themselves should | |
31 | prefer using the ptid.lwp field, leaving the ptid.tid field for any | |
32 | thread_stratum target that might want to sit on top. | |
33 | */ | |
d26e3629 | 34 | |
436252de | 35 | class ptid_t |
9a2c3737 | 36 | { |
436252de SM |
37 | public: |
38 | /* Must have a trivial defaulted default constructor so that the | |
39 | type remains POD. */ | |
40 | ptid_t () noexcept = default; | |
41 | ||
42 | /* Make a ptid given the necessary PID, LWP, and TID components. | |
43 | ||
44 | A ptid with only a PID (LWP and TID equal to zero) is usually used to | |
45 | represent a whole process, including all its lwps/threads. */ | |
46 | ||
47 | explicit constexpr ptid_t (int pid, long lwp = 0, long tid = 0) | |
48 | : m_pid (pid), m_lwp (lwp), m_tid (tid) | |
49 | {} | |
50 | ||
51 | /* Fetch the pid (process id) component from the ptid. */ | |
52 | ||
53 | constexpr int pid () const | |
54 | { return m_pid; } | |
55 | ||
56 | /* Return true if the ptid's lwp member is non-zero. */ | |
57 | ||
58 | constexpr bool lwp_p () const | |
59 | { return m_lwp != 0; } | |
60 | ||
61 | /* Fetch the lwp (lightweight process) component from the ptid. */ | |
62 | ||
63 | constexpr long lwp () const | |
64 | { return m_lwp; } | |
65 | ||
66 | /* Return true if the ptid's tid member is non-zero. */ | |
67 | ||
68 | constexpr bool tid_p () const | |
69 | { return m_tid != 0; } | |
70 | ||
71 | /* Fetch the tid (thread id) component from a ptid. */ | |
72 | ||
73 | constexpr long tid () const | |
74 | { return m_tid; } | |
75 | ||
76 | /* Return true if the ptid represents a whole process, including all its | |
77 | lwps/threads. Such ptids have the form of (pid, 0, 0), with | |
78 | pid != -1. */ | |
79 | ||
80 | constexpr bool is_pid () const | |
81 | { | |
82 | return (*this != make_null () | |
83 | && *this != make_minus_one () | |
84 | && m_lwp == 0 | |
85 | && m_tid == 0); | |
86 | } | |
87 | ||
88 | /* Compare two ptids to see if they are equal. */ | |
89 | ||
90 | constexpr bool operator== (const ptid_t &other) const | |
91 | { | |
92 | return (m_pid == other.m_pid | |
93 | && m_lwp == other.m_lwp | |
94 | && m_tid == other.m_tid); | |
95 | } | |
96 | ||
97 | /* Compare two ptids to see if they are different. */ | |
98 | ||
99 | constexpr bool operator!= (const ptid_t &other) const | |
100 | { | |
101 | return !(*this == other); | |
102 | } | |
103 | ||
104 | /* Return true if the ptid matches FILTER. FILTER can be the wild | |
105 | card MINUS_ONE_PTID (all ptids match it); can be a ptid representing | |
106 | a process (ptid.is_pid () returns true), in which case, all lwps and | |
107 | threads of that given process match, lwps and threads of other | |
108 | processes do not; or, it can represent a specific thread, in which | |
109 | case, only that thread will match true. The ptid must represent a | |
110 | specific LWP or THREAD, it can never be a wild card. */ | |
111 | ||
112 | constexpr bool matches (const ptid_t &filter) const | |
113 | { | |
114 | return (/* If filter represents any ptid, it's always a match. */ | |
115 | filter == make_minus_one () | |
116 | /* If filter is only a pid, any ptid with that pid | |
117 | matches. */ | |
118 | || (filter.is_pid () && m_pid == filter.pid ()) | |
119 | ||
120 | /* Otherwise, this ptid only matches if it's exactly equal | |
121 | to filter. */ | |
122 | || *this == filter); | |
123 | } | |
124 | ||
125 | /* Make a null ptid. */ | |
126 | ||
127 | static constexpr ptid_t make_null () | |
128 | { return ptid_t (0, 0, 0); } | |
129 | ||
130 | /* Make a minus one ptid. */ | |
131 | ||
132 | static constexpr ptid_t make_minus_one () | |
133 | { return ptid_t (-1, 0, 0); } | |
134 | ||
135 | private: | |
9a2c3737 | 136 | /* Process id. */ |
436252de | 137 | int m_pid; |
d26e3629 | 138 | |
9a2c3737 | 139 | /* Lightweight process id. */ |
436252de | 140 | long m_lwp; |
d26e3629 | 141 | |
9a2c3737 | 142 | /* Thread id. */ |
436252de | 143 | long m_tid; |
9a2c3737 | 144 | }; |
d26e3629 | 145 | |
d26e3629 | 146 | /* The null or zero ptid, often used to indicate no process. */ |
436252de | 147 | |
d26e3629 KY |
148 | extern ptid_t null_ptid; |
149 | ||
9a2c3737 | 150 | /* The (-1,0,0) ptid, often used to indicate either an error condition |
d26e3629 | 151 | or a "don't care" condition, i.e, "run all threads." */ |
436252de | 152 | |
d26e3629 KY |
153 | extern ptid_t minus_one_ptid; |
154 | ||
d26e3629 | 155 | |
436252de SM |
156 | /* The following functions are kept for backwards compatibility. The use of |
157 | the ptid_t methods is preferred. */ | |
158 | ||
159 | /* See ptid_t::ptid_t. */ | |
160 | ||
161 | extern ptid_t ptid_build (int pid, long lwp, long tid); | |
162 | ||
163 | /* See ptid_t::ptid_t. */ | |
164 | ||
165 | extern ptid_t pid_to_ptid (int pid); | |
166 | ||
167 | /* See ptid_t::pid. */ | |
168 | ||
169 | extern int ptid_get_pid (const ptid_t &ptid); | |
170 | ||
171 | /* See ptid_t::lwp. */ | |
172 | ||
173 | extern long ptid_get_lwp (const ptid_t &ptid); | |
174 | ||
175 | /* See ptid_t::tid. */ | |
176 | ||
177 | extern long ptid_get_tid (const ptid_t &ptid); | |
178 | ||
179 | /* See ptid_t::operator== and ptid_t::operator!=. */ | |
d26e3629 | 180 | |
436252de | 181 | extern int ptid_equal (const ptid_t &ptid1, const ptid_t &ptid2); |
d26e3629 | 182 | |
436252de | 183 | /* See ptid_t::is_pid. */ |
d26e3629 | 184 | |
436252de | 185 | extern int ptid_is_pid (const ptid_t &ptid); |
d26e3629 | 186 | |
436252de | 187 | /* See ptid_t::lwp_p. */ |
d26e3629 | 188 | |
436252de | 189 | extern int ptid_lwp_p (const ptid_t &ptid); |
d26e3629 | 190 | |
436252de | 191 | /* See ptid_t::tid_p. */ |
dfd4cc63 | 192 | |
436252de | 193 | extern int ptid_tid_p (const ptid_t &ptid); |
dfd4cc63 | 194 | |
436252de | 195 | /* See ptid_t::matches. */ |
2ebd5a35 | 196 | |
436252de | 197 | extern int ptid_match (const ptid_t &ptid, const ptid_t &filter); |
2ebd5a35 | 198 | |
d26e3629 | 199 | #endif |