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