1a45ae5f8SJohn Marino /* The ptid_t type and common functions operating on it.
2a45ae5f8SJohn Marino
3*ef5ccd6cSJohn Marino Copyright (C) 1986-2013 Free Software Foundation, Inc.
4a45ae5f8SJohn Marino
5a45ae5f8SJohn Marino This file is part of GDB.
6a45ae5f8SJohn Marino
7a45ae5f8SJohn Marino This program is free software; you can redistribute it and/or modify
8a45ae5f8SJohn Marino it under the terms of the GNU General Public License as published by
9a45ae5f8SJohn Marino the Free Software Foundation; either version 3 of the License, or
10a45ae5f8SJohn Marino (at your option) any later version.
11a45ae5f8SJohn Marino
12a45ae5f8SJohn Marino This program is distributed in the hope that it will be useful,
13a45ae5f8SJohn Marino but WITHOUT ANY WARRANTY; without even the implied warranty of
14a45ae5f8SJohn Marino MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15a45ae5f8SJohn Marino GNU General Public License for more details.
16a45ae5f8SJohn Marino
17a45ae5f8SJohn Marino You should have received a copy of the GNU General Public License
18a45ae5f8SJohn Marino along with this program. If not, see <http://www.gnu.org/licenses/>. */
19a45ae5f8SJohn Marino
20a45ae5f8SJohn Marino #include "ptid.h"
21a45ae5f8SJohn Marino
22a45ae5f8SJohn Marino /* Oft used ptids */
23a45ae5f8SJohn Marino ptid_t null_ptid = { 0, 0, 0 };
24a45ae5f8SJohn Marino ptid_t minus_one_ptid = { -1, 0, 0 };
25a45ae5f8SJohn Marino
26a45ae5f8SJohn Marino /* Create a ptid given the necessary PID, LWP, and TID components. */
27a45ae5f8SJohn Marino
28a45ae5f8SJohn Marino ptid_t
ptid_build(int pid,long lwp,long tid)29a45ae5f8SJohn Marino ptid_build (int pid, long lwp, long tid)
30a45ae5f8SJohn Marino {
31a45ae5f8SJohn Marino ptid_t ptid;
32a45ae5f8SJohn Marino
33a45ae5f8SJohn Marino ptid.pid = pid;
34a45ae5f8SJohn Marino ptid.lwp = lwp;
35a45ae5f8SJohn Marino ptid.tid = tid;
36a45ae5f8SJohn Marino return ptid;
37a45ae5f8SJohn Marino }
38a45ae5f8SJohn Marino
39a45ae5f8SJohn Marino /* Create a ptid from just a pid. */
40a45ae5f8SJohn Marino
41a45ae5f8SJohn Marino ptid_t
pid_to_ptid(int pid)42a45ae5f8SJohn Marino pid_to_ptid (int pid)
43a45ae5f8SJohn Marino {
44a45ae5f8SJohn Marino return ptid_build (pid, 0, 0);
45a45ae5f8SJohn Marino }
46a45ae5f8SJohn Marino
47a45ae5f8SJohn Marino /* Fetch the pid (process id) component from a ptid. */
48a45ae5f8SJohn Marino
49a45ae5f8SJohn Marino int
ptid_get_pid(ptid_t ptid)50a45ae5f8SJohn Marino ptid_get_pid (ptid_t ptid)
51a45ae5f8SJohn Marino {
52a45ae5f8SJohn Marino return ptid.pid;
53a45ae5f8SJohn Marino }
54a45ae5f8SJohn Marino
55a45ae5f8SJohn Marino /* Fetch the lwp (lightweight process) component from a ptid. */
56a45ae5f8SJohn Marino
57a45ae5f8SJohn Marino long
ptid_get_lwp(ptid_t ptid)58a45ae5f8SJohn Marino ptid_get_lwp (ptid_t ptid)
59a45ae5f8SJohn Marino {
60a45ae5f8SJohn Marino return ptid.lwp;
61a45ae5f8SJohn Marino }
62a45ae5f8SJohn Marino
63a45ae5f8SJohn Marino /* Fetch the tid (thread id) component from a ptid. */
64a45ae5f8SJohn Marino
65a45ae5f8SJohn Marino long
ptid_get_tid(ptid_t ptid)66a45ae5f8SJohn Marino ptid_get_tid (ptid_t ptid)
67a45ae5f8SJohn Marino {
68a45ae5f8SJohn Marino return ptid.tid;
69a45ae5f8SJohn Marino }
70a45ae5f8SJohn Marino
71a45ae5f8SJohn Marino /* ptid_equal() is used to test equality of two ptids. */
72a45ae5f8SJohn Marino
73a45ae5f8SJohn Marino int
ptid_equal(ptid_t ptid1,ptid_t ptid2)74a45ae5f8SJohn Marino ptid_equal (ptid_t ptid1, ptid_t ptid2)
75a45ae5f8SJohn Marino {
76a45ae5f8SJohn Marino return (ptid1.pid == ptid2.pid
77a45ae5f8SJohn Marino && ptid1.lwp == ptid2.lwp
78a45ae5f8SJohn Marino && ptid1.tid == ptid2.tid);
79a45ae5f8SJohn Marino }
80a45ae5f8SJohn Marino
81a45ae5f8SJohn Marino /* Returns true if PTID represents a process. */
82a45ae5f8SJohn Marino
83a45ae5f8SJohn Marino int
ptid_is_pid(ptid_t ptid)84a45ae5f8SJohn Marino ptid_is_pid (ptid_t ptid)
85a45ae5f8SJohn Marino {
86a45ae5f8SJohn Marino if (ptid_equal (minus_one_ptid, ptid))
87a45ae5f8SJohn Marino return 0;
88a45ae5f8SJohn Marino if (ptid_equal (null_ptid, ptid))
89a45ae5f8SJohn Marino return 0;
90a45ae5f8SJohn Marino
91a45ae5f8SJohn Marino return (ptid_get_lwp (ptid) == 0 && ptid_get_tid (ptid) == 0);
92a45ae5f8SJohn Marino }
93