fprintf_styled (gdb_stdout, metadata_style.style (), _("<no name>\n"));
 
   /* Print the TID and LWP.  */
-  printf_filtered (_("Thread: %#lx\n"), task_info->ptid.tid ());
+  printf_filtered (_("Thread: 0x%s\n"), phex_nz (task_info->ptid.tid (),
+                                                sizeof (ULONGEST)));
   printf_filtered (_("LWP: %#lx\n"), task_info->ptid.lwp ());
 
   /* If set, print the base CPU.  */
 
 bsd_uthread_target::pid_to_str (ptid_t ptid)
 {
   if (ptid.tid () != 0)
-    return string_printf ("process %d, thread 0x%lx",
-                         ptid.pid (), ptid.tid ());
+    return string_printf ("process %d, thread 0x%s",
+                         ptid.pid (),
+                         phex_nz (ptid.tid (), sizeof (ULONGEST)));
 
   return normal_pid_to_str (ptid);
 }
 
 static void
 save_waitstatus (struct thread_info *tp, const target_waitstatus *ws)
 {
-  infrun_debug_printf ("saving status %s for %d.%ld.%ld",
+  infrun_debug_printf ("saving status %s for %s",
                       target_waitstatus_to_string (ws).c_str (),
-                      tp->ptid.pid (),
-                      tp->ptid.lwp (),
-                      tp->ptid.tid ());
+                      tp->ptid.to_string ().c_str ());
 
   /* Record for later.  */
   tp->set_pending_waitstatus (*ws);
          struct regcache *regcache;
 
          infrun_debug_printf
-           ("target_wait %s, saving status for %d.%ld.%ld",
+           ("target_wait %s, saving status for %s",
             target_waitstatus_to_string (&event.ws).c_str (),
-            t->ptid.pid (), t->ptid.lwp (), t->ptid.tid ());
+            t->ptid.to_string ().c_str ());
 
          /* Record for later.  */
          save_waitstatus (t, &event.ws);
 
 gdbpy_create_ptid_object (ptid_t ptid)
 {
   int pid;
-  long tid, lwp;
+  long lwp;
+  ULONGEST tid;
   PyObject *ret;
 
   ret = PyTuple_New (3);
   gdbpy_ref<> lwp_obj = gdb_py_object_from_longest (lwp);
   if (lwp_obj == nullptr)
     return nullptr;
-  gdbpy_ref<> tid_obj = gdb_py_object_from_longest (tid);
+  gdbpy_ref<> tid_obj = gdb_py_object_from_ulongest (tid);
   if (tid_obj == nullptr)
     return nullptr;
 
 
      needed because sometimes the runtime will report an active task
      that hasn't yet been put on the list of tasks that is read by
      ada-tasks.c.  */
-  std::unordered_map<long, int> m_cpu_map;
+  std::unordered_map<ULONGEST, int> m_cpu_map;
 };
 
 /* Return true iff PTID corresponds to a ravenscar task.  */
   if (!is_ravenscar_task (ptid))
     return beneath ()->pid_to_str (ptid);
 
-  return string_printf ("Ravenscar Thread %#x", (int) ptid.tid ());
+  return string_printf ("Ravenscar Thread 0x%s",
+                       phex_nz (ptid.tid (), sizeof (ULONGEST)));
 }
 
 /* Temporarily set the ptid of a regcache to some other value.  When
 
            == resume_state::RESUMED_PENDING_VCONT)
          {
            remote_debug_printf ("Enqueueing phony stop reply for thread pending "
-                                "vCont-resume (%d, %ld, %ld)", tp->ptid.pid(),
-                                tp->ptid.lwp (), tp->ptid.tid ());
+                                "vCont-resume (%d, %ld, %s)", tp->ptid.pid(),
+                                tp->ptid.lwp (),
+                                pulongest (tp->ptid.tid ()));
 
            /* Check that the thread wasn't resumed with a signal.
               Generating a phony stop would result in losing the
 
   else if (ptid == null_ptid)
     xsnprintf (buf, sizeof (buf), "<null thread>");
   else if (ptid.tid () != 0)
-    xsnprintf (buf, sizeof (buf), "Thread %d.0x%lx",
-              ptid.pid (), ptid.tid ());
+    xsnprintf (buf, sizeof (buf), "Thread %d.0x%s",
+              ptid.pid (), phex_nz (ptid.tid (), sizeof (ULONGEST)));
   else if (ptid.lwp () != 0)
     xsnprintf (buf, sizeof (buf), "LWP %d.%ld",
               ptid.pid (), ptid.lwp ());
 
 
 #include "common-defs.h"
 #include "ptid.h"
+#include "print-utils.h"
 
 /* See ptid.h for these.  */
 
 std::string
 ptid_t::to_string () const
 {
-  return string_printf ("%d.%ld.%ld", m_pid, m_lwp, m_tid);
+  return string_printf ("%d.%ld.%s", m_pid, m_lwp, pulongest (m_tid));
 }
 
 
 #include <functional>
 #include <string>
+#include "gdbsupport/common-types.h"
 
 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, long tid = 0)
+  explicit constexpr ptid_t (int pid, long lwp = 0, ULONGEST tid = 0)
     : m_pid (pid), m_lwp (lwp), m_tid (tid)
   {}
 
 
   /* Fetch the tid (thread id) component from a ptid.  */
 
-  constexpr long tid () const
+  constexpr ULONGEST tid () const
   { return m_tid; }
 
   /* Return true if the ptid represents a whole process, including all its
   long m_lwp;
 
   /* Thread id.  */
-  long m_tid;
+  ULONGEST m_tid;
 };
 
 /* Functor to hash a ptid.  */