[03/12] gdbsupport: add type definitions for pid, lwp and tid

Message ID 20221206135729.3937767-4-simon.marchi@efficios.com
State Committed
Commit 7b065306be39502cd2e6b60696280ac720c67e66
Headers
Series Initial support for ROCm platform (AMDGPU) debugging |

Commit Message

Simon Marchi Dec. 6, 2022, 1:57 p.m. UTC
  A following patch will want to declare variables of the same time as
some ptid_t components.  To make that easy (and avoid harcoding those
types everywhere), define some type definitions in the ptid_t struct for
each of them.  Use them throughout ptid.h.

I initially used pid_t, lwp_t and tid_t, but there is the risk of some
system defining the pid_t type using a macro instead of a typedef, which
would break things.  So, use the _type suffix instead.

Change-Id: I820b0bea9dafcb4914f1c9ba4bb96b5c666c8dec
---
 gdbsupport/ptid.h | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)
  

Comments

Andrew Burgess Dec. 6, 2022, 4:36 p.m. UTC | #1
Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes:

> A following patch will want to declare variables of the same time as

typo: s/time/type/

> some ptid_t components.  To make that easy (and avoid harcoding those
> types everywhere), define some type definitions in the ptid_t struct for
> each of them.  Use them throughout ptid.h.
>
> I initially used pid_t, lwp_t and tid_t, but there is the risk of some
> system defining the pid_t type using a macro instead of a typedef, which
> would break things.  So, use the _type suffix instead.

Sounds good.  Now we just need to slowly convert the rest of GDB to use
these types :)

LGTM.
Thanks,
Andrew

>
> Change-Id: I820b0bea9dafcb4914f1c9ba4bb96b5c666c8dec
> ---
>  gdbsupport/ptid.h | 18 +++++++++++-------
>  1 file changed, 11 insertions(+), 7 deletions(-)
>
> diff --git a/gdbsupport/ptid.h b/gdbsupport/ptid.h
> index d66cd988459..6dcab984b99 100644
> --- a/gdbsupport/ptid.h
> +++ b/gdbsupport/ptid.h
> @@ -39,6 +39,10 @@
>  class ptid_t
>  {
>  public:
> +  using pid_type = int;
> +  using lwp_type = long;
> +  using tid_type = ULONGEST;
> +
>    /* Must have a trivial defaulted default constructor so that the
>       type remains POD.  */
>    ptid_t () noexcept = default;
> @@ -48,13 +52,13 @@ class ptid_t
>       A ptid with only a PID (LWP and TID equal to zero) is usually used to
>       represent a whole process, including all its lwps/threads.  */
>  
> -  explicit constexpr ptid_t (int pid, long lwp = 0, ULONGEST tid = 0)
> +  explicit constexpr ptid_t (pid_type pid, lwp_type lwp = 0, tid_type tid = 0)
>      : m_pid (pid), m_lwp (lwp), m_tid (tid)
>    {}
>  
>    /* Fetch the pid (process id) component from the ptid.  */
>  
> -  constexpr int pid () const
> +  constexpr pid_type pid () const
>    { return m_pid; }
>  
>    /* Return true if the ptid's lwp member is non-zero.  */
> @@ -64,7 +68,7 @@ class ptid_t
>  
>    /* Fetch the lwp (lightweight process) component from the ptid.  */
>  
> -  constexpr long lwp () const
> +  constexpr lwp_type lwp () const
>    { return m_lwp; }
>  
>    /* Return true if the ptid's tid member is non-zero.  */
> @@ -74,7 +78,7 @@ class ptid_t
>  
>    /* Fetch the tid (thread id) component from a ptid.  */
>  
> -  constexpr ULONGEST tid () const
> +  constexpr tid_type tid () const
>    { return m_tid; }
>  
>    /* Return true if the ptid represents a whole process, including all its
> @@ -144,13 +148,13 @@ class ptid_t
>  
>  private:
>    /* Process id.  */
> -  int m_pid;
> +  pid_type m_pid;
>  
>    /* Lightweight process id.  */
> -  long m_lwp;
> +  lwp_type m_lwp;
>  
>    /* Thread id.  */
> -  ULONGEST m_tid;
> +  tid_type m_tid;
>  };
>  
>  /* Functor to hash a ptid.  */
> -- 
> 2.38.1
  
Simon Marchi Dec. 7, 2022, 2:55 a.m. UTC | #2
On 12/6/22 11:36, Andrew Burgess wrote:
> Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes:
> 
>> A following patch will want to declare variables of the same time as
> 
> typo: s/time/type/

Fixed.

Simon
  

Patch

diff --git a/gdbsupport/ptid.h b/gdbsupport/ptid.h
index d66cd988459..6dcab984b99 100644
--- a/gdbsupport/ptid.h
+++ b/gdbsupport/ptid.h
@@ -39,6 +39,10 @@ 
 class ptid_t
 {
 public:
+  using pid_type = int;
+  using lwp_type = long;
+  using tid_type = ULONGEST;
+
   /* Must have a trivial defaulted default constructor so that the
      type remains POD.  */
   ptid_t () noexcept = default;
@@ -48,13 +52,13 @@  class ptid_t
      A ptid with only a PID (LWP and TID equal to zero) is usually used to
      represent a whole process, including all its lwps/threads.  */
 
-  explicit constexpr ptid_t (int pid, long lwp = 0, ULONGEST tid = 0)
+  explicit constexpr ptid_t (pid_type pid, lwp_type lwp = 0, tid_type tid = 0)
     : m_pid (pid), m_lwp (lwp), m_tid (tid)
   {}
 
   /* Fetch the pid (process id) component from the ptid.  */
 
-  constexpr int pid () const
+  constexpr pid_type pid () const
   { return m_pid; }
 
   /* Return true if the ptid's lwp member is non-zero.  */
@@ -64,7 +68,7 @@  class ptid_t
 
   /* Fetch the lwp (lightweight process) component from the ptid.  */
 
-  constexpr long lwp () const
+  constexpr lwp_type lwp () const
   { return m_lwp; }
 
   /* Return true if the ptid's tid member is non-zero.  */
@@ -74,7 +78,7 @@  class ptid_t
 
   /* Fetch the tid (thread id) component from a ptid.  */
 
-  constexpr ULONGEST tid () const
+  constexpr tid_type tid () const
   { return m_tid; }
 
   /* Return true if the ptid represents a whole process, including all its
@@ -144,13 +148,13 @@  class ptid_t
 
 private:
   /* Process id.  */
-  int m_pid;
+  pid_type m_pid;
 
   /* Lightweight process id.  */
-  long m_lwp;
+  lwp_type m_lwp;
 
   /* Thread id.  */
-  ULONGEST m_tid;
+  tid_type m_tid;
 };
 
 /* Functor to hash a ptid.  */