From: Tom Tromey Date: Thu, 16 Sep 2021 19:55:04 +0000 (-0600) Subject: Change ptid_t::tid to ULONGEST X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=96bbe3ef9653e23a17b2315627e0cab441815f2d;p=binutils-gdb.git Change ptid_t::tid to ULONGEST The ptid_t 'tid' member is normally used as an address in gdb -- both bsd-uthread and ravenscar-thread use it this way. However, because the type is 'long', this can cause problems with sign extension. This patch changes the type to ULONGEST to ensure that sign extension does not occur. --- diff --git a/gdb/ada-tasks.c b/gdb/ada-tasks.c index 80a72216f96..bef26e8e43f 100644 --- a/gdb/ada-tasks.c +++ b/gdb/ada-tasks.c @@ -1233,7 +1233,8 @@ info_task (struct ui_out *uiout, const char *taskno_str, struct inferior *inf) fprintf_styled (gdb_stdout, metadata_style.style (), _("\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. */ diff --git a/gdb/bsd-uthread.c b/gdb/bsd-uthread.c index f8353f07041..1e594983bcd 100644 --- a/gdb/bsd-uthread.c +++ b/gdb/bsd-uthread.c @@ -538,8 +538,9 @@ std::string 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); } diff --git a/gdb/infrun.c b/gdb/infrun.c index d1ac9b4cbbb..9567130f0d3 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -4646,11 +4646,9 @@ wait_one () 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); @@ -4845,9 +4843,9 @@ handle_one (const wait_one_event &event) 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); diff --git a/gdb/python/py-infthread.c b/gdb/python/py-infthread.c index 5645442a426..74bbe9935f0 100644 --- a/gdb/python/py-infthread.c +++ b/gdb/python/py-infthread.c @@ -296,7 +296,8 @@ PyObject * gdbpy_create_ptid_object (ptid_t ptid) { int pid; - long tid, lwp; + long lwp; + ULONGEST tid; PyObject *ret; ret = PyTuple_New (3); @@ -313,7 +314,7 @@ gdbpy_create_ptid_object (ptid_t ptid) 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; diff --git a/gdb/ravenscar-thread.c b/gdb/ravenscar-thread.c index 634af466790..6cc583ce348 100644 --- a/gdb/ravenscar-thread.c +++ b/gdb/ravenscar-thread.c @@ -164,7 +164,7 @@ private: 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 m_cpu_map; + std::unordered_map m_cpu_map; }; /* Return true iff PTID corresponds to a ravenscar task. */ @@ -469,7 +469,8 @@ ravenscar_thread_target::pid_to_str (ptid_t ptid) 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 diff --git a/gdb/remote.c b/gdb/remote.c index 49ed2099211..3ece443ad18 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -6907,8 +6907,9 @@ remote_target::remote_stop_ns (ptid_t ptid) == 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 diff --git a/gdbserver/target.cc b/gdbserver/target.cc index 6660cc04fd5..988c6d50c5c 100644 --- a/gdbserver/target.cc +++ b/gdbserver/target.cc @@ -286,8 +286,8 @@ target_pid_to_str (ptid_t ptid) else if (ptid == null_ptid) xsnprintf (buf, sizeof (buf), ""); 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 ()); diff --git a/gdbsupport/ptid.cc b/gdbsupport/ptid.cc index 2417120b1ee..e5180662612 100644 --- a/gdbsupport/ptid.cc +++ b/gdbsupport/ptid.cc @@ -19,6 +19,7 @@ #include "common-defs.h" #include "ptid.h" +#include "print-utils.h" /* See ptid.h for these. */ @@ -30,5 +31,5 @@ ptid_t const minus_one_ptid = ptid_t::make_minus_one (); 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)); } diff --git a/gdbsupport/ptid.h b/gdbsupport/ptid.h index a2553b29c1a..7cdf468589d 100644 --- a/gdbsupport/ptid.h +++ b/gdbsupport/ptid.h @@ -34,6 +34,7 @@ #include #include +#include "gdbsupport/common-types.h" class ptid_t { @@ -47,7 +48,7 @@ public: 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) {} @@ -73,7 +74,7 @@ public: /* 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 @@ -149,7 +150,7 @@ private: long m_lwp; /* Thread id. */ - long m_tid; + ULONGEST m_tid; }; /* Functor to hash a ptid. */