Fix crash on process name "(sd-pam)" (PR 16594).
[platform/upstream/binutils.git] / gdb / common / ptid.c
1 /* The ptid_t type and common functions operating on it.
2
3    Copyright (C) 1986-2014 Free Software Foundation, Inc.
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
22 /* See ptid.h for these.  */
23
24 ptid_t null_ptid = { 0, 0, 0 };
25 ptid_t minus_one_ptid = { -1, 0, 0 };
26
27 /* See ptid.h.  */
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
40 /* See ptid.h.  */
41
42 ptid_t
43 pid_to_ptid (int pid)
44 {
45   return ptid_build (pid, 0, 0);
46 }
47
48 /* See ptid.h.  */
49
50 int
51 ptid_get_pid (ptid_t ptid)
52 {
53   return ptid.pid;
54 }
55
56 /* See ptid.h.  */
57
58 long
59 ptid_get_lwp (ptid_t ptid)
60 {
61   return ptid.lwp;
62 }
63
64 /* See ptid.h.  */
65
66 long
67 ptid_get_tid (ptid_t ptid)
68 {
69   return ptid.tid;
70 }
71
72 /* See ptid.h.  */
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
82 /* See ptid.h.  */
83
84 int
85 ptid_is_pid (ptid_t ptid)
86 {
87   if (ptid_equal (minus_one_ptid, ptid)
88       || ptid_equal (null_ptid, ptid))
89     return 0;
90
91   return (ptid_get_lwp (ptid) == 0 && ptid_get_tid (ptid) == 0);
92 }
93
94 /* See ptid.h.  */
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
106 /* See ptid.h.  */
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 }