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