Commit | Line | Data |
---|---|---|
d26e3629 KY |
1 | /* The ptid_t type and common functions operating on it. |
2 | ||
ecd75fc8 | 3 | Copyright (C) 1986-2014 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 | #include "ptid.h" | |
21 | ||
9a2c3737 PA |
22 | /* See ptid.h for these. */ |
23 | ||
d26e3629 KY |
24 | ptid_t null_ptid = { 0, 0, 0 }; |
25 | ptid_t minus_one_ptid = { -1, 0, 0 }; | |
26 | ||
9a2c3737 | 27 | /* See ptid.h. */ |
d26e3629 KY |
28 | |
29 | ptid_t | |
30 | ptid_build (int pid, long lwp, long tid) | |
31 | { | |
32 | ptid_t ptid; | |
33 | ||
34 | ptid.pid = pid; | |
35 | ptid.lwp = lwp; | |
36 | ptid.tid = tid; | |
37 | return ptid; | |
38 | } | |
39 | ||
9a2c3737 | 40 | /* See ptid.h. */ |
d26e3629 KY |
41 | |
42 | ptid_t | |
43 | pid_to_ptid (int pid) | |
44 | { | |
45 | return ptid_build (pid, 0, 0); | |
46 | } | |
47 | ||
9a2c3737 | 48 | /* See ptid.h. */ |
d26e3629 KY |
49 | |
50 | int | |
51 | ptid_get_pid (ptid_t ptid) | |
52 | { | |
53 | return ptid.pid; | |
54 | } | |
55 | ||
9a2c3737 | 56 | /* See ptid.h. */ |
d26e3629 KY |
57 | |
58 | long | |
59 | ptid_get_lwp (ptid_t ptid) | |
60 | { | |
61 | return ptid.lwp; | |
62 | } | |
63 | ||
9a2c3737 | 64 | /* See ptid.h. */ |
d26e3629 KY |
65 | |
66 | long | |
67 | ptid_get_tid (ptid_t ptid) | |
68 | { | |
69 | return ptid.tid; | |
70 | } | |
71 | ||
9a2c3737 | 72 | /* See ptid.h. */ |
d26e3629 KY |
73 | |
74 | int | |
75 | ptid_equal (ptid_t ptid1, ptid_t ptid2) | |
76 | { | |
77 | return (ptid1.pid == ptid2.pid | |
78 | && ptid1.lwp == ptid2.lwp | |
79 | && ptid1.tid == ptid2.tid); | |
80 | } | |
81 | ||
9a2c3737 | 82 | /* See ptid.h. */ |
d26e3629 KY |
83 | |
84 | int | |
85 | ptid_is_pid (ptid_t ptid) | |
86 | { | |
dfd4cc63 LM |
87 | if (ptid_equal (minus_one_ptid, ptid) |
88 | || ptid_equal (null_ptid, ptid)) | |
d26e3629 KY |
89 | return 0; |
90 | ||
91 | return (ptid_get_lwp (ptid) == 0 && ptid_get_tid (ptid) == 0); | |
92 | } | |
dfd4cc63 | 93 | |
9a2c3737 | 94 | /* See ptid.h. */ |
dfd4cc63 LM |
95 | |
96 | int | |
97 | ptid_lwp_p (ptid_t ptid) | |
98 | { | |
99 | if (ptid_equal (minus_one_ptid, ptid) | |
100 | || ptid_equal (null_ptid, ptid)) | |
101 | return 0; | |
102 | ||
103 | return (ptid_get_lwp (ptid) != 0); | |
104 | } | |
105 | ||
9a2c3737 | 106 | /* See ptid.h. */ |
dfd4cc63 LM |
107 | |
108 | int | |
109 | ptid_tid_p (ptid_t ptid) | |
110 | { | |
111 | if (ptid_equal (minus_one_ptid, ptid) | |
112 | || ptid_equal (null_ptid, ptid)) | |
113 | return 0; | |
114 | ||
115 | return (ptid_get_tid (ptid) != 0); | |
116 | } | |
2ebd5a35 HZ |
117 | |
118 | int | |
119 | ptid_match (ptid_t ptid, ptid_t filter) | |
120 | { | |
121 | if (ptid_equal (filter, minus_one_ptid)) | |
122 | return 1; | |
123 | if (ptid_is_pid (filter) | |
124 | && ptid_get_pid (ptid) == ptid_get_pid (filter)) | |
125 | return 1; | |
126 | else if (ptid_equal (ptid, filter)) | |
127 | return 1; | |
128 | ||
129 | return 0; | |
130 | } |