Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/gnu/dist/toolchain/gdb Include both application threads and ...



details:   https://anonhg.NetBSD.org/src/rev/8a73f1fbf973
branches:  trunk
changeset: 543118:8a73f1fbf973
user:      nathanw <nathanw%NetBSD.org@localhost>
date:      Mon Feb 17 20:32:04 2003 +0000

description:
Include both application threads and "raw" LWPs in GDB's list of
threads. This is useful for a variety of things, including examing the
internal state of the thread library when things are going wrong
there.

Currently only works on core files; both ptrace and gdb will need a
bit more work before this will be useful on live processes.

Inspired by the similar behavior of the Solaris thread module.

diffstat:

 gnu/dist/toolchain/gdb/nbsd-thread.c |  62 ++++++++++++++++++++++++++---------
 1 files changed, 46 insertions(+), 16 deletions(-)

diffs (143 lines):

diff -r a111273b7edc -r 8a73f1fbf973 gnu/dist/toolchain/gdb/nbsd-thread.c
--- a/gnu/dist/toolchain/gdb/nbsd-thread.c      Mon Feb 17 20:07:06 2003 +0000
+++ b/gnu/dist/toolchain/gdb/nbsd-thread.c      Mon Feb 17 20:32:04 2003 +0000
@@ -325,8 +325,11 @@
   struct reg gregs;
   struct fpreg fpregs;
   int val;
+  struct cleanup *old_chain;
 
-  if (nbsd_thread_active)
+  old_chain = save_inferior_pid ();
+
+  if (nbsd_thread_active && IS_THREAD (inferior_pid))
     {
       if ((val = td_map_id2thr (main_ta, GET_THREAD (inferior_pid), &thread)) != 0)
        error ("nbsd_thread_fetch_registers: td_map_id2thr: %s\n",
@@ -342,11 +345,16 @@
     }
   else
     {
+      if (nbsd_thread_active)
+       inferior_pid = BUILD_LWP (GET_LWP (inferior_pid), 
+                                 GET_PROCESS (inferior_pid));
       if (target_has_execution)
        child_ops.to_fetch_registers (regno);
       else
        orig_core_ops.to_fetch_registers (regno);
     }
+  
+  do_cleanups (old_chain);
 }
 
 static void
@@ -357,8 +365,11 @@
   struct reg gregs;
   struct fpreg fpregs;
   int val;
+  struct cleanup *old_chain;
 
-  if (nbsd_thread_active)
+  old_chain = save_inferior_pid ();
+
+  if (nbsd_thread_active && IS_THREAD (inferior_pid))
     {
       val = td_map_id2thr (main_ta, GET_THREAD (inferior_pid), &thread);
       if (val != 0)
@@ -379,11 +390,16 @@
     }
   else
     {
-    if (target_has_execution)
-      child_ops.to_store_registers (regno);
-    else
-      orig_core_ops.to_store_registers (regno);
+      if (nbsd_thread_active)
+       inferior_pid = BUILD_LWP (GET_LWP (inferior_pid), 
+                                 GET_PROCESS (inferior_pid));
+      if (target_has_execution)
+       child_ops.to_store_registers (regno);
+      else
+       orig_core_ops.to_store_registers (regno);
     }
+
+  do_cleanups (old_chain);
 }
 
 
@@ -479,7 +495,10 @@
 {
   static char buf[100];
 
-  sprintf (buf, "Thread %d", GET_THREAD (pid));
+  if (IS_THREAD (pid))
+    sprintf (buf, "Thread %d", GET_THREAD (pid));
+  else
+    sprintf (buf, "LWP %d", GET_LWP (pid));
 
   return buf;
 }
@@ -545,25 +564,34 @@
 {
   td_thread_t *th;
   td_thread_info_t ti;
-  int val;
+  int retval;
+  struct cleanup *old_chain;
 
-  if (IS_THREAD (pid))
+  old_chain = save_inferior_pid ();
+
+  if (nbsd_thread_active && IS_THREAD (pid))
     {
+      retval = 0;
       if (td_map_id2thr (main_ta, GET_THREAD (pid), &th) == 0)
        {
          /* Thread found */
          if (td_thr_info (th, &ti) == 0)
-           return 1;
+           retval = 1;
        }
-      return 1;
     }
   else
     {
+      if (nbsd_thread_active)
+       inferior_pid = BUILD_LWP (GET_LWP (inferior_pid), 
+                                 GET_PROCESS (inferior_pid));
       if (target_has_execution)
-       return child_ops.to_thread_alive (GET_PROCESS (pid));
+       retval = child_ops.to_thread_alive (GET_PROCESS (pid));
       else
-       return orig_core_ops.to_thread_alive (GET_PROCESS (pid));
+       retval = orig_core_ops.to_thread_alive (GET_PROCESS (pid));
     }
+
+  do_cleanups (old_chain);
+  return retval;
 }
 
 
@@ -957,7 +985,7 @@
      asection *asect;
      PTR reg_sect_arg;
 {
-  int thread_id;
+  int regval;
   td_thread_t *dummy;
 
   asection *reg_sect = (asection *) reg_sect_arg;
@@ -965,9 +993,11 @@
   if (strncmp (bfd_section_name (abfd, asect), ".reg/", 5) != 0)
     return;
 
-  thread_id = atoi (bfd_section_name (abfd, asect) + 5);
+  regval = atoi (bfd_section_name (abfd, asect) + 5);
 
-  td_map_lwp2thr (main_ta, thread_id >> 16, &dummy);
+  td_map_lwp2thr (main_ta, regval >> 16, &dummy);
+
+  add_thread (BUILD_LWP(regval >> 16, main_pid));
 }
 
 static void



Home | Main Index | Thread Index | Old Index