mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2024-12-15 04:31:49 +08:00
436252de3e
I grew a bit tired of using ptid_get_{lwp,pid,tid} and friends, so I decided to make it a bit easier to use by making it a proper class. The fields are now private, so it's not possible to change a ptid_t field by mistake. The new methods of ptid_t map to existing functions/practice like this: ptid_t (pid, lwp, tid) -> ptid_build (pid, lwp, tid) ptid_t (pid) -> pid_to_ptid (pid) ptid.is_pid () -> ptid_is_pid (ptid) ptid == other -> ptid_equal (ptid, other) ptid != other -> !ptid_equal (ptid, other) ptid.pid () -> ptid_get_pid (ptid) ptid.lwp_p () -> ptid_lwp_p (ptid) ptid.lwp () -> ptid_get_lwp (ptid) ptid.tid_p () -> ptid_tid_p (ptid) ptid.tid () -> ptid_get_tid (ptid) ptid.matches (filter) -> ptid_match (ptid, filter) I've replaced the implementation of the existing functions with calls to the new methods. People are encouraged to gradually switch to using the ptid_t methods instead of the functions (or we can change them all in one pass eventually). Also, I'm not sure if it's worth it (because of ptid_t's relatively small size), but I have made the functions and methods take ptid_t arguments by const reference instead of by value. gdb/ChangeLog: * common/ptid.h (struct ptid): Change to... (class ptid_t): ... this. <ptid_t>: New constructors. <pid, lwp_p, lwp, tid_p, tid, is_pid, operator==, operator!=, matches>: New methods. <make_null, make_minus_one>: New static methods. <pid>: Rename to... <m_pid>: ...this. <lwp>: Rename to... <m_lwp>: ...this. <tid>: Rename to... <m_tid>: ...this. (ptid_build, ptid_get_pid, ptid_get_lwp, ptid_get_tid, ptid_equal, ptid_is_pid, ptid_lwp_p, ptid_tid_p, ptid_match): Take ptid arguments as references, move comment to class ptid_t. * common/ptid.c (null_ptid, minus_one_ptid): Initialize with ptid_t static methods. (ptid_build, pid_to_ptid, ptid_get_pid, ptid_get_tid, ptid_equal, ptid_is_pid, ptid_lwp_p, ptid_tid_p, ptid_match): Take ptid arguments as references, implement using ptid_t methods. * unittests/ptid-selftests.c: New file. * Makefile.in (SUBDIR_UNITTESTS_SRCS): Add unittests/ptid-selftests.c. (SUBDIR_UNITTESTS_OBS): Add unittests/ptid-selftests.o. gdb/gdbserver/ChangeLog: * server.c (handle_v_cont): Initialize thread_resume::thread with null_ptid.
107 lines
1.8 KiB
C
107 lines
1.8 KiB
C
/* The ptid_t type and common functions operating on it.
|
|
|
|
Copyright (C) 1986-2017 Free Software Foundation, Inc.
|
|
|
|
This file is part of GDB.
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
|
|
|
#include "common-defs.h"
|
|
#include "ptid.h"
|
|
|
|
/* See ptid.h for these. */
|
|
|
|
ptid_t null_ptid = ptid_t::make_null ();
|
|
ptid_t minus_one_ptid = ptid_t::make_minus_one ();
|
|
|
|
/* See ptid.h. */
|
|
|
|
ptid_t
|
|
ptid_build (int pid, long lwp, long tid)
|
|
{
|
|
return ptid_t (pid, lwp, tid);
|
|
}
|
|
|
|
/* See ptid.h. */
|
|
|
|
ptid_t
|
|
pid_to_ptid (int pid)
|
|
{
|
|
return ptid_t (pid);
|
|
}
|
|
|
|
/* See ptid.h. */
|
|
|
|
int
|
|
ptid_get_pid (const ptid_t &ptid)
|
|
{
|
|
return ptid.pid ();
|
|
}
|
|
|
|
/* See ptid.h. */
|
|
|
|
long
|
|
ptid_get_lwp (const ptid_t &ptid)
|
|
{
|
|
return ptid.lwp ();
|
|
}
|
|
|
|
/* See ptid.h. */
|
|
|
|
long
|
|
ptid_get_tid (const ptid_t &ptid)
|
|
{
|
|
return ptid.tid ();
|
|
}
|
|
|
|
/* See ptid.h. */
|
|
|
|
int
|
|
ptid_equal (const ptid_t &ptid1, const ptid_t &ptid2)
|
|
{
|
|
return ptid1 == ptid2;
|
|
}
|
|
|
|
/* See ptid.h. */
|
|
|
|
int
|
|
ptid_is_pid (const ptid_t &ptid)
|
|
{
|
|
return ptid.is_pid ();
|
|
}
|
|
|
|
/* See ptid.h. */
|
|
|
|
int
|
|
ptid_lwp_p (const ptid_t &ptid)
|
|
{
|
|
return ptid.lwp_p ();
|
|
}
|
|
|
|
/* See ptid.h. */
|
|
|
|
int
|
|
ptid_tid_p (const ptid_t &ptid)
|
|
{
|
|
return ptid.tid_p ();
|
|
}
|
|
|
|
/* See ptid.h. */
|
|
|
|
int
|
|
ptid_match (const ptid_t &ptid, const ptid_t &filter)
|
|
{
|
|
return ptid.matches (filter);
|
|
}
|