aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Tromey <tromey@adacore.com>2021-09-16 13:55:04 -0600
committerTom Tromey <tromey@adacore.com>2021-09-23 09:30:54 -0600
commit96bbe3ef9653e23a17b2315627e0cab441815f2d (patch)
treecf9ac694a99f0ae9755d3229767a905476a69c00
parent184ea2f7316c54dd5e0fa84f1fe07a222e8fb44c (diff)
downloadbinutils-96bbe3ef9653e23a17b2315627e0cab441815f2d.zip
binutils-96bbe3ef9653e23a17b2315627e0cab441815f2d.tar.gz
binutils-96bbe3ef9653e23a17b2315627e0cab441815f2d.tar.bz2
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.
-rw-r--r--gdb/ada-tasks.c3
-rw-r--r--gdb/bsd-uthread.c5
-rw-r--r--gdb/infrun.c10
-rw-r--r--gdb/python/py-infthread.c5
-rw-r--r--gdb/ravenscar-thread.c5
-rw-r--r--gdb/remote.c5
-rw-r--r--gdbserver/target.cc4
-rw-r--r--gdbsupport/ptid.cc3
-rw-r--r--gdbsupport/ptid.h7
9 files changed, 26 insertions, 21 deletions
diff --git a/gdb/ada-tasks.c b/gdb/ada-tasks.c
index 80a7221..bef26e8 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 (), _("<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. */
diff --git a/gdb/bsd-uthread.c b/gdb/bsd-uthread.c
index f8353f0..1e59498 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 d1ac9b4..9567130 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 5645442..74bbe99 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 634af46..6cc583c 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<long, int> m_cpu_map;
+ std::unordered_map<ULONGEST, int> 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 49ed209..3ece443 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 6660cc0..988c6d5 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), "<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 ());
diff --git a/gdbsupport/ptid.cc b/gdbsupport/ptid.cc
index 2417120..e518066 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 a2553b2..7cdf468 100644
--- a/gdbsupport/ptid.h
+++ b/gdbsupport/ptid.h
@@ -34,6 +34,7 @@
#include <functional>
#include <string>
+#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. */