gdb/common/ptid.c - gdb

Global variables defined

Functions defined

Source code

  1. /* The ptid_t type and common functions operating on it.

  2.    Copyright (C) 1986-2015 Free Software Foundation, Inc.

  3.    This file is part of GDB.

  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 3 of the License, or
  7.    (at your option) any later version.

  8.    This program is distributed in the hope that it will be useful,
  9.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11.    GNU General Public License for more details.

  12.    You should have received a copy of the GNU General Public License
  13.    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

  14. #include "common-defs.h"
  15. #include "ptid.h"

  16. /* See ptid.h for these.  */

  17. ptid_t null_ptid = { 0, 0, 0 };
  18. ptid_t minus_one_ptid = { -1, 0, 0 };

  19. /* See ptid.h.  */

  20. ptid_t
  21. ptid_build (int pid, long lwp, long tid)
  22. {
  23.   ptid_t ptid;

  24.   ptid.pid = pid;
  25.   ptid.lwp = lwp;
  26.   ptid.tid = tid;
  27.   return ptid;
  28. }

  29. /* See ptid.h.  */

  30. ptid_t
  31. pid_to_ptid (int pid)
  32. {
  33.   return ptid_build (pid, 0, 0);
  34. }

  35. /* See ptid.h.  */

  36. int
  37. ptid_get_pid (ptid_t ptid)
  38. {
  39.   return ptid.pid;
  40. }

  41. /* See ptid.h.  */

  42. long
  43. ptid_get_lwp (ptid_t ptid)
  44. {
  45.   return ptid.lwp;
  46. }

  47. /* See ptid.h.  */

  48. long
  49. ptid_get_tid (ptid_t ptid)
  50. {
  51.   return ptid.tid;
  52. }

  53. /* See ptid.h.  */

  54. int
  55. ptid_equal (ptid_t ptid1, ptid_t ptid2)
  56. {
  57.   return (ptid1.pid == ptid2.pid
  58.           && ptid1.lwp == ptid2.lwp
  59.           && ptid1.tid == ptid2.tid);
  60. }

  61. /* See ptid.h.  */

  62. int
  63. ptid_is_pid (ptid_t ptid)
  64. {
  65.   if (ptid_equal (minus_one_ptid, ptid)
  66.       || ptid_equal (null_ptid, ptid))
  67.     return 0;

  68.   return (ptid_get_lwp (ptid) == 0 && ptid_get_tid (ptid) == 0);
  69. }

  70. /* See ptid.h.  */

  71. int
  72. ptid_lwp_p (ptid_t ptid)
  73. {
  74.   if (ptid_equal (minus_one_ptid, ptid)
  75.       || ptid_equal (null_ptid, ptid))
  76.     return 0;

  77.   return (ptid_get_lwp (ptid) != 0);
  78. }

  79. /* See ptid.h.  */

  80. int
  81. ptid_tid_p (ptid_t ptid)
  82. {
  83.   if (ptid_equal (minus_one_ptid, ptid)
  84.       || ptid_equal (null_ptid, ptid))
  85.     return 0;

  86.   return (ptid_get_tid (ptid) != 0);
  87. }

  88. int
  89. ptid_match (ptid_t ptid, ptid_t filter)
  90. {
  91.   if (ptid_equal (filter, minus_one_ptid))
  92.     return 1;
  93.   if (ptid_is_pid (filter)
  94.       && ptid_get_pid (ptid) == ptid_get_pid (filter))
  95.     return 1;
  96.   else if (ptid_equal (ptid, filter))
  97.     return 1;

  98.   return 0;
  99. }