[PATCH] Rewrite default_get_ada_task_ptid

Tom Tromey <[email protected]>
Newsgroups gmane.comp.gdb.patches
Message-ID <[email protected]>
Internal testing on a somewhat unusual configuration lead me to
examine default_get_ada_task_ptid.

This function computes a ptid in a way that, I think, maybe nothing
else in gdb uses, specifying both the LWP and the thread.  This in
turns means that Ada functionality like "info tasks" will never find
the thread corresponding to an Ada task.

This patch rewrites default_get_ada_task_ptid to use the most normal
form of ptid_t.  Redundant target-specific implementations are
removed.

Some "weird" implementations remain, with darwin-nat.c being a
disturbing amount of code, sol-thread.c being somewhat unusual, and
aix-thread.c pointing out that it might be nice if the AIX support
were normalized here (meaning that I think it would be good if all
targets standardized on a single ptid_t format).

I couldn't figure out how to write a test case for this.  I had
believed that the problem arose from statically linking glibc, and
when the linux-thread-db was not pushed on the target stack; but more
testing shows that this is not in fact the problem, as
statically-linked executables work fine for me on my development
machine.  (If you're interested, you can try gdb.ada/tasks.exp with
static linking.)
---
 gdb/linux-thread-db.c | 10 ----------
 gdb/remote.c          | 11 -----------
 gdb/target.c          | 10 ++++------
 gdb/windows-nat.c     |  6 ------
 gdb/windows-nat.h     |  2 --
 5 files changed, 4 insertions(+), 35 deletions(-)

diff --git a/gdb/linux-thread-db.c b/gdb/linux-thread-db.c
index dd67950f619..a2a7c8da5da 100644
--- a/gdb/linux-thread-db.c
+++ b/gdb/linux-thread-db.c
@@ -101,7 +101,6 @@ class thread_db_target final : public target_ops
 				      CORE_ADDR load_module_addr,
 				      CORE_ADDR offset) override;
   const char *extra_thread_info (struct thread_info *) override;
-  ptid_t get_ada_task_ptid (long lwp, ULONGEST thread) override;
 
   thread_info *thread_handle_to_thread_info (const gdb_byte *thread_handle,
 					     int handle_len,
@@ -1820,15 +1819,6 @@ thread_db_target::get_thread_local_address (ptid_t ptid,
   return beneath->get_thread_local_address (ptid, lm, offset);
 }
 
-/* Implement the to_get_ada_task_ptid target method for this target.  */
-
-ptid_t
-thread_db_target::get_ada_task_ptid (long lwp, ULONGEST thread)
-{
-  /* NPTL uses a 1:1 model, so the LWP id suffices.  */
-  return ptid_t (inferior_ptid.pid (), lwp);
-}
-
 void
 thread_db_target::resume (ptid_t ptid, int step, enum gdb_signal signo)
 {
diff --git a/gdb/remote.c b/gdb/remote.c
index 194c4cbd9bb..cf6d88ba394 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -1035,8 +1035,6 @@ class remote_target : public process_stratum_target
 
   const char *extra_thread_info (struct thread_info *) override;
 
-  ptid_t get_ada_task_ptid (long lwp, ULONGEST thread) override;
-
   thread_info *thread_handle_to_thread_info (const gdb_byte *thread_handle,
 					     int handle_len,
 					     inferior *inf) override;
@@ -4737,15 +4735,6 @@ remote_target::static_tracepoint_markers_by_strid (const char *strid)
 }
 
 
-/* Implement the to_get_ada_task_ptid function for the remote targets.  */
-
-ptid_t
-remote_target::get_ada_task_ptid (long lwp, ULONGEST thread)
-{
-  return ptid_t (inferior_ptid.pid (), lwp);
-}
-
-
 /* Restart the remote side; this is an extended protocol operation.  */
 
 void
diff --git a/gdb/target.c b/gdb/target.c
index 5d937f3ae85..91a8d411843 100644
--- a/gdb/target.c
+++ b/gdb/target.c
@@ -1121,16 +1121,14 @@ default_terminal_info (struct target_ops *self, const char *args, int from_tty)
   gdb_printf (_("No saved terminal information.\n"));
 }
 
-/* A default implementation for the to_get_ada_task_ptid target method.
-
-   This function builds the PTID by using both LWP and TID as part of
-   the PTID lwp and tid elements.  The pid used is the pid of the
-   inferior_ptid.  */
+/* A default implementation for the to_get_ada_task_ptid target
+   method.  This function builds the PTID using just the LWP parameter
+   and the current inferior, as this is what most targets need.  */
 
 static ptid_t
 default_get_ada_task_ptid (struct target_ops *self, long lwp, ULONGEST tid)
 {
-  return ptid_t (inferior_ptid.pid (), lwp, tid);
+  return ptid_t (inferior_ptid.pid (), lwp);
 }
 
 static enum exec_direction_kind
diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c
index def8fa606f4..73db714d399 100644
--- a/gdb/windows-nat.c
+++ b/gdb/windows-nat.c
@@ -3392,12 +3392,6 @@ windows_nat_target::get_tib_address (ptid_t ptid, CORE_ADDR *addr)
   return true;
 }
 
-ptid_t
-windows_nat_target::get_ada_task_ptid (long lwp, ULONGEST thread)
-{
-  return ptid_t (inferior_ptid.pid (), lwp, 0);
-}
-
 /* Implementation of the to_thread_name method.  */
 
 const char *
diff --git a/gdb/windows-nat.h b/gdb/windows-nat.h
index 3349755022b..74d8e7e6503 100644
--- a/gdb/windows-nat.h
+++ b/gdb/windows-nat.h
@@ -228,8 +228,6 @@ struct windows_nat_target : public inf_child_target
 
   const char *pid_to_exec_file (int pid) override;
 
-  ptid_t get_ada_task_ptid (long lwp, ULONGEST thread) override;
-
   bool get_tib_address (ptid_t ptid, CORE_ADDR *addr) override;
 
   const char *thread_name (struct thread_info *) override;

base-commit: 7e7dd6cfcf60cda2506d19d88ff98622bf670dbd
-- 
2.55.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.